ATLAS Offline Software
TBDetDescrLoader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //Gaudi Includes
6 #include "GaudiKernel/IDataProviderSvc.h"
7 #include "GaudiKernel/SmartDataPtr.h"
8 
10 
11 //TBDetDescr includes
14 #include "TBDetDescrLoader.h"
15 
16 // Constructor & destructor
17 TBDetDescrLoader::TBDetDescrLoader(const std::string& name, ISvcLocator* pSvcLocator)
18  : AthAlgorithm(name, pSvcLocator),
19  m_TBDDM(0),
20  c_TBDDM(0)
21 {
22  declareProperty("TBDetDescrManager", m_TBDetDescrManager = "TBDetDescrMgr");
23  declareProperty("TBElementContainer", m_TBElementContainer = "TBElementCnt");
24  declareProperty("ReadAction", m_readAction = -1);
25  declareProperty("WriteAction", m_writeAction = 0);
26 }
27 
29 {
30 }
31 
32 // Alg standard interface function
34 {
35  StatusCode sc;
36 
37  if (m_readAction != 0) {
38 
39  ATH_MSG_INFO( "Creating TBDetDescrManager in DetectorStore" );
40 
41  m_TBDDM = new TBDetDescrManager();
42 
43  // somebody else should provide coordinates for all envelopes
44  // we can't do anything here
45  // so this initialization is not needed,
46  // it is kept here as an example
47  std::vector<TBElement> vec;
48  vec.resize(1); // it will contain just one "Unknown" element
49 
50  // initialize the manager with detectors we just created
52  m_TBDDM->print(msg());
53 
54  if (m_readAction < 0) {
55  m_readAction = 0;
56  sc=detStore()->record(m_TBDDM, m_TBDetDescrManager, true);
57  } else {
58  sc=detStore()->record(m_TBDDM, m_TBDetDescrManager, false);
59  }
60 
61  if(sc.isFailure()) {
62  ATH_MSG_ERROR( "failed to register TBDetDescrManager in Detector Store" );
63  m_readAction = 0;
64  ATH_MSG_ERROR( "resetting m_readAction to 0" );
65  delete m_TBDDM;
66  // do not exit wih FAILURE here
67  // probably manager is created already
68  // and we just want to use it
69  // return sc;
70  }
71  } else {
72 
73  DetDescrAddress * addr = new DetDescrAddress(
76 
77  sc = detStore()->recordAddress(addr);
78  if (sc != StatusCode::SUCCESS) {
79  ATH_MSG_INFO( "unable to fill address for " << (*addr->par())
80  << " with CLID " << addr->clID()
81  << " and storage type " << addr->svcType()
82  << " to detector store " );
83  }
84  else {
85  unsigned int st = addr->svcType();
86  ATH_MSG_INFO( "filling address for " << (*addr->par())
87  << " with CLID " << addr->clID()
88  << " and storage type " << st
89  << " to detector store " );
90  }
91  }
92 
93  if (m_writeAction != 0) {
94 
95  ATH_MSG_INFO( "Retrieving TBDetDescrManager from DetectorStore" );
96 
97  sc = detStore()->retrieve(c_TBDDM);
98  if (sc.isFailure()) {
99  ATH_MSG_ERROR( "Unable to retrieve TBDetDescrManager from DetectorStore" );
100  m_writeAction = 0;
101  ATH_MSG_ERROR( "resetting m_writeAction to 0" );
102  return StatusCode::RECOVERABLE;
103  }
104  c_TBDDM->print(msg());
105  }
106 
107  ATH_MSG_INFO( "initialization completed" );
108  return StatusCode::SUCCESS;
109 }
110 
112  StatusCode sc;
113 
114  TBElementContainer* pTBElementContainer;
115 
116  switch (m_readAction) {
117 
118  case 0: // do nothing
119  ATH_MSG_DEBUG( "readAction: do nothing" );
120 
121  // write to StoreGate only if we are not reading from it!
122 
123  switch (m_writeAction) {
124 
125  case 0: // do nothing
126  ATH_MSG_DEBUG( "writeAction: do nothing" );
127  break;
128 
129  case 1: // write once
130  m_writeAction = 0; // don't do anything anymore
131  // but without break proceed to next case
132  /* FALLTHROUGH */
133 
134  case 2: // write always
135 
136  ATH_MSG_DEBUG( "Action: write TBDetDescr to StoreGate" );
137 
138  pTBElementContainer = new TBElementContainer();
139 
140  c_TBDDM->getAll(pTBElementContainer);
141  c_TBDDM->print(msg());
142 
143  sc=evtStore()->record(pTBElementContainer, m_TBElementContainer, false);
144  if(sc.isFailure()) {
145  ATH_MSG_FATAL( "failed to register the TBElementContainer" );
146  return StatusCode::FAILURE;
147  }
148  break;
149 
150  default:
151  break;
152  }
153 
154  break;
155 
156  case 1: // read once
157  m_readAction = 0; // don't do anything anymore
158  // but without break proceed to next case
159  /* FALLTHROUGH */
160 
161  case 2: // read always
162 
163  ATH_MSG_DEBUG( "Action: read TBDetDescr from StoreGate" );
164  {
165  const TBElementContainer* pContainer = nullptr;
167  m_TBDDM->initialize(pContainer);
168  m_TBDDM->print(msg());
169  }
170  break;
171 
172  default:
173  break;
174 
175  }
176 
177  return StatusCode::SUCCESS;
178 }
179 
180 StatusCode
182  ATH_MSG_INFO( "finalized successfully" );
183  return StatusCode::SUCCESS;
184 }
185 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TBDetDescrLoader::TBDetDescrLoader
TBDetDescrLoader(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TBDetDescrLoader.cxx:17
TBDetDescrLoader.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TBDetDescrManager.h
TBDetDescrLoader::m_writeAction
int m_writeAction
Definition: TBDetDescrLoader.h:32
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DetDescrAddress.h
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
TBDetDescrLoader::m_TBDDM
TBDetDescrManager * m_TBDDM
Definition: TBDetDescrLoader.h:34
TBDetDescrLoader::c_TBDDM
const TBDetDescrManager * c_TBDDM
Definition: TBDetDescrLoader.h:35
TBDetDescrManager::initialize
void initialize(const std::vector< TBElement > &vec)
Definition: TBDetDescrManager.cxx:74
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TBDetDescrManager::getAll
void getAll(TBElementContainer *pTBElementContainer) const
Definition: TBDetDescrManager.cxx:108
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TBDetDescrManager::print
void print(MsgStream &log) const
Definition: TBDetDescrManager.cxx:146
TBDetDescrLoader::execute
virtual StatusCode execute() override
Definition: TBDetDescrLoader.cxx:111
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TBDetDescrLoader::initialize
virtual StatusCode initialize() override
Definition: TBDetDescrLoader.cxx:33
TBElementContainer.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DetDescrAddress
Definition: DetDescrAddress.h:32
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TBDetDescrLoader::m_readAction
int m_readAction
Definition: TBDetDescrLoader.h:31
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TBDetDescrLoader::m_TBDetDescrManager
std::string m_TBDetDescrManager
Definition: TBDetDescrLoader.h:29
TBElementContainer
Definition: TBElementContainer.h:18
TBDetDescrManager
Definition: TBDetDescrManager.h:21
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TBDetDescrLoader::m_TBElementContainer
std::string m_TBElementContainer
Definition: TBDetDescrLoader.h:30
TBDetDescrLoader::~TBDetDescrLoader
virtual ~TBDetDescrLoader()
Definition: TBDetDescrLoader.cxx:28
TBDetDescrLoader::finalize
virtual StatusCode finalize() override
Definition: TBDetDescrLoader.cxx:181