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