ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_ID.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
5#ifndef INDETIDENTIFIER_TRT_ID_H
6#define INDETIDENTIFIER_TRT_ID_H
18
20#include "Identifier/Identifier.h"
23#include "Identifier/IdHelper.h"
26
27#include <algorithm>
28#include <string>
29#include <map>
30#include <cassert>
31
32
34
80
81class TRT_ID final: public AtlasDetectorID
82{
83public:
85
86 typedef Identifier::size_type size_type;
87 typedef std::vector<Identifier>::const_iterator const_id_iterator;
90
92
93 TRT_ID();
96
98
99 bool is_valid() const;
101
103
104
106 Identifier barrel_ec_id(int barrel_ec, bool checks) const;
107
110 int phi_module,
111 int layer_or_wheel) const;
113 int phi_module,
114 int layer_or_wheel,
115 bool checks) const;
116
119
122 int phi_module,
123 int layer_or_wheel,
124 int straw_layer) const;
126 int phi_module,
127 int layer_or_wheel,
128 int straw_layer,
129 bool checks) const;
130
133
136 int straw_layer) const;
138 int straw_layer,
139 bool checks) const;
140
143
146 int phi_module,
147 int layer_or_wheel,
148 int straw_layer,
149 int straw) const;
151 int phi_module,
152 int layer_or_wheel,
153 int straw_layer,
154 int straw,
155 bool checks) const;
156
158 int straw_layer,
159 int straw) const;
161 int straw_layer,
162 int straw,
163 bool checks) const;
164
166 int straw) const;
168 int straw,
169 bool checks) const;
170
175
177
178
183
185
190
191
193
194
205
207
208
210
212 IdentifierHash straw_layer_hash(Identifier straw_layer_id) const;
213
216
218 bool is_barrel(const Identifier& id) const;
219
221 int barrel_ec(const Identifier& id) const;
222 int phi_module(const Identifier& id) const;
223 int layer_or_wheel(const Identifier& id) const;
224 int straw_layer(const Identifier& id) const;
225 int straw(const Identifier& id) const;
226
228 int straw_layer_max(const Identifier& id) const;
229 int straw_max(const Identifier& id) const;
231
232
234
235
242 IdContext straw_context() const;
244
245
247
248
249 virtual int get_id(const IdentifierHash& hash_id,
250 Identifier& id,
251 const IdContext* context = 0) const override final;
252
254 virtual int get_hash(const Identifier& id,
255 IdentifierHash& hash_id,
256 const IdContext* context = 0) const override final;
258
260
261
265
266
267
269 virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr) override final;
270
273 IdentifierHash& hash_id) const;
274
275
278 ExpandedIdentifier& exp_id,
279 const IdContext* context = 0) const;
280
282 void test_trt_ids();
284
285
289private:
290 typedef std::vector<Identifier> hash_vec;
291 typedef hash_vec::const_iterator hash_vec_it;
292
293 enum VALUES {
295 };
296
297 void barrel_ec_id_checks(int barrel_ec) const;
299 int phi_module,
300 int layer_or_wheel) const;
301 void straw_id_checks(int barrel_ec,
302 int phi_module,
303 int layer_or_wheel,
304 int straw_layer,
305 int straw) const;
306 void layer_id_checks(int barrel_ec,
307 int phi_module,
308 int layer_or_wheel,
309 int straw_layer) const;
310
311 int initLevelsFromDict();
312
313 void init_hashes();
314 // Private access only for hash from binary search - must have
315 // done init_straw_hashes for this to work
317
318 // print out the invalid message
319 void invalidMessage() const;
320
341
360
361 typedef std::pair<unsigned int, unsigned int> intPair;
362 typedef std::map<IdentifierHash, HashCalc> hashCalcMap;
363 std::vector<HashCalc> m_hash_calcs;
364 std::vector<intPair> m_hash_calcs_barrel_indexes;
365 std::vector<intPair> m_hash_calcs_endcap_indexes;
366
374};
375
376
377
378//using the macros below we can assign an identifier (and a version)
379//This is required and checked at compile time when you try to record/retrieve
380CLASS_DEF(TRT_ID, 2518, 1)
381
382
383//----------------------------------------------------------------------------
384inline bool
385TRT_ID::is_valid() const {
386 return(m_is_valid);
387}
388
389//----------------------------------------------------------------------------
390inline Identifier
391TRT_ID::barrel_ec_id(int barrel_ec, bool checks) const {
392 // Check if TRT_ID is valid for this layout
394
395 // Build identifier
396 Identifier result((Identifier::value_type) 0);
397
398 // Pack fields independently
402
403 if (checks) {
405 }
406
407 return result;
408}
409
410inline Identifier
414
415//----------------------------------------------------------------------------
416inline Identifier
418 int phi_module,
419 int layer_or_wheel,
420 bool checks) const {
421 // Check if TRT_ID is valid for this layout
423
424 // Build identifier
425 Identifier result((Identifier::value_type) 0);
426
427 // Pack fields independently
433
434 if (checks) {
436 }
437
438 return result;
439}
440
441inline Identifier
447
448//----------------------------------------------------------------------------
449inline Identifier
451 // Check if TRT_ID is valid for this layout
453
454 return(m_module_vec[module_hash]);
455}
456
457//----------------------------------------------------------------------------
459 // Check if TRT_ID is valid for this layout
461
462 return(m_straw_layer_vec[layer_hash]);
463}
464
465//----------------------------------------------------------------------------
466inline Identifier
468 int phi_module,
469 int layer_or_wheel,
470 int straw_layer,
471 bool checks) const {
472 // Check if TRT_ID is valid for this layout
474
475 // Build identifier
476 Identifier result((Identifier::value_type) 0);
477
478 // Pack fields independently
485
486 if (checks) {
488 }
489
490 return result;
491}
492
493inline Identifier
501
502//----------------------------------------------------------------------------
503inline Identifier
505 int straw_layer,
506 bool checks) const {
507 // Check if TRT_ID is valid for this layout
509
510 // Build identifier
512
513 // Reset field and then pack it
514 m_str_lay_impl.reset(result);
516
517 if (checks) {
522 }
523 return result;
524}
525
526inline Identifier
531
532//----------------------------------------------------------------------------
533inline Identifier
535 // Check if TRT_ID is valid for this layout
537
539 // Reset the straw field
540 m_straw_impl.reset(result);
541 return(result);
542}
543
544//----------------------------------------------------------------------------
545inline Identifier
547 int phi_module,
548 int layer_or_wheel,
549 int straw_layer,
550 int straw,
551 bool checks) const {
552 // Check if TRT_ID is valid for this layout
554
555 // Build identifier
556 Identifier result((Identifier::value_type) 0);
557
558 // Pack fields independently
566
567 if (checks) {
569 }
570
571 return result;
572}
573
574inline Identifier
576 int phi_module,
577 int layer_or_wheel,
578 int straw_layer,
579 int straw) const {
581 do_checks());
582}
583
584//----------------------------------------------------------------------------
585inline Identifier
587 int straw_layer,
588 int straw,
589 bool checks) const {
590 // Check if TRT_ID is valid for this layout
592
593 // Build identifier
595
596 // Reset fields and then pack them
597 m_str_lay_impl.reset(result);
598 m_straw_impl.reset(result);
601
602 if (checks) {
607 straw);
608 }
609 return result;
610}
611
612inline Identifier
614 int straw_layer,
615 int straw) const {
617}
618
619//----------------------------------------------------------------------------
620inline Identifier
622 int straw,
623 bool checks) const {
624 // Check if TRT_ID is valid for this layout
626
627 // Build identifier
629
630 // Reset field and then pack it
631 m_straw_impl.reset(result);
633
634 if (checks) {
639 straw);
640 }
641 return result;
642}
643
644inline Identifier
646 int straw) const {
647 return straw_id(layer_id, straw, do_checks());
648}
649
650//----------------------------------------------------------------------------
651inline Identifier
653 // Check if TRT_ID is valid for this layout
655
656
657 // Access id from vector ONLY if the vector has been initialized
658 // (done via init_straw_hash_vector();
659 // and reset by reset_straw_hash_vector();
660 if (straw_hash < m_straw_vec.size()) {
661 return(m_straw_vec[straw_hash]);
662 }
663 // Else return invalid id
665 return(result); // return hash in invalid state
666}
667
668//----------------------------------------------------------------------------
670 // Check if TRT_ID is valid for this layout
672
673 hash_vec_it it = std::lower_bound(m_module_vec.begin(),
674 m_module_vec.end(),
675 module_id);
676 // Require that module_id matches the one in vector
677 if (it != m_module_vec.end() && module_id == (*it)) {
678 return(it - m_module_vec.begin());
679 }
681 return(result); // return hash in invalid state
682}
683
684//----------------------------------------------------------------------------
685inline
688 // Check if TRT_ID is valid for this layout
690
691 hash_vec_it it = std::lower_bound(m_straw_layer_vec.begin(),
692 m_straw_layer_vec.end(),
693 straw_layer_id);
694 // Require that straw_layer_id matches the one in vector
695 if (it != m_straw_layer_vec.end() && straw_layer_id == (*it)) {
696 return(it - m_straw_layer_vec.begin());
697 }
699 return(result); // return hash in invalid state
700}
701
702//----------------------------------------------------------------------------
703inline
706//TRT_ID::straw_hash (Identifier straw_id, bool debug) const
707{
708 // Check if TRT_ID is valid for this layout
710
711 // Get index into hashCalc vector
712 unsigned int hcIndex = 0;
713 int be = barrel_ec(straw_id);
714 int lw = layer_or_wheel(straw_id);
715 int sl = straw_layer(straw_id);
716
717 if (is_barrel(straw_id)) {
718 unsigned int index = lw * 32 + sl;
719 if (index < m_hash_calcs_barrel_indexes.size()) {
720 hcIndex = (be < 0) ? m_hash_calcs_barrel_indexes[index].first :
722 } else {
723 std::cout << "straw_hash: index > barrel_index size - " << index
724 << " " << m_hash_calcs_barrel_indexes.size() << std::endl;
725 }
726 } else {
727 unsigned int index = lw;
728 if (index < m_hash_calcs_endcap_indexes.size()) {
729 hcIndex = (be < 0) ? m_hash_calcs_endcap_indexes[index].first :
731 } else {
732 std::cout << "straw_hash: index > endcap_index size - " << index
733 << " " << m_hash_calcs_endcap_indexes.size() << std::endl;
734 }
735 }
736
737
738
740 if (hcIndex < m_hash_calcs.size()) {
741 const HashCalc& hc = m_hash_calcs[hcIndex];
742 result = hc.m_hash +
744 (lw - hc.m_layerMin) * hc.m_nStrawLayers +
745 (sl - hc.m_strLayerMin) * hc.m_nstraws +
747
748
749 return(result);
750 } else {
751 std::cout << "straw_hash: hc index > hcCalc size - " << hcIndex
752 << " " << m_hash_calcs.size() << std::endl;
753 }
754 return(result);
755}
756
757//----------------------------------------------------------------------------
758inline
761 // Check if TRT_ID is valid for this layout
763
764 hash_vec_it it = std::lower_bound(m_straw_vec.begin(),
765 m_straw_vec.end(),
766 straw_id);
767
768
769
770 if (it != m_straw_vec.end()) {
771 return(it - m_straw_vec.begin());
772 }
774 return(result); // return hash in invalid state
775}
776
777//----------------------------------------------------------------------------
778inline
779void
781
782 ATH_MSG_ERROR(" TRT_ID is NOT valid for this layout. ");
783 ATH_MSG_ERROR(" Please use 'trt_id->is_valid()' if a layout test is needed. ");
784}
785
786//----------------------------------------------------------------------------
787inline bool
789 // Check if TRT_ID is valid for this layout
791
792 return(m_barrel_field.match(m_bec_impl.unpack(id)));
793}
794
795//----------------------------------------------------------------------------
796inline int
798 // Check if TRT_ID is valid for this layout
800
801 return(m_bec_impl.unpack(id));
802}
803
804//----------------------------------------------------------------------------
805inline int
807 // Check if TRT_ID is valid for this layout
809
810 return(m_phi_mod_impl.unpack(id));
811}
812
813//----------------------------------------------------------------------------
814inline int
816 // Check if TRT_ID is valid for this layout
818
819 return(m_lay_wheel_impl.unpack(id));
820}
821
822//----------------------------------------------------------------------------
823inline int
825 // Check if TRT_ID is valid for this layout
827
828 return(m_str_lay_impl.unpack(id));
829}
830
831//----------------------------------------------------------------------------
832inline int
833TRT_ID::straw(const Identifier& id) const {
834 // Check if TRT_ID is valid for this layout
836
837 return(m_straw_impl.unpack(id));
838}
839
840//----------------------------------------------------------------------------
843 // Check if TRT_ID is valid for this layout
845
846 return m_module_hash_max;
847}
848
849//----------------------------------------------------------------------------
852 // Check if TRT_ID is valid for this layout
854
856}
857
858//----------------------------------------------------------------------------
861 // Check if TRT_ID is valid for this layout
863
864 return m_straw_hash_max;
865}
866
867//----------------------------------------------------------------------------
869 // Check if TRT_ID is valid for this layout
871
872 return(m_module_vec.begin());
873}
874
875//----------------------------------------------------------------------------
877 // Check if TRT_ID is valid for this layout
879
880 return(m_module_vec.end());
881}
882
883//----------------------------------------------------------------------------
885 // Check if TRT_ID is valid for this layout
887
888 return(m_straw_layer_vec.begin());
889}
890
891//----------------------------------------------------------------------------
893 // Check if TRT_ID is valid for this layout
895
896 return(m_straw_layer_vec.end());
897}
898
899//----------------------------------------------------------------------------
901 // Check if TRT_ID is valid for this layout
903
904 return(m_full_straw_range.factory_begin());
905}
906
907//----------------------------------------------------------------------------
909 // Check if TRT_ID is valid for this layout
911
912 return(m_full_straw_range.factory_end());
913}
914
915#endif // INDETIDENTIFIER_TRT_ID_H
#define ATH_MSG_ERROR(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
virtual bool do_checks(void) const override
Checks are performed by default in debug compilation and NOT in optimized compilation.
int trt_field_value() const
AtlasDetectorID(const std::string &name, const std::string &group)
int indet_field_value() const
Provide efficient access to individual field values, for subclass idhelpers.
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
This is a "hash" representation of an Identifier.
A MultiRange combines several Ranges.
Definition MultiRange.h:17
size_type m_nstraws
Definition TRT_ID.h:358
size_type m_strLayerMin
Definition TRT_ID.h:356
IdentifierHash m_hash
Definition TRT_ID.h:353
size_type m_layerMin
Definition TRT_ID.h:355
size_type m_deltaPhi
Definition TRT_ID.h:354
size_type m_nStrawLayers
Definition TRT_ID.h:357
This is an Identifier helper class for the TRT subdetector.
Definition TRT_ID.h:82
void barrel_ec_id_checks(int barrel_ec) const
Definition TRT_ID.cxx:50
size_type m_straw_layer_hash_max
Definition TRT_ID.h:335
int phi_module(const Identifier &id) const
Definition TRT_ID.h:806
std::vector< intPair > m_hash_calcs_barrel_indexes
Definition TRT_ID.h:364
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:494
IdDictFieldImplementation m_str_lay_impl
Definition TRT_ID.h:372
MODULE_RANGE
Definition TRT_ID.h:286
@ NUMBER_OF_EC_MODULES
Definition TRT_ID.h:287
int straw_max(const Identifier &id) const
Definition TRT_ID.cxx:760
MultiRange::const_identifier_factory const_expanded_id_iterator
Definition TRT_ID.h:88
const_id_iterator module_begin() const
Iterators over full set of module ids. Module ids are sorted.
Definition TRT_ID.h:868
size_type m_PHI_MODULE_INDEX
Definition TRT_ID.h:326
MultiRange m_full_straw_layer_range
Definition TRT_ID.h:332
size_type straw_layer_hash_max() const
Definition TRT_ID.h:851
std::vector< intPair > m_hash_calcs_endcap_indexes
Definition TRT_ID.h:365
hash_vec m_module_vec
Definition TRT_ID.h:338
TRT_ID()
Definition TRT_ID.cxx:27
const_expanded_id_iterator straw_begin() const
For straw ids, only expanded id iterators are available.
Definition TRT_ID.h:900
IdentifierHash module_hash(Identifier module_id) const
module hash from id - optimized
Definition TRT_ID.h:669
void init_hashes()
Definition TRT_ID.cxx:245
IdContext straw_context() const
straw id
Definition TRT_ID.cxx:958
std::pair< unsigned int, unsigned int > intPair
Definition TRT_ID.h:361
IdDictFieldImplementation m_indet_impl
Definition TRT_ID.h:367
@ BARREL_VALUE
Definition TRT_ID.h:294
IdDictFieldImplementation m_phi_mod_impl
Definition TRT_ID.h:370
const_id_iterator module_end() const
Definition TRT_ID.h:876
IdDictFieldImplementation m_straw_impl
Definition TRT_ID.h:373
IdDictFieldImplementation m_trt_impl
Definition TRT_ID.h:368
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:705
size_type m_BARREL_EC_INDEX
Definition TRT_ID.h:325
size_type m_module_hash_max
Definition TRT_ID.h:334
void layer_id_checks(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer) const
Definition TRT_ID.cxx:106
std::map< IdentifierHash, HashCalc > hashCalcMap
Definition TRT_ID.h:362
MultiRange m_full_module_range
Definition TRT_ID.h:333
void test_trt_ids()
Tests of packing.
Definition TRT_ID.cxx:779
bool is_barrel(const Identifier &id) const
Test for barrel.
Definition TRT_ID.h:788
void invalidMessage() const
Definition TRT_ID.h:780
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:575
int straw_layer_max(const Identifier &id) const
Max values for each field (-999 == failure)
Definition TRT_ID.cxx:739
std::vector< Identifier > hash_vec
Definition TRT_ID.h:290
size_type m_trt_region_index
Definition TRT_ID.h:322
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition TRT_ID.h:797
size_type m_TRT_INDEX
Definition TRT_ID.h:324
IdentifierHash straw_layer_hash(Identifier straw_layer_id) const
straw_layer hash from id - optimized
Definition TRT_ID.h:687
Identifier module_id(int barrel_ec, int phi_module, int layer_or_wheel) const
For an individual module phi sector.
Definition TRT_ID.h:442
size_type m_STRAW_INDEX
Definition TRT_ID.h:329
hash_vec m_straw_vec
Definition TRT_ID.h:340
const IdDictDictionary * m_dict
Definition TRT_ID.h:330
MultiRange m_full_straw_range
Definition TRT_ID.h:331
bool is_valid() const
Definition TRT_ID.h:385
IdContext straw_layer_context() const
straw_layer id
Definition TRT_ID.cxx:948
void module_id_checks(int barrel_ec, int phi_module, int layer_or_wheel) const
Definition TRT_ID.cxx:66
int get_straw_layer_hash_calc(const ExpandedIdentifier &id, IdentifierHash &hash_id) const
Special method for timing tests.
Definition TRT_ID.cxx:648
size_type straw_hash_max() const
Definition TRT_ID.h:860
size_type m_STRAW_LAYER_INDEX
Definition TRT_ID.h:328
const_id_iterator straw_layer_end() const
Definition TRT_ID.h:892
Identifier::size_type size_type
Definition TRT_ID.h:86
int layer_or_wheel(const Identifier &id) const
Definition TRT_ID.h:815
IdContext module_context() const
module id
Definition TRT_ID.cxx:938
IdentifierHash straw_hash(Identifier straw_id) const
straw hash from id - optimized
Definition TRT_ID.h:705
int straw(const Identifier &id) const
Definition TRT_ID.h:833
int initLevelsFromDict()
Definition TRT_ID.cxx:531
size_type m_LAYER_OR_WHEEL_INDEX
Definition TRT_ID.h:327
IdDictFieldImplementation m_lay_wheel_impl
Definition TRT_ID.h:371
IdContext barrel_context() const
barrel_ec id
Definition TRT_ID.cxx:928
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override final
Set the IdDictionary.
Definition TRT_ID.cxx:128
size_type m_INDET_INDEX
Definition TRT_ID.h:323
std::vector< HashCalc > m_hash_calcs
Definition TRT_ID.h:363
bool m_is_valid
Definition TRT_ID.h:321
size_type m_straw_hash_max
Definition TRT_ID.h:336
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const override final
Create compact id from hash id (return == 0 for OK)
Definition TRT_ID.cxx:656
const_expanded_id_iterator straw_end() const
Definition TRT_ID.h:908
IdentifierHash straw_hash_bin(Identifier straw_id) const
Definition TRT_ID.h:760
void reset_straw_hash_vector()
Definition TRT_ID.cxx:476
IdDictFieldImplementation m_bec_impl
Definition TRT_ID.h:369
std::vector< Identifier >::const_iterator const_id_iterator
Definition TRT_ID.h:87
void straw_id_checks(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Definition TRT_ID.cxx:85
size_type module_hash_max() const
Definition TRT_ID.h:842
Range::field m_barrel_field
Definition TRT_ID.h:337
const_id_iterator straw_layer_begin() const
Iterators over full set of straw_layer ids. Straw_layer ids are sorted.
Definition TRT_ID.h:884
int straw_layer(const Identifier &id) const
Definition TRT_ID.h:824
hash_vec::const_iterator hash_vec_it
Definition TRT_ID.h:291
void init_straw_hash_vector()
The init will use up ~2 MB of memory, so one should do init, use straw_id and then reset.
Definition TRT_ID.cxx:481
hash_vec m_straw_layer_vec
Definition TRT_ID.h:339
void get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context=0) const
Definition TRT_ID.cxx:687
Identifier barrel_ec_id(int barrel_ec) const
For +/-barrel or +/-endcap id.
Definition TRT_ID.h:411
Definition index.py:1