Commit in lcdd on MAIN
include/IdFactory.hh+8-61.7 -> 1.8
       /ReadoutUtil.hh+4-11.10 -> 1.11
src/IdFactory.cc+67-471.15 -> 1.16
   /ReadoutUtil.cc+46-51.6 -> 1.7
+125-59
4 modified files
Fixed LCDD-8.  Can now use label 'volume' to get the copy or replica number of the volume in the idfield.

lcdd/include
IdFactory.hh 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- IdFactory.hh	19 Apr 2005 23:08:47 -0000	1.7
+++ IdFactory.hh	27 Jun 2005 21:45:20 -0000	1.8
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/include/IdFactory.hh,v 1.7 2005/04/19 23:08:47 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/include/IdFactory.hh,v 1.8 2005/06/27 21:45:20 jeremy Exp $
 #ifndef IdFactory_hh
 #define IdFactory_hh 1
 
@@ -28,18 +28,18 @@
 class IdFactory
 {
 public:
-  
+
   typedef unsigned int Bits;
 
 public:
 
   virtual ~IdFactory()
   {}
-  
+
 private:
 
   // class should not be instantiated
-  IdFactory() 
+  IdFactory()
   {}
 
 public:
@@ -53,14 +53,16 @@
   // lkp bin value by field name in segmentation
   static int findFieldIdxInSegmentation(G4Segmentation*, const std::string& field_name);
 
+  /* Check if PV list has PVid with given label. */
+  static bool hasPhysVolId(const std::vector<G4VPhysicalVolume*>& pvs, const std::string& field_name);
+
   // lkp bin value by field name in PV ids
   static int findIdInPhysVols(const std::vector<G4VPhysicalVolume*>& pvs, const std::string& field_name);
 
   // add physvolids from step to an IdVec
   static void addPhysVolIds(G4Step* aStep, IdVec& v);
 
-  // fetch pvids
-  //static std::vector<int> getPhysVolIdStack( G4Step* aStep );
+  // list of PVs
   static std::vector<G4VPhysicalVolume*> getPhysVolList( G4Step* aStep );
 };
 

lcdd/include
ReadoutUtil.hh 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- ReadoutUtil.hh	23 Jun 2005 23:42:20 -0000	1.10
+++ ReadoutUtil.hh	27 Jun 2005 21:45:20 -0000	1.11
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/include/ReadoutUtil.hh,v 1.10 2005/06/23 23:42:20 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/include/ReadoutUtil.hh,v 1.11 2005/06/27 21:45:20 jeremy Exp $
 #ifndef ReadoutUtil_hh
 #define ReadoutUtil_hh 1
 
@@ -63,6 +63,9 @@
 
   static G4ThreeVector transformGlobalToLocal(const G4Step* aStep,
 						     const G4ThreeVector& globalPos);
+
+  static int getVolumeNumber(G4TouchableHandle theTouchable, int historyDepth = -1);
+
 public:
 
   static const double PI;

lcdd/src
IdFactory.cc 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- IdFactory.cc	23 Jun 2005 23:46:59 -0000	1.15
+++ IdFactory.cc	27 Jun 2005 21:45:20 -0000	1.16
@@ -1,7 +1,7 @@
-// $Header: /cvs/lcd/lcdd/src/IdFactory.cc,v 1.15 2005/06/23 23:46:59 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/IdFactory.cc,v 1.16 2005/06/27 21:45:20 jeremy Exp $
 
 // set for verbose output from this class
-//#define ID_DEBUG 1
+#define ID_DEBUG 1
 
 // G4
 #include "G4Step.hh"
@@ -14,6 +14,7 @@
 #include "G4Segmentation.hh"
 #include "IdManager.hh"
 #include "IdFactory.hh"
+#include "ReadoutUtil.hh"
 
 using namespace std;
 
@@ -107,7 +108,7 @@
     Bits field_mask = (1 << field_bit_len) - 1;
 
 #ifdef ID_DEBUG
-      std::cout << "field_mask: " << hex << field_mask << std::endl;
+    std::cout << "field_mask: " << hex << field_mask << std::endl;
 #endif
 
     // apply bit mask and shift to proper left pos
@@ -188,7 +189,39 @@
       // find in PV ids
       if ( !fnd_it ) {
 	std::vector<G4VPhysicalVolume*> pv_list = IdFactory::getPhysVolList( aStep );
-	bin_val = findIdInPhysVols( pv_list, f->getLabel() );
+
+	if ( hasPhysVolId( pv_list, f->getLabel() ) ) {
+	  fnd_it = true;
+	  bin_val = findIdInPhysVols( pv_list, f->getLabel() );
+	}
+#ifdef ID_DEBUG
+	else {
+	  std::cout << "not in physvolids" << std::endl;
+	}
+#endif
+
+      }
+
+      /* Find in copy numbers of the volume. */
+      if (!fnd_it && f->getLabel() == "volume" ) {
+	bin_val = ReadoutUtil::getVolumeNumber( aStep->GetPreStepPoint()->GetTouchableHandle() );
+
+	if ( -1 == bin_val ) {
+	  G4Exception("FATAL ERROR: Valid copy number not found for PV.");
+	}
+	else {
+	  fnd_it = true;
+	}
+      }
+#ifdef ID_DEBUG
+	else {
+	  std::cout << "not in volume (copyNum)" << std::endl;
+	}
+#endif
+
+      /* Not found anywhere, so we need to die. */
+      if ( !fnd_it ) {
+	G4Exception("IdField <" + f->getLabel() + "> could not be found in segmentation, physvolids or copyNum.");
       }
 
       ids.push_back( bin_val );
@@ -275,12 +308,38 @@
     if (fnd) { break; }
   }
 
-  if ( !fnd ) {
-    std::cout << "FATAL ERROR: no match found for field <" << field_name << ">" << std::endl;
-    assert( fnd );
+  return id;
+}
+
+bool IdFactory::hasPhysVolId(const std::vector<G4VPhysicalVolume*>& pvs, const std::string& field_name)
+{
+  IdManager* id_mgr = IdManager::instance();
+
+  G4VPhysicalVolume* pv = 0;
+  bool fnd = false;
+
+  for ( std::vector<G4VPhysicalVolume*>::const_iterator iter_pv = pvs.begin();
+	iter_pv != pvs.end();
+	iter_pv++ ) {
+    pv = *iter_pv;
+
+    if ( id_mgr->hasPhysVolIds( pv ) ) {
+      PhysVolId::PhysVolIds pvids = id_mgr->getPhysVolIds( pv );
+      for ( PhysVolId::PhysVolIds::const_iterator iter = pvids.begin();
+	    iter != pvids.end();
+	    iter++ ) {
+
+	if ( (*iter).getFieldName() == field_name ) {
+	  fnd = true;
+	  break;
+	}
+      }
+    }
+
+    if (fnd) { break; }
   }
 
-  return id;
+  return fnd;
 }
 
 std::vector<G4VPhysicalVolume*> IdFactory::getPhysVolList( G4Step* aStep )
@@ -307,42 +366,3 @@
 
   return physVols;
 }
-
-/*
-  std::vector<int> IdFactory::getPhysVolIdStack( G4Step* aStep )
-  {
-  // vect to fill
-  std::vector<int> ids;
-
-  // list of PV to iterate
-  std::vector<G4VPhysicalVolume*> physVols = getPhysVolList( aStep );
-
-  // ptr to ID mgr
-  IdManager* id_mgr = IdManager::instance();
-
-  // iterate over PV, pushing ids onto return vec when found
-  for ( std::vector<G4VPhysicalVolume*>::const_iterator iter = physVols.begin();
-  iter != physVols.end();
-  iter++ ) {
-  G4VPhysicalVolume* pv = *iter;
-
-  // check has ids
-  if ( id_mgr->hasPhysVolIds( pv ) ) {
-
-  // retrieve and push back the ids onto return vec
-  PhysVolId::PhysVolIds pvids = id_mgr->getPhysVolIds( pv );
-  for ( PhysVolId::PhysVolIds::const_iterator iter = pvids.begin();
-  iter != pvids.end();
-  iter++ ) {
-  #ifdef ID_DEBUG
-  std::cout << "pushed back id <" << (*iter).getValue() << "> for <" << pv->GetName() << ">" << std::endl;
-  #endif
-  ids.push_back( (*iter).getValue() );
-  }
-  }
-  }
-
-  return ids;
-  }
-*/
-

lcdd/src
ReadoutUtil.cc 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- ReadoutUtil.cc	23 Jun 2005 23:42:20 -0000	1.6
+++ ReadoutUtil.cc	27 Jun 2005 21:45:20 -0000	1.7
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/ReadoutUtil.cc,v 1.6 2005/06/23 23:42:20 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/ReadoutUtil.cc,v 1.7 2005/06/27 21:45:20 jeremy Exp $
 #include "ReadoutUtil.hh"
 
 #include <cmath>
@@ -6,7 +6,7 @@
 const double ReadoutUtil::PI = acos(-1);
 
 G4ThreeVector ReadoutUtil::computeThreeVectorMean(const G4ThreeVector& vec1,
-				     const G4ThreeVector& vec2)
+						  const G4ThreeVector& vec2)
 {
   return (0.5 * (vec1 + vec2 ) );
 }
@@ -31,7 +31,7 @@
 }
 
 G4ThreeVector ReadoutUtil::getVolumeGlobalPosition(const G4StepPoint* aStepPoint,
-					     const G4ThreeVector& pnt )
+						   const G4ThreeVector& pnt )
 {
   return aStepPoint->GetTouchableHandle()->GetHistory()->GetTopTransform().Inverse().
     TransformPoint( pnt );
@@ -78,7 +78,7 @@
 }
 
 G4ThreeVector ReadoutUtil::transformLocalToGlobal(const G4Step* aStep,
-					    const G4ThreeVector& localPos)
+						  const G4ThreeVector& localPos)
 {
   // get touchable from PreStepPoint
   G4TouchableHandle theTouchable = aStep->GetPreStepPoint()->GetTouchableHandle();
@@ -90,7 +90,7 @@
 }
 
 G4ThreeVector ReadoutUtil::transformGlobalToLocal(const G4Step* aStep,
-					    const G4ThreeVector& globalPos)
+						  const G4ThreeVector& globalPos)
 {
   // get touchable from PreStepPoint
   G4TouchableHandle theTouchable = aStep->GetPreStepPoint()->GetTouchableHandle();
@@ -100,3 +100,44 @@
 
   return localPos;
 }
+
+int ReadoutUtil::getVolumeNumber(G4TouchableHandle theTouchable, int historyDepth)
+{
+  bool no_depth = false;
+
+  if (historyDepth == -1) {
+    no_depth = true;
+  }
+
+  G4VPhysicalVolume *pv = 0;
+
+  // pv only with depth arg
+  if (!no_depth) {
+    pv = theTouchable->GetHistory()->GetVolume(historyDepth);
+  }
+
+  int vnum = -1;
+
+  // rep num: no pv, replicated, parameterised
+  if ( !pv ||
+       pv->IsReplicated() ||
+       pv->IsParameterised() ) {
+
+    // no depth
+    if (no_depth) {
+      vnum = theTouchable->GetReplicaNumber();
+    }
+    // use history depth
+    else {
+      vnum = theTouchable->GetReplicaNumber(historyDepth);
+    }
+  }
+  // copy num: placement
+  else {
+    vnum = pv->GetCopyNo();
+  }
+
+  std::cout << "volume number: " << vnum << std::endl;
+
+  return vnum;
+}
CVSspam 0.2.8