ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_FillCablingData_TB04.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
23#include <fstream>
24
25#include "eformat/SourceIdentifier.h" // change to new eformat v3
27
28
29using eformat::helper::SourceIdentifier;
30
31// Utility namespace for file input sanitation
32namespace {
33 bool inRange(const int var, const int lo, const int hi) {
34 return not ((lo > var) or (hi < var));
35 }
36
37 const int invalidInput{-1};
38 const int maxPossiblePhiModule{9};
39 const int maxPossibleModule{3};
40 const int maxPossibleBufferLocation{2000};
41}
42
43static const InterfaceID IID_ITRT_FillCablingData_TB04
44 ("TRT_FillCablingData_TB04", 1, 0);
45
46 // Constructor
47TRT_FillCablingData_TB04::TRT_FillCablingData_TB04( const std::string& type, const std::string&
48name,const IInterface* parent ): AthAlgTool(type,name,parent),
49 m_TRTHelper(nullptr)
50{
51 declareInterface< TRT_FillCablingData_TB04 >( this );
52}
53
54
55 // Destructor
58
59
61{ return IID_ITRT_FillCablingData_TB04; }
62
63
64 // Initialisation
66{
67 ATH_MSG_INFO( "TRT_FillCablingData_TB04::initialize" );
68
69
70 // Get the TRT Helper
71 if (detStore()->retrieve(m_TRTHelper, "TRT_ID").isFailure())
72 {
73 ATH_MSG_FATAL( "Could not get TRT ID helper" );
74 return StatusCode::FAILURE;
75 }
76 m_cntx = m_TRTHelper->straw_layer_context();
77
79
83
84 ATH_MSG_INFO( "TRT_FillCablingData_TB04::initializiation finished" );
85
86 return StatusCode::SUCCESS;
87}
88
89
91{
92 delete m_cabling;
93
94 StatusCode sc = AlgTool::finalize();
95 return sc;
96}
97
98
103
104
106{
107 m_numberOfRings = 3;
108
112
114
115 // Mapping from phi sector index to source id
116 m_phi_to_source.push_back( 0x310003 ); // Phi 0 is Source ID 0x3103
117 m_phi_to_source.push_back( 0x310002 ); // Phi 1 is Source ID 0x3102
118 // NB: Source ID 0x3101 is the 3S boards on BOTH Phi 0 and Phi 1
119
120
121 int numberOfStrawsInLayersA[] = {15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18,
122 18, 18, 18, 18, 19, 19, 19, 18};
123
124 int numberOfStrawsInLayersB[] = {19, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21,
125 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 24, 24, 23};
126
127 int numberOfStrawsInLayersC[] = {23, 24, 24, 24, 24, 25, 25, 25, 25, 25, 26,
128 26, 26, 26, 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 29, 29, 29, 29, 28};
129
130 std::vector<int> ncol0 (std::begin(numberOfStrawsInLayersA),
131 std::end(numberOfStrawsInLayersA));
132 std::vector<int> ncol1 (std::begin(numberOfStrawsInLayersB),
133 std::end(numberOfStrawsInLayersB));
134 std::vector<int> ncol2 (std::begin(numberOfStrawsInLayersC),
135 std::end(numberOfStrawsInLayersC));
136
137 m_ncol.push_back(std::move(ncol0));
138 m_ncol.push_back(std::move(ncol1));
139 m_ncol.push_back(std::move(ncol2));
140
141 m_StrawsByModule[0] = 329;
142 m_StrawsByModule[1] = 520;
143 m_StrawsByModule[2] = 793;
144
145}
146
147
148 // Fill Tables with IDs for all straws
150{
151 // Reading mapping
152 // Important number for converter!!! Pay attention!!!
153 // Another side has Id = -1
154 int barrelId = -1;
155 int phiModuleId, moduleId, strawLayerId, strawInLayerId,
156 strawNumberInModule,BufferLocation;
157 Identifier strawID, IdLayer;
158 IdentifierHash hashId;
159
160 // Loop over two RODs (not PhiModules!)
161 for (int rod = 0; rod < m_numberOfIdentifierSectors; rod++ )
162 {
163 std::vector<Identifier> tempbuff;
164 std::vector<IdentifierHash> tempbuff2;
165 for (int i = 0; i < 8*13*16; i++){
166 Identifier id(0);
167 tempbuff.push_back(id);
168 tempbuff2.emplace_back(0);
169 }
170 m_cabling->zero_identifierForAllStraws(rod, tempbuff);
171 m_cabling->zero_identifierHashForAllStraws(rod, tempbuff2);
172
173 std::ostringstream ssFile;
174 ssFile << rod;
175 std::string dataFile = "TRT_TB04_IdMapping_ROD" + ssFile.str() + ".dat";
176
177 std::string file = PathResolver::find_file (dataFile, "DATAPATH");
178
179 std::ifstream inputFile (file.c_str());
180 if (!inputFile)
181 ATH_MSG_FATAL( "TRT_FillCablingData_TB04: Could not open file " << dataFile );
182
183 /*
184 * We now loop over all buffer locations
185 * Read-out order is:
186 * ROD 0: 3S1, 3S2 (Assumed: UB3S and DB3S)
187 * ROD 1+2: 3L2, 3L1, 2L2, 2S, 2L1, 1S, 1L
188 * Data-files have been assembled in that order
189 * The individual file is ordered first after board and then
190 * after buffer location
191 */
192
193
194 while(!inputFile.eof()){
195 /*
196 * Need to add moduleId to data file, as the absolute strawnumber
197 * is relative to the module layer
198 * Also add phiModuleId. This is the easiest.
199 */
200 inputFile >> phiModuleId >> moduleId >> strawNumberInModule
201 >> BufferLocation;
202
203 // Sanitize input from file
204 const bool validPhi = inRange(phiModuleId, invalidInput, maxPossiblePhiModule);
205 const bool validModule = inRange(moduleId, invalidInput, maxPossibleModule);
206 const bool validStrawNumber = inRange(strawNumberInModule, invalidInput, m_StrawsByModule[moduleId]);
207 //coverity[tainted_data]
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 */
311std::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 */
407std::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
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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
bool inRange(const double *boundaries, const double value, const double tolerance=0.02)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
This is a "hash" representation of an Identifier.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
static const InterfaceID & interfaceID()
std::vector< std::vector< int > > m_ncol
TRT_FillCablingData_TB04(const std::string &type, const std::string &name, const IInterface *parent)
void fillCollID(uint32_t rob_id, std::vector< IdentifierHash > &ids)
std::vector< uint32_t > getRobID(Identifier id) const
std::vector< uint32_t > m_phi_to_source
TFile * file