lcdd/src
diff -u -r1.18 -r1.19
--- IdFactory.cc 15 Jul 2005 22:43:56 -0000 1.18
+++ IdFactory.cc 16 Jul 2005 00:18:46 -0000 1.19
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/IdFactory.cc,v 1.18 2005/07/15 22:43:56 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/IdFactory.cc,v 1.19 2005/07/16 00:18:46 jeremy Exp $
// set for verbose output from this class
//#define ID_DEBUG 1
@@ -23,12 +23,12 @@
Id64bit IdFactory::createId64bit(const IdVec& idvec, IdSpec* idspec)
{
#ifdef ID_DEBUG
- std::cout << std::endl;
- std::cout.setf( ios::hex );
- std::cout << "IdFactory::createId64bit()" << std::endl;
- std::cout << "idvec size: " << idvec.size() << std::endl;
- std::cout << "idspec numFields: " << idspec->getNumFields() << std::endl;
- std::cout << "idspec bitLength: " << idspec->getBitLength() << std::endl;
+ G4cout << G4endl;
+ G4cout.setf( ios::hex );
+ G4cout << "IdFactory::createId64bit()" << G4endl;
+ G4cout << "idvec size: " << idvec.size() << G4endl;
+ G4cout << "idspec numFields: " << idspec->getNumFields() << G4endl;
+ G4cout << "idspec bitLength: " << idspec->getBitLength() << G4endl;
#endif
/* IdVec (expanded id) size must equal IdSpec size or die. */
@@ -89,7 +89,7 @@
/* If 1st time, set id val pntr. */
if (!next_id) {
#ifdef ID_DEBUG
- std::cout << "setting ptr to next id" << std::endl;
+ G4cout << "setting ptr to next id" << G4endl;
#endif
++id64_val_idx;
id64_val_ptr = &id64_val[id64_val_idx];
@@ -101,26 +101,31 @@
}
#ifdef ID_DEBUG
- std::cout << "idspec_idx: " << dec << idspec_idx << std::endl;
- std::cout << "shifting left: " << dec << field_bit_len << std::endl;
- std::cout << "curr_bit: " << dec << curr_bit << std::endl;
- std::cout << "field_label: " << id_field->getLabel() << std::endl;
- std::cout << "field_start: " << field_start << std::endl;
- std::cout << "field_val: " << dec << field_val << std::endl;
- std::cout << "field_bit_len: " << dec << field_bit_len << std::endl;
+ G4cout << "idspec_idx: " << dec << idspec_idx << G4endl;
+ G4cout << "shifting left: " << dec << field_bit_len << G4endl;
+ G4cout << "curr_bit: " << dec << curr_bit << G4endl;
+ G4cout << "field_label: " << id_field->getLabel() << G4endl;
+ G4cout << "field_start: " << field_start << G4endl;
+ G4cout << "field_val (dec): " << dec << field_val << G4endl;
+ G4cout << "field_val (hex): " << hex << field_val << G4endl;
+ G4cout << "field_bit_len: " << dec << field_bit_len << G4endl;
#endif
Bits field_mask = makeBitMask(field_bit_len);
- /* Check that this value doesn't overflow the assigned length. */
- if ( checkOverflow(field_val, field_mask) != 0 ) {
- G4cerr << "Value <" << field_val << "> is too big for the field <" << id_field->getLabel() << ">." << G4endl;
- G4Exception("FATAL ERROR: Id value too large for field.");
+ /* For positive values, check that this value doesn't overflow the assigned length. */
+ if ( field_val > 0 ) {
+ if ( checkOverflow(field_val, field_mask) != 0 ) {
+ G4cerr << "Value <" << field_val << "> is too big for the field <" << id_field->getLabel() << ">." << G4endl;
+ G4Exception("FATAL ERROR: Id value too large for field.");
+ }
+ }
+ else {
+
}
#ifdef ID_DEBUG
- std::cout << "field_mask: " << hex << field_mask << std::endl;
- std::cout << "field_check: " << hex << field_check << std::endl;
+ G4cout << "field_mask: " << hex << field_mask << G4endl;
#endif
/* Apply bit mask and shift to proper left pos. */
@@ -133,8 +138,8 @@
curr_bit += id_field->getLength();
#ifdef ID_DEBUG
- std::cout << "id64_val (hex): " << hex << *id64_val_ptr << std::endl;
- std::cout << std::endl;
+ G4cout << "id64_val (hex): " << hex << *id64_val_ptr << G4endl;
+ G4cout << G4endl;
#endif
/* Increment the idspec idx. */
@@ -142,11 +147,11 @@
}
#ifdef ID_DEBUG
- std::cout << "end curr_bit: " << dec << curr_bit << std::endl;
- std::cout << "end id64[0]: " << hex << id64_val[0] << std::endl;
- std::cout << "end id64[1]: " << hex << id64_val[1] << std::endl;
- std::cout.unsetf( ios::hex );
- std::cout << std::endl << std::endl;
+ G4cout << "end curr_bit: " << dec << curr_bit << G4endl;
+ G4cout << "end id64[0]: " << hex << id64_val[0] << G4endl;
+ G4cout << "end id64[1]: " << hex << id64_val[1] << G4endl;
+ G4cout.unsetf( ios::hex );
+ G4cout << G4endl << G4endl;
#endif
/* Set the two 32-bit ids in the packed id to return. */
@@ -163,7 +168,18 @@
inline IdFactory::Bits IdFactory::checkOverflow(Id64bit::ElementType val, Bits mask)
{
- return (Bits)((mask ^ MASK_ON) & val);
+ Bits xbits = 0x0;
+
+ if ( val >= 0 ) {
+ xbits = (Bits)((mask ^ MASK_ON) & val);
+ }
+ else {
+ xbits = (Bits)((mask ^ MASK_ON) ^ val);
+ }
+
+ //G4cout << "overflow bits (hex): " << hex << xbits << G4endl;
+
+ return xbits;
}
IdVec IdFactory::createOrderedIdVec(G4Step* aStep, const G4SensitiveDetector* sd)
@@ -190,7 +206,7 @@
bool fnd_it = false;
#ifdef ID_DEBUG
- std::cout << "handling field: " << f->getLabel() << std::endl;
+ G4cout << "handling field: " << f->getLabel() << G4endl;
#endif
// look in seg, if exists
@@ -203,7 +219,7 @@
}
#ifdef ID_DEBUG
else {
- std::cout << "not in segmentation" << std::endl;
+ G4cout << "not in segmentation" << G4endl;
}
#endif
}
@@ -218,7 +234,7 @@
}
#ifdef ID_DEBUG
else {
- std::cout << "not in physvolids" << std::endl;
+ G4cout << "not in physvolids" << G4endl;
}
#endif
@@ -237,7 +253,7 @@
}
#ifdef ID_DEBUG
else {
- std::cout << "not in volume (copyNum)" << std::endl;
+ G4cout << "not in volume (copyNum)" << G4endl;
}
#endif
@@ -249,7 +265,7 @@
ids.push_back( bin_val );
#ifdef ID_DEBUG
- std::cout << "set bin val: " << bin_val << std::endl << std::endl;
+ G4cout << "set bin val: " << bin_val << G4endl << G4endl;
#endif
}
}
@@ -285,7 +301,7 @@
IdManager* id_mgr = IdManager::instance();
#ifdef ID_DEBUG
- std::cout << "looking for field_name match on <" << field_name << ">" << std::endl;
+ G4cout << "looking for field_name match on <" << field_name << ">" << G4endl;
#endif
int id = 0;
@@ -298,7 +314,7 @@
pv = *iter_pv;
#ifdef ID_DEBUG
- std::cout << "searching in ids of PV <" << pv->GetName() << ">" << std::endl;
+ G4cout << "searching in ids of PV <" << pv->GetName() << ">" << G4endl;
#endif
if ( id_mgr->hasPhysVolIds( pv ) ) {
@@ -308,12 +324,12 @@
iter++ ) {
#ifdef ID_DEBUG
- std::cout << "current field <" << (*iter).getFieldName() << ">" << std::endl;
+ G4cout << "current field <" << (*iter).getFieldName() << ">" << G4endl;
#endif
if ( (*iter).getFieldName() == field_name ) {
#ifdef ID_DEBUG
- std::cout << "found a match" << std::endl;
+ G4cout << "found a match" << G4endl;
#endif
id = (*iter).getValue();
fnd = true;
@@ -321,7 +337,7 @@
}
#ifdef ID_DEBUG
else {
- std::cout << "no match on this PV" << std::endl;
+ G4cout << "no match on this PV" << G4endl;
}
#endif
}
@@ -382,7 +398,7 @@
physVols.push_back( pv );
#ifdef ID_DEBUG
- std::cout << "pushed back <" << pv->GetName() << ">" << std::endl;
+ G4cout << "pushed back <" << pv->GetName() << ">" << G4endl;
#endif
}