Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

geo::CellUniqueId Class Reference

Map a TGeo path to a unique ID number for a cell in the detector. More...

#include <CellUniqueId.h>

List of all members.

Public Types

enum  { kLvl = 3, kFac = 1000 }

Public Member Functions

 CellUniqueId ()
 CellUniqueId (const char *path)
void Set (const char *path)
bool operator!= (const CellUniqueId &rhs) const
bool operator== (const CellUniqueId &rhs) const
bool operator< (const CellUniqueId &rhs) const
bool operator<= (const CellUniqueId &rhs) const
bool operator> (const CellUniqueId &rhs) const
bool operator>= (const CellUniqueId &rhs) const
 ClassDef (CellUniqueId, 1)

Public Attributes

unsigned long int fId [kLvl]


Detailed Description

Map a TGeo path to a unique ID number for a cell in the detector.

Definition at line 15 of file CellUniqueId.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
kLvl  Number of long ints required.
kFac  Factor to use in assembling numbers.

Definition at line 30 of file CellUniqueId.h.

00030          {
00031       kLvl = 3,    
00032       kFac = 1000 
00033     };


Constructor & Destructor Documentation

CellUniqueId::CellUniqueId  ) 
 

Definition at line 14 of file CellUniqueId.cxx.

References fId, and kLvl.

00015 {
00016   register int i;
00017   for (i=0; i<kLvl; ++i) fId[i] = 0;
00018 }

CellUniqueId::CellUniqueId const char *  path  ) 
 

Definition at line 22 of file CellUniqueId.cxx.

References Set().

00023 {
00024   this->Set(path);
00025 }


Member Function Documentation

geo::CellUniqueId::ClassDef CellUniqueId  ,
 

bool CellUniqueId::operator!= const CellUniqueId rhs  )  const
 

Definition at line 102 of file CellUniqueId.cxx.

References fId, and kLvl.

00103 {
00104   register int i;
00105   for (i=0; i<kLvl; ++i) if (fId[i] != rhs.fId[i]) return true;
00106   return false;
00107 }

bool CellUniqueId::operator< const CellUniqueId rhs  )  const
 

Definition at line 111 of file CellUniqueId.cxx.

References fId, and kLvl.

00112 {
00113   register int i;
00114   for (i=0; i<kLvl; ++i) {
00115     if (fId[i] < rhs.fId[i]) return true;
00116     if (fId[i] > rhs.fId[i]) return false;
00117   }
00118   return false;
00119 }

bool CellUniqueId::operator<= const CellUniqueId rhs  )  const
 

Definition at line 123 of file CellUniqueId.cxx.

References fId, and kLvl.

00124 {
00125   register int i;
00126   for (i=0; i<kLvl; ++i) {
00127     if (fId[i] < rhs.fId[i]) return true;
00128     if (fId[i] > rhs.fId[i]) return false;
00129   }
00130   return true;
00131 }

bool CellUniqueId::operator== const CellUniqueId rhs  )  const
 

Definition at line 93 of file CellUniqueId.cxx.

References fId, and kLvl.

00094 {
00095   register int i;
00096   for (i=0; i<kLvl; ++i) if (fId[i] != rhs.fId[i]) return false;
00097   return true;
00098 }

bool CellUniqueId::operator> const CellUniqueId rhs  )  const
 

Definition at line 135 of file CellUniqueId.cxx.

References fId, and kLvl.

00136 {
00137   register int i;
00138   for (i=0; i<kLvl; ++i) {
00139     if (fId[i] > rhs.fId[i]) return true;
00140     if (fId[i] < rhs.fId[i]) return false;
00141   }
00142   return false;
00143 }

bool CellUniqueId::operator>= const CellUniqueId rhs  )  const
 

Definition at line 147 of file CellUniqueId.cxx.

References fId, and kLvl.

00148 {
00149   register int i;
00150   for (i=0; i<kLvl; ++i) {
00151     if (fId[i] > rhs.fId[i]) return true;
00152     if (fId[i] < rhs.fId[i]) return false;
00153   }
00154   return true;
00155 }

void CellUniqueId::Set const char *  path  ) 
 

Setting a unique id is a somewhat tricky busines. To save memory, the ROOT TGeo classes re-used physical volumes. So, if the material and geometry for all the cells is the same, they will be represented by the same object. A volume in the detector is then uniquely identified by the "path" to that volume. In the TGeo classes this is represented by a string of the format:

World_1/BigVolume_4/SmallVolume_6/TinyVolume_9

The numbers in the path are the "copy" numbers for the volumes. To make look ups faster, this routine maps this string path name to a long integer number. In the above case, that number would be 1004006009.

Due to the depth of the geometry, these integers can become quite large. To ensure that enough digits are available, they are stored in three long ints (fId[0-2])

Parameters:
path : The TGeo 'directory' path to the physical volume

Definition at line 48 of file CellUniqueId.cxx.

References fId, kFac, and kLvl.

Referenced by geo::CellGeo::CellGeo(), CellUniqueId(), geo::Geometry::CurrentCell(), geo::Geometry::CurrentCellId(), and novamc::MCApplication::Stepping().

00049 {
00050   register int i, j=0, k;
00051   char buff[8];              // Will hold the digits extracted from 'path'
00052   bool lastisnumber = false; // Was the last charater seen in 'path' a digit?
00053   
00054   fId[0] = fId[1] = fId[2] = 0;
00055   memset(buff,'\0',8*sizeof(char));
00056 
00057   // Loop over all charaters in 'path'
00058   for (i=0; ; ++i) {
00059     // If current character in the string is a digit, copy it to the
00060     // buffer
00061     if (path[i]>='0' && path[i]<='9') {
00062       buff[j] = path[i];
00063       ++j;
00064       lastisnumber = true;
00065     }
00066     else {
00067       // If the current charater in the string is not a digit, but the
00068       // last character was, the number in 'buff' is complete and
00069       // ready to be added to the unique id
00070       if (lastisnumber) {
00071         for (k=0; k<kLvl; ++k) {
00072           // Check if the k'th component of fId has already saturated
00073           // the size of a ULONG. If yes, continue to the next
00074           // component.
00075           if (fId[k]>0 && ULONG_MAX/fId[k]<kFac) continue;
00076           fId[k] += kFac*fId[k] + atoi(buff);
00077           break;
00078         }
00079         // Clear the buffer to ready ourselves for the next digit in
00080         // the string
00081         memset(buff, '\0', 8*sizeof(char));
00082         j = 0;
00083       }
00084       lastisnumber = false;
00085     }
00086     // Are we done parsing 'path'?
00087     if (path[i] == '\0') break;
00088   }
00089 }


Member Data Documentation

unsigned long int geo::CellUniqueId::fId[kLvl]
 

Definition at line 34 of file CellUniqueId.h.

Referenced by CellUniqueId(), geo::Geometry::CurrentCell(), geo::Geometry::IdToCell(), main(), geo::Geometry::MakeIdMap(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), and Set().


The documentation for this class was generated from the following files:
Generated on Sun Aug 17 02:05:53 2008 for NOvA Offline by doxygen 1.3.5