ATLAS Offline Software
CondSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "CondSvc.h"
6 #include "GaudiKernel/EventIDBase.h"
7 #include "AthenaKernel/StoreID.h"
9 
10 
11 //---------------------------------------------------------------------------
12 
13 CondSvc::CondSvc( const std::string& name, ISvcLocator* svcLoc ):
14  base_class(name,svcLoc),
15  m_sgs("StoreGateSvc/ConditionStore", name)
16 {
17 }
18 
19 //---------------------------------------------------------------------------
20 
22 }
23 
24 //---------------------------------------------------------------------------
26 CondSvc::validRanges( std::vector< EventIDRange >& ranges, const DataObjID& id ) const
27 {
28  // Direct retrieve doesn't work for some reason
29  /*CondContBase const* condObject;
30  StatusCode sc = m_sgs->retrieve( condObject, id.key() );
31  if ( sc.isSuccess() ) {
32  ranges = condObject->ranges();
33  }*/
34 
35  // Retrieve all conditions data and search
37  StatusCode sc = m_sgs->retrieve( cib, cie );
38  if ( sc.isSuccess() ) {
39  while ( cib != cie ) {
40  if ( cib->id() == id ) {
41  ranges = cib->ranges();
42  }
43  ++cib;
44  }
45  }
46 
47  return sc;
48 }
49 
50 //---------------------------------------------------------------------------
53 
54  // Initialise mother class in order to print DEBUG messages during initialize()
56  msg().setLevel( m_outputLevel.value() );
57 
58  if (!sc.isSuccess()) {
59  warning () << "Base class could not be initialized" << endmsg;
60  return StatusCode::FAILURE;
61  }
62 
63  if (!m_sgs.isValid()) {
64  error() << "could not get ConditionStore" << endmsg;
65  return StatusCode::FAILURE;
66  }
67 
68  return StatusCode::SUCCESS;
69 
70 }
71 //---------------------------------------------------------------------------
72 
73 // void
74 // CondSvc::dump() const {
75 
76 // std::ostringstream ost;
77 // dump(ost);
78 
79 // info() << ost.str() << endmsg;
80 
81 // }
82 
83 
84 //---------------------------------------------------------------------------
85 
86 void
87 CondSvc::dump(std::ostream& ost) const {
88 
89  std::lock_guard<mutex_t> lock(m_lock);
90 
91  ost << "CondSvc::dump()";
92 
93  ost << "\ndumping id->alg map\n";
94  for (const auto& ent : m_idMap) {
95  ost << std::endl << " + " << ent.first << " : ";
96  for (const auto& a : ent.second) {
97  ost << " " << a->name();
98  }
99  }
100 
101  ost << "\n\ndumping alg->id map\n";
102  for (const auto& ent : m_algMap) {
103  ost << std::endl << " + " << ent.first->name() << " : ";
104  for (const auto& a : ent.second) {
105  ost << " " << a;
106  }
107  }
108  ost << "\n\ndumping ConditionStore:\n\n";
109 
111  if (m_sgs->retrieve(cib,cie).isSuccess()) {
112  while (cib != cie) {
113  ost << " + ";
114  cib->list(ost);
115  ++cib;
116  }
117  }
118 
119  ost << "\n";
120 
121 }
122 
123 //---------------------------------------------------------------------------
124 
127  ATH_MSG_DEBUG( "CondSvc::finalize()" );
128  return StatusCode::SUCCESS;
129 }
130 
131 
134 {
135  // Call this now, in case there's no CondInputLoader.
136  ATH_CHECK( setupDone() );
137  return StatusCode::SUCCESS;
138 }
139 
140 
143 
144  ATH_MSG_DEBUG( "CondSvc::stop()" );
145 
146  if (msgLvl(MSG::DEBUG)) {
147  std::ostringstream ost;
148  dump(ost);
149 
150  ATH_MSG_DEBUG( ost.str() );
151  }
152 
153  return StatusCode::SUCCESS;
154 
155 }
156 
157 //---------------------------------------------------------------------------
158 
159 StatusCode
160 CondSvc::regHandle(IAlgorithm* alg, const Gaudi::DataHandle& dh) {
161 
162  std::lock_guard<mutex_t> lock(m_lock);
163  return regHandle_i(alg, dh);
164 
165 }
166 
167 //---------------------------------------------------------------------------
168 
169 // separate implementation to avoid the use of a recursive mutex
170 StatusCode
171 CondSvc::regHandle_i(IAlgorithm* alg, const Gaudi::DataHandle& dh) {
172 
173  ATH_MSG_DEBUG( "regHandle: alg: " << alg->name() << " id: "
174  << dh.fullKey() );
175 
176  if (dh.mode() != Gaudi::DataHandle::Writer) {
177  info() << dh.fullKey() << " is a ReadHandle. no need to register"
178  << endmsg;
179  return StatusCode::SUCCESS;
180  }
181 
182  id_map_t::iterator itd2 = m_idMap.find(dh.fullKey());
183  if (itd2 != m_idMap.end()) {
184  IAlgorithm *ia = *(itd2->second.begin());
185  if (ia->name() != alg->name()) {
186  error() << "WriteCondHandle " << dh.fullKey()
187  << " is already registered against a different Algorithm "
188  << ia->name()
189  << ". This is not allowed."
190  << endmsg;
191  return StatusCode::FAILURE;
192  }
193  // FIXME : so why is it a set<IAlgorithm*> ??
194  }
195 
196  // m_keyMap[key] = dh.fullKey();
197  m_condAlgs.insert(alg);
198 
199  m_condIDs.emplace( dh.fullKey() );
200 
201  // id_map_t::iterator itd2 = m_idMap.find(dh.fullKey());
202  if (itd2 != m_idMap.end()) {
203  itd2->second.insert( alg );
204  } else {
205  m_idMap[dh.fullKey()] = IAlgHashSet { alg };
206  }
207 
208  alg_map_t::iterator ita2 = m_algMap.find(alg);
209  if (ita2 != m_algMap.end()) {
210  ita2->second.insert( dh.fullKey() );
211  } else {
212  m_algMap[alg] = DataObjIDColl { dh.fullKey() };
213  }
214 
215  StatusCode sc(StatusCode::SUCCESS);
216 
217  CLID clid = dh.fullKey().clid();
218  const SG::BaseInfoBase* bib = SG::BaseInfoBase::find( clid );
219  if ( bib ) {
220  for (CLID clid2 : bib->get_bases()) {
221  if (clid2 != clid) {
222  SG::VarHandleKey vhk(clid2,dh.objKey(),Gaudi::DataHandle::Writer,
224  if (regHandle_i(alg, vhk).isFailure()) {
225  sc = StatusCode::FAILURE;
226  }
227  }
228  }
229  }
230 
231 
232 
233  return sc;
234 
235 }
236 
237 //---------------------------------------------------------------------------
238 
239 bool
240 CondSvc::getInvalidIDs(const EventContext& ctx, DataObjIDColl& invalidIDs) {
241  std::lock_guard<mutex_t> lock(m_lock);
242 
243  EventIDBase now(ctx.eventID());
244 
245  std::ostringstream ost;
246  ost << "getInvalidIDS " << ctx.eventID()
247  << ": retrieving all ConstIterator<CondContBase>";
249  if (m_sgs->retrieve(cib,cie).isSuccess()) {
250  while(cib != cie) {
251  ost << std::endl << " + " << cib.key() << " " << cib->valid(now)
252  << " id: " << cib->id();
253 
254  if (! (cib->valid(now)) ) {
255  invalidIDs.insert( cib->id() );
256  }
257 
258  ++cib;
259  }
260  } else {
261  ATH_MSG_DEBUG(ost.str());
262  ATH_MSG_DEBUG("ConditionStore is empty");
263  return false;
264  }
265 
266  ost << std::endl << " -> found " << invalidIDs.size() << " invalid IDs";
267 
268  ATH_MSG_DEBUG( ost.str() );
269 
270  return true;
271 }
272 
273 //---------------------------------------------------------------------------
274 
275 bool
276 CondSvc::getIDValidity(const EventContext& ctx, DataObjIDColl& validIDs,
277  DataObjIDColl& invalidIDs) {
278  std::lock_guard<mutex_t> lock(m_lock);
279 
280  EventIDBase now(ctx.eventID());
281 
282  std::ostringstream ost;
283  ost << "getValidIDS " << ctx.eventID()
284  << ": retrieving all ConstIterator<CondContBase>";
286  if (m_sgs->retrieve(cib,cie).isSuccess()) {
287  while(cib != cie) {
288  ost << std::endl << " + " << cib.key() << " v: " << cib->valid(now)
289  << " id: " << cib->id();
290 
291  if ( cib->valid(now) ) {
292  validIDs.insert( cib->id() );
293  } else {
294  invalidIDs.insert( cib->id() );
295  }
296 
297  ++cib;
298  }
299  } else {
300  ATH_MSG_DEBUG( ost.str() );
301  ATH_MSG_DEBUG( "Condition store empty." );
302  return false;
303  }
304 
305  ost << std::endl << " -> found " << validIDs.size() << " valid, "
306  << invalidIDs.size() << " invalid IDs";
307 
308  ATH_MSG_DEBUG( ost.str() );
309 
310  return true;
311 }
312 
313 //---------------------------------------------------------------------------
314 
315 bool
316 CondSvc::getValidIDs(const EventContext& ctx, DataObjIDColl& validIDs) {
317  std::lock_guard<mutex_t> lock(m_lock);
318 
319  EventIDBase now(ctx.eventID());
320 
321  std::ostringstream ost;
322  ost << "getValidIDS " << ctx.eventID()
323  << ": retrieving all ConstIterator<CondContBase>";
325  if (m_sgs->retrieve(cib,cie).isSuccess()) {
326  while(cib != cie) {
327  ost << std::endl << " + " << cib.key() << " v: " << cib->valid(now)
328  << " id: " << cib->id();
329 
330  if ( cib->valid(now) ) {
331  validIDs.insert( cib->id() );
332  }
333 
334  ++cib;
335  }
336  } else {
337  ATH_MSG_DEBUG( ost.str() );
338  ATH_MSG_DEBUG( "Condition store empty." );
339  return false;
340  }
341 
342  ost << std::endl << " -> found " << validIDs.size() << " valid IDs";
343 
344  ATH_MSG_DEBUG( ost.str() );
345 
346  return true;
347 }
348 
349 //---------------------------------------------------------------------------
350 
351 bool
352 CondSvc::isValidID(const EventContext& ctx, const DataObjID& id) const {
353  // Don't take out the lock here.
354  // In many-thread jobs, a lock here becomes heavily contended.
355  // The only potential conflict is with startConditionSetup(),
356  // which should only be called during START.
357 
358  EventIDBase now(ctx.eventID());
359 
360  // FIXME: this is ugly, but we need to strip out the name of the store.
361  std::string sk = id.key();
362  if (sk.starts_with( StoreID::storeName(StoreID::CONDITION_STORE))) {
363  sk.erase(0,15);
364  }
365 
366  auto it = m_condConts.find (sk);
367  if (it != m_condConts.end()) {
368  bool valid = it->second->valid (now);
369  ATH_MSG_VERBOSE("CondSvc::isValidID: now: " << ctx.eventID() << " id : "
370  << id << (valid ? ": T" : ": F") );
371  return valid;
372  }
373  else {
374  ATH_MSG_ERROR( "Cannot find CondCont " << id );
375  }
376 
377  ATH_MSG_DEBUG("CondSvc::isValidID: now: " << ctx.eventID() << " id: "
378  << id << " : F");
379  return false;
380 
381 }
382 
383 //---------------------------------------------------------------------------
384 
385 bool
386 CondSvc::isRegistered(const DataObjID& id) const {
387 
388  return (m_condIDs.find(id) != m_condIDs.end());
389 
390 }
391 
392 //---------------------------------------------------------------------------
393 
394 
395 bool
396 CondSvc::isRegistered(IAlgorithm* ialg) const {
397 
398  return (m_condAlgs.find(ialg) != m_condAlgs.end());
399 
400 }
401 
402 //---------------------------------------------------------------------------
403 
404 
405 const DataObjIDColl&
407 
408  return m_condIDs;
409 
410 }
411 
412 //---------------------------------------------------------------------------
413 
414 
416 {
417  std::lock_guard<mutex_t> lock(m_lock);
418 
420  if (m_sgs->retrieve(cib,cie).isSuccess()) {
421  while(cib != cie) {
422  m_condConts[cib.key()] = &*cib;
423  ++cib;
424  }
425  }
426 
427  return StatusCode::SUCCESS;
428 }
grepfile.info
info
Definition: grepfile.py:38
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
trigbs_pickEvents.ranges
ranges
Definition: trigbs_pickEvents.py:60
CondSvc::initialize
virtual StatusCode initialize() override
Definition: CondSvc.cxx:52
CondSvc::m_sgs
ServiceHandle< StoreGateSvc > m_sgs
Definition: CondSvc.h:101
CondSvc.h
CondSvc::isValidID
virtual bool isValidID(const EventContext &, const DataObjID &) const override
Definition: CondSvc.cxx:352
SGout2dot.alg
alg
Definition: SGout2dot.py:243
python.trigbs_prescaleL1.ost
ost
Definition: trigbs_prescaleL1.py:104
CondCont.h
Hold mappings of ranges to condition objects.
CondSvc::finalize
virtual StatusCode finalize() override
Definition: CondSvc.cxx:126
SG::detail::IteratorBase::key
const std::string & key() const
Get the key string with which the current object was stored.
Definition: SGIterator.cxx:155
initialize
void initialize()
Definition: run_EoverP.cxx:894
CondSvc::regHandle
virtual StatusCode regHandle(IAlgorithm *alg, const Gaudi::DataHandle &id) override
Definition: CondSvc.cxx:160
skel.it
it
Definition: skel.GENtoEVGEN.py:396
CondSvc::m_condConts
CondContMap_t m_condConts
Definition: CondSvc.h:117
CondSvc::dump
virtual void dump(std::ostream &) const override
Definition: CondSvc.cxx:87
PyPoolBrowser.dh
dh
Definition: PyPoolBrowser.py:102
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::BaseInfoBase::get_bases
const std::vector< CLID > & get_bases() const
Return the class IDs of all known bases of T (that have class IDs).
Definition: BaseInfo.cxx:304
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CondSvc::isRegistered
virtual bool isRegistered(const DataObjID &) const override
Definition: CondSvc.cxx:386
CondSvc::validRanges
virtual StatusCode validRanges(std::vector< EventIDRange > &ranges, const DataObjID &id) const override
Definition: CondSvc.cxx:26
CondSvc::~CondSvc
~CondSvc()
Definition: CondSvc.cxx:21
StoreID::CONDITION_STORE
@ CONDITION_STORE
Definition: StoreID.h:28
calibdata.valid
list valid
Definition: calibdata.py:45
python.handimod.now
now
Definition: handimod.py:675
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
BaseInfo.h
Provide an interface for finding inheritance information at run time.
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CondSvc::CondSvc
CondSvc(const std::string &name, ISvcLocator *svc)
Definition: CondSvc.cxx:13
CondSvc::getInvalidIDs
virtual bool getInvalidIDs(const EventContext &, DataObjIDColl &ids)
Definition: CondSvc.cxx:240
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
CondSvc::m_condIDs
DataObjIDColl m_condIDs
Definition: CondSvc.h:112
StoreID.h
CondSvc::conditionIDs
virtual const DataObjIDColl & conditionIDs() const override
Definition: CondSvc.cxx:406
CondSvc::stop
virtual StatusCode stop() override
Definition: CondSvc.cxx:142
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CondSvc::m_algMap
alg_map_t m_algMap
Definition: CondSvc.h:107
SG::BaseInfoBase::find
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
Definition: BaseInfo.cxx:569
CondSvc::m_lock
mutex_t m_lock
Definition: CondSvc.h:120
CondSvc::m_condAlgs
std::set< IAlgorithm * > m_condAlgs
Definition: CondSvc.h:110
CondSvc::regHandle_i
StatusCode regHandle_i(IAlgorithm *alg, const Gaudi::DataHandle &id)
Definition: CondSvc.cxx:171
SG::VarHandleKey
A property holding a SG store/key/clid from which a VarHandle is made.
Definition: StoreGate/StoreGate/VarHandleKey.h:62
a
TList * a
Definition: liststreamerinfos.cxx:10
CondSvc::m_idMap
id_map_t m_idMap
Definition: CondSvc.h:106
DEBUG
#define DEBUG
Definition: page_access.h:11
SG::BaseInfoBase
The non-template portion of the BaseInfo implementation.
Definition: Control/AthenaKernel/AthenaKernel/BaseInfo.h:451
CondSvc::start
virtual StatusCode start() override
Definition: CondSvc.cxx:133
LHEF::Writer
Pythia8::Writer Writer
Definition: Prophecy4fMerger.cxx:12
get_generator_info.error
error
Definition: get_generator_info.py:40
CondSvc::IAlgHashSet
std::set< IAlgorithm *, iAlgHasher > IAlgHashSet
Definition: CondSvc.h:103
SG::ConstIterator
Definition: SGIterator.h:163
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
StoreID::storeName
static const std::string & storeName(const StoreID::type &s)
Definition: StoreID.cxx:77
CondSvc::getIDValidity
virtual bool getIDValidity(const EventContext &, DataObjIDColl &validIDs, DataObjIDColl &invalidIDs)
Definition: CondSvc.cxx:276
CondSvc::getValidIDs
virtual bool getValidIDs(const EventContext &, DataObjIDColl &ids)
Definition: CondSvc.cxx:316
CondSvc::setupDone
virtual StatusCode setupDone() override
To be called after changes to the set of conditions containers in the conditions store.
Definition: CondSvc.cxx:415