ATLAS Offline Software
TRT_IDDetDescrCnv.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /***************************************************************************
6  InDet DetDescrCnv package
7  -----------------------------------------
8  ***************************************************************************/
9 
10 #include "TRT_IDDetDescrCnv.h"
11 
14 #include "GaudiKernel/MsgStream.h"
15 #include "StoreGate/StoreGateSvc.h"
16 
18 #include "InDetIdentifier/TRT_ID.h"
19 
20 
21 //--------------------------------------------------------------------
22 
23 long int
25 {
26  return (storageType());
27 }
28 
29 //--------------------------------------------------------------------
30 
33 {
34  // First call parent init
36  MsgStream log(msgSvc(), "TRT_IDDetDescrCnv");
37  log << MSG::DEBUG << "in initialize" << endmsg;
38 
39  if (sc.isFailure()) {
40  log << MSG::ERROR << "DetDescrConverter::initialize failed" << endmsg;
41  return sc;
42  }
43 
44  // The following is an attempt to "bootstrap" the loading of a
45  // proxy for TRT_ID into the detector store. However,
46  // TRT_IDDetDescrCnv::initialize is NOT called by the conversion
47  // service. So for the moment, this cannot be use. Instead the
48  // DetDescrCnvSvc must do the bootstrap from a parameter list.
49 
50 
51 // // Add InDet_DetDescrManager proxy as entry point to the detector store
52 // // - this is ONLY needed for the manager of each system
53 // sc = addToDetStore(classID(), "PidelID");
54 // if (sc.isFailure()) {
55 // log << MSG::FATAL << "Unable to add proxy for TRT_ID to the Detector Store!" << endmsg;
56 // return StatusCode::FAILURE;
57 // } else {}
58 
59  return StatusCode::SUCCESS;
60 }
61 
62 //--------------------------------------------------------------------
63 
66 {
67  MsgStream log(msgSvc(), "TRT_IDDetDescrCnv");
68  log << MSG::DEBUG << "in finalize" << endmsg;
69 
70  return StatusCode::SUCCESS;
71 }
72 
73 //--------------------------------------------------------------------
74 
76 TRT_IDDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
77 {
78  //StatusCode sc = StatusCode::SUCCESS;
79  MsgStream log(msgSvc(), "TRT_IDDetDescrCnv");
80  log << MSG::INFO << "in createObj: creating a TRT_ID helper object in the detector store" << endmsg;
81 
82  // Create a new TRT_ID
83 
84  DetDescrAddress* ddAddr;
85  ddAddr = dynamic_cast<DetDescrAddress*> (pAddr);
86  if(!ddAddr) {
87  log << MSG::FATAL << "Could not cast to DetDescrAddress." << endmsg;
88  return StatusCode::FAILURE;
89  }
90 
91  // Get the StoreGate key of this container.
92  std::string helperKey = *( ddAddr->par() );
93  if ("" == helperKey) {
94  log << MSG::DEBUG << "No Helper key " << endmsg;
95  }
96  else {
97  log << MSG::DEBUG << "Helper key is " << helperKey << endmsg;
98  }
99 
100 
101  // get DetectorStore service
103  StatusCode status = serviceLocator()->service("DetectorStore", detStore);
104  if (status.isFailure()) {
105  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
106  return StatusCode::FAILURE;
107  } else {}
108 
109  // Get the dictionary manager from the detector store
110  const IdDictManager* idDictMgr;
111  status = detStore->retrieve(idDictMgr, "IdDict");
112  if (status.isFailure()) {
113  log << MSG::FATAL << "Could not get IdDictManager !" << endmsg;
114  return StatusCode::FAILURE;
115  }
116  else {
117  log << MSG::DEBUG << " Found the IdDictManager. " << endmsg;
118  }
119 
120  // Only initialize helper if it is the first pass or if there is a
121  // change in the the file or tag
122  bool initHelper = false;
123 
124  const IdDictMgr* mgr = idDictMgr->manager();
125 
126  // Internal InDet id tag
127  std::string inDetIDTag = mgr->tag();
128 
129  // DoChecks flag
130  bool doChecks = mgr->do_checks();
131 
132  IdDictDictionary* dict = mgr->find_dictionary("InnerDetector");
133  if (!dict) {
134  log << MSG::ERROR
135  << "unable to find idDict for InnerDetector"
136  << endmsg;
137  return StatusCode::FAILURE;
138  }
139 
140  // File to be read for InDet ids
141  std::string inDetIDFileName = dict->file_name();
142 
143  // Tag of RDB record for InDet ids
144  std::string inDetIdDictTag = dict->dict_tag();
145 
146 
147  if (m_trtId) {
148 
149  // TRT id helper already exists - second pass. Check for a
150  // change
151  if (inDetIDTag != m_inDetIDTag) {
152  // Internal InDet id tag
153  initHelper = true;
154  log << MSG::DEBUG << " Changed internal InDet id tag: "
155  << inDetIDTag << endmsg;
156  }
157  if (inDetIDFileName != m_inDetIDFileName) {
158  // File to be read for InDet ids
159  initHelper = true;
160  log << MSG::DEBUG << " Changed InDetFileName:"
161  << inDetIDFileName << endmsg;
162  }
163  if (inDetIdDictTag != m_inDetIdDictTag) {
164  // Tag of RDB record for InDet ids
165  initHelper = true;
166  log << MSG::DEBUG << " Changed InDetIdDictTag: "
167  << inDetIdDictTag
168  << endmsg;
169  }
170  if (doChecks != m_doChecks) {
171  // DoChecks flag
172  initHelper = true;
173  log << MSG::DEBUG << " Changed doChecks flag: "
174  << doChecks
175  << endmsg;
176  }
177  }
178  else {
179  // create the helper
180  m_trtId = new TRT_ID;
181  initHelper = true;
182  // add in message service for printout
184  }
185 
186  if (initHelper) {
187  if (idDictMgr->initializeHelper(*m_trtId)) {
188  log << MSG::WARNING << "Unable to initialize TRT_ID" << endmsg;
189  //return StatusCode::FAILURE;
190  }
191  // Save state:
192  m_inDetIDTag = inDetIDTag;
193  m_inDetIDFileName = inDetIDFileName;
194  m_inDetIdDictTag = inDetIdDictTag;
195  m_doChecks = doChecks;
196  }
197 
198  // Pass a pointer to the container to the Persistency service by reference.
199  pObj = SG::asStorable(m_trtId);
200 
201  return StatusCode::SUCCESS;
202 
203 }
204 
205 //--------------------------------------------------------------------
206 
207 long
209 {
210  return DetDescr_StorageType;
211 }
212 
213 //--------------------------------------------------------------------
214 const CLID&
216  return ClassID_traits<TRT_ID>::ID();
217 }
218 
219 //--------------------------------------------------------------------
221  :
223  m_trtId(nullptr),
224  m_doChecks(false)
225 {}
226 
227 
228 
TRT_IDDetDescrCnv::m_trtId
TRT_ID * m_trtId
The helper - only will create it once.
Definition: TRT_IDDetDescrCnv.h:55
TRT_IDDetDescrCnv::repSvcType
virtual long int repSvcType() const
Definition: TRT_IDDetDescrCnv.cxx:24
AtlasDetectorID::setMessageSvc
virtual void setMessageSvc(IMessageSvc *msgSvc) override
Definition: AtlasDetectorID.cxx:748
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
DetDescr_StorageType
const long DetDescr_StorageType
Definition: DetDescrCnvSvc.cxx:20
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
TRT_IDDetDescrCnv::m_inDetIDFileName
std::string m_inDetIDFileName
File to be read for InDet ids.
Definition: TRT_IDDetDescrCnv.h:58
initialize
void initialize()
Definition: run_EoverP.cxx:894
TRT_IDDetDescrCnv.h
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
DetDescrAddress.h
SG::asStorable
DataObject * asStorable(T *pObject)
Definition: StorableConversions.h:158
TRT_IDDetDescrCnv::initialize
virtual StatusCode initialize()
Definition: TRT_IDDetDescrCnv.cxx:32
IdDictManager.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
TRT_IDDetDescrCnv::storageType
static long storageType()
Definition: TRT_IDDetDescrCnv.cxx:208
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
TRT_IDDetDescrCnv::m_inDetIDTag
std::string m_inDetIDTag
Internal InDet id tag.
Definition: TRT_IDDetDescrCnv.h:64
IdDictMgr
Definition: IdDictDefs.h:32
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
DetDescrConverter
Definition: DetDescrConverter.h:32
DetDescrAddress
Definition: DetDescrAddress.h:32
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
TRT_IDDetDescrCnv::m_inDetIdDictTag
std::string m_inDetIdDictTag
Tag of RDB record for InDet ids.
Definition: TRT_IDDetDescrCnv.h:61
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
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
IdDictDictionary::dict_tag
std::string dict_tag(void) const
Access to the dictionary tag.
Definition: IdDictDefs.h:700
IdDictManager::initializeHelper
int initializeHelper(IdHelper &helper) const
Return value: 0 OK, >0 error.
Definition: IdDictManager.cxx:44
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
IdDictManager
IdDictManager is the interface to identifier dictionaries.
Definition: IdDictManager.h:36
TRT_IDDetDescrCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Definition: TRT_IDDetDescrCnv.cxx:76
IdDictDictionary
Definition: IdDictDefs.h:97
TRT_IDDetDescrCnv::m_doChecks
bool m_doChecks
Whether or not.
Definition: TRT_IDDetDescrCnv.h:67
TRT_ID
Definition: TRT_ID.h:84
IdDictDictionary::file_name
std::string file_name(void) const
Access to file name.
Definition: IdDictDefs.h:692
DetDescrConverter.h
DEBUG
#define DEBUG
Definition: page_access.h:11
IdDictManager::manager
const IdDictMgr * manager(void) const
Definition: IdDictManager.cxx:37
TRT_IDDetDescrCnv::finalize
virtual StatusCode finalize()
Definition: TRT_IDDetDescrCnv.cxx:65
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
merge.status
status
Definition: merge.py:17
TRT_IDDetDescrCnv::TRT_IDDetDescrCnv
TRT_IDDetDescrCnv(ISvcLocator *svcloc)
Definition: TRT_IDDetDescrCnv.cxx:220
StoreGateSvc.h
TRT_IDDetDescrCnv::classID
static const CLID & classID()
Definition: TRT_IDDetDescrCnv.cxx:215