ATLAS Offline Software
Loading...
Searching...
No Matches
IOVSvcTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "IOVSvcTool.h"
6/*****************************************************************************
7 *
8 * IOVSvcTool.cxx
9 * IOVSvc
10 *
11 * Author: Charles Leggett
12 *
13 * Tool to provide automatic updating and callbacks for time dependent data
14 *
15 *****************************************************************************/
16
17
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/IIncidentSvc.h"
20#include "GaudiKernel/Incident.h"
21#include "GaudiKernel/IAlgTool.h"
22#include "GaudiKernel/IToolSvc.h"
23#include "GaudiKernel/IClassIDSvc.h"
24#include "GaudiKernel/Guards.h"
25#include "GaudiKernel/ConcurrencyFlags.h"
26
33#include "SGTools/DataProxy.h"
35
36#include "IOVEntry.h"
37#include "IOVSvc/IOVAddress.h"
38#include "CBTree.h"
40
41#include <stdint.h>
42#include <ctype.h>
43#include <stdexcept>
44#include <atomic>
45
46using SG::DataProxy;
48
49std::string toUpper(const std::string& str) {
50 const char *cstr = str.c_str();
51 std::string str2("");
52 for (unsigned int i=0; i < str.length(); ++i) {
53 str2 += toupper(*(cstr+i));
54 }
55
56 return str2;
57}
58
59namespace {
60 std::atomic<bool> s_firstRun(true);
61}
62
63/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
64
65using namespace std;
66
67//
69//
70
71bool
73 const SG::TransientAddress* y) const {
74
75 if ( x->clID() == y->clID() ) {
76 return ( x->name() < y->name() );
77 } else {
78 return ( x->clID() < y->clID() );
79 }
80
81}
82
83//
85//
86
87bool
89 if (a&&b) {
90 if (a->name()!=b->name()) return a->name()<b->name();
91 if (a->clID()!=b->clID()) return a->clID()<b->clID();
92 }
93 //Fall back to ptr comp (in principle random, but similar name and
94 //clid means that the path in COOL is likely to be similar):
95 return a<b;
96}
97
98//
100//
101
102
103IOVSvcTool::IOVSvcTool(const std::string& type, const std::string& name,
104 const IInterface* parent):
105 base_class( type, name, parent ),
106 m_storeName("StoreGateSvc"),
107 p_cndSvc("DetectorStore",name),
108 p_incSvc("IncidentSvc",name), p_PPSvc("ProxyProviderSvc",name),
109 p_CLIDSvc("ClassIDSvc",name), p_toolSvc("ToolSvc",name),
110 p_startSet(nullptr),
111 p_stopSet(nullptr)
112{
113 m_trigTree = new CBTree();
114}
115
116/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
117
119
120 // cleanup
121
122 std::map<const DataProxy*, IOVEntry*>::iterator itr;
123 for (itr = m_entries.begin(); itr != m_entries.end(); ++itr) {
124 IOVEntry *ent = itr->second;
125 delete (ent);
126 }
127
128 ObjMap::iterator oitr;
129 for (oitr = m_objMap.begin(); oitr != m_objMap.end(); ++oitr) {
130 delete ( oitr->second );
131 }
132
133 for (std::map<CallBackID, BFCN*>::iterator i = m_cbidMap.begin();
134 i != m_cbidMap.end();
135 ++i)
136 {
137 delete i->second;
138 }
139
140 std::set< const TransientAddress*, SortTADptr >::const_iterator titr;
141 for (titr = m_preLoad.begin(); titr != m_preLoad.end(); ++titr)
142 {
143 delete *titr;
144 }
145
146 delete m_trigTree;
147
148}
149
150/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
151
152StatusCode
154
155 SmartIF<IProperty> iovSvcProp{service("IOVSvc")};
156 ATH_CHECK( iovSvcProp.isValid() );
157
158 ATH_CHECK( setProperty( iovSvcProp->getProperty("preLoadRanges") ) );
159 ATH_CHECK( setProperty( iovSvcProp->getProperty("preLoadData") ) );
160 ATH_CHECK( setProperty( iovSvcProp->getProperty("partialPreLoadData") ) );
161 ATH_CHECK( setProperty( iovSvcProp->getProperty("preLoadExtensibleFolders") ) );
162 ATH_CHECK( setProperty( iovSvcProp->getProperty("updateInterval") ) );
163 ATH_CHECK( setProperty( iovSvcProp->getProperty("sortKeys") ) );
164 ATH_CHECK( setProperty( iovSvcProp->getProperty("forceResetAtBeginRun") ) );
165 ATH_CHECK( setProperty( iovSvcProp->getProperty("OutputLevel") ) );
166
167 int pri=100;
168
169 std::string updi = toUpper(m_updateInterval);
170
171 if (updi== "JOB") {
172 m_checkOnce = true;
173 m_checkTrigger = "BeginRun";
174 p_incSvc->addListener( this, "BeginRun", pri, true);
175 msg() << MSG::INFO;
176 msg().setColor(MSG::GREEN);
177 msg() << "IOVRanges will be checked only ";
178 msg().setColor(MSG::CYAN);
179 msg() << "once";
180 msg().setColor(MSG::GREEN);
181 msg() << " at the start of the job" << endmsg;
182 } else if (updi == "RUN") {
183 m_checkTrigger = "BeginRun";
184 p_incSvc->addListener( this, "BeginRun", pri, true);
185 msg() << MSG::INFO;
186 msg().setColor(MSG::GREEN);
187 msg() << "IOVRanges will be checked at every ";
188 msg().setColor(MSG::CYAN);
189 msg() << "Run" << endmsg;
190 } else if (updi == "EVENT") {
191 m_checkTrigger = "BeginEvent";
192 p_incSvc->addListener( this, "BeginEvent", pri, true);
193 p_incSvc->addListener( this, "BeginRun", pri, true);
194 msg() << MSG::INFO;
195 msg().setColor(MSG::GREEN);
196 msg() << "IOVRanges will be checked at every ";
197 msg().setColor(MSG::CYAN);
198 msg() << "Event" << endmsg;
199 } else {
200 ATH_MSG_FATAL("jobOption \"updateInterval\" must be one of "
201 << "\"event\" \"run\" or \"job\"");
202 return StatusCode::FAILURE;
203 }
204
205 if (m_preLoadData) {
206 msg() << MSG::INFO;
207 msg().setColor(MSG::GREEN);
208 msg() << "IOV Data will be preloaded at the same interval" << endmsg;
209 }
210
211 ATH_MSG_DEBUG("Tool initialized");
212
213 return StatusCode::SUCCESS;
214}
215
216
217/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
218
219void
220IOVSvcTool::handle(const Incident &inc) {
221
222 bool initial_first = m_first;
223
224 // Don't bother doing anything if we're handled the first run, and
225 // preLoadData has been set, or if we only want to check once at the
226 // beginning of the job
227 if (!initial_first && m_preLoadData && m_checkOnce) {
228 return;
229 }
230 else if (!initial_first) {
231 if ( inc.type() != m_checkTrigger && inc.type() != IncidentType::BeginRun ) {
232 return;
233 }
234 }
235
236 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
237 if (initial_first) {
238 if (!m_first && m_preLoadData && m_checkOnce) {
239 return;
240 }
241 // cppcheck-suppress oppositeInnerCondition
242 else if (!m_first) {
243 if ( inc.type() != m_checkTrigger && inc.type() != IncidentType::BeginRun ) {
244 return;
245 }
246 }
247 // cppcheck-suppress identicalInnerCondition
248 if (m_first) {
249 for (const auto& e : m_ignoredProxyNames) {
250 DataProxy* proxy = p_cndSvc->proxy(e.first,e.second);
251 ATH_MSG_DEBUG("retrieving "<<fullProxyName(e.first,e.second));
252 if (proxy == nullptr) {
253 ATH_MSG_ERROR("ignoreProxy: could not retrieve proxy "
254 << fullProxyName(e.first,e.second) << " from store");
255 } else {
256 ignoreProxy( proxy );
257 ATH_MSG_DEBUG("will ignore resetting proxy " << fullProxyName(proxy));
258 }
259 }
260 m_first = false;
261 }
262 else {
263 initial_first=false;
264 }
265 }//end first
266 const bool first = initial_first;
267
268 // Forcing IOV checks on the first event in the run for AthenaMP (ATEAM-439)
269 if(Gaudi::Concurrency::ConcurrencyFlags::numProcs()==0) {
270 if (inc.type() == IncidentType::BeginRun) {
271 m_firstEventOfRun = true;
272 }
273
274 if (inc.type() == IncidentType::BeginEvent && m_firstEventOfRun) {
275 m_firstEventOfRun = false;
276 if (m_checkTrigger == "BeginEvent") {
277 return;
278 }
279 }
280 }
281
282 set< DataProxy*, SortDPptr > proxiesToReset;
283 if ( inc.type() == m_checkTrigger || inc.type() == IncidentType::BeginRun ) {
284
285 const EventContext& context = inc.context();
286
287 IOVTime curTime;
288
289 const EventIDBase& eventID = context.eventID();
290 uint32_t event = eventID.lumi_block();
291 uint32_t run = eventID.run_number();
292
293 ATH_MSG_DEBUG("Got event info: " << "run="<< run << ", event=" << event);
294 curTime.setRunEvent(run,event);
295
296 // get ns timestamp from event
297 curTime.setTimestamp(1000000000L*(uint64_t)eventID.time_stamp() + eventID.time_stamp_ns_offset());
298
299 if (msgLvl(MSG::DEBUG)) {
300 msg().setColor(MSG::YELLOW,MSG::RED);
301 msg() << inc.type() << ": [R/LB] = " << curTime << endmsg;
302 }
303
304 if (inc.type() == IncidentType::BeginRun) {
305 // Signal BeginRun directly to IOVDbSvc
306 SmartIF<IIOVDbSvc> iovDB{service("IOVDbSvc", false)};
307 if (!iovDB) {
308 ATH_MSG_DEBUG("Unable to get the IOVDbSvc");
309 return;
310 }
311 if (StatusCode::SUCCESS != iovDB->signalBeginRun(curTime,
312 inc.context()))
313 {
314 ATH_MSG_ERROR("Unable to signal begin run to IOVDbSvc");
315 return;
316 }
317 else {
318 ATH_MSG_DEBUG("Signaled begin run to IOVDbSvc " << curTime);
319 }
320 }
321
322 if (first) {
323
324 std::set< const TransientAddress*, SortTADptr >::const_iterator titr;
325 for (titr = m_preLoad.begin(); titr != m_preLoad.end(); ++titr) {
326 const TransientAddress *tad = *titr;
327 StatusCode sc = regProxy(tad->clID(), tad->name());
328 if (StatusCode::SUCCESS != sc) {
329 ATH_MSG_ERROR("handle: Could not register proxy for " <<
330 fullProxyName(tad->clID(), tad->name()));
331 return;
332 }
333 }
334
335 if (msgLvl(MSG::VERBOSE)) {
337 msg() << endmsg;
338 }
339
340 if (msgLvl(MSG::DEBUG)) {
341 msg() << "Callback Tree:" << endmsg;
342 m_trigTree->printTree();
343 }
344
345 // preLoad the ranges and data if requested.
346 if (preLoadProxies(inc.context()).isFailure()) {
347 ATH_MSG_ERROR("Problems preloading IOVRanges");
348 throw( std::runtime_error("IOVSvcTool::preLoadProxies") );
349 }
350
351 // Signal EndProxyPreload directly to IOVDbSvc
352 SmartIF<IIOVDbSvc> iovDB{service("IOVDbSvc", false)};
353 if (iovDB) {
354 iovDB->signalEndProxyPreload();
355 ATH_MSG_DEBUG("Signaled end proxy preload to IOVDbSvc " << curTime);
356 }
357 }// end if first
358
359 // If preLoadData has been set, never check validity of data again.
360 if (m_preLoadData && m_checkOnce) {
361 return;
362 }
363
364 // Otherwise, do the normal check for validity
365
366
367 if (msgLvl(MSG::DEBUG)) {
369 PrintStopSet();
370 msg() << endmsg;
371 }
372
373 std::map<BFCN*, std::list<std::string> > resetKeys;
374
375 //
378 //
379
380 if (inc.type() == IncidentType::BeginRun && m_forceReset && !s_firstRun) {
381
382 ATH_MSG_DEBUG("Resetting all proxies on BeginRun incident for store \""
383 << m_storeName << "\"");
384
385 if (msgLvl(MSG::VERBOSE)) {
386 std::set< const SG::DataProxy* >::const_iterator pit;
387 for (SG::DataProxy* p : m_proxies) {
388 msg() << " " << m_names.at(p) << std::endl;
389 }
390 msg() << endmsg;
391 }
392 proxiesToReset = m_proxies;
393 m_triggered = false;
394 } else {
395 scanStartSet(m_startSet_Clock,"(ClockTime)",proxiesToReset,curTime);
396 scanStartSet(m_startSet_RE,"(R/E)",proxiesToReset,curTime);
397
398 scanStopSet(m_stopSet_Clock,"(ClockTime)",proxiesToReset,curTime);
399 scanStopSet(m_stopSet_RE,"(R/E)",proxiesToReset,curTime);
400 }
401
402 for (auto p : m_ignoredProxies) {
403 auto itr = proxiesToReset.find(p);
404 if (itr != proxiesToReset.end()) {
405 proxiesToReset.erase( itr );
406 }
407 }
408
409 // If MT, must not call any callback functions after first event
410 if (!first && proxiesToReset.size() > 0 &&
411 ( (Gaudi::Concurrency::ConcurrencyFlags::numThreads() +
412 Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents()) > 0 ) ) {
413 ATH_MSG_FATAL("Cannot update Conditions via callback functions in MT after the first event");
414 for (const auto* prox : proxiesToReset) {
415 ATH_MSG_FATAL("CLID=" << prox->clID() << ", name=" << prox->name());
416 }
417 throw GaudiException("Cannot update Conditions via callback functions in MT after the first event",name(),StatusCode::FAILURE);
418 }
419
420 //
423 //
424 for (DataProxy* prx : proxiesToReset) {
425 ATH_MSG_VERBOSE("clearing proxy payload for " << m_names.at(prx));
426
427 // Reset proxy except when one wants to reset callbacks
428
429 if (!m_resetAllCallbacks) p_cndSvc->clearProxyPayload( prx );
430
431 m_trigTree->cascadeTrigger(true, prx);
432
433 // Load data if preload requested.
434
435 if ( (m_partialPreLoadData &&
436 m_partPreLoad.find(TADkey(*prx)) != m_partPreLoad.end())
437 ||
438 m_preLoadData ) {
439 ATH_MSG_VERBOSE("preloading data");
440
441 Gaudi::Guards::AuditorGuard auditor(m_names.at(prx), auditorSvc(), "preLoadProxy");
442 if (prx->accessData() == nullptr) {
443 ATH_MSG_ERROR("problems preloading data for " << m_names.at(prx));
444 }
445 }
446
447 std::list<std::string> keys;
448 pair<pmITR,pmITR> fitr = m_proxyMap.equal_range( prx );
449 for (pmITR p=fitr.first; p!=fitr.second; ++p) {
450 BFCN *f = p->second;
451 std::string key = prx->name();
452 resetKeys[f].emplace_back(prx->name());
453 }
454 }
455
457
458 // Check to see if it's first event, and if preLoadProxies has already
459 // called the functions
460
461 IOVCallbackError* perr(0);
462
463 if (! (first && m_triggered) ) {
464 for (int i=2; i<= m_trigTree->maxLevel(); ++i) {
465 CBTree::nodeSet::const_iterator itt, itt_s, itt_e;
466 m_trigTree->listNodes( i, itt_s, itt_e );
467 for (itt = itt_s; itt != itt_e; ++itt) {
468 CBNode* node = *itt;
469
470 if (node->trigger()) {
471 BFCN *ff = node->fcn();
472 auditorSvc()->before("Callback",m_fcnMap.at(ff).name(),inc.context());
473 if ((*ff)(i,resetKeys[ff]).isFailure()) {
474 auditorSvc()->after("Callback",m_fcnMap.at(ff).name(),inc.context());
475 ATH_MSG_ERROR("Problems calling " << m_fcnMap.at(ff).name()
476 << std::endl << "Skipping all subsequent callbacks.");
477 // this will cause a mem leak, but I don't care
478 perr = new IOVCallbackError(m_fcnMap.at(ff).name());
479 break;
480 }
481 auditorSvc()->after("Callback",m_fcnMap.at(ff).name(),inc.context());
482 }
483 }
484 if (perr != nullptr) break;
485 }
486 }
487
488
490 m_trigTree->clearTrigger();
491
498 m_resetAllCallbacks = false;
499 if (perr != nullptr) throw (*perr);
500 return;
501 }
502
503
505 std::map<const DataProxy*, IOVEntry*>::iterator pitr;
506 for (DataProxy* prx : proxiesToReset) {
507 pitr = m_entries.find( prx );
508 if ( pitr != m_entries.end() && pitr->second->range()->isInRange(curTime) ) {
509 ATH_MSG_VERBOSE("range still valid for " << m_names.at(prx));
510 } else {
511 ATH_MSG_DEBUG("calling provider()->udpateAddress(TAD) for " << m_names.at(prx) );
512 if (!prx->updateAddress()) {
513 ATH_MSG_ERROR("handle: Could not update address");
514 if (perr != nullptr) throw (*perr);
515 return;
516 }
517 }
518
519 if (msgLvl(MSG::VERBOSE)) {
520 IOpaqueAddress *ioa = prx->address();
521 // Print out some debug info if this is an IOVAddress (coming
522 // from IOVASCIIDbSvc)
523 IOVAddress *iova = dynamic_cast<IOVAddress*>(ioa);
524 if (iova != nullptr) {
525 ATH_MSG_VERBOSE(" range: " << iova->range());
526 }
527 }
528
529 }
530
531 if (perr != nullptr) throw (*perr);
532
533 } // end if(inc.type() == m_checkTrigger)
534
535 if ( inc.type() == IncidentType::BeginRun) {
536 s_firstRun = false;
537 }
538
539}
540
541/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
542
546StatusCode
547IOVSvcTool::regProxy( DataProxy *proxy, const std::string& key) {
548
549
550 if (proxy == nullptr) {
551 ATH_MSG_ERROR("proxy == 0");
552 return StatusCode::FAILURE;
553 }
554
555 ATH_MSG_DEBUG("registering proxy " << fullProxyName(proxy) << " at " << proxy);
556
557 if (m_proxies.find(proxy) != m_proxies.end()) {
558 ATH_MSG_DEBUG("Proxy for " << fullProxyName(proxy)
559 << " already registered: " << proxy->name());
560 return StatusCode::SUCCESS;
561 }
562
563 std::string tname, fullname;
564 ATH_CHECK( p_CLIDSvc->getTypeNameOfID(proxy->clID(), tname) );
565
566 fullname = tname + "[" + key + "]";
567
568 m_proxies.insert( proxy );
569 m_names[ proxy ] = fullname;
570
571 m_trigTree->addNode(proxy,fullname);
572
573 return StatusCode::SUCCESS;
574
575}
576
577
578/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
579
583StatusCode
585
586
587 if (proxy == nullptr) {
588 ATH_MSG_ERROR("proxy == 0");
589 return StatusCode::FAILURE;
590 }
591
592 ATH_MSG_DEBUG("removing proxy " << fullProxyName(proxy) << " at " << proxy);
593
594 std::set<SG::DataProxy*, SortDPptr>::iterator itr = m_proxies.find(proxy);
595 if (itr == m_proxies.end()) {
596 ATH_MSG_DEBUG("Proxy for " << fullProxyName(proxy)
597 << " not registered: " << proxy->name());
598 return StatusCode::SUCCESS;
599 }
600
601 m_proxies.erase( itr );
602
603 m_trigTree->delNode(proxy);
604
605 return StatusCode::SUCCESS;
606
607}
608
609/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
610
611namespace {
612
613 template <class SET>
614 void removeFromSet (IOVEntry* ent, SET& set)
615 {
616 typename SET::iterator it = set.lower_bound(ent);
617 while (it != set.end() && !set.key_comp()(*it, ent) && !set.key_comp()(ent,*it)) {
618 if (*it == ent)
619 set.erase (it++);
620 else
621 ++it;
622 }
623 }
624
625
626} // anonymous namespace
627
628/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
629
633StatusCode
635 SG::DataProxy *pNew) {
636 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
637 assert(nullptr != pOld);
638 assert(nullptr != pNew);
639
640 ATH_MSG_DEBUG("replace proxy " << fullProxyName(pOld)
641 << " @" << pOld << " with " << fullProxyName(pNew)
642 << " @" << pNew);
643
644 //start with the proxy list
645 if (0 == m_proxies.erase(pOld)) {
646 ATH_MSG_DEBUG("unregProxy: original proxy "
647 << fullProxyName(pOld) << " not found. Will return now ");
648 return StatusCode::SUCCESS;
649 }
650 m_proxies.insert(pNew);
651 //new name (possibly identical to old)
652 m_names.erase(pOld);
653 std::string tname;
654 ATH_CHECK( p_CLIDSvc->getTypeNameOfID(pNew->clID(), tname) );
655
656 m_names[pNew]=tname + "[" + pNew->name() + "]";
657
658 if (pOld != pNew) {
659 std::map< const SG::DataProxy*, IOVEntry*>::iterator ent =
660 m_entries.find(pOld);
661 if (ent != m_entries.end()) {
662 removeFromSet (ent->second, m_startSet_Clock);
663 removeFromSet (ent->second, m_startSet_RE);
664 removeFromSet (ent->second, m_stopSet_Clock);
665 removeFromSet (ent->second, m_stopSet_RE);
666
667 setRange_impl (pNew, *(const_cast<IOVRange*>(ent->second->range())));
668 delete ent->second;
669 m_entries.erase (ent);
670 }
671 }
672
673 return (m_trigTree->replaceProxy(pOld, pNew) ?
674 StatusCode::SUCCESS :
675 StatusCode::FAILURE );
676
677}
678/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
679
683StatusCode
684IOVSvcTool::regProxy( const CLID& clid, const std::string& key ) {
685
686 DataProxy* proxy = p_cndSvc->proxy(clid,key);
687
688 if (proxy == nullptr) {
689 ATH_MSG_ERROR("regProxy could not retrieve proxy "
690 << fullProxyName(clid,key) << " from store");
691 return StatusCode::FAILURE;
692 }
693
694 return ( regProxy(proxy, key) );
695
696}
697
698/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
699
703StatusCode
704IOVSvcTool::deregProxy( const CLID& clid, const std::string& key ) {
705
706 DataProxy* proxy = p_cndSvc->proxy(clid,key);
707
708 if (proxy == nullptr) {
709 ATH_MSG_ERROR("regProxy could not retrieve proxy "
710 << fullProxyName(clid,key) << " from store");
711 return StatusCode::FAILURE;
712 }
713
714 return ( deregProxy(proxy) );
715
716}
717
718/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
719
723StatusCode
725
726 // check to see if it's a duplicate in preLoad
727 if (m_preLoad.find( tad_in ) != m_preLoad.end()) {
728 ATH_MSG_WARNING("preLoadTAD: TransientAddress ("
729 << tad_in->clID() << "/" << tad_in->name()
730 << ") alread in preLoad set. Not inserting");
731 return StatusCode::SUCCESS;
732 }
733
734 // check to see if it's a duplicate in partPreLoad
735 if (m_partPreLoad.find( TADkey(*tad_in) ) != m_partPreLoad.end()) {
736 ATH_MSG_WARNING("preLoadTAD: TransientAddress ("
737 << tad_in->clID() << "/" << tad_in->name()
738 << ") alread in partPreLoad set. Not inserting");
739 return StatusCode::SUCCESS;
740 }
741
742 TransientAddress* tad = new TransientAddress (tad_in->clID(),tad_in->name());
743 m_preLoad.insert( tad );
744
745 return StatusCode::SUCCESS;
746}
747
748/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
749
753StatusCode
755
756 if (m_preLoad.find(tad_in) != m_preLoad.end()) {
757 ATH_MSG_WARNING("preLoadDataTAD: TransientAddress "
758 << fullProxyName( tad_in )
759 << " alread in preLoad set. Not inserting");
760 return StatusCode::SUCCESS;
761 }
762
763 if (m_partPreLoad.find(TADkey(*tad_in)) != m_partPreLoad.end()) {
764 ATH_MSG_WARNING("preLoadDataTAD: TransientAddress "
765 << fullProxyName( tad_in )
766 << " alread in partPreLoad set. Not inserting");
767 return StatusCode::SUCCESS;
768 }
769
770 TransientAddress* tad = new TransientAddress (tad_in->clID(),tad_in->name());
771 m_preLoad.insert( tad );
772 m_partPreLoad.insert( TADkey(*tad) );
773
774 return StatusCode::SUCCESS;
775}
776
777/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
778
780{
781 if (iovr.start().isTimestamp()) {
784 } else {
787 }
788
789 IOVRange *range = new IOVRange(iovr);
790
792 if ( itr != m_entries.end() ) {
793
794 IOVEntry *ent = itr->second;
795 const IOVRange *irn = ent->range();
796
797 if (*irn == iovr) {
798 ATH_MSG_DEBUG("Range has not changed. Returning");
799 delete range;
800 return;
801 // is this true? still in the start and stop sets? FIXME
802 }
803
804
805 startITR sitr = ent->getStartITR();
806 if ( !ent->removedStart() ) {
807 p_startSet->erase( sitr );
808 }
809
810
811
812 stopITR pitr = ent->getStopITR();
813 if ( !ent->removedStop() ) {
814 p_stopSet->erase( pitr );
815 }
816
817 delete ent;
818 }
819
820 ATH_MSG_DEBUG("adding to start and stop sets");
821 IOVEntry *ent = new IOVEntry(proxy,range);
822
823 m_entries[ proxy ] = ent;
824
825 ent->setStartITR( p_startSet->insert( ent ) );
826 ent->setStopITR( p_stopSet->insert( ent ) );
827}
828
829
830StatusCode
831IOVSvcTool::setRange(const CLID& clid, const std::string& key,
832 IOVRange& iovr)
833{
834
835 ATH_MSG_DEBUG("setRange() for clid: " << clid << " key: " << key
836 << " in IOVrange:" << iovr);
837
838 if (!iovr.start().isValid() || !iovr.stop().isValid()) {
839 ATH_MSG_ERROR("IOVRange " << iovr << "is not valid. Start OK: "
840 << iovr.start().isValid() << " Stop OK: " << iovr.stop().isValid()
841 << " run/evt/time min/max "
842 << IOVTime::MINRUN << "/" << IOVTime::MAXRUN << " "
843 << IOVTime::MINEVENT << "/" << IOVTime::MAXEVENT << " "
844 << IOVTime::MINTIMESTAMP << "/" << IOVTime::MAXTIMESTAMP << " ");
845 return StatusCode::FAILURE;
846 }
847
848 DataProxy* proxy = p_cndSvc->proxy(clid,key);
849
850 if (proxy == nullptr) {
851 ATH_MSG_ERROR("setRange: Could not locate proxy for " << fullProxyName(clid,key));
852 return StatusCode::FAILURE;
853 }
854
855 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
856 setRange_impl (proxy, iovr);
857 return StatusCode::SUCCESS;
858}
859/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
860
861StatusCode
862IOVSvcTool::getRange(const CLID& clid, const std::string& key,
863 IOVRange& iov) const {
864
865 DataProxy* dp = p_cndSvc->proxy(clid,key);
866
867 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
868 std::map<const DataProxy*,IOVEntry*>::const_iterator itr(m_entries.find(dp));
869 if (itr == m_entries.end()) {
870 return StatusCode::FAILURE;
871 }
872
873 iov = *(itr->second->range());
874
875 return StatusCode::SUCCESS;
876
877}
878
879/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
880
881StatusCode
882IOVSvcTool::getRangeFromDB(const CLID& clid, const std::string& key,
883 IOVRange& range, std::string &tag,
884 std::unique_ptr<IOpaqueAddress>& ioa,
885 const IOVTime& curTime) const {
886
887 if (curTime.isValid()) {
888 return getRangeFromDB(clid, key, curTime, range, tag, ioa);
889 } else {
890 ATH_MSG_ERROR("Current Event not defined");
891 return StatusCode::FAILURE;
892 }
893
894}
895
896/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
897
898StatusCode
899IOVSvcTool::getRangeFromDB(const CLID& clid, const std::string& key,
900 const IOVTime& time, IOVRange& range,
901 std::string& tag,
902 std::unique_ptr<IOpaqueAddress>& ioa) const {
903 StatusCode sc(StatusCode::FAILURE);
904 DataProxy* dp = p_cndSvc->proxy(clid,key);
905 if (nullptr != dp) {
906 IIOVDbSvc *idb =
907 dynamic_cast<IIOVDbSvc*>(dp->provider());
908 if (idb != nullptr) {
909 sc = idb->getRange(clid, key, time, range, tag, ioa);
910 } else {
911 ATH_MSG_ERROR("Provider is not an IIOVDbSvc");
912 }
913 } else {
914 ATH_MSG_ERROR("No proxy found for clid " << clid << " key " << key);
915 }
916 return sc;
917}
918
919/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
920
921StatusCode
922IOVSvcTool::setRangeInDB(const CLID& clid, const std::string& key,
923 const IOVRange& range, const std::string &tag) {
924
925
926 if (!range.start().isValid() || !range.stop().isValid()) {
927 ATH_MSG_ERROR("IOVRange " << range << "is not valid.");
928 return StatusCode::FAILURE;
929 }
930
931 DataProxy* dp = p_cndSvc->proxy(clid,key);
932
933 if (dp == nullptr) {
934 ATH_MSG_ERROR("no Proxy found for " << fullProxyName( clid, key ));
935 return StatusCode::FAILURE;
936 }
937
938 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
939 std::map<const DataProxy*,IOVEntry*>::const_iterator itr(m_entries.find(dp));
940 if (itr == m_entries.end()) {
941 ATH_MSG_WARNING(fullProxyName(clid,key) << " not registered with the IOVSvc");
942 }
943
944 IAddressProvider *iadp = dp->provider();
945 IIOVDbSvc *idb = dynamic_cast<IIOVDbSvc*>(iadp);
946
947 if (idb != nullptr) {
948 return idb->setRange(clid, key, range, tag);
949 } else {
950 ATH_MSG_ERROR("Provider is not an IIOVDbSvc");
951 return StatusCode::FAILURE;
952 }
953
954}
955
956/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
957
958StatusCode
959IOVSvcTool::preLoadProxies(const EventContext& ctx) {
960
961 ATH_MSG_DEBUG("preLoadProxies()");
962
963 StatusCode scr(StatusCode::SUCCESS);
964
965 SmartIF<IIOVDbSvc> iovDB{service("IOVDbSvc", false)};
966
967 std::map<BFCN*, std::list<std::string> > resetKeys;
968 for (DataProxy* dp : m_proxies) {
969 Gaudi::Guards::AuditorGuard auditor(m_names[dp], auditorSvc(), "preLoadProxy");
970
971 if (msgLvl(MSG::VERBOSE)) {
972 msg().setColor(MSG::CYAN);
973 msg() << "loading proxy for CLID: " << dp->clID()
974 << " " << m_names[dp] << endmsg;
975 }
976
977 if (dp->provider() == nullptr) {
978 msg() << MSG::FATAL << "No provider found for proxy " << m_names[dp]
979 << ". It is probably not a conditions object" << endl;
980 msg() << "Proxy Map: ";
981 PrintProxyMap(dp);
982 msg() << endmsg;
983 scr = StatusCode::FAILURE;
984 return (scr);
985 }
986
987
988 StatusCode sc;
989 // preload IOVRanges for callback functions or if jobOption set
990 // This gets us to an IAddressProvider (eg IOVDbSvc)
991 pair<pmITR,pmITR> pi = m_proxyMap.equal_range(dp);
992 if (pi.first != pi.second || m_preLoadRanges) {
993 ATH_MSG_VERBOSE("updating Range");
994 if (!dp->updateAddress())
995 sc = StatusCode::FAILURE;
996 }
997
998 if ( ( m_partialPreLoadData &&
999 m_partPreLoad.find(TADkey(*dp)) != m_partPreLoad.end() )
1000 || m_preLoadData ) {
1001
1002 IIOVDbSvc::KeyInfo kinfo;
1003 if ( !m_preLoadExtensibleFolders && iovDB &&
1004 iovDB->getKeyInfo(dp->name(), kinfo) && kinfo.extensible ) {
1005 ATH_MSG_VERBOSE("not preloading data for extensible folder " << dp->name());
1006 }
1007 else {
1008 ATH_MSG_VERBOSE("preloading data for ("
1009 << dp->clID() << "/"
1010 << dp->name() << ")");
1011 if( dp->accessData() != nullptr ) {
1012 sc = StatusCode::SUCCESS;
1013 } else {
1014 sc = StatusCode::FAILURE;
1015 ATH_MSG_ERROR("preLoading proxies: accessData() failed for " <<
1016 dp->clID() << "/" << dp->name() << ")");
1017 }
1018 }
1019 }
1020
1021 if (sc.isFailure()) scr=sc;
1022
1023
1024 // accumulate callBacks
1025 pmITR pitr;
1026 for (pitr=pi.first; pitr!=pi.second; ++pitr) {
1027 BFCN *f = pitr->second;
1028 resetKeys[f].emplace_back(dp->name());
1029 }
1030
1031 CBNode* cn = m_trigTree->findNode( dp );
1032 if (cn != nullptr) {
1033 m_trigTree->cascadeTrigger(1, cn);
1034 }
1035
1036 }
1037
1038 if (scr.isFailure()) {
1039 ATH_MSG_ERROR("Problems preLoading proxies. No callbacks triggered.");
1040 return scr;
1041 }
1042
1044 for (int i=2; i<= m_trigTree->maxLevel(); ++i) {
1045 CBTree::nodeSet::const_iterator itt, itt_s, itt_e;
1046 m_trigTree->listNodes( i, itt_s, itt_e );
1047 for (itt = itt_s; itt != itt_e; ++itt) {
1048 CBNode* node = *itt;
1049
1050 if (node->trigger()) {
1051 BFCN *ff = node->fcn();
1052 if (m_sortKeys) { resetKeys[ff].sort(); }
1053 auditorSvc()->before("Callback",m_fcnMap[ff].name(),ctx);
1054 if ((*ff)(i,resetKeys[ff]).isFailure()) {
1055 auditorSvc()->after("Callback",m_fcnMap[ff].name(),ctx);
1056 ATH_MSG_ERROR("Problems calling ");
1057 return StatusCode::FAILURE;
1058 }
1059 auditorSvc()->after("Callback",m_fcnMap[ff].name(),ctx);
1060 }
1061 }
1062 }
1063
1064 m_trigTree->clearTrigger();
1065
1066 m_triggered = true;
1067
1068 return scr;
1069}
1070/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1071
1072StatusCode
1073IOVSvcTool::triggerCallback(IOVSvcCallBackFcn* fcn, const std::string& key ) {
1074
1075 ATH_MSG_VERBOSE("triggerCallback(BFCN*)");
1076
1077 int I {}; // initialize to something
1078 std::list<std::string> klist;
1079 klist.push_back(key);
1080 if ( (*fcn)(I,klist).isFailure() ) {
1081 ATH_MSG_ERROR("calling ");
1082 return StatusCode::FAILURE;
1083 }
1084
1085 return StatusCode::SUCCESS;
1086
1087}
1088/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1089
1090StatusCode
1092 const std::string& key ) {
1093
1094 ATH_MSG_VERBOSE("triggerCallback(DataProxy*)");
1095
1096 std::map<const SG::DataProxy*, BFCN*>::const_iterator pitr =
1097 m_proxyMap.find(dp);
1098 if (pitr == m_proxyMap.end()) {
1099 ATH_MSG_ERROR("no callback associated with DataProxy " << m_names[dp]);
1100 return StatusCode::FAILURE;
1101 }
1102
1103 BFCN* fcn = pitr->second;
1104
1105 return ( triggerCallback(fcn,key) );
1106
1107}
1108
1109/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1110
1111void
1113 startITR start_itr;
1114 std::string objname;
1115
1116 if (m_startSet_Clock.begin() != m_startSet_Clock.end()) {
1117 msg() << endl << "ClockTime start set: " << endl;
1118 for (start_itr = m_startSet_Clock.begin(); start_itr!=m_startSet_Clock.end(); ++start_itr ) {
1119 objname = m_names.at( (*start_itr)->proxy() );
1120 msg() << " " << objname << " (" << (*start_itr)->proxy() << ") "
1121 << (*start_itr)->range()->start() << endl;
1122 }
1123 msg() << endl;
1124 }
1125
1126 if (m_startSet_RE.begin() != m_startSet_RE.end()) {
1127 msg() << "Run/Event start set: " << endl;
1128 for (start_itr = m_startSet_RE.begin(); start_itr!=m_startSet_RE.end();++start_itr ) {
1129 objname = m_names.at( (*start_itr)->proxy() );
1130 msg() << " " << objname << " (" << (*start_itr)->proxy() << ") "
1131 << (*start_itr)->range()->start() << endl;
1132 }
1133 }
1134
1135}
1136
1137/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1138
1139void
1141 stopITR stop_itr;
1142 std::string objname;
1143
1144 if (m_stopSet_Clock.begin() != m_stopSet_Clock.end()) {
1145 msg() << endl << "ClockTime stop set: " << endl;
1146 for( stop_itr=m_stopSet_Clock.begin(); stop_itr!=m_stopSet_Clock.end(); ++stop_itr ) {
1147 objname = m_names.at((*stop_itr)->proxy());
1148 msg() << " " << objname << " (" << (*stop_itr)->proxy() << ") "
1149 << (*stop_itr)->range()->stop() << endl;
1150 }
1151 msg() << endl;
1152 }
1153
1154 if (m_stopSet_RE.begin() != m_stopSet_RE.end()) {
1155 msg() << "Run/Event stop set: " << endl;
1156 for( stop_itr=m_stopSet_RE.begin(); stop_itr!=m_stopSet_RE.end(); ++stop_itr ) {
1157 objname = m_names.at((*stop_itr)->proxy());
1158 msg() << " " << objname << " (" << (*stop_itr)->proxy() << ") "
1159 << (*stop_itr)->range()->stop() << endl;
1160 }
1161 }
1162}
1163
1164/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1165
1166void
1168 msg() << endl;
1169 msg() << "------------------------------ IOVSvc Proxy Map "
1170 << "------------------------------" << endl;
1171
1172 for (DataProxy* p : m_proxies) {
1173 PrintProxyMap(p);
1174 }
1175 msg() << "----------------------------------------------------------"
1176 << "---------------------" << endl;
1177}
1178
1179/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1180
1181void
1183
1184 auto it = m_names.find(dp);
1185 msg() << " " << dp << " " << dp->clID() << " "
1186 << (it == m_names.end() ? "???" : it->second) << endl;
1187 auto pi = m_proxyMap.equal_range(dp);
1188 if (pi.first == pi.second) {
1189 msg() << " -> no callback associated" << endl;
1190 } else {
1191 for (auto pitr=pi.first; pitr!=pi.second; ++pitr) {
1192 BFCN* fcn = pitr->second;
1194 if (fitr != m_fcnMap.end()) {
1195 CallBackID cbid = fitr->second;
1196 msg() << " -> " << fcn << " " << cbid.name() << endl;
1197 }
1198 }
1199 }
1200}
1201
1202/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1203/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1204
1205StatusCode
1207 const CallBackID& c,
1208 const IOVSvcCallBackFcn& fcn,
1209 bool trigger) {
1210
1211 std::string tname,fullname;
1212 StatusCode sc = p_CLIDSvc->getTypeNameOfID( dp->clID(), tname );
1213 if (sc.isFailure()) {
1214 ATH_MSG_ERROR("Unable to get type name from ClassIDSvc");
1215 return StatusCode::FAILURE;
1216 }
1217 fullname = tname + "[" + dp->name() + "]";
1218
1219 // see if proxy already bound
1220 if (m_proxies.find( dp ) == m_proxies.end()) {
1221 ATH_MSG_ERROR("Cannot register object " << c.name()
1222 << " with DataHandle " << fullname
1223 << " -> Need to bind DataHandle first");
1224 return StatusCode::FAILURE;
1225 } else {
1226 m_names[dp] = fullname;
1227 }
1228
1229 // check if this prox/function pair already registered
1230
1231 std::pair<pmITR,pmITR> fitr = m_proxyMap.equal_range( dp );
1232 for (pmITR p=fitr.first; p!=fitr.second; ++p) {
1233 if ( m_fcnMap[p->second] == c ) {
1234 ATH_MSG_ERROR("CallBack function " << c.name()
1235 << " already registered against " << fullname);
1236 return StatusCode::FAILURE;
1237 }
1238 }
1239
1240 // this function could have already been registered against another
1241 // DataProxy, so see if we can find it.
1242 BFCN *obs;
1243 if (m_cbidMap.find(c) == m_cbidMap.end()) {
1244 // obs = new BFCN (boost::bind(updFcn,const_cast<T*>(obj),_1,_2));
1245 obs = new BFCN(fcn);
1246 m_cbidMap[c] = obs;
1247 m_fcnMap[obs] = c;
1248 } else {
1249 obs = m_cbidMap[c];
1250 }
1251
1252 m_proxyMap.insert(std::pair<const SG::DataProxy*,BFCN* >(dp,obs));
1253 m_bfcnMap.insert(std::pair<BFCN*, const SG::DataProxy*> (obs,dp));
1254
1255 // attach pointer to map of CallBackIDs
1256 ObjMap::const_iterator oitr = m_objMap.find(c.ptr());
1257 if ( oitr != m_objMap.end()) {
1258 oitr->second->insert(c);
1259 } else {
1260 std::set<CallBackID> *cbs = new std::set<CallBackID>;
1261 cbs->insert( c );
1262 m_objMap[c.ptr()] = cbs;
1263 }
1264
1265 // add it to the trigger tree.
1266 CBNode *cn = m_trigTree->findNode(obs);
1267 if ( cn == nullptr) {
1268 m_trigTree->addNode(obs,c,dp);
1269 } else {
1270 CBNode *cp = m_trigTree->findNode(dp);
1271 if (cp)
1272 m_trigTree->connectNode(cn,cp);
1273 else
1274 ATH_MSG_ERROR("Cannot find callback node for parent DataProxy "
1275 << dp->name());
1276 }
1277
1278 ATH_MSG_DEBUG("register by " << c.name() << " bound to " << fullname);
1279
1280 if (trigger) {
1281 if (m_first) {
1282 ATH_MSG_INFO("Still in initialize phase, not tiggering callback for "
1283 << c.name() << " bound to " << fullname);
1284 } else {
1285 return triggerCallback(obs, dp->name());
1286 }
1287 }
1288
1289 return StatusCode::SUCCESS;
1290
1291}
1292/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1293
1294StatusCode
1296 const CallBackID& c2, const IOVSvcCallBackFcn& fcn2,
1297 bool trigger) {
1298
1299 // Check if second function has been registered with same proxy
1300 BFCN *obs1 = m_cbidMap[c1];
1301 BFCN *obs2;
1302 std::set<const SG::DataProxy*> proxyset;
1303 if (m_cbidMap.find(c2) != m_cbidMap.end()) {
1304 obs2 = m_cbidMap[c2];
1305
1306 std::pair<fnITR,fnITR> fi1 = m_bfcnMap.equal_range( obs1 );
1307 for (fnITR fitr1= fi1.first; fitr1!=fi1.second; ++fitr1) {
1308 const SG::DataProxy* prx1 = fitr1->second;
1309
1310 std::pair<fnITR,fnITR> fi2 = m_bfcnMap.equal_range( obs2 );
1311 for (fnITR fitr2=fi2.first; fitr2!=fi2.second; ++fitr2) {
1312 const SG::DataProxy* prx2 = fitr2->second;
1313
1314 if (prx1 == prx2) {
1315 ATH_MSG_DEBUG("Callback function " << c2.name()
1316 << " cannot be registered since it has already been registered "
1317 << "against " << m_names[prx1]);
1318 } else {
1319 proxyset.insert(prx1); // don't care if it gets done many times
1320 }
1321 }
1322 }
1323 } else {
1324 obs2 = new BFCN( fcn2 );
1325 m_cbidMap[c2] = obs2;
1326 m_fcnMap[obs2] = c2;
1327
1328 // get all proxies that fcn1 is registered against
1329 std::pair<fnITR,fnITR> fi1 = m_bfcnMap.equal_range( obs1 );
1330 for(fnITR fitr1=fi1.first; fitr1!=fi1.second; ++fitr1) {
1331 const SG::DataProxy *prx1 = fitr1->second;
1332 proxyset.insert(prx1);
1333 }
1334 }
1335
1336 if (proxyset.size() == 0) {
1337 ATH_MSG_DEBUG("Callback function " << c2.name()
1338 << " cannot be registered, since it has already been registered"
1339 << " against everything it can be.");
1340 return StatusCode::SUCCESS;
1341 }
1342
1343 // attach pointer to map of CallBackIDs
1344 ObjMap::const_iterator oitr = m_objMap.find(c2.ptr());
1345 if ( oitr != m_objMap.end()) {
1346 oitr->second->insert(c2);
1347 } else {
1348 std::set<CallBackID> *cbs = new std::set<CallBackID>;
1349 cbs->insert( c2 );
1350 m_objMap[c2.ptr()] = cbs;
1351 }
1352
1353 // Link fcn2 to all proxies known to fcn1
1354 std::set<const SG::DataProxy*>::iterator pitr;
1355 std::list<std::string> klist;
1356 for (pitr=proxyset.begin(); pitr!=proxyset.end(); ++pitr) {
1357 const SG::DataProxy* prx = *pitr;
1358 m_proxyMap.insert(std::pair<const SG::DataProxy*,BFCN* >(prx,obs2));
1359 m_bfcnMap.insert(std::pair<BFCN*,const SG::DataProxy*>(obs2,prx));
1360
1361 ATH_MSG_DEBUG("register by " << c2.name() << " bound to " << m_names[prx]);
1362 klist.push_back( prx->name() );
1363
1364 }
1365
1366 // note that the ordering of the parameters in addNode is the reverse
1367 // order of regFcn
1368 CBNode *cn = m_trigTree->findNode(obs2);
1369 if ( cn == nullptr) {
1370 m_trigTree->addNode(obs2,c2,obs1);
1371 } else {
1372 CBNode *cp = m_trigTree->findNode(obs1);
1373 if (cp == nullptr) {
1374 ATH_MSG_ERROR("regFcn: could not locate parent of " << cn->name()
1375 << ". This should never happen");
1376 return StatusCode::FAILURE;
1377 }
1378 m_trigTree->connectNode(cn,cp);
1379 }
1380
1381
1382 if (trigger) {
1383 if (m_first) {
1384 ATH_MSG_INFO("Still in initialize phase, not tiggering callback for "
1385 << c2.name() << " bound to " << *klist.begin());
1386 } else {
1387 return triggerCallback(obs2, *(klist.begin()) );
1388 }
1389 }
1390
1391 return StatusCode::SUCCESS;
1392
1393}
1394
1395/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1396
1397StatusCode
1398IOVSvcTool::regFcn(const IAlgTool* ia,
1399 const CallBackID& c2, const IOVSvcCallBackFcn& fcn2,
1400 bool trigger) {
1401
1402 ObjMap::const_iterator oitr = m_objMap.find( ia );
1403
1404 if (oitr == m_objMap.end()) {
1405 // tool not registered at all
1406 ATH_MSG_ERROR("No callback registered with AlgTool " << ia->name());
1407 return StatusCode::FAILURE;
1408
1409 } else {
1410 std::set<CallBackID> *sc = oitr->second;
1411
1412 if (sc->size() == 1) {
1413 // this is ok - only one callback registered with this tool
1414 CallBackID cb = *(sc->begin());
1415
1416 return regFcn(cb, c2, fcn2, trigger);
1417
1418 } else {
1419 // there is more than one callback registered to this tool
1420 ATH_MSG_ERROR("More than one callback registered to AlgTool "
1421 << ia->name() << ". Found : " << sc->size());
1422 return StatusCode::FAILURE;
1423 }
1424 }
1425
1426}
1427
1428/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1429
1430StatusCode
1431IOVSvcTool::getTriggeredTools(const std::string& key,
1432 std::set<std::string>& tools) {
1433
1434 bool match = false;
1435 for (pmITR pitr=m_proxyMap.begin(); pitr != m_proxyMap.end(); ++pitr) {
1436 if (key == pitr->first->name()) {
1437 tools.insert( m_fcnMap[pitr->second].objName() );
1438 match = true;
1439 }
1440 }
1441
1442 return ( (match) ? StatusCode::SUCCESS : StatusCode::FAILURE );
1443}
1444
1445
1446/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1447
1448StatusCode
1450 // Set flag to reset all proxies
1451 m_resetAllCallbacks = true;
1452 return (StatusCode::SUCCESS);
1453}
1454
1455/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1456
1457void
1458IOVSvcTool::scanStartSet(startSet &pSet, const std::string &type,
1459 std::set<SG::DataProxy*, SortDPptr> &proxiesToReset,
1460 const IOVTime& curTime) const {
1461
1462 if (pSet.begin()==pSet.end()) return;
1463
1464 if (msgLvl(MSG::DEBUG)) {
1465 msg() << MSG::DEBUG << "--> scan for resets: start set: " << type << endl;
1466 }
1467
1468 startITR start_itr( pSet.begin() );
1469 while ( start_itr != pSet.end() ) {
1470
1471 if (m_resetAllCallbacks || (*start_itr)->range()->start() > curTime) {
1472 if (msgLvl(MSG::DEBUG)) {
1473 msg() << "\t" << m_names.at((*start_itr)->proxy()) << ": "
1474 << (*start_itr)->range()->start()<<" <- removed"<<endl;
1475 }
1476 proxiesToReset.insert( (*start_itr)->proxy() );
1477
1478 (*start_itr)->setRemovedStart( true );
1479 pSet.erase(start_itr++);
1480
1481 } else {
1482 break;
1483 }
1484 }
1485
1486 if (msgLvl(MSG::DEBUG)) {
1487 msg() << endmsg;
1488 }
1489
1490}
1491
1492/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1493
1494void
1495IOVSvcTool::scanStopSet(stopSet &pSet, const std::string &type,
1496 std::set<SG::DataProxy*, SortDPptr> &proxiesToReset,
1497 const IOVTime& curTime) const {
1498
1499 if (pSet.begin()==pSet.end()) return;
1500 if (msgLvl(MSG::DEBUG)) {
1501 msg() << MSG::DEBUG << "--> scan for resets: stop set: " << type << endl;
1502 }
1503
1504 stopITR stop_itr(pSet.begin());
1505 while ( stop_itr != pSet.end() ) {
1506
1507 if (m_resetAllCallbacks || (*stop_itr)->range()->stop() <= curTime) {
1508 if (msgLvl(MSG::DEBUG)) {
1509 msg() << " " << m_names.at((*stop_itr)->proxy()) << ": "
1510 << (*stop_itr)->range()->stop()<< " -> removed"<<endl;
1511 }
1512 proxiesToReset.insert( (*stop_itr)->proxy() );
1513
1514 (*stop_itr)->setRemovedStop( true );
1515 pSet.erase(stop_itr++);
1516
1517 } else {
1518 break;
1519 }
1520 }
1521 if (msgLvl(MSG::DEBUG)) {
1522 msg() << endmsg;
1523 }
1524
1525}
1526
1527/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1528
1529bool
1531
1532 return ! ( m_proxies.find( proxy ) == m_proxies.end() );
1533
1534}
1535
1536/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1537
1538bool
1539IOVSvcTool::holdsProxy( const CLID& clid, const std::string& key ) const {
1540
1541 DataProxy* proxy = p_cndSvc->proxy(clid,key);
1542
1543 if (proxy == nullptr) {
1544 ATH_MSG_ERROR("holdsProxy: could not retrieve proxy "
1545 << fullProxyName(clid,key) << " from store");
1546 return false;
1547 }
1548
1549 return ( holdsProxy(proxy) );
1550
1551}
1552
1553/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1554
1555bool
1557
1558 return ! (m_cbidMap.find(cb) == m_cbidMap.end());
1559
1560}
1561
1562/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1563
1564bool
1565IOVSvcTool::holdsAlgTool( const IAlgTool* ia ) const {
1566
1567 ObjMap::const_iterator oitr = m_objMap.find( ia );
1568
1569 return !(oitr == m_objMap.end());
1570
1571}
1572
1573/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1574
1575void
1577
1578 for (DataProxy* prx : m_proxies) {
1579 ATH_MSG_VERBOSE("clearing proxy payload for " << m_names[prx]);
1580
1581 p_cndSvc->clearProxyPayload(prx);
1582
1583 m_trigTree->cascadeTrigger(true, prx);
1584
1585 }
1586
1587}
1588
1589/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1590
1591std::string
1593
1594 return fullProxyName(tad->clID(), tad->name());
1595
1596}
1597
1598/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1599
1600std::string
1602 return fullProxyName(dp->clID(), dp->name());
1603}
1604
1605/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1606
1607std::string
1608IOVSvcTool::fullProxyName( const CLID& clid, const std::string& key ) const {
1609
1610 std::string fullname, tname;
1611 if (p_CLIDSvc->getTypeNameOfID( clid, tname ).isFailure()) {
1612 fullname = "[";
1613 fullname += std::to_string(clid);
1614 fullname += '/';
1615 fullname += key;
1616 fullname += ']';
1617 } else {
1618 fullname = "[";
1619 fullname += tname;
1620 fullname += ':';
1621 fullname += std::to_string(clid);
1622 fullname += '/';
1623 fullname += key;
1624 fullname += ']';
1625 }
1626
1627 return fullname;
1628}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
uint32_t CLID
The Class ID type.
Abstract interface to IOVDbSvc to access IOVRange and tag information.
Validity Range object.
boost::function< StatusCode(IOVSVC_CALLBACK_ARGS) > IOVSvcCallBackFcn
the type of an IOVSvc call back: it wraps both the method and the object the method is called on
Definition IOVSvcDefs.h:58
std::string toUpper(const std::string &str)
static Double_t a
static Double_t sc
#define SET(n)
Definition MD5.cxx:147
#define I(x, y, z)
Definition MD5.cxx:116
void setProperty(columnar::PythonToolHandle &self, const std::string &key, nb::object value)
#define pi
#define y
#define x
const std::string & name() const
Definition CBNode.h:74
const std::string & name() const
Definition CallBackID.h:36
interface for IOA providers
Abstract interface to IOVDbSvc to access IOVRange and tag information.
Definition IIOVDbSvc.h:38
virtual IOVRange range() const
Retrieve IOVRange.
Definition IOVAddress.h:126
void setStartITR(startITR itr)
Definition IOVEntry.h:75
void setStopITR(stopITR itr)
Definition IOVEntry.h:76
const IOVRange * range() const
Definition IOVEntry.h:63
startITR getStartITR() const
Definition IOVEntry.h:78
bool removedStop() const
Definition IOVEntry.h:70
bool removedStart() const
Definition IOVEntry.h:69
stopITR getStopITR() const
Definition IOVEntry.h:79
Validity Range object.
Definition IOVRange.h:30
const IOVTime & stop() const
Definition IOVRange.h:39
const IOVTime & start() const
Definition IOVRange.h:38
bool m_checkOnce
Definition IOVSvcTool.h:245
virtual bool holdsAlgTool(const IAlgTool *ia) const override
virtual StatusCode regProxy(SG::DataProxy *proxy, const std::string &key) override
Register a DataProxy with the service.
virtual StatusCode getTriggeredTools(const std::string &key, std::set< std::string > &tools) override
std::multimap< constSG::DataProxy *, BFCN * >::iterator pmITR
Definition IOVSvcTool.h:194
void setRange_impl(SG::DataProxy *proxy, IOVRange &iovr)
Gaudi::Property< bool > m_forceReset
Definition IOVSvcTool.h:256
std::string fullProxyName(const SG::TransientAddress *) const
std::multiset< IOVEntry *, IOVEntry::IOVEntryStartCritereon > startSet
Definition IOVSvcTool.h:196
ObjMap m_objMap
Definition IOVSvcTool.h:223
Gaudi::Property< bool > m_preLoadRanges
Definition IOVSvcTool.h:251
std::set< std::pair< CLID, std::string > > m_ignoredProxyNames
Definition IOVSvcTool.h:217
ServiceHandle< IClassIDSvc > p_CLIDSvc
Definition IOVSvcTool.h:188
std::multimap< BFCN *, constSG::DataProxy * >::iterator fnITR
Definition IOVSvcTool.h:195
void PrintStopSet() const
virtual StatusCode replaceProxy(SG::DataProxy *pOld, SG::DataProxy *pNew) override
replace a registered DataProxy with a new version
Gaudi::Property< bool > m_partialPreLoadData
Definition IOVSvcTool.h:253
stopSet::iterator stopITR
Definition IOVSvcTool.h:199
Gaudi::Property< bool > m_sortKeys
Definition IOVSvcTool.h:255
std::map< CallBackID, BFCN * > m_cbidMap
Definition IOVSvcTool.h:220
startSet::iterator startITR
Definition IOVSvcTool.h:198
StatusCode preLoadProxies(const EventContext &ctx)
std::string m_storeName
Definition IOVSvcTool.h:183
virtual StatusCode setRangeInDB(const CLID &clid, const std::string &key, const IOVRange &range, const std::string &tag) override
bool m_triggered
Definition IOVSvcTool.h:246
virtual void resetAllProxies() override
std::set< TADkey_t > m_partPreLoad
Definition IOVSvcTool.h:242
startSet * p_startSet
Definition IOVSvcTool.h:227
stopSet m_stopSet_Clock
Definition IOVSvcTool.h:231
std::map< BFCN *, CallBackID > m_fcnMap
Definition IOVSvcTool.h:219
std::set< const SG::TransientAddress *, SortTADptr > m_preLoad
Definition IOVSvcTool.h:235
virtual StatusCode preLoadTAD(const SG::TransientAddress *) override
add to a set of TADs that will be registered at start of first event
IOVSvcTool(const std::string &type, const std::string &name, const IInterface *parent)
std::set< SG::DataProxy * > m_ignoredProxies
Definition IOVSvcTool.h:216
void scanStopSet(stopSet &pSet, const std::string &type, std::set< SG::DataProxy *, SortDPptr > &proxiesToReset, const IOVTime &curTime) const
virtual StatusCode reinitialize() override
ServiceHandle< IProxyProviderSvc > p_PPSvc
Definition IOVSvcTool.h:187
void PrintStartSet() const
std::map< const SG::DataProxy *, IOVEntry * > m_entries
Definition IOVSvcTool.h:225
std::atomic< bool > m_first
Definition IOVSvcTool.h:244
stopSet m_stopSet_RE
Definition IOVSvcTool.h:231
Gaudi::Property< std::string > m_updateInterval
Definition IOVSvcTool.h:257
Gaudi::Property< bool > m_preLoadData
Definition IOVSvcTool.h:252
StatusCode triggerCallback(IOVSvcCallBackFcn *, const std::string &key)
virtual void ignoreProxy(const CLID &clid, const std::string &key) override
Definition IOVSvcTool.h:161
stopSet * p_stopSet
Definition IOVSvcTool.h:228
void scanStartSet(startSet &pSet, const std::string &type, std::set< SG::DataProxy *, SortDPptr > &proxiesToReset, const IOVTime &curTime) const
virtual bool holdsCallback(const CallBackID &) const override
std::string m_checkTrigger
Definition IOVSvcTool.h:249
std::map< const SG::DataProxy *, std::string > m_names
Definition IOVSvcTool.h:201
virtual StatusCode initialize() override
TADkey_t TADkey(const SG::DataProxy &p)
Definition IOVSvcTool.h:238
std::multimap< const SG::DataProxy *, BFCN * > m_proxyMap
Definition IOVSvcTool.h:213
void PrintProxyMap() const
virtual StatusCode regFcn(SG::DataProxy *dp, const CallBackID &c, const IOVSvcCallBackFcn &fcn, bool trigger=false) override
CBTree * m_trigTree
Definition IOVSvcTool.h:233
virtual StatusCode deregProxy(SG::DataProxy *proxy) override
Deregister a DataProxy with the service.
IOVSvcCallBackFcn BFCN
Definition IOVSvcTool.h:193
startSet m_startSet_Clock
Definition IOVSvcTool.h:230
bool m_firstEventOfRun
Definition IOVSvcTool.h:247
Gaudi::Property< bool > m_preLoadExtensibleFolders
Definition IOVSvcTool.h:254
std::multimap< BFCN *, const SG::DataProxy * > m_bfcnMap
Definition IOVSvcTool.h:214
virtual StatusCode getRange(const CLID &clid, const std::string &key, IOVRange &iov) const override
virtual bool holdsProxy(SG::DataProxy *proxy) const override
ServiceHandle< IToolSvc > p_toolSvc
Definition IOVSvcTool.h:189
virtual StatusCode getRangeFromDB(const CLID &clid, const std::string &key, IOVRange &range, std::string &tag, std::unique_ptr< IOpaqueAddress > &ioa, const IOVTime &curTime) const override
virtual StatusCode preLoadDataTAD(const SG::TransientAddress *) override
add to a set of TADs that who's data will be preLoaded
std::multiset< IOVEntry *, IOVEntry::IOVEntryStopCritereon > stopSet
Definition IOVSvcTool.h:197
ServiceHandle< StoreGateSvc > p_cndSvc
Definition IOVSvcTool.h:185
virtual void handle(const Incident &) override
bool m_resetAllCallbacks
Definition IOVSvcTool.h:248
ServiceHandle< IIncidentSvc > p_incSvc
Definition IOVSvcTool.h:186
std::set< SG::DataProxy *, SortDPptr > m_proxies
Definition IOVSvcTool.h:212
virtual StatusCode setRange(const CLID &clid, const std::string &key, IOVRange &) override
startSet m_startSet_RE
Definition IOVSvcTool.h:230
virtual ~IOVSvcTool()
Basic time unit for IOVSvc.
Definition IOVTime.h:33
static constexpr uint64_t MAXTIMESTAMP
Definition IOVTime.h:58
static constexpr uint32_t MAXRUN
Definition IOVTime.h:48
void setRunEvent(uint32_t run, uint32_t event) noexcept
Definition IOVTime.cxx:96
bool isValid() const noexcept
Definition IOVTime.cxx:117
static constexpr uint32_t MINEVENT
Definition IOVTime.h:50
static constexpr uint64_t MINTIMESTAMP
Definition IOVTime.h:56
void setTimestamp(uint64_t timestamp) noexcept
Definition IOVTime.cxx:72
static constexpr uint32_t MAXEVENT
Definition IOVTime.h:51
static constexpr uint32_t MINRUN
Definition IOVTime.h:44
bool isTimestamp() const noexcept
Definition IOVTime.h:111
CLID clID() const
Retrieve clid.
virtual const name_type & name() const override final
Retrieve data object key == string.
CLID clID() const
Retrieve string key:
const std::string & name() const
Get the primary (hashed) SG key.
bool operator()(const SG::DataProxy *, const SG::DataProxy *) const
bool operator()(const SG::TransientAddress *, const SG::TransientAddress *) const
STL iterator class.
STL iterator class.
Definition node.h:24
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357
Definition run.py:1
STL namespace.
Filled by IIOVDbSvc::getKeyInfo.
Definition IIOVDbSvc.h:44
MsgStream & msg
Definition testRead.cxx:32