| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

TouchableToDetectorElement Class Reference

Implimentation of ITouchableToDetectorElement. First attempt; uses no caches or other optimization. More...

#include <TouchableToDetectorElement.h>

Inheritance diagram for TouchableToDetectorElement:

[legend]
Collaboration diagram for TouchableToDetectorElement:
[legend]
List of all members.

Public Member Functions

 TouchableToDetectorElement (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~TouchableToDetectorElement ()
virtual StatusCode GetBestDetectorElement (const G4TouchableHistory *inHistory, const std::vector< std::string > &inPath, const IDetectorElement *&outElement, int &outCompatibility)
 Do the conversion.
virtual StatusCode G4VolumeToDetDesc (const G4VPhysicalVolume *inVol, const IPVolume *&outVol)
 Utility to do a simpler conversion: find the IPVolume from a G4PhysicalVolume.
virtual StatusCode ClearCache ()
 Clear caches in case of geometry change.
virtual StatusCode G4VolumeToDetDesc (const G4VPhysicalVolume *inVol, const IPVolume *&outVol, ILVolume::ReplicaPath &outPath)
 Utility to do a simpler conversion: find the IPVolume from a G4PhysicalVolume.
StatusCode GetSpecifiedVolume (const G4TouchableHistory *inHistory, SpecifiedVolume &outVol)
StatusCode GetSpecifiedVolume (const IDetectorElement *inElem, const IDetectorElement *inTopElem, SpecifiedVolume &outVol)
int Compatability (const SpecifiedVolume &inPlace, const SpecifiedVolume &inContainer)
 Returns -1 if incompatible, returns number that increases the better the container describes the place.
template<class T>
StatusCode FindObjectsInDirectory (const std::string &dirname, std::vector< const T * > &outList)
virtual StatusCode initialize ()
virtual StatusCode finalize ()
INTupleSvcntupleSvc () const
INTupleSvcevtColSvc () const
IDataProviderSvcdetSvc () const
IDataProviderSvcevtSvc () const
IIncidentSvcincSvc () const
IChronoStatSvcchronoSvc () const
IHistogramSvchistoSvc () const
IAlgContextSvccontextSvc () const
DataObjectput (IDataProviderSvc *svc, DataObject *object, const std::string &address, const bool useRootInTES=true) const
DataObjectput (DataObject *object, const std::string &address, const bool useRootInTES=true) const
Gaudi::Utils::GetData< TYPE
>::return_type 
get (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
Gaudi::Utils::GetData< TYPE
>::return_type 
get (const std::string &location, const bool useRootInTES=true) const
TYPE * getDet (IDataProviderSvc *svc, const std::string &location) const
TYPE * getDet (const std::string &location) const
bool exist (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
bool exist (const std::string &location, const bool useRootInTES=true) const
bool existDet (IDataProviderSvc *svc, const std::string &location) const
bool existDet (const std::string &location) const
TYPE * getOrCreate (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const
TYPE * getOrCreate (const std::string &location, const bool useRootInTES=true) const
TOOL * tool (const std::string &type, const std::string &name, const IInterface *parent=0, bool create=true) const
TOOL * tool (const std::string &type, const IInterface *parent=0, bool create=true) const
SERVICE * svc (const std::string &name, const bool create=true) const
IUpdateManagerSvcupdMgrSvc () const
IDataProviderSvcfastContainersSvc () const
StatusCode Error (const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
StatusCode Warning (const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
StatusCode Print (const std::string &msg, const StatusCode st=StatusCode::SUCCESS, const MSG::Level lev=MSG::INFO) const
StatusCode Assert (const bool ok, const std::string &message="", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Assert (const bool ok, const char *message, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg, const GaudiException &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg, const std::exception &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
StatusCode Exception (const std::string &msg="no message", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
MsgStreammsgStream (const MSG::Level level) const
MsgStreamalways () const
MsgStreamfatal () const
MsgStreamerr () const
MsgStreamerror () const
MsgStreamwarning () const
MsgStreaminfo () const
MsgStreamdebug () const
MsgStreamverbose () const
MsgStreammsg () const
const Statisticscounters () const
StatEntitycounter (const std::string &tag) const
MSG::Level msgLevel () const
bool msgLevel (const MSG::Level level) const
void resetMsgStream () const
bool typePrint () const
bool propsPrint () const
bool statPrint () const
bool errorsPrint () const
long printStat (const MSG::Level level=MSG::ALWAYS) const
long printErrors (const MSG::Level level=MSG::ALWAYS) const
long printProps (const MSG::Level level=MSG::ALWAYS) const
void registerCondition (const std::string &condition, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (const std::string &condition, CondType *&condPtrDest, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (char *condition, StatusCode(CallerClass::*mf)()=NULL)
void registerCondition (TargetClass *condition, StatusCode(CallerClass::*mf)()=NULL)
StatusCode runUpdate ()
TransientFastContainer< T > * getFastContainer (const std::string &location, typename TransientFastContainer< T >::size_type initial=0)
StatusCode release (const IInterface *interface) const
virtual unsigned long release ()
const std::string & context () const
const std::string & rootInTES () const
double globalTimeOffset () const
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvUnknown)
virtual unsigned long addRef ()
virtual const std::string & name () const
virtual const std::string & type () const
virtual const IInterfaceparent () const
virtual StatusCode configure ()
virtual StatusCode start ()
virtual StatusCode stop ()
virtual StatusCode terminate ()
virtual StatusCode reinitialize ()
virtual StatusCode restart ()
virtual Gaudi::StateMachine::State FSMState () const
virtual Gaudi::StateMachine::State targetFSMState () const
virtual StatusCode sysInitialize ()
virtual StatusCode sysStart ()
virtual StatusCode sysStop ()
virtual StatusCode sysFinalize ()
virtual StatusCode sysReinitialize ()
virtual StatusCode sysRestart ()
virtual StatusCode setProperty (const Property &p)
virtual StatusCode setProperty (const std::string &s)
virtual StatusCode setProperty (const std::string &n, const std::string &v)
StatusCode setProperty (const std::string &name, const TYPE &value)
virtual StatusCode getProperty (Property *p) const
virtual const PropertygetProperty (const std::string &name) const
virtual StatusCode getProperty (const std::string &n, std::string &v) const
virtual const std::vector<
Property * > & 
getProperties () const
PropertyMgrgetPropertyMgr ()
ISvcLocatorserviceLocator () const
ISvcLocatorsvcLoc () const
IMessageSvcmsgSvc () const
IToolSvctoolSvc () const
StatusCode setProperties ()
StatusCode service (const std::string &name, T *&svc, bool createIf=true) const
StatusCode service (const std::string &type, const std::string &name, T *&svc) const
void declInterface (const InterfaceID &, void *)
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
IAuditorSvcauditorSvc () const
IMonitorSvcmonitorSvc () const
void declareInfo (const std::string &name, const T &var, const std::string &desc) const
void declareInfo (const std::string &name, const std::string &format, const void *var, int size, const std::string &desc) const

Static Public Member Functions

static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()
static const InterfaceIDinterfaceID ()

Public Attributes

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR

Protected Types

typedef std::map< std::string,
StatEntity
Statistics
typedef std::map< std::string,
unsigned int > 
Counter
typedef std::vector< IAlgTool * > AlgTools
typedef std::pair< IInterface *,
std::string > 
ServiceEntry
typedef std::vector< ServiceEntryServices

Protected Member Functions

StatusCode releaseTool (const IAlgTool *tool) const
StatusCode releaseSvc (const IInterface *svc) const
int outputLevel () const
virtual unsigned long refCount () const
IntegerPropertyoutputLevelProperty ()
void initOutputLevel (Property &prop)

Static Protected Attributes

static const bool IgnoreRootInTES
static const bool UseRootInTES

Private Types

 SUCCESS
 NO_INTERFACE
 VERSMISMATCH
 LAST_ERROR
enum  Status

Private Member Functions

virtual const std::string & type () const =0
virtual const IInterfaceparent () const =0
virtual StatusCode configure ()=0
virtual StatusCode initialize ()=0
virtual StatusCode start ()=0
virtual StatusCode stop ()=0
virtual StatusCode finalize ()=0
virtual StatusCode terminate ()=0
virtual StatusCode reinitialize ()=0
virtual StatusCode restart ()=0
virtual Gaudi::StateMachine::State FSMState () const =0
virtual StatusCode sysInitialize ()=0
virtual StatusCode sysStart ()=0
virtual StatusCode sysStop ()=0
virtual StatusCode sysFinalize ()=0
virtual StatusCode sysReinitialize ()=0
virtual StatusCode sysRestart ()=0
virtual unsigned long refCount () const =0
virtual const std::string & name () const =0
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)=0
virtual unsigned long addRef ()=0
virtual unsigned long release ()=0

Static Private Member Functions

static const InterfaceIDinterfaceID ()

Classes

struct  SpecifiedVolume

Detailed Description

Implimentation of ITouchableToDetectorElement. First attempt; uses no caches or other optimization.

Author:
Nathaniel Tagg (tagg@minos.phy.tufts.edu)

Definition at line 13 of file TouchableToDetectorElement.h.


Constructor & Destructor Documentation

TouchableToDetectorElement::TouchableToDetectorElement ( const std::string &  type,
const std::string &  name,
const IInterface parent 
)

Definition at line 17 of file TouchableToDetectorElement.cc.

00021        : GaudiTool(type,name,parent)
00022 {
00023   declareInterface<ITouchableToDetectorElement>(this);
00024   
00025 }

virtual TouchableToDetectorElement::~TouchableToDetectorElement (  )  [inline, virtual]

Definition at line 19 of file TouchableToDetectorElement.h.

00019 {};


Member Function Documentation

StatusCode TouchableToDetectorElement::GetBestDetectorElement ( const G4TouchableHistory *  inHistory,
const std::vector< std::string > &  inPath,
const IDetectorElement *&  outElement,
int &  outCompatibility 
) [virtual]

Do the conversion.

Implements ITouchableToDetectorElement.

Definition at line 164 of file TouchableToDetectorElement.cc.

00167                                                                          : The best element (may be zero!) 
00168                           int& outCompatibility )              // output: the goodness of the match (higher is better)
00169 {
00170   TouchableToDetectorElement::SpecifiedVolume g4place; 
00171   StatusCode sc = GetSpecifiedVolume(inHistory, g4place);
00172   if(sc.isFailure()) return sc;
00173 
00174   // At the moment, the best possible match is to the top Element, which has only basic compatibility.
00175   outCompatibility = 0x7fffffff; // Maximum possible int.
00176   outElement = g4place.mTop;
00177 
00178   // Find a list we want to compare to.
00179   //debug() << "Getting list of elements" << endreq;
00180   std::vector<const IDetectorElement*> elements;
00181   
00182   // Search each path, looking for things.
00183   for(unsigned int i = 0; i< inPaths.size(); ++i) {
00184     sc = FindObjectsInDirectory<IDetectorElement>(inPaths[i],elements);
00185     if(sc.isFailure()) return sc;
00186   }
00187 
00188   // Now compare each one to our current.
00189   for(unsigned int i=0; i<elements.size(); ++i) {
00190     TouchableToDetectorElement::SpecifiedVolume trialVolume;
00191     sc = GetSpecifiedVolume(elements[i], g4place.mTop, trialVolume);
00192     if(sc.isFailure()) continue;
00193 
00194     int compat = Compatability(g4place,trialVolume);
00195     if((compat >= 0) && (compat<outCompatibility)) {
00196       outElement = elements[i];
00197       outCompatibility = compat;
00198     }
00199   }
00200 
00201   return StatusCode::SUCCESS; 
00202 }

StatusCode TouchableToDetectorElement::G4VolumeToDetDesc ( const G4VPhysicalVolume *  inVol,
const IPVolume *&  outVol 
) [virtual]

Utility to do a simpler conversion: find the IPVolume from a G4PhysicalVolume.

Thin wrapper around the other used one.

Parameters:
inVol  Input G4 volume
outVol  Output DetDesc volume

Implements ITouchableToDetectorElement.

Definition at line 28 of file TouchableToDetectorElement.cc.

00031 {
00035   ILVolume::ReplicaPath rp;
00036   return G4VolumeToDetDesc(inVol,outVol,rp);
00037 }

virtual StatusCode TouchableToDetectorElement::ClearCache (  )  [inline, virtual]

Clear caches in case of geometry change.

Implements ITouchableToDetectorElement.

Definition at line 35 of file TouchableToDetectorElement.h.

00035 { return StatusCode::SUCCESS; }; // no caches here.

StatusCode TouchableToDetectorElement::G4VolumeToDetDesc ( const G4VPhysicalVolume *  inVol,
const IPVolume *&  outVol,
ILVolume::ReplicaPath outPath 
) [virtual]

Utility to do a simpler conversion: find the IPVolume from a G4PhysicalVolume.

Utility for the Touchable Searcher below, and also useful by itself. This function takes the g4physical volume and parses the name to figure out a) what ultimate IPVolume that it corresponds to, and b) the supporting replica path missing from geant 4 That last is a list of physical volume 'ReplicaType' (ints). This will usually be just one int (which physical volume it is in the logical volume) but can be longer if there are IPVolumes that are not represented in geant4. Assemblies often do this.

Parameters:
inVol  Input G4 volume
outVol  Output DetDesc volume
outPath  Output detdesc support path (in detdesc)

Definition at line 39 of file TouchableToDetectorElement.cc.

00043 {
00053   
00054   if(!inVol) {
00055     return StatusCode::FAILURE;
00056   }
00057   
00058   std::string pvpath = inVol->GetName();
00059   
00060   const ILVolume* lv = 0;
00061   const IPVolume* pv = 0;
00062    // This is a top-level call
00063    // Look for an explicit logical volume name.
00064   std::string lname = pvpath;
00065   std::string::size_type p = pvpath.find_first_of('#');
00066   if(p!= std::string::npos) {
00067     lname = pvpath.substr(0,p);
00068     pvpath.erase(0,p+1); // strip off this part.
00069   } 
00070   
00071   // Find the logical volume.
00072   if(!exist<ILVolume>(detSvc(),lname,false)) {
00073     err() << "Can't find lvolume at path " << lname << " when parsing physvol " << inVol->GetName() << endreq;
00074     return StatusCode::FAILURE;
00075   }    
00076   lv= getDet<ILVolume>(lname);
00077   
00078   // Keep eating the remaining string until we have fully parsed the remaining logical/physical path sequence.
00079   while(pvpath.size() > 0) {
00080     // Make sure the current logical volume is good.
00081     if(!lv) {
00082       err() << "Can't find lvolume." << endreq;
00083       return StatusCode::FAILURE;
00084     }
00085 
00086     // parse out the next bit before a hash mark:
00087     std::string pname = pvpath;
00088     std::string::size_type p = pvpath.find_first_of('#');
00089     if(p != std::string::npos ) {
00090       pname.erase(p,std::string::npos);
00091       pvpath.erase(0,p+1); // Ok, take this stuff off the front.
00092     } else {
00093       pvpath.erase();
00094     }
00095   
00096     ILVolume::ReplicaType replica = 0;
00097     pv = 0;
00098     for ( ILVolume::ReplicaType i = 0; i< lv->noPVolumes(); ++i ){
00099       const IPVolume* apv = lv->pvolume(i);
00100       if(!apv) {
00101         err() << "Bad link to IPVolume from " << lv->name() << endreq;
00102         return StatusCode::FAILURE;
00103       }
00104       // Look for a match.
00105       if(apv->name() == pname){ pv = apv; replica = i; break;}
00106     } // End of loop over physical volumes in lv
00107     
00108     if(!pv) {
00109       err() << "Couldn't find a match for physical volume with name " << pname << " in lvolume name " << lv->name() << endreq;
00110       return StatusCode::FAILURE;
00111     }
00112     // Finally, this is what we were after:
00113     outPath.push_back(replica);      
00114     
00115     // Advance lvolume
00116     lv = pv->lvolume();
00117   }
00118 
00119   outVol = pv;
00120 
00121   return StatusCode::SUCCESS;
00122 }

StatusCode TouchableToDetectorElement::GetSpecifiedVolume ( const G4TouchableHistory *  inHistory,
SpecifiedVolume outVol 
)

Definition at line 204 of file TouchableToDetectorElement.cc.

00207 {
00208   //debug() << "Building SpecVol from G4TouchableHistory" << endreq;
00209   if(!inHistory) {
00210     err() << "No good TouchableHistory provided." << endreq;
00211     return StatusCode::FAILURE;
00212   }
00213 
00214   // Try to find the topmost level, which should be a DetectorElement.
00215   G4VPhysicalVolume* top = inHistory->GetVolume(inHistory->GetHistoryDepth()-1);
00216   if(!top) {
00217     err() << "Got null G4VPhysicalVolume pointer in the bottom of G4TouchableHistory. Huh???" << endreq;
00218     return StatusCode::FAILURE;
00219   }
00220   if(!exist<IDetectorElement>(detSvc(),top->GetName()),false) {
00221     err() << "Can't find detector element at the bottom of the G4TouchableHistory, name = " << top->GetName() << endreq;
00222     return StatusCode::FAILURE;
00223   }
00224 
00225   outVol.mTop = getDet<IDetectorElement>(top->GetName());
00226   outVol.mRpath.clear();
00227 
00228    // Ok, now parse the rest of the history.
00229    // This could in principle be sped up by caching the resulting sub-SpecfiedVolumes and storing keyed by
00230    // G4VPhysicalVolume pointer. But that would result in a fair number of things laying around, and it's
00231    // not clear if the speed is important yet.
00232 
00233   for(int ind=inHistory->GetHistoryDepth()-2; ind>=0;  --ind){
00234     G4VPhysicalVolume* g4pv = inHistory->GetVolume(ind);
00235      // Now, parse the volume name.
00236     ILVolume::ReplicaPath subpath;
00237     const IPVolume* pv;
00238     StatusCode sc = G4VolumeToDetDesc(g4pv,pv,subpath);
00239     if(sc.isFailure()) return sc;
00240 
00241     // Tack this onto the end of the list.
00242     outVol.mRpath.insert(outVol.mRpath.end(),subpath.begin(),subpath.end());
00243     
00244   } // End loop over history
00245   
00246   return StatusCode::SUCCESS;
00247 }

StatusCode TouchableToDetectorElement::GetSpecifiedVolume ( const IDetectorElement inElem,
const IDetectorElement inTopElem,
SpecifiedVolume outVol 
)

Definition at line 249 of file TouchableToDetectorElement.cc.

00250 {
00254   const IGeometryInfo* topGeo = inTopElem->geometry();
00255   const IGeometryInfo* trialGeo = inElem->geometry();
00256 
00257   // Try to build up a full replica path.
00258   outVol.mRpath.clear();
00259   outVol.mTop = 0;
00260   
00261   const IGeometryInfo* curGeo = trialGeo;
00262   while(curGeo!=topGeo) {
00263     //std::string sstart;
00264     //curGeo->location(sstart, rpath);
00265     
00266     ILVolume::ReplicaPath rpath;
00267     IGeometryInfo* nextGeo;
00268     curGeo->location(nextGeo, rpath);
00269     curGeo = nextGeo;
00270     outVol.mRpath.insert(outVol.mRpath.begin(),rpath.begin(),rpath.end());
00271     if(0==curGeo) break;
00272   }
00273   if(curGeo==topGeo) outVol.mTop = inTopElem;
00274   else outVol.mTop = 0; // This is an error, but I don't know how to fix it.. how do you go from GeometryInfo to a detector element, 
00275   // especially if it's an 'orphan' or a 'ghost'? Maybe it doesn't matter, since it isnt' used.
00276   
00277   // debug() << "Built SpecVol from " << inElem->name() << ":" << endreq;
00278   // if(outVol.mTop)
00279   //    debug() << outVol.mTop->name();
00280   // for(unsigned int i=0;i<outVol.mRpath.size();i++) debug() << " [" << outVol.mRpath[i] << "]";
00281   // debug() << endreq;
00282   
00283   return StatusCode::SUCCESS; 
00284 }

int TouchableToDetectorElement::Compatability ( const SpecifiedVolume inPlace,
const SpecifiedVolume inContainer 
)

Returns -1 if incompatible, returns number that increases the better the container describes the place.

Definition at line 287 of file TouchableToDetectorElement.cc.

00288 {
00289   // Check to ensure that they share a top volume. This will fail for DetElements at, for instance, different
00290   // sites than the simulated site.
00291   if(inPlace.mTop != inContainer.mTop) return -1; // They don't match at the top.
00292   
00293   // Check to see that the container is at least as specific as the place. 
00294   // If not, the container specifies a deeper detector element than the place
00295   // e.g. This condition catches container=PMT, place=rock
00296   if(inContainer.mRpath.size() > inPlace.mRpath.size()) return -1;
00297 
00298   // Check through to see if it matches at every level.
00299   for(unsigned int i=0; i< inContainer.mRpath.size(); ++i ){
00300     if(inContainer.mRpath[i] != inPlace.mRpath[i]) return -1; // There's a mismatch, throw this one out.
00301   }
00302   
00303   // Ok, it checks at every level of the container. 
00304   // The goodness of the match is the specificity of the place minus the specificity of the container.
00305   // This is zero for a perfect match.
00306   return inPlace.mRpath.size() - inContainer.mRpath.size();
00307 }

template<class T>
StatusCode TouchableToDetectorElement::FindObjectsInDirectory ( const std::string &  dirname,
std::vector< const T * > &  outList 
)

Definition at line 127 of file TouchableToDetectorElement.cc.

00131 {
00135   info() << "Looking for structures in " << dirname << endreq;
00136   if (!existDet<DataObject>(dirname)) {
00137     err() << "No " << dirname << " in TDS" << endreq;
00138     return StatusCode::FAILURE;
00139   }
00140   const DataObject *d = getDet<DataObject>(dirname);
00141 
00142   const T* t = dynamic_cast<const T*>(d);
00143   if(t) list.push_back(t);
00144 
00145   IRegistry* dr = d->registry();
00146   using namespace DataSvcHelpers;
00147   RegistryEntry* dre = dynamic_cast<RegistryEntry*>(dr);
00148   if (!dre) {
00149     err() << "Failed to get RegistryEntry on DataObject" << d << endreq;
00150     return StatusCode::FAILURE;
00151   }
00152 
00153   RegistryEntry::Iterator it = dre->begin(), done = dre->end();
00154   for (; it != done; ++it) {
00155     std::string id = (*it)->identifier();
00156     StatusCode sc = FindObjectsInDirectory<T>(id,list);
00157     if(sc.isFailure()) return sc;
00158   }
00159 
00160   return StatusCode::SUCCESS;  
00161 }

const InterfaceID & ITouchableToDetectorElement::interfaceID (  )  [static, inherited]

Reimplemented from IAlgTool.

Definition at line 8 of file ITouchableToDetectorElement.cc.

00009 { 
00010     return IID_ITouchableToDetectorElement; 
00011 }


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:32:10 2011 for G4DataHelpers by doxygen 1.4.7