ATLAS Offline Software
TRT_FillCablingData_TB04.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Implementation file for TRT_FillCablingData_TB04 class
7 //
8 
9 /*
10  * Assumptions:
11  * One side of the barrel is readout, namely side A
12  * We need to map between phi sector index used in the offline and
13  * the Source IDs programmed in the hardware.
14  *
15  * The m_identifier* and m_collID vectors are indexed by ROB source ID - 1.
16  * The magic mapping between ROB source IDs and phi sector indices is in
17  * getRobID() and in fillCollID(). Everything else should just fall
18  * through and gets the Right Answer.
19  */
20 
21 
22 //#include <iostream>
24 #include <fstream>
25 
26 #include "eformat/SourceIdentifier.h" // change to new eformat v3
28 
29 
30 using eformat::helper::SourceIdentifier;
31 
32 // Utility namespace for file input sanitation
33 namespace {
34  bool inRange(const int var, const int lo, const int hi) {
35  return not ((lo > var) or (hi < var));
36  }
37 
38  const int invalidInput{-1};
39  const int maxPossiblePhiModule{9};
40  const int maxPossibleModule{3};
41  const int maxPossibleBufferLocation{2000};
42 }
43 
44 static const InterfaceID IID_ITRT_FillCablingData_TB04
45  ("TRT_FillCablingData_TB04", 1, 0);
46 
47  // Constructor
48 TRT_FillCablingData_TB04::TRT_FillCablingData_TB04( const std::string& type, const std::string&
49 name,const IInterface* parent ): AthAlgTool(type,name,parent),
50  m_TRTHelper(nullptr)
51 {
52  declareInterface< TRT_FillCablingData_TB04 >( this );
53 }
54 
55 
56  // Destructor
58 {}
59 
60 
62 { return IID_ITRT_FillCablingData_TB04; }
63 
64 
65  // Initialisation
67 {
68  ATH_MSG_INFO( "TRT_FillCablingData_TB04::initialize" );
69 
70 
71  // Get the TRT Helper
72  if (detStore()->retrieve(m_TRTHelper, "TRT_ID").isFailure())
73  {
74  ATH_MSG_FATAL( "Could not get TRT ID helper" );
75  return StatusCode::FAILURE;
76  }
78 
80 
82  defineTables();
83  defineCollID();
84 
85  ATH_MSG_INFO( "TRT_FillCablingData_TB04::initializiation finished" );
86 
87  return StatusCode::SUCCESS;
88 }
89 
90 
92 {
93  delete m_cabling;
94 
96  return sc;
97 }
98 
99 
101 {
102  return m_cabling;
103 }
104 
105 
107 {
108  m_numberOfRings = 3;
109 
110  m_numberOfLayersA = 19;
111  m_numberOfLayersB = 24;
112  m_numberOfLayersC = 30;
113 
115 
116  // Mapping from phi sector index to source id
117  m_phi_to_source.push_back( 0x310003 ); // Phi 0 is Source ID 0x3103
118  m_phi_to_source.push_back( 0x310002 ); // Phi 1 is Source ID 0x3102
119  // NB: Source ID 0x3101 is the 3S boards on BOTH Phi 0 and Phi 1
120 
121 
122  int numberOfStrawsInLayersA[] = {15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18,
123  18, 18, 18, 18, 19, 19, 19, 18};
124 
125  int numberOfStrawsInLayersB[] = {19, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21,
126  22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 24, 24, 23};
127 
128  int numberOfStrawsInLayersC[] = {23, 24, 24, 24, 24, 25, 25, 25, 25, 25, 26,
129  26, 26, 26, 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 29, 29, 29, 29, 28};
130 
131  std::vector<int> ncol0 (std::begin(numberOfStrawsInLayersA),
132  std::end(numberOfStrawsInLayersA));
133  std::vector<int> ncol1 (std::begin(numberOfStrawsInLayersB),
134  std::end(numberOfStrawsInLayersB));
135  std::vector<int> ncol2 (std::begin(numberOfStrawsInLayersC),
136  std::end(numberOfStrawsInLayersC));
137 
138  m_ncol.push_back(ncol0);
139  m_ncol.push_back(ncol1);
140  m_ncol.push_back(ncol2);
141 
142  m_StrawsByModule[0] = 329;
143  m_StrawsByModule[1] = 520;
144  m_StrawsByModule[2] = 793;
145 
146 }
147 
148 
149  // Fill Tables with IDs for all straws
151 {
152  // Reading mapping
153  // Important number for converter!!! Pay attention!!!
154  // Another side has Id = -1
155  int barrelId = -1;
156  int phiModuleId, moduleId, strawLayerId, strawInLayerId,
157  strawNumberInModule,BufferLocation;
158  Identifier strawID, IdLayer;
159  IdentifierHash hashId;
160 
161  // Loop over two RODs (not PhiModules!)
162  for (int rod = 0; rod < m_numberOfIdentifierSectors; rod++ )
163  {
164  std::vector<Identifier> tempbuff;
165  std::vector<IdentifierHash> tempbuff2;
166  for (int i = 0; i < 8*13*16; i++){
167  Identifier id(0);
168  tempbuff.push_back(id);
169  tempbuff2.emplace_back(0);
170  }
173 
174  std::ostringstream ssFile;
175  ssFile << rod;
176  std::string dataFile = "TRT_TB04_IdMapping_ROD" + ssFile.str() + ".dat";
177 
178  std::string file = PathResolver::find_file (dataFile, "DATAPATH");
179 
180  std::ifstream inputFile (file.c_str());
181  if (!inputFile)
182  ATH_MSG_FATAL( "TRT_FillCablingData_TB04: Could not open file " << dataFile );
183 
184  /*
185  * We now loop over all buffer locations
186  * Read-out order is:
187  * ROD 0: 3S1, 3S2 (Assumed: UB3S and DB3S)
188  * ROD 1+2: 3L2, 3L1, 2L2, 2S, 2L1, 1S, 1L
189  * Data-files have been assembled in that order
190  * The individual file is ordered first after board and then
191  * after buffer location
192  */
193 
194 
195  while(!inputFile.eof()){
196  /*
197  * Need to add moduleId to data file, as the absolute strawnumber
198  * is relative to the module layer
199  * Also add phiModuleId. This is the easiest.
200  */
201  inputFile >> phiModuleId >> moduleId >> strawNumberInModule
202  >> BufferLocation;
203 
204  // Sanitize input from file
205  const bool validPhi = inRange(phiModuleId, invalidInput, maxPossiblePhiModule);
206  const bool validModule = inRange(moduleId, invalidInput, maxPossibleModule);
207  const bool validStrawNumber = inRange(strawNumberInModule, invalidInput, m_StrawsByModule[moduleId]);
208  const bool validBuffer = inRange(BufferLocation, invalidInput, maxPossibleBufferLocation);
209  if (not (validPhi and validModule and validStrawNumber and validBuffer)) {
210  ATH_MSG_WARNING("One of the following is out of range: " << phiModuleId << ", " << moduleId
211  << ", " << strawNumberInModule << ", " << BufferLocation);
212  continue;
213  }
214 
215  // Swap of phi sectors for ROD 0: 3S1, 3S2
216  if (rod == 0) {
217  if (phiModuleId == 0)
218  phiModuleId = 1;
219  else
220  phiModuleId = 0;
221  }
222 
223 
224  int rodSourceId=0;
225  if ( rod == 0 )
226  rodSourceId = 1;
227  else if ( rod == 1 )
228  rodSourceId = 2;
229  else if ( rod == 2 )
230  rodSourceId = 3;
231  else
232  {
233  ATH_MSG_ERROR( " Bad rod index! (" << rod << ")" );
234  return;
235  }
236 
237  /*
238  * DAQ numbers (seems to) go from 1, whereas offline Identifiers
239  * go from 0, so we'll just fix this:
240  */
241  strawNumberInModule--;
242  if (strawNumberInModule < 0) {
243  ATH_MSG_WARNING("Straw number in module became negative: " << strawNumberInModule);
244  continue;
245  }
246 
247  //Need to retrieve strawLayerId & strawInLayerId from ncols...
248  strawLayerId=0;
249  strawInLayerId=strawNumberInModule;
250 
251  while(strawInLayerId>=0){
252  //std::cout << "moduleID, strawLyerID" << moduleId << strawLayerId << std::endl;
253  strawInLayerId -= m_ncol[moduleId][strawLayerId];
254  strawLayerId++;
255  }
256  // Taking a step back
257  strawLayerId--;
258  strawInLayerId += m_ncol[moduleId][strawLayerId];
259 
260  //Apparently this is needed to skip to the next line
261  inputFile.ignore(256,'\n');
262 
263 
264  // Construct an Identifier and put it in the list
265  strawID = m_TRTHelper->straw_id(barrelId, phiModuleId, moduleId,
266  strawLayerId, strawInLayerId);
267  m_cabling->set_identifierForAllStraws(0x310000 + rodSourceId, BufferLocation, strawID);
268 
269  // Construct Hash and put it in the list
270  IdLayer = m_TRTHelper->layer_id(strawID);
271  if ( !m_TRTHelper->get_hash(IdLayer, hashId, &m_cntx) )
272  m_cabling->set_identifierHashForAllStraws(0x310000 + rodSourceId,
273  BufferLocation, hashId);
274  else
275  ATH_MSG_DEBUG( "defineTables: unable to get hash for IdLayer " << IdLayer );
276 
277  } // end of loop over straw in ROD
278 
279  inputFile.close(); //
280  } // end of loop over RODs
281 
282  return;
283 }
284 
285 /*
286  * Define map of collection IDs for all ROBs
287  */
289 {
290 
291  // Start from 1 because we have no Source ID = 0
292  for(int rod = 1; rod <= m_numberOfIdentifierSectors; rod++ )
293  {
294  uint32_t RODSourceId = 0x310000 + rod;
295 
296  std::vector<IdentifierHash> * vectID = new std::vector<IdentifierHash>();
297  fillCollID(RODSourceId, *vectID);
298 
299  m_cabling->add_collID(RODSourceId, vectID);
300  }
301 
302  return;
303 }
304 
305 
306 /*
307  * Input: ROB Source ID
308  * Output: List of Hash IDs, one for each of 73 layers
309  */
311 std::vector<IdentifierHash> & ids)
312 {
313 
314  int barrelId, phiModule=-1;
315  IdentifierHash idHash;
316 
317  int module;
318 
319  eformat::helper::SourceIdentifier id (rob_id);
320  module = (int) id.module_id();
321 
322  barrelId = -1;
323 
324  // Define Phi sector depending on ROB number
325  // 3102 - Phi 1; 3103 - Phi 0;
326  if (module == 2)
327  {
328  phiModule = 1;
329  }
330  else if (module == 3)
331  {
332  phiModule = 0;
333  }
334 
335  if ( module == 1 ) // XXX -- ROB with both 3S boards!
336  {
337  int ring = 2; // Only Module Type 3!
338  for ( int phiModule=0; phiModule<2; phiModule++ )
339 
340  {
341  for (int layer = 0; layer < m_numberOfLayersC; ++layer)
342  {
343  Identifier id = m_TRTHelper->layer_id(barrelId, phiModule,
344  ring, layer);
345  if (!m_TRTHelper->get_hash(id, idHash, &m_cntx))
346  {
347  ids.push_back(idHash);
348  }
349  else
350  ATH_MSG_FATAL( " Unable to get hash for id " << m_TRTHelper->show_to_string(id) );
351  }
352  }
353 
354  return;
355  }
356 
357 
358  for (int ring = 0; ring < m_numberOfRings; ++ring)
359  {
360  if (ring == 0) // Module Type 1
361  {
362  for (int layer = 0; layer < m_numberOfLayersA; ++layer)
363  {
364  Identifier id = m_TRTHelper->layer_id(barrelId, phiModule,
365  ring, layer);
366  if (!m_TRTHelper->get_hash(id, idHash, &m_cntx))
367  ids.push_back(idHash);
368  else
369  ATH_MSG_FATAL( " Unable to get hash for id " << m_TRTHelper->show_to_string(id) );
370  }
371  }
372  else if (ring == 1) // Module Type 2
373  {
374  for (int layer = 0; layer < m_numberOfLayersB; ++layer)
375  {
376  Identifier id = m_TRTHelper->layer_id(barrelId, phiModule,
377  ring, layer);
378  if (!m_TRTHelper->get_hash(id, idHash, &m_cntx))
379  ids.push_back(idHash);
380  else
381  ATH_MSG_FATAL( " Unable to get hash for id " << m_TRTHelper->show_to_string(id) );
382  }
383  }
384  else // Module Type 3
385  {
386  for (int layer = 0; layer < m_numberOfLayersC; ++layer)
387  {
388  Identifier id = m_TRTHelper->layer_id(barrelId, phiModule,
389  ring, layer);
390  if (!m_TRTHelper->get_hash(id, idHash, &m_cntx))
391  ids.push_back(idHash);
392  else
393  ATH_MSG_FATAL( " Unable to get hash for id " << m_TRTHelper->show_to_string(id) );
394  }
395  }
396  }
397 
398  return;
399 }
400 
401 /*
402  * Get ROBIDs for each Detector Element (Straw Layer)
403  *
404  * Input : Straw ID
405  * Output: list of ROB Source IDs
406  */
407 std::vector<uint32_t> TRT_FillCablingData_TB04::getRobID(Identifier id) const
408 {
409  std::vector<uint32_t> v;
410 
411 
412  int id_barrel_ec = m_TRTHelper->barrel_ec(id);
413  int id_phi_module = m_TRTHelper->phi_module(id);
414 
415  /*
416  * It seems to be assumed that the ROD/ROB source IDs are aligned to
417  * the phi sector numbering. This is NOT the case for TB04, so we
418  * need to fix it up.
419  * In addition, for Module type 3 (ie, layer 2), we need to read out
420  * the ROB with the 3S boards (number 1), as well as the ROB with
421  * the rest of the sector.
422  * We assume only one side here.
423  */
424  if (id_barrel_ec == -1)
425  {
426  v.push_back( m_phi_to_source[id_phi_module] );
427 
428 // !!! Artificial inclusion of the ROB XXX (which is in both
429 // phi-sectors) in list of ROBs for each collection. !!!
430 // This is done in order to have this ROB data to be read in
431 // BS converter
432 
433  v.push_back( 0x310001 );
434  }
435  else
436  ATH_MSG_WARNING ( \
437  " TRT_FillCablingData_TB04 --> Couldn't get RobID for given Identifier " \
438  << m_TRTHelper->print_to_string(id) << ", cabling differs from dictionary " );
439 
440  return v;
441 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TRT_FillCablingData_TB04::fillData
TRT_CablingData * fillData()
Definition: TRT_FillCablingData_TB04.cxx:100
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
TRT_ID::layer_id
Identifier layer_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer) const
For an individual straw layer.
Definition: TRT_ID.h:500
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
TRT_FillCablingData_TB04::m_numberOfRings
int m_numberOfRings
Definition: TRT_FillCablingData_TB04.h:77
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TRT_FillCablingData_TB04::fillCollID
void fillCollID(uint32_t rob_id, std::vector< IdentifierHash > &ids)
Definition: TRT_FillCablingData_TB04.cxx:310
TRT_FillCablingData_TB04::TRT_FillCablingData_TB04
TRT_FillCablingData_TB04(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TRT_FillCablingData_TB04.cxx:48
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
TRT_CablingData::set_identifierHashForAllStraws
void set_identifierHashForAllStraws(int rod, int bufferPosition, IdentifierHash hashId)
Definition: TRT_CablingData.cxx:107
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TRT_FillCablingData_TB04::m_phi_to_source
std::vector< uint32_t > m_phi_to_source
Definition: TRT_FillCablingData_TB04.h:89
TRT_FillCablingData_TB04::getRobID
std::vector< uint32_t > getRobID(Identifier id) const
Definition: TRT_FillCablingData_TB04.cxx:407
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TRT_CablingData::set_identifierForAllStraws
void set_identifierForAllStraws(int rod, int bufferPosition, Identifier strawID)
Definition: TRT_CablingData.cxx:86
TRT_FillCablingData_TB04::m_StrawsByModule
int m_StrawsByModule[3]
Definition: TRT_FillCablingData_TB04.h:105
IOVDbNamespace::inRange
bool inRange(const NumericType &val, const std::pair< NumericType, NumericType > &range)
Function to check whether a number is in the inclusive range, given as a pair.
Definition: IOVDbCoolFunctions.h:42
TRT_FillCablingData_TB04::m_numberOfIdentifierSectors
int m_numberOfIdentifierSectors
Definition: TRT_FillCablingData_TB04.h:83
TRT_FillCablingData_TB04::defineCollID
void defineCollID()
Definition: TRT_FillCablingData_TB04.cxx:288
TRT_FillCablingData_TB04::defineParameters
void defineParameters()
Definition: TRT_FillCablingData_TB04.cxx:106
TRT_FillCablingData_TB04::interfaceID
static const InterfaceID & interfaceID()
Definition: TRT_FillCablingData_TB04.cxx:61
ActsProtoTrackCreationAndFitConfig.dataFile
dataFile
Definition: ActsProtoTrackCreationAndFitConfig.py:137
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TRT_FillCablingData_TB04::m_numberOfLayersA
int m_numberOfLayersA
Definition: TRT_FillCablingData_TB04.h:78
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
python.PyAthena.module
module
Definition: PyAthena.py:134
TRT_CablingData::zero_identifierForAllStraws
void zero_identifierForAllStraws(int rod, const std::vector< Identifier > &tempbuff)
Definition: TRT_CablingData.cxx:35
TRT_FillCablingData_TB04::m_numberOfLayersC
int m_numberOfLayersC
Definition: TRT_FillCablingData_TB04.h:80
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRT_ID::get_hash
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const override final
Create hash id from compact id (return == 0 for OK)
Definition: TRT_ID.cxx:946
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
TRT_CablingData::add_collID
void add_collID(uint32_t rob_id, std::vector< IdentifierHash > *vectID)
Definition: TRT_CablingData.cxx:168
TRT_ID::straw_layer_context
IdContext straw_layer_context(void) const
straw_layer id
Definition: TRT_ID.h:713
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
TRT_FillCablingData_TB04::initialize
virtual StatusCode initialize()
Definition: TRT_FillCablingData_TB04.cxx:66
file
TFile * file
Definition: tile_monitor.h:29
TRT_FillCablingData_TB04::~TRT_FillCablingData_TB04
virtual ~TRT_FillCablingData_TB04()
Definition: TRT_FillCablingData_TB04.cxx:57
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
TRT_FillCablingData_TB04::defineTables
void defineTables()
Definition: TRT_FillCablingData_TB04.cxx:150
RunTileMonitoring.rod
rod
Definition: RunTileMonitoring.py:134
AtlasDetectorID::print_to_string
std::string print_to_string(Identifier id, const IdContext *context=0) const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:655
PathResolver.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
TRT_FillCablingData_TB04::m_cntx
IdContext m_cntx
Definition: TRT_FillCablingData_TB04.h:67
TRT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: TRT_ID.h:875
TRT_FillCablingData_TB04::finalize
virtual StatusCode finalize()
Definition: TRT_FillCablingData_TB04.cxx:91
python.PyAthena.v
v
Definition: PyAthena.py:157
TRT::Hit::phiModule
@ phiModule
Definition: HitInfo.h:80
AtlasDetectorID::show_to_string
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:574
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TRT_FillCablingData_TB04::m_TRTHelper
const TRT_ID * m_TRTHelper
Definition: TRT_FillCablingData_TB04.h:65
TRT_CablingData
Definition: TRT_CablingData.h:18
TRT_FillCablingData_TB04.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthAlgTool
Definition: AthAlgTool.h:26
IdentifierHash
Definition: IdentifierHash.h:38
TRT_FillCablingData_TB04::m_cabling
TRT_CablingData * m_cabling
Definition: TRT_FillCablingData_TB04.h:69
TRT_FillCablingData_TB04::m_numberOfLayersB
int m_numberOfLayersB
Definition: TRT_FillCablingData_TB04.h:79
TRT_ID::straw_id
Identifier straw_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Three ways of getting id for a single straw:
Definition: TRT_ID.h:581
TRT_FillCablingData_TB04::m_ncol
std::vector< std::vector< int > > m_ncol
Definition: TRT_FillCablingData_TB04.h:103
TRT_CablingData::zero_identifierHashForAllStraws
void zero_identifierHashForAllStraws(int rod, const std::vector< IdentifierHash > &tempbuff)
Definition: TRT_CablingData.cxx:42