ATLAS Offline Software
MdtCsmIdHash.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GaudiKernel/Bootstrap.h"
6 #include "GaudiKernel/GaudiException.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/IMessageSvc.h"
9 #include "GaudiKernel/StatusCode.h"
10 #include "StoreGate/StoreGateSvc.h"
11 
12 #include "MuonRDO/MdtCsmIdHash.h"
13 
14 #include <cassert>
15 #include <iostream>
16 
17 // This class converts a Mdt Identifier into a integer, according to its
18 // fields
19 
20 
21 // default contructor
23 {
24  IMessageSvc* msgSvc;
25  ISvcLocator* svcLoc = Gaudi::svcLocator( );
26  assert(svcLoc);
27  StatusCode sc = svcLoc->service( "MessageSvc", msgSvc );
28  if (sc.isFailure()) std::cout << "Fail to locate Message Service" << std::endl;
29 
30  MsgStream log(msgSvc, "MuonDigitContainer" );
31 
32  log << MSG::DEBUG << " MdtCsmIdHash Constructor "<<endmsg;
33 
34  const MdtIdHelper* mdtHelper=nullptr;
35  StoreGateSvc* detStore=nullptr;
36  sc = svcLoc->service("DetectorStore", detStore);
37 
38  if (sc.isSuccess()) {
39  sc = detStore->retrieve( mdtHelper, "MDTIDHELPER" );
40  if (sc.isFailure())
41  log << MSG::ERROR << " Cannot retrieve MdtIdHelper " << endmsg;
42  } else
43  log << MSG::ERROR << " MdtIdHelper not found in DetectorStore " << endmsg;
44  //too bad, we bail out (PC)
45  if (!sc.isSuccess()) throw GaudiException("can not get MdtIdHelper",
46  "MdtCsmIdHash::MdtCsmIdHash()", sc);
47 
48 
49  unsigned int used = mdtHelper->module_hash_max();
50  IdContext context = mdtHelper->module_context();
51 
52  if( mdtHelper->stationNameIndex("BME") != -1 ) {
53  used = mdtHelper->detectorElement_hash_max();
54  context = mdtHelper->detectorElement_context();
55  }
56 
57  for(unsigned int hash=0; hash < used; ++hash){
58  Identifier id;
59  if (!mdtHelper->get_id(hash,id,&context)) {
60  m_lookup[id]=(int) hash;
61  m_int2id.push_back(id);
62  } else log << MSG::ERROR << "MDT hash constructor failed!" << endmsg;
63  }
64 
65  log << MSG::DEBUG << "Number of valid MDT Element IDs " << used << endmsg;
66  m_size = (int) used;
67 }
68 
70 
71  if(index>=0 && index < m_size) {
72  return m_int2id[index] ;
73  }
74  // return blank id for invalid index
75  std::cout <<" MdtCsmIdHash::ERROR : identifier invalid ID "<<std::endl;
76  Identifier id;
77  return id;
78 
79 }
80 
81 int MdtCsmIdHash::operator() (const ID& id) const {
82 
83  std::map<ID,int>::const_iterator it = m_lookup.find(id);
84  if(it!=m_lookup.end()){
85  return (*it).second;
86  }
87 
88  // FIXME -1 for invalid ID?
89  return -1;
90 
91 }
92 
93 int MdtCsmIdHash::max() const {
94 
95 return m_size;
96 
97 }
98 
100 
101 return 0;
102 
103 }
used
MuonIdHelper::stationNameIndex
int stationNameIndex(const std::string &name) const
Definition: MuonIdHelper.cxx:846
MuonIdHelper::detectorElement_context
IdContext detectorElement_context() const
id for detector element
Definition: MuonIdHelper.cxx:740
MdtCsmIdHash::MdtCsmIdHash
MdtCsmIdHash()
Definition: MdtCsmIdHash.cxx:22
MuonIdHelper::get_id
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const override
Create compact id from hash id (return == 0 for OK)
Definition: MuonIdHelper.cxx:69
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
index
Definition: index.py:1
MuonIdHelper::detectorElement_hash_max
size_type detectorElement_hash_max() const
Definition: MuonIdHelper.h:186
MdtCsmIdHash::m_size
int m_size
total number of IDs
Definition: MdtCsmIdHash.h:41
skel.it
it
Definition: skel.GENtoEVGEN.py:423
MdtCsmIdHash::m_int2id
std::vector< ID > m_int2id
reverse lookup
Definition: MdtCsmIdHash.h:49
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MdtCsmIdHash.h
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MdtIdHelper
Definition: MdtIdHelper.h:61
MdtCsmIdHash::max
int max() const
return maximum number of IDs
Definition: MdtCsmIdHash.cxx:93
MdtCsmIdHash::offset
static int offset()
return offset
Definition: MdtCsmIdHash.cxx:99
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
MuonIdHelper::module_hash_max
size_type module_hash_max() const
the maximum hash value
Definition: MuonIdHelper.cxx:752
DeMoScan.index
string index
Definition: DeMoScan.py:362
MdtCsmIdHash::operator()
int operator()(const ID &id) const
Convert ID to int.
Definition: MdtCsmIdHash.cxx:81
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonIdHelper::module_context
IdContext module_context() const
id for module
Definition: MuonIdHelper.cxx:735
MdtCsmIdHash::m_lookup
std::map< Identifier, int > m_lookup
lookup table
Definition: MdtCsmIdHash.h:45
IdContext
class IdContext
Definition: IdContext.h:34
StoreGateSvc.h
MdtCsmIdHash::identifier
ID identifier(int i) const
reverse conversion
Definition: MdtCsmIdHash.cxx:69