ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_FillCablingData_SR1_ECC.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_SR1_ECC class
7// P.T. Keener
8//
9
10/*
11 * Assumptions:
12 * One side of the barrel is readout, namely side A
13 * We need to map between phi sector index used in the offline and
14 * the Source IDs programmed in the hardware.
15 *
16 * The m_identifier* and m_collID vectors are indexed by ROB source ID - 1.
17 * The magic mapping between ROB source IDs and phi sector indices is in
18 * getRobID() and in fillCollID(). Everything else should just fall
19 * through and gets the Right Answer.
20 */
21
22//#include <stdio.h>
23
24//#include <iostream>
26#include <fstream>
27
28//#include <functional>
29//#include <algorithm>
30
31#include "eformat/SourceIdentifier.h" // change to new eformat v3
33
34
35
36using eformat::helper::SourceIdentifier;
37using namespace std;
38
39static
40bool greater_RG_GCM( const GlobalCableMap_t *a, const GlobalCableMap_t *b ),
42
43static const InterfaceID IID_ITRT_FillCablingData_SR1_ECC
44 ("TRT_FillCablingData_SR1_ECC", 1, 0);
45
46 // Constructor
47TRT_FillCablingData_SR1_ECC::TRT_FillCablingData_SR1_ECC( const std::string& type, const std::string&
48name,const IInterface* parent ): AthAlgTool(type,name,parent),
49 m_TRTHelper(nullptr)
50{
51 declareInterface< TRT_FillCablingData_SR1_ECC >( this );
52}
53
54
55 // Destructor
58
59
62
63
64 // Initialisation
66{
67 ATH_MSG_INFO( "TRT_FillCablingData_SR1_ECC::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
78
80
81
85
86 ATH_MSG_INFO( "TRT_FillCablingData_SR1_ECC::initializiation finished" );
87
88 return StatusCode::SUCCESS;
89}
90
91
93{
94 delete m_cabling;
95
96 StatusCode sc = AlgTool::finalize();
97 return sc;
98}
99
100
105
106
108{
109 m_numberOfRings = 3;
110
114
115 // m_numberOfStrawsInBarrelROD = 1642;
117
118 // Mapping from phi sector index to source id
119 //m_phi_to_source.push_back( 2 ); // Phi 0 is Source ID 0x3102
120 //m_phi_to_source.push_back( 3 ); // Phi 1 is Source ID 0x3103
121 // m_phi_to_source.push_back( 3 ); // Phi 0 is Source ID 0x3103
122 // m_phi_to_source.push_back( 2 ); // Phi 1 is Source ID 0x3102
123 // NB: Source ID 0x3101 is the 3S boards on BOTH Phi 0 and Phi 1
124
125
126 int tmpArray[] = {15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, // Module Type 1
127 18, 18, 18, 18, 19, 19, 19, 18, // Module Type 1
128 19, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, // Module Type 2
129 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 24, 24, 23, // Module Type 2
130 23, 24, 24, 24, 24, 25, 25, 25, 25, 25, 26, // Module Type 3
131 26, 26, 26, 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, // Module Type 3
132 28, 29, 29, 29, 29, 28, -1}; // Module Type 3
133
134 int i=0;
135 int RunningCount=0;
136 while( -1 != tmpArray[i] )
137 {
138 RunningCount += tmpArray[i];
139 m_numberOfStrawsInLayers.push_back( RunningCount );
140
141 i++;
142 }
143 m_numberOfStrawsInLayers.push_back( -1 );
144
145 return;
146}
147
148
149 // Fill Tables with IDs for all straws
151{
152 ATH_MSG_INFO( "In defineTables" );
153
154
155
156 // Reading mapping
157 int moduleId, strawLayerId, strawInLayerId;
158 Identifier strawID;
159 IdentifierHash hashId;
160
161 uint32_t strawNumber, bufferOffset;
162 string thisLine;
163
164 std::string dataFile;
165 std::string file;
166
167 std::ifstream *inputFile;
168
169 /**************************************************************/
170 /* Endcap Connector Tables */
171 /**************************************************************/
172
173 /*
174 * We assume the data look like:
175
176 group 3
177 group 2
178 group 1
179 group 0
180
181 and within each group (444 words):
182
183 <DTMROC head 25> <DTMROC head 24> ... <DTMROC head 13>
184 <start word>
185 <DTMROC 25, chan 15> <DTMROC 24, chan 16> ... <DTMROC 13, chan 16>
186 <DTMROC 25, chan 14> <DTMROC 24, chan 14> ... <DTMROC 13, chan 14>
187 ... ... ...
188 <DTMROC 25, chan 0> <DTMROC 24, chan 0> ... <DTMROC 13, chan 0>
189
190 <DTMROC head 12> <DTMROC head 11> ... <DTMROC head 0>
191 <start word>
192 <DTMROC 12, chan 15> <DTMROC 11, chan 16> ... <DTMROC 0, chan 16>
193 <DTMROC 12, chan 14> <DTMROC 11, chan 14> ... <DTMROC 0, chan 14>
194 ... ... ...
195 <DTMROC 12, chan 0> <DTMROC 11, chan 0> ... <DTMROC 0, chan 0>
196
197 */
198
199
200 /*
201 * Left sectors, layers 0-63
202 */
203 ATH_MSG_INFO( "defineTables: rod1l " );
204
205 dataFile = "TRT_SR1_ec_rod1l.dat";
206 file = PathResolver::find_file (dataFile, "DATAPATH");
207 inputFile = new std::ifstream( file.c_str() );
208
209 if (!inputFile->is_open())
210 {
211 ATH_MSG_FATAL( "TRT_FillCablingData_SR1_ECC: Could not open file " << dataFile );
212 }
213
214 while ( getline( *inputFile, thisLine ) )
215 {
216 int rodgroup, rodline, dtmchannel, strawlayer, strawnumber;
217
218 string::size_type loc = thisLine.find( '#' );
219 if ( loc != string::npos )
220 {
221 thisLine.replace( loc, thisLine.length(), 1, ' ' );
222
223 loc = thisLine.find_first_not_of( " \t" );
224 if ( loc == string::npos )
225 continue;
226 }
227
228 istringstream parse( thisLine );
229
230 parse >> rodgroup >> rodline >> dtmchannel >> strawlayer >> strawnumber;
231 // parse >> strawNumber >> bufferOffset;
232
233 /*
234 * HACK! We do not have a good straw numbering scheme for the endcap
235 * and we do not yet have enough info to produce a real offline
236 * identifier. So we make something up!
237 */
238
239 strawNumber = (strawlayer & 0xff) << 8 | (strawnumber & 0xff);
240
241 bufferOffset = ((3 - rodgroup) * 444) + 14;
242 if ( rodline > 12 )
243 {
244 bufferOffset += (25 - rodline) + ((dtmchannel) * 13);
245 }
246 else
247 {
248 bufferOffset += 222 + (12 - rodline) + ((dtmchannel) * 13);
249 }
250
251 m_ec_1l_map[bufferOffset] = strawNumber;
252 }
253
254 inputFile->close();
255
256
257 /*
258 * Left sectors, layers 64-95
259 */
260 ATH_MSG_INFO( "defineTables: rod2l " );
261
262 dataFile = "TRT_SR1_ec_rod2l.dat";
263 file = PathResolver::find_file (dataFile, "DATAPATH");
264 inputFile = new std::ifstream( file.c_str() );
265
266 if (!inputFile->is_open())
267 {
268 ATH_MSG_FATAL( "TRT_FillCablingData_SR1_ECC: Could not open file " << dataFile );
269 }
270
271 while ( getline( *inputFile, thisLine ) )
272 {
273 int rodgroup, rodline, dtmchannel, strawlayer, strawnumber;
274
275 string::size_type loc = thisLine.find( '#' );
276 if ( loc != string::npos )
277 {
278 thisLine.replace( loc, thisLine.length(), 1, ' ' );
279
280 loc = thisLine.find_first_not_of( " \t" );
281 if ( loc == string::npos )
282 continue;
283 }
284
285 istringstream parse( thisLine );
286
287 parse >> rodgroup >> rodline >> dtmchannel >> strawlayer >> strawnumber;
288 // parse >> strawNumber >> bufferOffset;
289
290 /*
291 * HACK! We do not have a good straw numbering scheme for the endcap
292 * and we do not yet have enough info to produce a real offline
293 * identifier. So we make something up!
294 */
295
296 strawNumber = (strawlayer & 0xff) << 8 | (strawnumber & 0xff);
297
298 bufferOffset = ((1 - rodgroup) * 444) + 14;
299 if ( rodline > 12 )
300 {
301 bufferOffset += (25 - rodline) + ((dtmchannel) * 13);
302 }
303 else
304 {
305 bufferOffset += 222 + (12 - rodline) + ((dtmchannel) * 13);
306 }
307
308 m_ec_2l_map[bufferOffset] = strawNumber;
309 }
310
311 inputFile->close();
312
313
314 /*
315 * Left sectors, layers 96-159
316 */
317 ATH_MSG_INFO( "defineTables: rod3l " );
318
319 dataFile = "TRT_SR1_ec_rod3l.dat";
320 file = PathResolver::find_file (dataFile, "DATAPATH");
321 inputFile = new std::ifstream( file.c_str() );
322
323 if (!inputFile->is_open())
324 {
325 ATH_MSG_FATAL( "TRT_FillCablingData_SR1_ECC: Could not open file " << dataFile );
326 }
327
328 while ( getline( *inputFile, thisLine ) )
329 {
330 int rodgroup, rodline, dtmchannel, strawlayer, strawnumber;
331
332 string::size_type loc = thisLine.find( '#' );
333 if ( loc != string::npos )
334 {
335 thisLine.replace( loc, thisLine.length(), 1, ' ' );
336
337 loc = thisLine.find_first_not_of( " \t" );
338 if ( loc == string::npos )
339 continue;
340 }
341
342 istringstream parse( thisLine );
343
344 parse >> rodgroup >> rodline >> dtmchannel >> strawlayer >> strawnumber;
345 // parse >> strawNumber >> bufferOffset;
346
347 /*
348 * HACK! We do not have a good straw numbering scheme for the endcap
349 * and we do not yet have enough info to produce a real offline
350 * identifier. So we make something up!
351 */
352
353 strawNumber = (strawlayer & 0xff) << 8 | (strawnumber & 0xff);
354
355 bufferOffset = ((3 - rodgroup) * 444) + 14;
356 if ( rodline > 12 )
357 {
358 bufferOffset += (25 - rodline) + ((dtmchannel) * 13);
359 }
360 else
361 {
362 bufferOffset += 222 + (12 - rodline) + ((dtmchannel) * 13);
363 }
364
365 m_ec_3l_map[bufferOffset] = strawNumber;
366 }
367
368 inputFile->close();
369
370
371 /*
372 * Right sectors, layers 0-63
373 */
374 ATH_MSG_INFO( "defineTables: rod1r " );
375
376 dataFile = "TRT_SR1_ec_rod1r.dat";
377 file = PathResolver::find_file (dataFile, "DATAPATH");
378 inputFile = new std::ifstream( file.c_str() );
379
380 if (!inputFile->is_open())
381 {
382 ATH_MSG_FATAL( "TRT_FillCablingData_SR1_ECC: Could not open file " << dataFile );
383 }
384
385 while ( getline( *inputFile, thisLine ) )
386 {
387 int rodgroup, rodline, dtmchannel, strawlayer, strawnumber;
388
389 string::size_type loc = thisLine.find( '#' );
390 if ( loc != string::npos )
391 {
392 thisLine.replace( loc, thisLine.length(), 1, ' ' );
393
394 loc = thisLine.find_first_not_of( " \t" );
395 if ( loc == string::npos )
396 continue;
397 }
398
399 istringstream parse( thisLine );
400
401 parse >> rodgroup >> rodline >> dtmchannel >> strawlayer >> strawnumber;
402 // parse >> strawNumber >> bufferOffset;
403
404 /*
405 * HACK! We do not have a good straw numbering scheme for the endcap
406 * and we do not yet have enough info to produce a real offline
407 * identifier. So we make something up!
408 */
409
410 strawNumber = (strawlayer & 0xff) << 8 | (strawnumber & 0xff);
411
412 bufferOffset = ((3 - rodgroup) * 444) + 14;
413 if ( rodline > 12 )
414 {
415 bufferOffset += (25 - rodline) + ((dtmchannel) * 13);
416 }
417 else
418 {
419 bufferOffset += 222 + (12 - rodline) + ((dtmchannel) * 13);
420 }
421
422 m_ec_1r_map[bufferOffset] = strawNumber;
423 }
424
425 inputFile->close();
426
427
428 /*
429 * Right sectors, layers 64-95
430 */
431 ATH_MSG_INFO( "defineTables: rod2r " );
432
433 dataFile = "TRT_SR1_ec_rod2r.dat";
434 file = PathResolver::find_file (dataFile, "DATAPATH");
435 inputFile = new std::ifstream( file.c_str() );
436
437 if (!inputFile->is_open())
438 {
439 ATH_MSG_FATAL( "TRT_FillCablingData_SR1_ECC: Could not open file " << dataFile );
440 }
441
442 while ( getline( *inputFile, thisLine ) )
443 {
444 int rodgroup, rodline, dtmchannel, strawlayer, strawnumber;
445
446 string::size_type loc = thisLine.find( '#' );
447 if ( loc != string::npos )
448 {
449 thisLine.replace( loc, thisLine.length(), 1, ' ' );
450
451 loc = thisLine.find_first_not_of( " \t" );
452 if ( loc == string::npos )
453 continue;
454 }
455
456 istringstream parse( thisLine );
457
458 parse >> rodgroup >> rodline >> dtmchannel >> strawlayer >> strawnumber;
459 // parse >> strawNumber >> bufferOffset;
460
461 /*
462 * HACK! We do not have a good straw numbering scheme for the endcap
463 * and we do not yet have enough info to produce a real offline
464 * identifier. So we make something up!
465 */
466
467 strawNumber = (strawlayer & 0xff) << 8 | (strawnumber & 0xff);
468
469 bufferOffset = ((1 - rodgroup) * 444) + 14;
470 if ( rodline > 12 )
471 {
472 bufferOffset += (25 - rodline) + ((dtmchannel) * 13);
473 }
474 else
475 {
476 bufferOffset += 222 + (12 - rodline) + ((dtmchannel) * 13);
477 }
478
479 m_ec_2r_map[bufferOffset] = strawNumber;
480 }
481
482 inputFile->close();
483
484
485 /*
486 * Right sectors, layers 96-159
487 */
488 ATH_MSG_INFO( "defineTables: rod3r " );
489
490 dataFile = "TRT_SR1_ec_rod3r.dat";
491 file = PathResolver::find_file (dataFile, "DATAPATH");
492 inputFile = new std::ifstream( file.c_str() );
493
494 if (!inputFile->is_open())
495 {
496 ATH_MSG_FATAL( "TRT_FillCablingData_SR1_ECC: Could not open file " << dataFile );
497 }
498
499 while ( getline( *inputFile, thisLine ) )
500 {
501 int rodgroup, rodline, dtmchannel, strawlayer, strawnumber;
502
503 string::size_type loc = thisLine.find( '#' );
504 if ( loc != string::npos )
505 {
506 thisLine.replace( loc, thisLine.length(), 1, ' ' );
507
508 loc = thisLine.find_first_not_of( " \t" );
509 if ( loc == string::npos )
510 continue;
511 }
512
513 istringstream parse( thisLine );
514
515 parse >> rodgroup >> rodline >> dtmchannel >> strawlayer >> strawnumber;
516 // parse >> strawNumber >> bufferOffset;
517
518 /*
519 * HACK! We do not have a good straw numbering scheme for the endcap
520 * and we do not yet have enough info to produce a real offline
521 * identifier. So we make something up!
522 */
523
524 strawNumber = (strawlayer & 0xff) << 8 | (strawnumber & 0xff);
525
526 bufferOffset = ((3 - rodgroup) * 444) + 14;
527 if ( rodline > 12 )
528 {
529 bufferOffset += (25 - rodline) + ((dtmchannel) * 13);
530 }
531 else
532 {
533 bufferOffset += 222 + (12 - rodline) + ((dtmchannel) * 13);
534 }
535
536 m_ec_3r_map[bufferOffset] = strawNumber;
537 }
538
539 inputFile->close();
540
541 /**************************************************************/
542 /* Global Cabling Specification */
543 /**************************************************************/
544
545 ATH_MSG_INFO( "defineTables: Global Spec " );
546
547 dataFile = "TRT_SR1_EndcapC_Cable_map.dat";
548
549
550 file = PathResolver::find_file (dataFile, "DATAPATH");
551 inputFile = new std::ifstream( file.c_str() );
552
553 if (!inputFile->is_open())
554 {
555 ATH_MSG_FATAL( "TRT_FillCablingData_SR1_ECC: Could not open file " << dataFile );
556 }
557
558 uint32_t srcId;
559 std::string feId;
560
561 while ( getline( *inputFile, thisLine ) )
562 {
563 if ( thisLine.length() == 0 )
564 continue;
565
566 string::size_type loc = thisLine.find( '#' );
567 if ( loc != string::npos )
568 {
569 thisLine.replace( loc, thisLine.length(), 1, ' ' );
570
571 loc = thisLine.find_first_not_of( " \t" );
572 if ( loc == string::npos )
573 continue;
574 }
575
576
577 istringstream parse( thisLine );
578
580
581 parse >> (hex) >> srcId >> (dec) >> my_map->Phi >> my_map->RODGroup >> my_map->FEid;
582
583
584 // int this_phi; // set but not used
585
586 if ( (srcId & 0xFF0000) == 0x310000 )
587 {
588 my_map->SubDet = 1;
589 // this_phi = my_map->Phi; // set but not used
590 }
591 else if ( (srcId & 0xFF0000) == 0x320000 )
592 {
593 my_map->SubDet = -1;
594 // this_phi = -my_map->Phi; // set but not used
595 }
596 else if ( (srcId & 0xFF0000) == 0x330000 )
597 {
598 my_map->SubDet = 2;
599 // this_phi = my_map->Phi; // set but not used
600 }
601 else if ( (srcId & 0xFF0000) == 0x340000 )
602 {
603 my_map->SubDet = -2;
604 // this_phi = -my_map->Phi; // set but not used
605 }
606 else {
607 ATH_MSG_FATAL( "TRT_FillCablingData_SR1_ECC: Invalid source id " << (hex) << srcId << (dec) );
608 my_map->SubDet = 0;
609 }
610
611
612 /*
613 * my_phi is
614 32 - 63 for +barrel
615 64 - 95 for +end cap
616 -32 - -63 for -barrel
617 -64 - -95 for -end cap
618 */
619
620
621 // int my_phi = my_map->Phi * my_map->SubDet;
622 int my_phi = my_map->SubDet * 32 + my_map->Phi;
623
624
625 std::vector<uint32_t>::iterator it = (m_phi_to_source[my_phi]).begin();
626 while ( (it != (m_phi_to_source[my_phi]).end()) && (srcId != *it) )
627 ++it;
628
629 if ( it == m_phi_to_source[my_phi].end() )
630 {
631 (m_phi_to_source[my_phi]).push_back( srcId );
632 }
633
634
635 (m_CableMap[srcId]).push_back( my_map );
636 }
637
638 inputFile->close();
639
640#ifdef NOTDEF
641 int ptk_i;
642 for ( ptk_i=1; ptk_i<=444; ptk_i++ )
643 {
644 std::map<int, int>::iterator map_it = m_1BS_1BL_map.find( ptk_i );
645 // if ( map_it != m_1BS_1BL_map.end() )
646 // cout << "Offset " << map_it->first << " is Straw " << map_it->second << endl;
647 }
648#endif // NOTDEF
649
650 GlobalCableMap::iterator pos;
651 for ( pos=m_CableMap.begin(); pos != m_CableMap.end(); ++pos )
652 {
653 std::vector< GlobalCableMap_t *> GCM;
654
655 GCM = pos->second;
656
657 sort( GCM.begin(), GCM.end(), greater_RG_GCM );
658
659 int ConnectorCount=-1;
660 std::vector< GlobalCableMap_t *>::iterator it;
661 for ( it=GCM.begin(); it != GCM.end(); ++it )
662 {
663 ConnectorCount++;
664
665 GlobalCableMap_t *my_map = *it;
666 std::map<int, int> con_map;
667
668
669 if ( my_map->FEid == "1BS_1BL" )
670 con_map = m_1BS_1BL_map;
671 else if ( my_map->FEid == "2BS_2BL1" )
672 con_map = m_2BS_2BL1_map;
673 else if ( my_map->FEid == "2BL2_3BL1" )
674 con_map = m_2BL2_3BL1_map;
675 else if ( my_map->FEid == "3BL2" )
676 con_map = m_3BL2_map;
677 else if ( my_map->FEid == "3BS" )
678 con_map = m_3BS_map;
679 else if ( my_map->FEid == "1FS_1FL" )
680 con_map = m_1FS_1FL_map;
681 else if ( my_map->FEid == "2FS_2FL1" )
682 con_map = m_2FS_2FL1_map;
683 else if ( my_map->FEid == "2FL2_3FL1" )
684 con_map = m_2FL2_3FL1_map;
685 else if ( my_map->FEid == "3FL2" )
686 con_map = m_3FL2_map;
687 else if ( my_map->FEid == "3FS" )
688 con_map = m_3FS_map;
689 else if ( my_map->FEid == "ec_rod1l" )
690 con_map = m_ec_1l_map;
691 else if ( my_map->FEid == "ec_rod2l" )
692 con_map = m_ec_2l_map;
693 else if ( my_map->FEid == "ec_rod3l" )
694 con_map = m_ec_3l_map;
695 else if ( my_map->FEid == "ec_rod1r" )
696 con_map = m_ec_1r_map;
697 else if ( my_map->FEid == "ec_rod2r" )
698 con_map = m_ec_2r_map;
699 else if ( my_map->FEid == "ec_rod3r" )
700 con_map = m_ec_3r_map;
701
702
703 int i;
704 Identifier NULLstrawID(0);
705
706 if ( abs( my_map->SubDet ) == 1 ) // barrel
707 {
708 for ( i=1; i<=444; i++ ) // loop over buffer offset
709 {
710 std::map<int, int>::iterator map_it = con_map.find( i );
711
712 if ( map_it == con_map.end() )
713 {
714 m_cabling->set_identifierForAllStraws( pos->first,
715 i + ConnectorCount*444,
716 NULLstrawID );
717 continue;
718 }
719
720 int BufferLocation = map_it->first + ConnectorCount*444;
721 int Straw = map_it->second - 1; // Offline starts at 0
722
723 strawLayerId = 0;
724 while ( (m_numberOfStrawsInLayers[strawLayerId] <= Straw) &&
725 (m_numberOfStrawsInLayers[strawLayerId] != -1) )
726 {
727 strawLayerId++;
728 }
729
730 if ( m_numberOfStrawsInLayers[strawLayerId] == -1)
731 {
732 ATH_MSG_WARNING( "Invalid Straw in table: " << Straw );
733 continue;
734 }
735
736
737 strawInLayerId = m_numberOfStrawsInLayers[strawLayerId] - Straw - 1;
738
739 moduleId = -1;
740 if ( strawLayerId < m_numberOfLayersA )
741 moduleId = 0;
742 else if ( strawLayerId < (m_numberOfLayersA + m_numberOfLayersB) )
743 {
744 moduleId = 1;
745 strawLayerId = strawLayerId - m_numberOfLayersA;
746 }
747 else if ( strawLayerId < (m_numberOfLayersA + m_numberOfLayersB + m_numberOfLayersC) )
748 {
749 moduleId = 2;
750 strawLayerId = strawLayerId - (m_numberOfLayersA + m_numberOfLayersB);
751 }
752
753
754
755 strawID = m_TRTHelper->straw_id( my_map->SubDet, my_map->Phi,
756 moduleId, strawLayerId,
757 strawInLayerId );
758
759
760 m_cabling->set_identifierForAllStraws( pos->first, BufferLocation,
761 strawID );
762
763
764 // IdLayer = m_TRTHelper->layer_id( strawID );
765
766 // int result = m_TRTHelper->get_hash( strawID, hashId, &m_cntx );
767
768 Identifier Lid = m_TRTHelper->layer_id( my_map->SubDet,
769 my_map->Phi, moduleId,
770 strawLayerId );
771
772 int result = m_TRTHelper->get_hash( Lid, hashId, &m_cntx );
773 if ( result != 0 )
774 {
775 ATH_MSG_WARNING( ">>>>>>>>>>> Get Hash FAILED! <<<<<<<<<<" );
776 ATH_MSG_WARNING( "Straw = " << Straw \
777 << " array = " << m_numberOfStrawsInLayers[strawLayerId] \
778 << " SubDet = " << my_map->SubDet \
779 << " Phi = " << my_map->Phi \
780 << " Module = " << moduleId \
781 << " Layer = " << strawLayerId \
782 << " StrInLay = " << strawInLayerId );
783 }
784
785
786 m_cabling->set_identifierHashForAllStraws( pos->first,
787 BufferLocation,
788 hashId );
789 }
790 }
791 else // Endcap
792 {
793 for ( i=0; i<1776; i++ ) // loop over buffer offset
794 {
795 std::map<int, int>::iterator map_it = con_map.find( i );
796
797 if ( map_it == con_map.end() )
798 {
799 m_cabling->set_identifierForAllStraws( pos->first, i,
800 NULLstrawID );
801 continue;
802 }
803
804 int BufferLocation = i;
805 int Straw = map_it->second; // Offline starts at 0
806
807 strawLayerId = (Straw >> 8) & 0xff;
808 strawInLayerId = Straw & 0xff;
809
810 moduleId = strawLayerId / 8;
811 if ( moduleId < 12 ) // A wheel?
812 {
813 moduleId = moduleId / 2;
814 strawLayerId = strawLayerId % 16;
815 }
816 else // B wheel
817 {
818 moduleId = moduleId - 6;
819 strawLayerId = strawLayerId % 8;
820 }
821
822
823 strawID = m_TRTHelper->straw_id( my_map->SubDet, my_map->Phi,
824 moduleId, strawLayerId,
825 strawInLayerId );
826
827
828 // Decode the identifier
829 // ExpandedIdentifier strawExpId;
830 // m_TRTHelper->get_expanded_id (strawID, strawExpId);
831 // ATH_MSG_INFO( "defineTables() - Identifier: "
832 // << std::left << std::setw(20) << std::string(strawExpId) << std::setw(0)
833 // << " robId: " << std::hex << pos->first << std::dec << " bufferOffset: " << BufferLocation );
834
835 // ATH_MSG_INFO( m_TRTHelper->print_to_string( strawID ) << " bufferOffset: " << BufferLocation );
836
837 m_cabling->set_identifierForAllStraws( pos->first, BufferLocation,
838 strawID );
839
840
841 // IdLayer = m_TRTHelper->layer_id( strawID );
842
843 // int result = m_TRTHelper->get_hash( strawID, hashId, &m_cntx );
844
845 Identifier Lid = m_TRTHelper->layer_id( my_map->SubDet,
846 my_map->Phi, moduleId,
847 strawLayerId );
848
849 int result = m_TRTHelper->get_hash( Lid, hashId, &m_cntx );
850 if ( result != 0 )
851 {
852 ATH_MSG_WARNING( ">>>>>>>>>>> Get Hash FAILED! <<<<<<<<<<" );
853
854 ATH_MSG_WARNING( "Straw = " << Straw \
855 << " SubDet = " << my_map->SubDet \
856 << " Phi = " << my_map->Phi \
857 << " Module = " << moduleId \
858 << " Layer = " << strawLayerId \
859 << " StrInLay = " << strawInLayerId );
860 }
861
862
863 m_cabling->set_identifierHashForAllStraws( pos->first,
864 BufferLocation,
865 hashId );
866 } // loop over bufferOffsets
867 } // Endcap
868 } // loop over GCM
869 } // loop over CableMap
870
871
872
873 ATH_MSG_INFO( "Out of defineTables" );
874
875 return;
876}
877
878/*
879 * Define map of collection IDs for all ROBs
880 */
882{
883
884 ATH_MSG_INFO( "In defineCollID()" );
885
886 GlobalCableMap::iterator pos;
887 for ( pos=m_CableMap.begin(); pos != m_CableMap.end(); ++pos )
888 {
889 std::vector<IdentifierHash> * vectID = new std::vector<IdentifierHash>();
890 fillCollID( pos->first, *vectID);
891
892 ATH_MSG_INFO( "Adding Collid for ROB " << std::hex << pos->first << std::dec );
893
894 m_cabling->add_collID( pos->first, vectID);
895 }
896
897 return;
898}
899
900
901/*
902 * Input: ROB Source ID
903 * Output: List of Hash IDs, one for each of 73 layers
904 */
906std::vector<IdentifierHash> & ids)
907{
908
909 IdentifierHash idHash;
910
911 // eformat::SubDetector det_id; // set but not used
912 // int module; // set but not used
913
914 eformat::helper::SourceIdentifier id (rob_id);
915 // det_id = id.subdetector_id(); // set but not used
916 // module = (int) id.module_id(); // set but not used
917
918
919 std::map<int, std::vector<GlobalCableMap_t *> >::iterator map_it = m_CableMap.find( rob_id );
920 if ( map_it == m_CableMap.end() )
921 {
922 ATH_MSG_FATAL( "fillCollID: Unable to get CableMap for rob_id " << std::hex << rob_id << std::dec );
923 return;
924 }
925
926 std::vector< GlobalCableMap_t *> GCM = map_it->second;
927
928 sort( GCM.begin(), GCM.end(), greater_Phi_GCM );
929
930 std::vector<GlobalCableMap_t *>::iterator it;
931
932
933 it=GCM.begin();
934 while ( it != GCM.end() )
935 {
936 GlobalCableMap_t *my_map = *it;
937 int rings = 0;
938 int phi = my_map->Phi;
939 int barrelId = my_map->SubDet;
940
941 if ( abs( barrelId ) == 1 ) // barrel?
942 {
943
944 bool done = !((my_map->SubDet == barrelId) && (my_map->Phi == phi));
945 while ( !done && (it != GCM.end()) )
946 {
947
948
949 if ( (my_map->FEid == "1BS_1BL") || (my_map->FEid == "1FS_1FL") )
950 rings |= 1;
951 else if ( (my_map->FEid == "2BS_2BL1") || (my_map->FEid == "2FS_2FL1") )
952 rings |= 2;
953 else if ( (my_map->FEid == "2BL2_3BL1") || (my_map->FEid == "2FL2_3FL1") )
954 rings |= 3;
955 else if ( (my_map->FEid == "3BL2") || (my_map->FEid == "3BS") ||
956 (my_map->FEid == "3FL2") || (my_map->FEid == "3FS") )
957 rings |= 4;
958
959 ++it;
960
961 if ( it != GCM.end() )
962 {
963 my_map = *it;
964 done = !((my_map->SubDet == barrelId) && (my_map->Phi == phi));
965 }
966
967 }
968
969
970 int phiModule = phi;
971
972 for (int ring = 0; ring < m_numberOfRings; ++ring)
973 {
974 if ( (ring == 0) && ((1<<ring) & rings) ) // Module Type 1
975 {
976 for (int layer = 0; layer < m_numberOfLayersA; ++layer)
977 {
978 Identifier id = m_TRTHelper->layer_id(barrelId, phiModule,
979 ring, layer);
980
981 if (!m_TRTHelper->get_hash(id, idHash, &m_cntx))
982 {
983 ids.push_back(idHash);
984 }
985 else
986 ATH_MSG_FATAL( " Unable to get hash for id " << m_TRTHelper->show_to_string(id) );
987 }
988 }
989 else if ( (ring == 1) && ((1<<ring) & rings) ) // Module Type 2
990 {
991 for (int layer = 0; layer < m_numberOfLayersB; ++layer)
992 {
993 Identifier id = m_TRTHelper->layer_id(barrelId, phiModule,
994 ring, layer);
995
996 if (!m_TRTHelper->get_hash(id, idHash, &m_cntx))
997 {
998 ids.push_back(idHash);
999 }
1000 else
1001 ATH_MSG_FATAL( " Unable to get hash for id " << m_TRTHelper->show_to_string(id) );
1002 }
1003 }
1004 else if ( (ring == 2) && ((1<<ring) & rings) ) // Module Type 3
1005 {
1006 for (int layer = 0; layer < m_numberOfLayersC; ++layer)
1007 {
1008 Identifier id = m_TRTHelper->layer_id(barrelId, phiModule,
1009 ring, layer);
1010
1011 if (!m_TRTHelper->get_hash(id, idHash, &m_cntx))
1012 {
1013 ids.push_back(idHash);
1014 }
1015 else
1016 ATH_MSG_FATAL( " Unable to get hash for id " << m_TRTHelper->show_to_string(id) );
1017
1018 }
1019 }
1020 }
1021 }
1022 else // End cap
1023 {
1024 int StartWheel=0;
1025 int EndWheel=0;
1026 int StartLayer=0;
1027 int EndLayer=0;
1028
1029 int phiModule = phi;
1030
1031 bool done = !((my_map->SubDet == barrelId) && (my_map->Phi == phi));
1032 while ( !done && (it != GCM.end()) )
1033 {
1034
1035 if ( (my_map->FEid == "ec_rod1l") ||
1036 (my_map->FEid == "ec_rod1r") )
1037 {
1038 StartWheel = 0;
1039 EndWheel = 4;
1040 StartLayer = 0;
1041 EndLayer = 16;
1042 }
1043 else if ( (my_map->FEid == "ec_rod2l") ||
1044 (my_map->FEid == "ec_rod2r") )
1045 {
1046 StartWheel = 4;
1047 EndWheel = 6;
1048 StartLayer = 0;
1049 EndLayer = 16;
1050 }
1051 else if ( (my_map->FEid == "ec_rod3l") ||
1052 (my_map->FEid == "ec_rod3r") )
1053 {
1054 StartWheel = 6;
1055 EndWheel = 14;
1056 StartLayer = 0;
1057 EndLayer = 8;
1058 }
1059 else
1060 {
1061 ATH_MSG_ERROR( "Invalid my_map->FEid. This should not happen!" );
1062 return;
1063 }
1064
1065 ++it;
1066
1067 if ( it != GCM.end() )
1068 {
1069 my_map = *it;
1070 done = !((my_map->SubDet == barrelId) && (my_map->Phi == phi));
1071 }
1072
1073 }
1074
1075
1076 for (int wheel = StartWheel; wheel < EndWheel; wheel++ )
1077 {
1078 for (int layer = StartLayer; layer < EndLayer; layer++ )
1079 {
1080 Identifier id = m_TRTHelper->layer_id( barrelId, phiModule,
1081 wheel, layer);
1082
1083 if (!m_TRTHelper->get_hash(id, idHash, &m_cntx))
1084 {
1085 ids.push_back(idHash);
1086 }
1087 else
1088 ATH_MSG_FATAL( " Unable to get hash for id " << m_TRTHelper->show_to_string(id) );
1089 } // loop over layer
1090 } // loop over wheel
1091 } // endcap
1092 }
1093
1094 return;
1095}
1096
1097/*
1098 * Get ROBIDs for each Detector Element (Straw Layer)
1099 *
1100 * Input : Straw ID
1101 * Output: list of ROB Source IDs
1102 */
1104{
1105 std::vector<uint32_t> v;
1106
1107
1108 int id_barrel_ec = m_TRTHelper->barrel_ec(id);
1109 int id_phi_module = m_TRTHelper->phi_module(id);
1110 //int id_layer = m_TRTHelper->layer_or_wheel(id);
1111
1112 /*
1113 * It seems to be assumed that the ROD/ROB source IDs are aligned to
1114 * the phi sector numbering. This is NOT the case for SR1, so we
1115 * need to fix it up.
1116 * In addition, for Module type 3 (ie, layer 2), we need to read out
1117 * the ROB with the 3S boards (number 1), as well as the ROB with
1118 * the rest of the sector.
1119 * We assume only one side here.
1120 */
1121
1122 id_phi_module = id_phi_module + 32 * id_barrel_ec;
1123
1124 const auto& it = m_phi_to_source.find (id_phi_module);
1125 if (it != m_phi_to_source.end()) {
1126 for (uint32_t thisId : it->second) {
1127 eformat::helper::SourceIdentifier sid( thisId );
1128 v.push_back(sid.code());
1129 }
1130 }
1131
1132 return v;
1133}
1134
1135
1136
1137/*
1138 * Sort Global Cable Map by ROD Group
1139 */
1140static
1142{
1143 return ( a->RODGroup > b->RODGroup );
1144}
1145
1146/*
1147 * Sort Global Cable Map by phi
1148 */
1149static
1151{
1152 return ( a->Phi > b->Phi );
1153}
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
static Double_t a
static Double_t sc
static bool greater_RG_GCM(const GlobalCableMap_t *a, const GlobalCableMap_t *b)
static bool greater_Phi_GCM(const GlobalCableMap_t *a, const GlobalCableMap_t *b)
static bool greater_RG_GCM(const GlobalCableMap_t *a, const GlobalCableMap_t *b)
static bool greater_Phi_GCM(const GlobalCableMap_t *a, const GlobalCableMap_t *b)
static const InterfaceID IID_ITRT_FillCablingData_SR1_ECC("TRT_FillCablingData_SR1_ECC", 1, 0)
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()
void fillCollID(uint32_t rob_id, std::vector< IdentifierHash > &ids)
TRT_FillCablingData_SR1_ECC(const std::string &type, const std::string &name, const IInterface *parent)
std::vector< uint32_t > getRobID(Identifier id) const
std::map< int, std::vector< uint32_t > > m_phi_to_source
std::map< std::string, std::string > parse(const std::string &list)
STL namespace.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TFile * file