00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef DETECTORDESCRIPTION_MUONIDHELPER_H
00011 #define DETECTORDESCRIPTION_MUONIDHELPER_H
00012
00013
00014
00015 #include "AtlasDetDescr/AtlasDetectorID.h"
00016 #include "Identifier/IdentifierHash.h"
00017 #include "IdDict/IdDictFieldImplementation.h"
00018 #include "IdDict/IdDictDefs.h"
00019 #include "Identifier/Range.h"
00020 #include "Identifier/IdHelper.h"
00021 #include "CLIDSvc/CLASS_DEF.h"
00022
00023 #include <cassert>
00024 #include <string>
00025 #include <vector>
00026 #include <set>
00027 #include <stdexcept>
00028
00029 class IdDictDictionary;
00030 class IMessageSvc;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 class MuonIdHelper : public AtlasDetectorID
00089 {
00090 public:
00091
00092
00093
00094 MuonIdHelper();
00095
00096
00097
00098 virtual ~MuonIdHelper();
00099
00100
00101
00102 Identifier muon() const;
00103
00104
00105
00106 bool is_muon(const Identifier& id) const;
00107 bool is_mdt (const Identifier& id) const;
00108 bool is_csc (const Identifier& id) const;
00109 bool is_rpc (const Identifier& id) const;
00110 bool is_tgc (const Identifier& id) const;
00111
00112
00113 bool is_stgc (const Identifier& id) const;
00114 bool is_mm (const Identifier& id) const;
00115
00116
00117
00118 int stationName(const Identifier& id) const;
00119 int stationEta (const Identifier& id) const;
00120 int stationPhi (const Identifier& id) const;
00121 int technology (const Identifier& id) const;
00122
00123
00124
00125 int stationRegion(const Identifier& id) const;
00126
00127 bool isBarrel (const Identifier& id) const;
00128 bool isEndcap (const Identifier& id) const;
00129 bool isForward (const Identifier& id) const;
00130 bool isSmall (const Identifier& id) const;
00131 bool isBarrel (const int& stationNameIndex) const;
00132 bool isEndcap (const int& stationNameIndex) const;
00133 bool isForward (const int& stationNameIndex) const;
00134 bool isSmall (const int& stationNameIndex) const;
00135
00136
00137
00138 int stationNameIndex(const std::string& name) const;
00139 int technologyIndex(const std::string& name) const;
00140 const std::string& stationNameString(const int& index) const;
00141 const std::string& technologyString(const int& index) const;
00142 int nStationNames() const;
00143
00144
00145
00146 void print(const Identifier& id) const;
00147
00149
00150 public:
00151
00152 typedef Identifier::size_type size_type;
00153 typedef MultiRange::const_identifier_factory const_expanded_id_iterator;
00154 typedef std::vector<Identifier>::const_iterator const_id_iterator;
00155
00157 virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr);
00158
00164 IdContext technology_context (void) const;
00166 IdContext module_context (void) const;
00168 IdContext detectorElement_context (void) const;
00170 IdContext channel_context (void) const;
00171
00173 virtual int gasGap(const Identifier& id) const =0 ;
00174 virtual int channel(const Identifier& id) const =0;
00175 virtual bool measuresPhi(const Identifier& id) const =0 ;
00176 virtual int get_module_hash (const Identifier& id, IdentifierHash& hash_id ) const;
00177 virtual int get_detectorElement_hash (const Identifier& id, IdentifierHash& hash_id ) const;
00178 virtual int get_channel_hash (const Identifier& id, IdentifierHash& hash_id ) const;
00179
00181 virtual int get_id (const IdentifierHash& hash_id,Identifier& id, const IdContext* context = 0) const;
00182
00184 virtual int get_hash (const Identifier& id, IdentifierHash& hash_id, const IdContext* context = 0) const;
00185
00187 int get_expanded_id (const Identifier& id, ExpandedIdentifier& exp_id, const IdContext* context) const;
00188
00191 int get_id (const ExpandedIdentifier& old_id, Identifier& new_id) const;
00193 MultiRange multiRange (void) const;
00194
00196 size_type module_hash_max (void) const;
00197 size_type detectorElement_hash_max (void) const { return m_detectorElement_hash_max; } ;
00198 size_type channel_hash_max (void) const;
00199
00201 std::vector<Identifier> idVector (void) const;
00202
00206 const_id_iterator module_begin (void) const;
00207 const_id_iterator module_end (void) const;
00208
00212 const_id_iterator detectorElement_begin (void) const;
00213 const_id_iterator detectorElement_end (void) const;
00214
00218 const_id_iterator channel_begin (void) const;
00219 const_id_iterator channel_end (void) const;
00220
00223 int get_prev_in_phi (const IdentifierHash& id, IdentifierHash& prev) const;
00224 int get_next_in_phi (const IdentifierHash& id, IdentifierHash& next) const;
00225 int get_prev_in_eta (const IdentifierHash& id, IdentifierHash& prev) const;
00226 int get_next_in_eta (const IdentifierHash& id, IdentifierHash& next) const;
00227
00229 void test_module_packing (void) const;
00230 void test_id (const Identifier& id, const IdContext& context) const;
00231
00232 int stationNameIndexMax() const;
00233 int technologyNameIndexMax() const;
00234
00235 static const std::string BAD_NAME;
00236
00237 protected:
00238
00239 enum {NOT_VALID_HASH = 64000};
00240
00241 typedef std::vector<Identifier> id_vec;
00242 typedef id_vec::const_iterator id_vec_it;
00243 typedef std::vector<unsigned short> hash_vec;
00244 typedef hash_vec::const_iterator hash_vec_it;
00245
00246 int initLevelsFromDict(void);
00247 int init_hashes(void);
00248 virtual int init_detectorElement_hashes(void);
00249 int init_channel_hashes(void);
00250 int init_neighbors(void);
00251
00252
00253 int get_expanded_id_calc (const Identifier& compact_id, ExpandedIdentifier& id, const IdContext* context) const;
00254
00255
00256 int get_compact_id (const ExpandedIdentifier& id, Identifier& compact_id, const IdContext* context) const;
00257
00258 virtual int get_hash_calc (const Identifier& compact_id, IdentifierHash& hash_id, const IdContext* context) const;
00259
00260 size_type m_station_region_index;
00261 size_type m_MUON_INDEX;
00262 size_t m_GROUP_INDEX;
00263 size_type m_NAME_INDEX;
00264 size_type m_ETA_INDEX;
00265 size_type m_PHI_INDEX;
00266 size_type m_TECHNOLOGY_INDEX;
00267 size_type m_MODULE_INDEX;
00268 size_type m_DETECTORELEMENT_INDEX;
00269 size_type m_CHANNEL_INDEX;
00270 const IdDictDictionary* m_dict;
00271
00272 MultiRange m_muon_range;
00273 MultiRange m_full_module_range;
00274 size_type m_module_hash_max;
00275 id_vec m_module_vec;
00276
00277 MultiRange m_muon_channel_range;
00278 MultiRange m_full_channel_range;
00279 size_type m_channel_hash_max;
00280 id_vec m_channel_vec;
00281
00282 MultiRange m_muon_detectorElement_range;
00283 MultiRange m_full_detectorElement_range;
00284 size_type m_detectorElement_hash_max;
00285 id_vec m_detectorElement_vec;
00286
00287 hash_vec m_prev_phi_module_vec;
00288 hash_vec m_next_phi_module_vec;
00289 hash_vec m_prev_eta_module_vec;
00290 hash_vec m_next_eta_module_vec;
00291
00292 IdDictFieldImplementation m_muon_impl;
00293 IdDictFieldImplementation m_sta_impl;
00294 IdDictFieldImplementation m_eta_impl;
00295 IdDictFieldImplementation m_phi_impl;
00296 IdDictFieldImplementation m_tec_impl;
00297
00299
00300 protected:
00301
00302
00303 IMessageSvc* m_msgSvc;
00304
00305
00306
00307 bool validStation(int stationName, int technology) const;
00308
00309
00310
00311 void addStationID(Identifier& id, int stationName, int stationEta, int stationPhi, int technology) const ;
00312
00313 void addStationID(ExpandedIdentifier& id, int stationName, int stationEta, int stationPhi, int technology) const;
00314
00315 private:
00316
00317
00318 inline MuonIdHelper(const MuonIdHelper & other) : AtlasDetectorID(other) {}
00319 inline MuonIdHelper & operator=(const MuonIdHelper &right);
00320
00321
00322
00323 std::vector< std::string > m_stationNameVector;
00324 std::vector< std::string > m_technologyNameVector;
00325
00326
00327 std::set< int > m_isBarrel;
00328 std::set< int > m_isSmall;
00329 std::set< int > m_isForward;
00330
00331
00332
00333 enum MuonIndices
00334 {
00335 StationNameIndex = 1,
00336 StationEtaIndex = 2,
00337 StationPhiIndex = 3,
00338 TechnologyIndex = 4
00339 };
00340
00341 protected:
00342 mutable MsgStream *m_Log;
00343 inline virtual void create_mlog() const;
00344
00345 };
00346
00347
00348
00349 typedef MuonIdHelper MuonID;
00350
00351
00352
00353
00354 inline Identifier MuonIdHelper::muon() const
00355 {
00356 return AtlasDetectorID::muon();
00357 }
00358
00359
00360 inline void MuonIdHelper::print(const Identifier& id) const
00361 {
00362 AtlasDetectorID::print(id);
00363 }
00364
00365 inline IdContext MuonIdHelper::technology_context (void) const {
00366 ExpandedIdentifier id;
00367 return (IdContext(id, 0, m_TECHNOLOGY_INDEX));
00368
00369 }
00370
00371 inline IdContext MuonIdHelper::module_context (void) const {
00372 ExpandedIdentifier id;
00373 return (IdContext(id, 0, m_MODULE_INDEX));
00374
00375 }
00376
00377 inline IdContext MuonIdHelper::detectorElement_context (void) const {
00378 ExpandedIdentifier id;
00379 return (IdContext(id, 0, m_DETECTORELEMENT_INDEX));
00380
00381 }
00382
00383 inline IdContext MuonIdHelper::channel_context (void) const {
00384 ExpandedIdentifier id;
00385 return (IdContext(id, 0, m_CHANNEL_INDEX));
00386
00387 }
00388
00389 inline MultiRange MuonIdHelper::multiRange(void) const {
00390 return m_full_module_range;
00391 }
00392
00393 inline MuonIdHelper::size_type MuonIdHelper::module_hash_max(void) const {
00394 return m_module_hash_max;
00395 }
00396
00397 inline MuonIdHelper::size_type MuonIdHelper::channel_hash_max(void) const {
00398 return m_channel_hash_max;
00399 }
00400
00401 inline std::vector<Identifier> MuonIdHelper::idVector(void) const {
00402 return m_module_vec;
00403 }
00404
00405 inline MuonIdHelper::const_id_iterator MuonIdHelper::module_begin (void) const
00406 {
00407 return (m_module_vec.begin());
00408 }
00409
00410 inline MuonIdHelper::const_id_iterator MuonIdHelper::module_end (void) const
00411 {
00412 return (m_module_vec.end());
00413 }
00414
00415 inline MuonIdHelper::const_id_iterator MuonIdHelper::detectorElement_begin (void) const
00416 {
00417 return (m_detectorElement_vec.begin());
00418 }
00419
00420 inline MuonIdHelper::const_id_iterator MuonIdHelper::detectorElement_end (void) const
00421 {
00422 return (m_detectorElement_vec.end());
00423 }
00424
00425 inline MuonIdHelper::const_id_iterator MuonIdHelper::channel_begin (void) const
00426 {
00427 return (m_channel_vec.begin());
00428 }
00429
00430 inline MuonIdHelper::const_id_iterator MuonIdHelper::channel_end (void) const
00431 {
00432 return (m_channel_vec.end());
00433 }
00434
00435
00436 inline bool MuonIdHelper::validStation(int stationName, int technology) const
00437 {
00438 if ((stationName < 0) || (stationName > stationNameIndexMax())) return false;
00439 if ((technology < 0) || (technology > technologyNameIndexMax())) return false;
00440 return true;
00441 }
00442
00443 inline void MuonIdHelper::addStationID(ExpandedIdentifier& id, int stationName, int stationEta, int stationPhi, int technology) const {
00444
00445 id << stationName << stationEta << stationPhi << technology;
00446 assert(id.last_error() == ExpandedIdentifier::none);
00447 }
00448
00449
00450 inline bool MuonIdHelper::is_muon(const Identifier& id) const
00451 {
00452 return AtlasDetectorID::is_muon(id);
00453 }
00454
00455
00456 inline bool MuonIdHelper::is_mdt(const Identifier& id) const
00457 {
00458 return AtlasDetectorID::is_mdt(id);
00459 }
00460
00461
00462 inline bool MuonIdHelper::is_csc(const Identifier& id) const
00463 {
00464 return AtlasDetectorID::is_csc(id);
00465 }
00466
00467
00468 inline bool MuonIdHelper::is_rpc(const Identifier& id) const
00469 {
00470 return AtlasDetectorID::is_rpc(id);
00471 }
00472
00473
00474 inline bool MuonIdHelper::is_tgc(const Identifier& id) const
00475 {
00476 return AtlasDetectorID::is_tgc(id);
00477 }
00478
00479
00480 inline bool MuonIdHelper::is_stgc(const Identifier& id) const
00481 {
00482 return AtlasDetectorID::is_stgc(id);
00483 }
00484
00485
00486 inline bool MuonIdHelper::is_mm(const Identifier& id) const
00487 {
00488 return AtlasDetectorID::is_mm(id);
00489 }
00490
00491
00492 inline int MuonIdHelper::stationName(const Identifier& id) const
00493 {
00494 int result = m_sta_impl.unpack(id);
00495 return result;
00496 }
00497
00498 inline int MuonIdHelper::stationEta(const Identifier& id) const
00499 {
00500 int result = m_eta_impl.unpack(id);
00501 return result;
00502 }
00503
00504 inline int MuonIdHelper::stationPhi(const Identifier& id) const
00505 {
00506 int result = m_phi_impl.unpack(id);
00507 return result;
00508 }
00509
00510 inline int MuonIdHelper::technology(const Identifier& id) const
00511 {
00512 int result = m_tec_impl.unpack(id);
00513 return result;
00514 }
00515
00516 inline int MuonIdHelper::stationNameIndexMax() const
00517 {
00518 return (m_stationNameVector.size() - 1);
00519 }
00520
00521 inline int MuonIdHelper::technologyNameIndexMax() const
00522 {
00523 return (m_technologyNameVector.size() - 1);
00524 }
00525
00526
00527 inline bool MuonIdHelper::isBarrel(const Identifier& id) const
00528 {
00529 return isBarrel(stationName(id));
00530 }
00531
00532 inline bool MuonIdHelper::isEndcap(const Identifier& id) const
00533 {
00534 return isEndcap(stationName(id));
00535 }
00536
00537 inline bool MuonIdHelper::isForward(const Identifier& id) const
00538 {
00539 return isForward(stationName(id));
00540 }
00541
00542 inline bool MuonIdHelper::isSmall(const Identifier& id) const
00543 {
00544 return isSmall(stationName(id));
00545 }
00546
00547 inline bool MuonIdHelper::isBarrel(const int& stationNameIndex) const
00548 {
00549 return (m_isBarrel.count(stationNameIndex) == 1);
00550 }
00551
00552 inline bool MuonIdHelper::isEndcap(const int& stationNameIndex) const
00553 {
00554 return (m_isBarrel.count(stationNameIndex) == 0);
00555 }
00556
00557 inline bool MuonIdHelper::isForward(const int& stationNameIndex) const
00558 {
00559 return (m_isForward.count(stationNameIndex) == 1);
00560 }
00561
00562 inline bool MuonIdHelper::isSmall(const int& stationNameIndex) const
00563 {
00564 return (m_isSmall.count(stationNameIndex) == 1);
00565 }
00566
00567
00568 inline int MuonIdHelper::stationNameIndex(const std::string& name) const
00569 {
00570
00571 int index = -1;
00572 std::vector< std::string >::const_iterator first = m_stationNameVector.begin();
00573 std::vector< std::string >::const_iterator last = m_stationNameVector.end();
00574 int counter = 0;
00575 while (first != last) {
00576 if (name.compare(*first) == 0) {
00577 index = counter;
00578 break;
00579 }
00580 ++first;
00581 ++counter;
00582 }
00583 return index;
00584 }
00585
00586 inline int MuonIdHelper::technologyIndex(const std::string& name) const
00587 {
00588
00589 int index = -1;
00590 std::vector< std::string >::const_iterator first = m_technologyNameVector.begin();
00591 std::vector< std::string >::const_iterator last = m_technologyNameVector.end();
00592 int counter = 0;
00593 while (first != last) {
00594 if (name.compare(*first) == 0) {
00595 index = counter;
00596 break;
00597 }
00598 ++first;
00599 ++counter;
00600 }
00601 return index;
00602 }
00603
00604 inline const std::string& MuonIdHelper::stationNameString(const int& index) const
00605 {
00606 assert ( index >= 0 && index <= stationNameIndexMax() );
00607 static std::string name;
00608 if ( index >= 0 && index <= stationNameIndexMax() ) {
00609 name = m_stationNameVector[index];
00610 if (name.empty()) {
00611 name = BAD_NAME;
00612 }
00613 } else {
00614 name = BAD_NAME;
00615 }
00616 return name;
00617 }
00618
00619 inline const std::string& MuonIdHelper::technologyString(const int& index) const
00620 {
00621 assert ( index >= 0 && index <= technologyNameIndexMax() );
00622 static std::string name;
00623 if (index >= 0 && index <= technologyNameIndexMax()) {
00624 name = m_technologyNameVector[index];
00625 if (name.empty()) {
00626 name = BAD_NAME;
00627 }
00628 } else {
00629 name = BAD_NAME;
00630 }
00631 return name;
00632 }
00633
00634 inline int MuonIdHelper::nStationNames() const
00635 {
00636 return (int)m_isSmall.size();
00637 }
00638
00639 #endif // DETECTORDESCRIPTION_MUONIDHELPER_H
00640