EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicGeoMap.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicGeoMap.cxx
1 //
2 // AYK (ayk@bnl.gov), 2014/08/20
3 //
4 // EIC basic geometry map class;
5 //
6 
7 #include <TGeoManager.h>
8 
9 #include <EicGeoMap.h>
10 
11 // =======================================================================================
12 
14 {
15  unsigned accu = 0;
16 
17  for(int lv=0; lv<mGeantVolumeLevels.size(); lv++)
18  {
20 
21  if (!lptr->mMaxEntryNum) continue;
22 
23  //printf("--> %d\n", lptr->mMaxEntryNum);
25 
26  // Setting shift on "empty" (ignored) levels will not hurt;
27  mask->SetShift(accu);
28  accu += mask->GetBitNum();
29  } //for lv
30 
31  //printf("%d\n", accu);
32 
33  if (accu > _GEANT_INDEX_BIT_NUM_) {
34  printf("-E- EicGeoMap::CalculateBitPattern(): bit pattern can not handle more "
35  "than %d bits, sorry!\n", _GEANT_INDEX_BIT_NUM_);
36  return -1;
37  } //if
38 
39  if (accu) mMappingTableDim = UGeantIndex_t(0x1) << accu;
40 
41  return 0;
42 } // EicGeoMap::CalculateBitPattern()
43 
44 // ---------------------------------------------------------------------------------------
45 
46 int EicGeoMap::AddGeantVolumeLevel(const TString &volumeName, UGeantIndex_t maxEntryNum)
47 {
48  // Check for volume name double counting;
49  for(int lv=0; lv<mGeantVolumeLevels.size(); lv++)
50  {
52 
53  if (volumeName == lptr->mVolumeName)
54  {
55  printf("-E- EicGeoMap::addVolumeLevel(): '%s' accounted twice!\n", volumeName.Data());
56  return -1;
57  } //if
58  } //for lv
59 
60  GeantVolumeLevel *lptr = new GeantVolumeLevel();
61  mGeantVolumeLevels.push_back(lptr);
62  lptr->mVolumeName = volumeName;
63  lptr->mMaxEntryNum = maxEntryNum;
64 
65  return 0;
66 } // EicGeoMap::AddGeantVolumeLevel()
67 
68 // ---------------------------------------------------------------------------------------
69 
71 {
72  UGeantIndex_t idL = 0x0;
73 
74  // A lousy protection; yet want to see this happen before taking more clean measures;
75  if (value == _LOGICAL_INDEX_INVALID_) {
76  printf("-E- EicGeoMap::SetMappingTableEntry(): attempt to set invalid mapping entry!\n");
77  return -1;
78  } //if
79 
80  if (!mMappingTable)
81  {
82  // See error message in CalculateBitPattern();
83  if (CalculateBitPattern()) return -1;
84 
85  // Allocate mapping table and initialize to "illegal" values;
87 
88  for(UGeantIndex_t iq=0; iq<mMappingTableDim; iq++)
89  mMappingTable[iq] = _LOGICAL_INDEX_INVALID_;//~ULogicalIndex_t(0);
90  } // if
91 
92  // Calculate multi-index;
93  for(unsigned lv=0; lv<mGeantVolumeLevels.size(); lv++)
94  {
96 
97  // Skip dummy levels entirely;
98  if (!lptr->mMaxEntryNum) continue;
99 
100  if (id[lv] >= lptr->mMaxEntryNum) {
101  printf("-E- EicGeoMap::SetMappingTableEntry(): index '%d' exceeds limit (%d) for '%s'\n",
102  id[lv], lptr->mMaxEntryNum-1, lptr->GetVolumeName().Data());
103  return -1;
104  } //if
105 
106  idL |= id[lv] << lptr->mBitMask->GetShift();
107  } //for lv
108 
109  // Since individual values were checked, can not be out of range here;
110  // yet check for double-assignment (no harm, but better should not happen);
111  if (mMappingTable[idL] != _LOGICAL_INDEX_INVALID_) { //~ULogicalIndex_t(0)) {
112  printf("-E- EicGeoMap::SetMappingTableEntry(): attempt to set index '%u' twice!\n", idL);
113  return -1;
114  } //if
115 
116  mMappingTable[idL] = value;
117 
118  return 0;
119 } // EicGeoMap::SetMappingTableEntry()
120 
121 // ---------------------------------------------------------------------------------------
122 
124 {
125  for(unsigned lv=0; lv<mGeantVolumeLevels.size(); lv++)
126  {
128  TGeoVolume *volume = gGeoManager->GetVolume(lptr->mVolumeName);
129 
130  if (!volume)
131  {
132  printf("-E- EicGeoMap::CalculateMappingTableSignature(): unknown volume name (%s0!\n",
133  lptr->mVolumeName.Data());
134  return -1;
135  } //if
136 
137  lptr->mVolumeID = volume->GetNumber();
138  } //for lv
139 
140  return 0;
141 } // EicGeoMap::CalculateMappingTableSignature()
142 
143 // ---------------------------------------------------------------------------------------
144 
145 bool EicGeoMap::IsMySignature(const unsigned lvIds[]) const
146 {
147  for(unsigned lv=0; lv<mGeantVolumeLevels.size(); lv++)
148  {
150 
151  if (lvIds[lv] != lptr->mVolumeID) return false;
152  } //for lv
153 
154  return true;
155 } // EicGeoMap::IsMySignature()
156 
157 // =======================================================================================
158 
163