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