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"
46 std::atomic<bool> s_firstRun(
true);
57 if (
a->name()!=b->name())
return a->name()<b->name();
58 if (
a->clID()!=b->clID())
return a->clID()<b->clID();
71 const IInterface* parent):
72 base_class(
type, name, parent ),
85 SmartIF<IProperty> iovSvcProp{service(
"IOVSvc")};
101 std::transform(updi.begin(), updi.end(), updi.begin(),
102 [](
unsigned char c) { return std::toupper(c); });
107 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
109 msg().setColor(MSG::GREEN);
110 msg() <<
"IOVRanges will be checked only ";
111 msg().setColor(MSG::CYAN);
113 msg().setColor(MSG::GREEN);
114 msg() <<
" at the start of the job" <<
endmsg;
115 }
else if (updi ==
"RUN") {
117 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
119 msg().setColor(MSG::GREEN);
120 msg() <<
"IOVRanges will be checked at every ";
121 msg().setColor(MSG::CYAN);
123 }
else if (updi ==
"EVENT") {
125 p_incSvc->addListener(
this,
"BeginEvent", pri,
true);
126 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
128 msg().setColor(MSG::GREEN);
129 msg() <<
"IOVRanges will be checked at every ";
130 msg().setColor(MSG::CYAN);
134 <<
"\"event\" \"run\" or \"job\"");
135 return StatusCode::FAILURE;
140 msg().setColor(MSG::GREEN);
141 msg() <<
"IOV Data will be preloaded at the same interval" <<
endmsg;
146 return StatusCode::SUCCESS;
163 else if (!initial_first) {
164 if ( inc.type() !=
m_checkTrigger && inc.type() != IncidentType::BeginRun ) {
169 std::scoped_lock lock(m_handleMutex);
176 if ( inc.type() !=
m_checkTrigger && inc.type() != IncidentType::BeginRun ) {
185 if (proxy ==
nullptr) {
199 const bool first = initial_first;
202 if(Gaudi::Concurrency::ConcurrencyFlags::numProcs()==0) {
203 if (inc.type() == IncidentType::BeginRun) {
215 std::set< SG::DataProxy*, SortDPptr > proxiesToReset;
216 if ( inc.type() ==
m_checkTrigger || inc.type() == IncidentType::BeginRun ) {
218 const EventIDBase& eventID = inc.context().eventID();
219 const uint32_t
event = eventID.lumi_block();
220 const uint32_t
run = eventID.run_number();
227 curTime.
setTimestamp(1000000000L*(uint64_t)eventID.time_stamp() + eventID.time_stamp_ns_offset());
229 if (msgLvl(MSG::DEBUG)) {
230 msg().setColor(MSG::YELLOW,MSG::RED);
231 msg() << inc.type() <<
": [R/LB] = " << curTime <<
endmsg;
234 if (inc.type() == IncidentType::BeginRun) {
236 SmartIF<IIOVDbSvc> iovDB{service(
"IOVDbSvc",
false)};
241 if (StatusCode::SUCCESS != iovDB->signalBeginRun(curTime,
255 StatusCode
sc =
regProxy(tad->clID(), tad->name());
256 if (StatusCode::SUCCESS !=
sc) {
263 if (msgLvl(MSG::VERBOSE)) {
271 throw( std::runtime_error(
"IOVSvcTool::preLoadProxies") );
275 SmartIF<IIOVDbSvc> iovDB{service(
"IOVDbSvc",
false)};
277 iovDB->signalEndProxyPreload();
278 ATH_MSG_DEBUG(
"Signaled end proxy preload to IOVDbSvc " << curTime);
290 if (msgLvl(MSG::DEBUG)) {
301 if (inc.type() == IncidentType::BeginRun &&
m_forceReset && !s_firstRun) {
303 ATH_MSG_DEBUG(
"Resetting all proxies on BeginRun incident for store \""
306 if (msgLvl(MSG::VERBOSE)) {
322 auto itr = proxiesToReset.find(p);
323 if (itr != proxiesToReset.end()) {
324 proxiesToReset.erase( itr );
329 if (!first && !proxiesToReset.empty() &&
330 ( (Gaudi::Concurrency::ConcurrencyFlags::numThreads() +
331 Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents()) > 0 ) ) {
332 ATH_MSG_FATAL(
"Cannot update Conditions via callback functions in MT after the first event");
334 ATH_MSG_FATAL(
"CLID=" << prox->clID() <<
", name=" << prox->name());
336 throw GaudiException(
"Cannot update Conditions via callback functions in MT after the first event",name(),StatusCode::FAILURE);
358 Gaudi::Guards::AuditorGuard auditor(
m_names.at(prx), auditorSvc(),
"preLoadProxy");
359 if (prx->accessData() ==
nullptr) {
369 if ( pitr !=
m_entries.end() && pitr->second->range()->isInRange(curTime) ) {
373 if (!prx->updateAddress()) {
379 if (msgLvl(MSG::VERBOSE)) {
380 IOpaqueAddress *ioa = prx->address();
384 if (iova !=
nullptr) {
393 if ( inc.type() == IncidentType::BeginRun) {
408 if (proxy ==
nullptr) {
410 return StatusCode::FAILURE;
417 <<
" already registered: " << proxy->name());
418 return StatusCode::SUCCESS;
424 const std::string fullname = tname +
"[" + key +
"]";
427 m_names[ proxy ] = std::move(fullname);
429 return StatusCode::SUCCESS;
443 if (proxy ==
nullptr) {
445 return StatusCode::FAILURE;
453 <<
" not registered: " << proxy->name());
454 return StatusCode::SUCCESS;
459 return StatusCode::SUCCESS;
472 auto it =
set.lower_bound(ent);
473 while (it !=
set.end() && !
set.key_comp()(*it, ent) && !
set.key_comp()(ent,*it)) {
493 std::scoped_lock lock(m_handleMutex);
494 assert(
nullptr != pOld);
495 assert(
nullptr != pNew);
505 return StatusCode::SUCCESS;
529 return StatusCode::SUCCESS;
542 if (proxy ==
nullptr) {
545 return StatusCode::FAILURE;
562 if (proxy ==
nullptr) {
565 return StatusCode::FAILURE;
583 << tad_in->
clID() <<
"/" << tad_in->
name()
584 <<
") alread in preLoad set. Not inserting");
585 return StatusCode::SUCCESS;
591 << tad_in->
clID() <<
"/" << tad_in->
name()
592 <<
") alread in partPreLoad set. Not inserting");
593 return StatusCode::SUCCESS;
596 m_preLoad.insert( std::make_unique<SG::TransientAddress>(tad_in->
clID(),tad_in->
name()) );
598 return StatusCode::SUCCESS;
612 <<
" alread in preLoad set. Not inserting");
613 return StatusCode::SUCCESS;
619 <<
" alread in partPreLoad set. Not inserting");
620 return StatusCode::SUCCESS;
623 auto tad = std::make_unique<SG::TransientAddress>(tad_in->
clID(),tad_in->
name());
627 return StatusCode::SUCCESS;
642 auto range = std::make_unique<IOVRange>(iovr);
647 const auto& ent = itr->second;
649 if (*ent->
range() == iovr) {
668 auto ent = std::make_unique<IOVEntry>(proxy, std::move(range));
671 m_entries.insert_or_assign(proxy, std::move(ent));
680 ATH_MSG_DEBUG(
"setRange() for clid: " << clid <<
" key: " << key
681 <<
" in IOVrange:" << iovr);
684 ATH_MSG_ERROR(
"IOVRange " << iovr <<
"is not valid. Start OK: "
686 <<
" run/evt/time min/max "
690 return StatusCode::FAILURE;
695 if (proxy ==
nullptr) {
697 return StatusCode::FAILURE;
700 std::scoped_lock lock(m_handleMutex);
702 return StatusCode::SUCCESS;
712 std::scoped_lock lock(m_handleMutex);
715 return StatusCode::FAILURE;
718 iov = *(itr->second->range());
720 return StatusCode::SUCCESS;
729 std::unique_ptr<IOpaqueAddress>& ioa,
730 const IOVTime& curTime)
const {
736 return StatusCode::FAILURE;
747 std::unique_ptr<IOpaqueAddress>& ioa)
const {
748 StatusCode
sc(StatusCode::FAILURE);
752 dynamic_cast<IIOVDbSvc*
>(dp->provider());
753 if (idb !=
nullptr) {
754 sc = idb->getRange(clid, key, time, range, tag, ioa);
759 ATH_MSG_ERROR(
"No proxy found for clid " << clid <<
" key " << key);
768 const IOVRange& range,
const std::string &tag) {
771 if (!range.start().isValid() || !range.stop().isValid()) {
773 return StatusCode::FAILURE;
780 return StatusCode::FAILURE;
783 std::scoped_lock lock(m_handleMutex);
791 if (idb !=
nullptr) {
792 return idb->setRange(clid, key, range, tag);
795 return StatusCode::FAILURE;
807 StatusCode scr(StatusCode::SUCCESS);
809 SmartIF<IIOVDbSvc> iovDB{service(
"IOVDbSvc",
false)};
812 Gaudi::Guards::AuditorGuard auditor(
m_names[dp], auditorSvc(),
"preLoadProxy");
814 if (msgLvl(MSG::VERBOSE)) {
815 msg().setColor(MSG::CYAN);
816 msg() <<
"loading proxy for CLID: " << dp->clID()
820 if (dp->provider() ==
nullptr) {
821 msg() << MSG::FATAL <<
"No provider found for proxy " <<
m_names[dp]
822 <<
". It is probably not a conditions object" << std::endl;
823 msg() <<
"Proxy Map: ";
826 scr = StatusCode::FAILURE;
836 if (!dp->updateAddress())
837 sc = StatusCode::FAILURE;
846 iovDB->getKeyInfo(dp->name(), kinfo) && kinfo.
extensible ) {
847 ATH_MSG_VERBOSE(
"not preloading data for extensible folder " << dp->name());
852 << dp->name() <<
")");
853 if( dp->accessData() !=
nullptr ) {
854 sc = StatusCode::SUCCESS;
856 sc = StatusCode::FAILURE;
857 ATH_MSG_ERROR(
"preLoading proxies: accessData() failed for " <<
858 dp->clID() <<
"/" << dp->name() <<
")");
863 if (
sc.isFailure()) scr=
sc;
867 if (scr.isFailure()) {
882 msg() << std::endl <<
"ClockTime start set: " << std::endl;
885 msg() <<
" " << objname <<
" (" << ent->
proxy() <<
") "
892 msg() <<
"Run/Event start set: " << std::endl;
895 msg() <<
" " << objname <<
" (" << ent->
proxy() <<
") "
909 msg() << std::endl <<
"ClockTime stop set: " << std::endl;
912 msg() <<
" " << objname <<
" (" << ent->
proxy() <<
") "
919 msg() <<
"Run/Event stop set: " << std::endl;
922 msg() <<
" " << objname <<
" (" << ent->
proxy() <<
") "
933 msg() <<
"------------------------------ IOVSvc Proxy Map "
934 <<
"------------------------------" << std::endl;
939 msg() <<
"----------------------------------------------------------"
940 <<
"---------------------" << std::endl;
949 msg() <<
" " << dp <<
" " << dp->clID() <<
" "
950 << (it ==
m_names.end() ?
"???" : it->second) << std::endl;
958 std::set<SG::DataProxy*, SortDPptr> &proxiesToReset,
959 const IOVTime& curTime)
const {
961 if (pSet.empty())
return;
963 if (msgLvl(MSG::DEBUG)) {
964 msg() << MSG::DEBUG <<
"--> scan for resets: start set: " <<
type << std::endl;
967 auto start_itr( pSet.begin() );
968 while ( start_itr != pSet.end() ) {
970 if ((*start_itr)->range()->start() > curTime) {
971 if (msgLvl(MSG::DEBUG)) {
972 msg() <<
"\t" <<
m_names.at((*start_itr)->proxy()) <<
": "
973 << (*start_itr)->range()->start()<<
" <- removed" << std::endl;
975 proxiesToReset.insert( (*start_itr)->proxy() );
977 (*start_itr)->setRemovedStart(
true );
978 pSet.erase(start_itr++);
985 if (msgLvl(MSG::DEBUG)) {
995 std::set<SG::DataProxy*, SortDPptr> &proxiesToReset,
996 const IOVTime& curTime)
const {
998 if (pSet.empty())
return;
999 if (msgLvl(MSG::DEBUG)) {
1000 msg() << MSG::DEBUG <<
"--> scan for resets: stop set: " <<
type << std::endl;
1003 auto stop_itr(pSet.begin());
1004 while ( stop_itr != pSet.end() ) {
1006 if ((*stop_itr)->range()->stop() <= curTime) {
1007 if (msgLvl(MSG::DEBUG)) {
1008 msg() <<
" " <<
m_names.at((*stop_itr)->proxy()) <<
": "
1009 << (*stop_itr)->range()->stop()<<
" -> removed" << std::endl;
1011 proxiesToReset.insert( (*stop_itr)->proxy() );
1013 (*stop_itr)->setRemovedStop(
true );
1014 pSet.erase(stop_itr++);
1020 if (msgLvl(MSG::DEBUG)) {
1042 if (proxy ==
nullptr) {
1086 std::string fullname, tname;
1087 if (
p_CLIDSvc->getTypeNameOfID( clid, tname ).isFailure()) {
1089 fullname += std::to_string(clid);
1097 fullname += std::to_string(clid);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
uint32_t CLID
The Class ID type.
Abstract interface to IOVDbSvc to access IOVRange and tag information.
void setProperty(columnar::PythonToolHandle &self, const std::string &key, nb::object value)
interface for IOA providers
Abstract interface to IOVDbSvc to access IOVRange and tag information.
virtual IOVRange range() const
Retrieve IOVRange.
void setStopITR(StopSet_t::iterator itr)
StopSet_t::iterator getStopITR() const
std::multiset< IOVEntry *, IOVEntryStopCritereon > StopSet_t
StartSet_t::iterator getStartITR() const
std::multiset< IOVEntry *, IOVEntryStartCritereon > StartSet_t
void setStartITR(StartSet_t::iterator itr)
bool removedStart() const
const IOVTime & stop() const
const IOVTime & start() const
Basic time unit for IOVSvc.
static constexpr uint64_t MAXTIMESTAMP
static constexpr uint32_t MAXRUN
void setRunEvent(uint32_t run, uint32_t event) noexcept
bool isValid() const noexcept
static constexpr uint32_t MINEVENT
static constexpr uint64_t MINTIMESTAMP
void setTimestamp(uint64_t timestamp) noexcept
static constexpr uint32_t MAXEVENT
static constexpr uint32_t MINRUN
bool isTimestamp() const noexcept
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.
Filled by IIOVDbSvc::getKeyInfo.
bool operator()(const SG::DataProxy *, const SG::DataProxy *) const
int run(int argc, char *argv[])