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"
50 const char *cstr =
str.c_str();
52 for (
unsigned int i=0;
i <
str.length(); ++
i) {
53 str2 += toupper(*(cstr+
i));
60 std::atomic<bool> s_firstRun(
true);
75 if (
x->clID() ==
y->clID() ) {
76 return (
x->name() <
y->name() );
78 return (
x->clID() <
y->clID() );
90 if (
a->name()!=
b->name())
return a->name()<
b->name();
91 if (
a->clID()!=
b->clID())
return a->clID()<
b->clID();
104 const IInterface*
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),
130 delete ( oitr->second );
140 std::set< const TransientAddress*, SortTADptr >::const_iterator titr;
155 SmartIF<IProperty> iovSvcProp{service(
"IOVSvc")};
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") ) );
174 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
177 msg() <<
"IOVRanges will be checked only ";
178 msg().setColor(MSG::CYAN);
181 msg() <<
" at the start of the job" <<
endmsg;
182 }
else if (updi ==
"RUN") {
184 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
187 msg() <<
"IOVRanges will be checked at every ";
188 msg().setColor(MSG::CYAN);
190 }
else if (updi ==
"EVENT") {
192 p_incSvc->addListener(
this,
"BeginEvent", pri,
true);
193 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
196 msg() <<
"IOVRanges will be checked at every ";
197 msg().setColor(MSG::CYAN);
201 <<
"\"event\" \"run\" or \"job\"");
202 return StatusCode::FAILURE;
208 msg() <<
"IOV Data will be preloaded at the same interval" <<
endmsg;
213 return StatusCode::SUCCESS;
230 else if (!initial_first) {
231 if ( inc.type() !=
m_checkTrigger && inc.type() != IncidentType::BeginRun ) {
236 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
243 if ( inc.type() !=
m_checkTrigger && inc.type() != IncidentType::BeginRun ) {
252 if (
proxy ==
nullptr) {
266 const bool first = initial_first;
269 if(Gaudi::Concurrency::ConcurrencyFlags::numProcs()==0) {
270 if (inc.type() == IncidentType::BeginRun) {
282 set< DataProxy*, SortDPptr > proxiesToReset;
283 if ( inc.type() ==
m_checkTrigger || inc.type() == IncidentType::BeginRun ) {
285 const EventContext& context = inc.context();
289 const EventIDBase& eventID = context.eventID();
290 uint32_t event = eventID.lumi_block();
297 curTime.setTimestamp(1000000000L*(
uint64_t)eventID.time_stamp() + eventID.time_stamp_ns_offset());
301 msg() << inc.type() <<
": [R/LB] = " << curTime <<
endmsg;
304 if (inc.type() == IncidentType::BeginRun) {
306 SmartIF<IIOVDbSvc> iovDB{service(
"IOVDbSvc",
false)};
311 if (StatusCode::SUCCESS != iovDB->signalBeginRun(curTime,
324 std::set< const TransientAddress*, SortTADptr >::const_iterator titr;
328 if (StatusCode::SUCCESS !=
sc) {
348 throw( std::runtime_error(
"IOVSvcTool::preLoadProxies") );
352 SmartIF<IIOVDbSvc> iovDB{service(
"IOVDbSvc",
false)};
354 iovDB->signalEndProxyPreload();
355 ATH_MSG_DEBUG(
"Signaled end proxy preload to IOVDbSvc " << curTime);
373 std::map<BFCN*, std::list<std::string> > resetKeys;
380 if (inc.type() == IncidentType::BeginRun &&
m_forceReset && !s_firstRun) {
382 ATH_MSG_DEBUG(
"Resetting all proxies on BeginRun incident for store \""
386 std::set< const SG::DataProxy* >::const_iterator pit;
403 auto itr = proxiesToReset.find(
p);
404 if (itr != proxiesToReset.end()) {
405 proxiesToReset.erase( itr );
410 if (!
first && proxiesToReset.size() > 0 &&
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());
417 throw GaudiException(
"Cannot update Conditions via callback functions in MT after the first event",
name(),StatusCode::FAILURE);
441 Gaudi::Guards::AuditorGuard auditor(
m_names.at(prx), auditorSvc(),
"preLoadProxy");
442 if (prx->accessData() ==
nullptr) {
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) {
451 std::string
key = prx->name();
452 resetKeys[
f].push_back(
key);
465 CBTree::nodeSet::const_iterator itt, itt_s, itt_e;
467 for (itt = itt_s; itt != itt_e; ++itt) {
470 if (
node->trigger()) {
472 auditorSvc()->before(
"Callback",
m_fcnMap.at(
ff).name());
473 if ((*
ff)(
i,resetKeys[
ff]).isFailure()) {
474 auditorSvc()->after(
"Callback",
m_fcnMap.at(
ff).name());
476 << std::endl <<
"Skipping all subsequent callbacks.");
481 auditorSvc()->after(
"Callback",
m_fcnMap.at(
ff).name());
485 if (
perr !=
nullptr)
break;
509 if ( pitr !=
m_entries.end() && pitr->second->range()->isInRange(curTime) ) {
513 if (!prx->updateAddress()) {
521 IOpaqueAddress *ioa = prx->address();
525 if (iova !=
nullptr) {
536 if ( inc.type() == IncidentType::BeginRun) {
551 if (
proxy ==
nullptr) {
553 return StatusCode::FAILURE;
560 <<
" already registered: " <<
proxy->name());
561 return StatusCode::SUCCESS;
564 std::string tname, fullname;
567 fullname = tname +
"[" +
key +
"]";
574 return StatusCode::SUCCESS;
588 if (
proxy ==
nullptr) {
590 return StatusCode::FAILURE;
598 <<
" not registered: " <<
proxy->name());
599 return StatusCode::SUCCESS;
606 return StatusCode::SUCCESS;
618 while (
it !=
set.end() && !
set.key_comp()(*
it, ent) && !
set.key_comp()(ent,*
it)) {
637 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
638 assert(
nullptr != pOld);
639 assert(
nullptr != pNew);
649 return StatusCode::SUCCESS;
668 setRange_impl (pNew, *(
const_cast<IOVRange*
>(ent->second->range())));
675 StatusCode::SUCCESS :
676 StatusCode::FAILURE );
689 if (
proxy ==
nullptr) {
692 return StatusCode::FAILURE;
709 if (
proxy ==
nullptr) {
712 return StatusCode::FAILURE;
730 << tad_in->
clID() <<
"/" << tad_in->
name()
731 <<
") alread in preLoad set. Not inserting");
732 return StatusCode::SUCCESS;
738 << tad_in->
clID() <<
"/" << tad_in->
name()
739 <<
") alread in partPreLoad set. Not inserting");
740 return StatusCode::SUCCESS;
746 return StatusCode::SUCCESS;
760 <<
" alread in preLoad set. Not inserting");
761 return StatusCode::SUCCESS;
767 <<
" alread in partPreLoad set. Not inserting");
768 return StatusCode::SUCCESS;
775 return StatusCode::SUCCESS;
782 if (iovr.start().isTimestamp()) {
790 IOVRange *
range =
new IOVRange(iovr);
796 const IOVRange *irn = ent->
range();
837 <<
" in IOVrange:" << iovr);
839 if (!iovr.start().isValid() || !iovr.stop().isValid()) {
840 ATH_MSG_ERROR(
"IOVRange " << iovr <<
"is not valid. Start OK: "
841 << iovr.start().isValid() <<
" Stop OK: " << iovr.stop().isValid()
842 <<
" run/evt/time min/max "
846 return StatusCode::FAILURE;
851 if (
proxy ==
nullptr) {
853 return StatusCode::FAILURE;
856 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
858 return StatusCode::SUCCESS;
864 IOVRange&
iov)
const {
868 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
869 std::map<const DataProxy*,IOVEntry*>::const_iterator itr(
m_entries.find(
dp));
871 return StatusCode::FAILURE;
874 iov = *(itr->second->range());
876 return StatusCode::SUCCESS;
885 std::unique_ptr<IOpaqueAddress>& ioa,
886 const IOVTime& curTime)
const {
888 if (curTime.isValid()) {
892 return StatusCode::FAILURE;
903 std::unique_ptr<IOpaqueAddress>& ioa)
const {
909 if (
idb !=
nullptr) {
924 const IOVRange&
range,
const std::string &
tag) {
927 if (!
range.start().isValid() || !
range.stop().isValid()) {
929 return StatusCode::FAILURE;
936 return StatusCode::FAILURE;
939 std::lock_guard<std::recursive_mutex> lock(m_handleMutex);
940 std::map<const DataProxy*,IOVEntry*>::const_iterator itr(
m_entries.find(
dp));
948 if (
idb !=
nullptr) {
952 return StatusCode::FAILURE;
966 SmartIF<IIOVDbSvc> iovDB{service(
"IOVDbSvc",
false)};
968 std::map<BFCN*, std::list<std::string> > resetKeys;
970 Gaudi::Guards::AuditorGuard auditor(
m_names[
dp], auditorSvc(),
"preLoadProxy");
973 msg().setColor(MSG::CYAN);
974 msg() <<
"loading proxy for CLID: " <<
dp->clID()
978 if (
dp->provider() ==
nullptr) {
980 <<
". It is probably not a conditions object" << endl;
981 msg() <<
"Proxy Map: ";
984 scr = StatusCode::FAILURE;
995 if (!
dp->updateAddress())
996 sc = StatusCode::FAILURE;
1005 iovDB->getKeyInfo(
dp->name(), kinfo) && kinfo.
extensible ) {
1010 <<
dp->clID() <<
"/"
1011 <<
dp->name() <<
")");
1012 if(
dp->accessData() !=
nullptr ) {
1013 sc = StatusCode::SUCCESS;
1015 sc = StatusCode::FAILURE;
1016 ATH_MSG_ERROR(
"preLoading proxies: accessData() failed for " <<
1017 dp->clID() <<
"/" <<
dp->name() <<
")");
1022 if (
sc.isFailure()) scr=
sc;
1027 for (pitr=
pi.first; pitr!=
pi.second; ++pitr) {
1028 BFCN *
f = pitr->second;
1029 std::string
key =
dp->name();
1030 resetKeys[
f].push_back(
key);
1034 if (cn !=
nullptr) {
1040 if (scr.isFailure()) {
1041 ATH_MSG_ERROR(
"Problems preLoading proxies. No callbacks triggered.");
1047 CBTree::nodeSet::const_iterator itt, itt_s, itt_e;
1049 for (itt = itt_s; itt != itt_e; ++itt) {
1052 if (
node->trigger()) {
1056 if ((*
ff)(
i,resetKeys[
ff]).isFailure()) {
1059 return StatusCode::FAILURE;
1080 std::list<std::string> klist;
1081 klist.push_back(
key);
1082 if ( (*fcn)(
I,klist).isFailure() ) {
1084 return StatusCode::FAILURE;
1087 return StatusCode::SUCCESS;
1094 const std::string&
key ) {
1098 std::map<const SG::DataProxy*, BFCN*>::const_iterator pitr =
1102 return StatusCode::FAILURE;
1105 BFCN* fcn = pitr->second;
1116 std::string objname;
1119 msg() << endl <<
"ClockTime start set: " << endl;
1121 objname =
m_names.at( (*start_itr)->proxy() );
1122 msg() <<
" " << objname <<
" (" << (*start_itr)->proxy() <<
") "
1123 << (*start_itr)->range()->start() << endl;
1129 msg() <<
"Run/Event start set: " << endl;
1131 objname =
m_names.at( (*start_itr)->proxy() );
1132 msg() <<
" " << objname <<
" (" << (*start_itr)->proxy() <<
") "
1133 << (*start_itr)->range()->start() << endl;
1144 std::string objname;
1147 msg() << endl <<
"ClockTime stop set: " << endl;
1149 objname =
m_names.at((*stop_itr)->proxy());
1150 msg() <<
" " << objname <<
" (" << (*stop_itr)->proxy() <<
") "
1151 << (*stop_itr)->range()->stop() << endl;
1157 msg() <<
"Run/Event stop set: " << endl;
1159 objname =
m_names.at((*stop_itr)->proxy());
1160 msg() <<
" " << objname <<
" (" << (*stop_itr)->proxy() <<
") "
1161 << (*stop_itr)->range()->stop() << endl;
1171 msg() <<
"------------------------------ IOVSvc Proxy Map "
1172 <<
"------------------------------" << endl;
1177 msg() <<
"----------------------------------------------------------"
1178 <<
"---------------------" << endl;
1186 msg() <<
" " <<
dp <<
" " <<
dp->clID() <<
" "
1189 if (
pi.first ==
pi.second) {
1190 msg() <<
" -> no callback associated" << endl;
1192 for (
auto pitr=
pi.first; pitr!=
pi.second; ++pitr) {
1193 BFCN* fcn = pitr->second;
1194 map<BFCN*,CallBackID>::const_iterator fitr =
m_fcnMap.find(fcn);
1196 msg() <<
" -> " << fcn <<
" " << cbid.
name() << endl;
1210 std::string tname,fullname;
1212 if (
sc.isFailure()) {
1214 return StatusCode::FAILURE;
1216 fullname = tname +
"[" +
dp->name() +
"]";
1221 <<
" with DataHandle " << fullname
1222 <<
" -> Need to bind DataHandle first");
1223 return StatusCode::FAILURE;
1230 std::pair<pmITR,pmITR> fitr =
m_proxyMap.equal_range(
dp );
1231 for (
pmITR p=fitr.first;
p!=fitr.second; ++
p) {
1234 <<
" already registered against " << fullname);
1235 return StatusCode::FAILURE;
1244 obs =
new BFCN(fcn);
1251 m_proxyMap.insert(std::pair<const SG::DataProxy*,BFCN* >(
dp,obs));
1252 m_bfcnMap.insert(std::pair<BFCN*, const SG::DataProxy*> (obs,
dp));
1255 ObjMap::const_iterator oitr =
m_objMap.find(
c.ptr());
1257 oitr->second->insert(
c);
1259 std::set<CallBackID> *cbs =
new std::set<CallBackID>;
1266 if ( cn ==
nullptr) {
1273 ATH_MSG_ERROR(
"Cannot find callback node for parent DataProxy "
1277 ATH_MSG_DEBUG(
"register by " <<
c.name() <<
" bound to " << fullname);
1281 ATH_MSG_INFO(
"Still in initialize phase, not tiggering callback for "
1282 <<
c.name() <<
" bound to " << fullname);
1288 return StatusCode::SUCCESS;
1301 std::set<const SG::DataProxy*> proxyset;
1305 std::pair<fnITR,fnITR> fi1 =
m_bfcnMap.equal_range( obs1 );
1306 for (
fnITR fitr1= fi1.first; fitr1!=fi1.second; ++fitr1) {
1309 std::pair<fnITR,fnITR> fi2 =
m_bfcnMap.equal_range( obs2 );
1310 for (
fnITR fitr2=fi2.first; fitr2!=fi2.second; ++fitr2) {
1315 <<
" cannot be registered since it has already been registered "
1316 <<
"against " <<
m_names[prx1]);
1318 proxyset.insert(prx1);
1323 obs2 =
new BFCN( fcn2 );
1328 std::pair<fnITR,fnITR> fi1 =
m_bfcnMap.equal_range( obs1 );
1329 for(
fnITR fitr1=fi1.first; fitr1!=fi1.second; ++fitr1) {
1331 proxyset.insert(prx1);
1335 if (proxyset.size() == 0) {
1337 <<
" cannot be registered, since it has already been registered"
1338 <<
" against everything it can be.");
1339 return StatusCode::SUCCESS;
1343 ObjMap::const_iterator oitr =
m_objMap.find(
c2.ptr());
1345 oitr->second->insert(
c2);
1347 std::set<CallBackID> *cbs =
new std::set<CallBackID>;
1354 std::list<std::string> klist;
1355 for (pitr=proxyset.begin(); pitr!=proxyset.end(); ++pitr) {
1357 m_proxyMap.insert(std::pair<const SG::DataProxy*,BFCN* >(prx,obs2));
1358 m_bfcnMap.insert(std::pair<BFCN*,const SG::DataProxy*>(obs2,prx));
1361 klist.push_back( prx->name() );
1368 if ( cn ==
nullptr) {
1372 if (
cp ==
nullptr) {
1374 <<
". This should never happen");
1375 return StatusCode::FAILURE;
1383 ATH_MSG_INFO(
"Still in initialize phase, not tiggering callback for "
1384 <<
c2.name() <<
" bound to " << *klist.begin());
1390 return StatusCode::SUCCESS;
1401 ObjMap::const_iterator oitr =
m_objMap.find( ia );
1405 ATH_MSG_ERROR(
"No callback registered with AlgTool " << ia->name());
1406 return StatusCode::FAILURE;
1409 std::set<CallBackID> *
sc = oitr->second;
1411 if (
sc->size() == 1) {
1415 return regFcn(cb,
c2, fcn2, trigger);
1419 ATH_MSG_ERROR(
"More than one callback registered to AlgTool "
1420 << ia->name() <<
". Found : " <<
sc->size());
1421 return StatusCode::FAILURE;
1431 std::set<std::string>&
tools) {
1435 if (
key == pitr->first->name()) {
1441 return ( (
match) ? StatusCode::SUCCESS : StatusCode::FAILURE );
1451 return (StatusCode::SUCCESS);
1458 std::set<SG::DataProxy*, SortDPptr> &proxiesToReset,
1459 const IOVTime& curTime)
const {
1461 if (pSet.begin()==pSet.end())
return;
1467 startITR start_itr( pSet.begin() );
1468 while ( start_itr != pSet.end() ) {
1472 msg() <<
"\t" <<
m_names.at((*start_itr)->proxy()) <<
": "
1473 << (*start_itr)->range()->start()<<
" <- removed"<<endl;
1475 proxiesToReset.insert( (*start_itr)->proxy() );
1477 (*start_itr)->setRemovedStart(
true );
1478 pSet.erase(start_itr++);
1495 std::set<SG::DataProxy*, SortDPptr> &proxiesToReset,
1496 const IOVTime& curTime)
const {
1498 if (pSet.begin()==pSet.end())
return;
1503 stopITR stop_itr(pSet.begin());
1504 while ( stop_itr != pSet.end() ) {
1508 msg() <<
" " <<
m_names.at((*stop_itr)->proxy()) <<
": "
1509 << (*stop_itr)->range()->stop()<<
" -> removed"<<endl;
1511 proxiesToReset.insert( (*stop_itr)->proxy() );
1513 (*stop_itr)->setRemovedStop(
true );
1514 pSet.erase(stop_itr++);
1542 if (
proxy ==
nullptr) {
1566 ObjMap::const_iterator oitr =
m_objMap.find( ia );
1609 std::string fullname, tname;
1610 if (
p_CLIDSvc->getTypeNameOfID( clid, tname ).isFailure()) {