ATLAS Offline Software
HGTD_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 #include "HGTD_IDDetDescrCnv.h"
7 
10 #include "StoreGate/StoreGateSvc.h"
11 
13 
15 
16 //--------------------------------------------------------------------
17 
18 long int
20 {
21  return (storageType());
22 }
23 
24 //--------------------------------------------------------------------
25 
28 {
29  // First call parent init
31 
32  return StatusCode::SUCCESS;
33 }
34 
35 //--------------------------------------------------------------------
36 
38 HGTD_IDDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
39 {
40  ATH_MSG_INFO( "in createObj: creating a HGTD_ID helper object in the detector store" );
41 
42  // Create a new HGTD_ID
43 
44  DetDescrAddress* ddAddr;
45  ddAddr = dynamic_cast<DetDescrAddress*> (pAddr);
46  if(!ddAddr) {
47  ATH_MSG_FATAL( "Could not cast to DetDescrAddress." );
48  return StatusCode::FAILURE;
49  }
50 
51  // Get the StoreGate key of this container.
52  std::string helperKey = *( ddAddr->par() );
53  if ("" == helperKey) {
54  ATH_MSG_DEBUG( "No Helper key " );
55  }
56  else {
57  ATH_MSG_DEBUG( "Helper key is " << helperKey );
58  }
59 
60  // get DetectorStore service
62  StatusCode status = serviceLocator()->service("DetectorStore", detStore);
63  if (status.isFailure()) {
64  ATH_MSG_FATAL( "DetectorStore service not found !" );
65  return StatusCode::FAILURE;
66  } else {}
67 
68  // Get the dictionary manager from the detector store
69  const IdDictManager* idDictMgr;
70  status = detStore->retrieve(idDictMgr, "IdDict");
71  if (status.isFailure()) {
72  ATH_MSG_FATAL( "Could not get IdDictManager !" );
73  return StatusCode::FAILURE;
74  }
75  else {
76  ATH_MSG_DEBUG( " Found the IdDictManager. " );
77  }
78 
79 
80  // Only initialize helper if it is the first pass or if there is a
81  // change in the the file or tag
82  bool initHelper = false;
83 
84  const IdDictMgr* mgr = idDictMgr->manager();
85 
86  // Internal InDet id tag
87  std::string inDetIDTag = mgr->tag();
88 
89  // DoChecks flag
90  bool doChecks = mgr->do_checks();
91 
92  IdDictDictionary* dict = mgr->find_dictionary("InnerDetector");
93  if (!dict) {
94  ATH_MSG_ERROR( "unable to find idDict for InnerDetector" );
95  return StatusCode::FAILURE;
96  }
97 
98  // File to be read for InDet ids
99  std::string inDetIDFileName = dict->file_name();
100  // Tag of RDB record for InDet ids
101  std::string inDetIdDictTag = dict->dict_tag();
102 
103  if (m_hgtdId) {
104  // HGTD id helper already exists - second pass. Check for a
105  // change
106  if (inDetIDTag != m_inDetIDTag) {
107  // Internal InDet id tag
108  initHelper = true;
109  ATH_MSG_DEBUG( " Changed internal InDet id tag: " << inDetIDTag );
110  }
111  if (inDetIDFileName != m_inDetIDFileName) {
112  // File to be read for InDet ids
113  initHelper = true;
114  ATH_MSG_DEBUG( " Changed InDetFileName:" << inDetIDFileName );
115  }
116  if (inDetIdDictTag != m_inDetIdDictTag) {
117  // Tag of RDB record for InDet ids
118  initHelper = true;
119  ATH_MSG_DEBUG( " Changed InDetIdDictTag: " << inDetIdDictTag );
120  }
121  if (doChecks != m_doChecks) {
122  // DoChecks flag
123  initHelper = true;
124  ATH_MSG_DEBUG( " Changed doChecks flag: " << doChecks );
125  }
126  }
127  else {
128  // create the helper
129  m_hgtdId = std::make_unique<HGTD_ID>();
130  initHelper = true;
131  // add in message service for printout
132  m_hgtdId->setMessageSvc(msgSvc());
133  if(dict->m_version == "P2-RUN4"){
134  m_hgtdId->set_useNewIdentifierScheme(true);
135  }
136  }
137 
138  if (initHelper) {
139  if (idDictMgr->initializeHelper(*m_hgtdId)) {
140  ATH_MSG_ERROR( "Unable to initialize HGTD_ID" );
141  return StatusCode::FAILURE;
142  }
143  // Save state:
144  m_inDetIDTag = inDetIDTag;
145  m_inDetIDFileName = inDetIDFileName;
146  m_inDetIdDictTag = inDetIdDictTag;
147  m_doChecks = doChecks;
148  }
149 
150  // Pass a pointer to the container to the Persistency service by reference.
151  pObj = SG::asStorable(m_hgtdId.release());
152 
153  return StatusCode::SUCCESS;
154 
155 }
156 
157 //--------------------------------------------------------------------
158 
159 long
161 {
162  return DetDescr_StorageType;
163 }
164 
165 //--------------------------------------------------------------------
166 const CLID&
169 }
170 
171 //--------------------------------------------------------------------
173  :
175  AthMessaging(svcloc->service< IMessageSvc >( "MessageSvc" ),"HGTD_IDDetDescrCnv"),
176  m_hgtdId(),
177  m_doChecks(false)
178 
179 {}
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
HGTD_IDDetDescrCnv::m_inDetIDTag
std::string m_inDetIDTag
Internal InDet id tag.
Definition: HGTD_IDDetDescrCnv.h:47
AthCheckMacros.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
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
HGTD_IDDetDescrCnv::m_inDetIdDictTag
std::string m_inDetIdDictTag
Tag of RDB record for InDet ids.
Definition: HGTD_IDDetDescrCnv.h:44
HGTD_IDDetDescrCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override final
Definition: HGTD_IDDetDescrCnv.cxx:38
HGTD_IDDetDescrCnv::storageType
static long storageType()
Definition: HGTD_IDDetDescrCnv.cxx:160
DetDescrAddress.h
SG::asStorable
DataObject * asStorable(T *pObject)
Definition: StorableConversions.h:158
IdDictManager.h
HGTD_IDDetDescrCnv::classID
static const CLID & classID()
Definition: HGTD_IDDetDescrCnv.cxx:167
IdDictDictionary::m_version
std::string m_version
Definition: IdDictDefs.h:284
HGTD_IDDetDescrCnv::initialize
virtual StatusCode initialize() override final
Definition: HGTD_IDDetDescrCnv.cxx: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
HGTD_IDDetDescrCnv.h
IdDictMgr
Definition: IdDictDefs.h:32
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
DetDescrConverter
Definition: DetDescrConverter.h:32
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DetDescrAddress
Definition: DetDescrAddress.h:32
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HGTD_ID
Definition: HGTD_ID.h:47
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
HGTD_IDDetDescrCnv::repSvcType
virtual long int repSvcType() const override final
Definition: HGTD_IDDetDescrCnv.cxx:19
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
HGTD_IDDetDescrCnv::m_hgtdId
std::unique_ptr< HGTD_ID > m_hgtdId
The helper - only will create it once.
Definition: HGTD_IDDetDescrCnv.h:38
IdDictManager::manager
const IdDictMgr * manager(void) const
Definition: IdDictManager.cxx:37
HGTD_IDDetDescrCnv::m_inDetIDFileName
std::string m_inDetIDFileName
File to be read for InDet ids.
Definition: HGTD_IDDetDescrCnv.h:41
merge.status
status
Definition: merge.py:17
HGTD_IDDetDescrCnv::HGTD_IDDetDescrCnv
HGTD_IDDetDescrCnv(ISvcLocator *svcloc)
Definition: HGTD_IDDetDescrCnv.cxx:172
StoreGateSvc.h
HGTD_IDDetDescrCnv::m_doChecks
bool m_doChecks
Whether or not.
Definition: HGTD_IDDetDescrCnv.h:50