18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/IAlgTool.h"
20#include "GaudiKernel/IToolSvc.h"
21#include "GaudiKernel/IClassIDSvc.h"
22#include "GaudiKernel/IConversionSvc.h"
36const std::string defaultStore =
"StoreGateSvc";
43bool eventIDMatch (
const EventIDBase& e1,
const EventIDBase& e2)
46 if (
e1.run_number() !=
e2.run_number())
return false;
47 if (
e1.lumi_block() !=
e2.lumi_block())
return false;
49 if (
e1.isTimeStamp()) {
50 if (
e1.time_stamp() !=
e2.time_stamp())
return false;
51 if (
e1.time_stamp_ns_offset() !=
e2.time_stamp_ns_offset())
return false;
66 : base_class( name, svc ),
69 p_sgs(
"StoreGateSvc",name),
79 msg().setLevel( m_outputLevel.value() );
86 return StatusCode::SUCCESS;
96 const std::string& storeName ) {
100 if (ist ==
nullptr) {
101 ATH_MSG_ERROR(
"regProxy: no IOVSvcTool associated with store \""
102 << storeName <<
"\" and failed to create one" );
103 return (StatusCode::FAILURE);
107 if (ist2 !=
nullptr) {
111 <<
"\", it is already registered with store \""
113 return StatusCode::FAILURE;
116 <<
" already registered with store \"" << storeName <<
"\""
118 return StatusCode::SUCCESS;
133 const std::string& storeName ) {
137 if (ist ==
nullptr) {
138 ATH_MSG_ERROR(
"regProxy: no IOVSvcTool associated with store \""
139 << storeName <<
"\" and failed to create one." );
140 return (StatusCode::FAILURE);
144 if (ist2 !=
nullptr) {
148 <<
" with store " << storeName
149 <<
", it is already registered with store \""
151 return StatusCode::FAILURE;
154 <<
" already registered with store \"" << storeName <<
"\""
156 return StatusCode::SUCCESS;
174 if (ist ==
nullptr) {
177 return StatusCode::FAILURE;
194 if (ist ==
nullptr) {
197 return StatusCode::FAILURE;
211 const std::string& storeName ) {
214 if (ist ==
nullptr) {
216 << storeName <<
" and failed to create one" );
231 const std::string& storeName ) {
233 StatusCode
sc(StatusCode::FAILURE);
235 if (ist !=
nullptr) {
238 ATH_MSG_ERROR(
"regProxy: no IOVSvcTool associated with store \""
239 << storeName <<
"\" and failed to create one." );
253 const std::string& storeName ) {
257 if (ist ==
nullptr) {
258 ATH_MSG_ERROR(
"preLoadTAD: no IOVSvcTool associated with store \""
259 << storeName <<
"\" and failed to create one." );
260 return StatusCode::FAILURE;
274 const std::string& storeName ) {
277 if (ist ==
nullptr) {
278 ATH_MSG_ERROR(
"preLoadDataTAD: no IOVSvcTool associated with store \""
279 << storeName <<
"\" and failed to create one." );
280 return StatusCode::FAILURE;
291 IOVRange& iovr,
const std::string& storeName) {
296 if (ist ==
nullptr) {
297 ATH_MSG_ERROR(
"setRange: no IOVSvcTool associated with store \""
298 << storeName <<
"\" and failed to create one." );
299 return StatusCode::FAILURE;
303 if (ist2 ==
nullptr) {
305 <<
" not registered with store \"" << storeName <<
"\". Doing it now"
307 if (ist->
regProxy(clid, key).isFailure()) {
308 return StatusCode::FAILURE;
310 }
else if (ist2 != ist) {
311 ATH_MSG_INFO(
"setRange: when registering proxy (clid: "
312 << clid <<
" key: " << key <<
") with store \"" << storeName
313 <<
"\" --> already registered with store \"" << ist2->
getStoreName()
315 return StatusCode::FAILURE;
318 return ist->
setRange( clid, key, iovr );
326 const std::string& storeName) {
331 if (ist ==
nullptr) {
332 ATH_MSG_ERROR(
"dropObjectFromDB: no IOVSvcTool associated with store "
333 << storeName <<
" and failed to create one." );
334 return StatusCode::FAILURE;
338 if (proxy ==
nullptr) {
339 ATH_MSG_DEBUG(
"Proxy for (clid: " << clid <<
" key: " << key <<
") in store " << storeName
340 <<
" does not exist. Cannot drop associated object.");
341 return StatusCode::SUCCESS;
349 if (iovDB !=
nullptr) {
353 ATH_MSG_ERROR(
"dropObjectFromDB: Provider for " << key <<
" is not an IIOVDbSvc.");
354 return StatusCode::FAILURE;
357 return StatusCode::SUCCESS;
368 if (ist ==
nullptr) {
370 <<
" not registered" );
371 return StatusCode::FAILURE;
373 return ist->
getRange( clid, key, iov );
383 std::unique_ptr<IOpaqueAddress>& ioa,
384 const EventIDBase& now)
const {
389 if (ist ==
nullptr) {
392 return StatusCode::FAILURE;
395 uint32_t
event = now.lumi_block();
396 uint32_t
run = now.run_number();
400 curTime.
setTimestamp(1000000000L*
static_cast<uint64_t
>(now.time_stamp()) + now.time_stamp_ns_offset());
403 return ist->
getRangeFromDB( clid, key, range, tag, ioa, curTime );
414 std::unique_ptr<IOpaqueAddress>& ioa)
const {
419 if (ist ==
nullptr) {
422 return StatusCode::FAILURE;
433 const IOVRange& range,
const std::string &tag) {
436 if (ist ==
nullptr) {
439 return StatusCode::FAILURE;
452 for (
const auto& [name, ist] :
m_toolMap) {
453 sc &= ist->reinitialize();
466 std::string store(storeName);
467 std::string toolName(
"IOVSvcTool");
468 if (storeName ==
"default") {
469 store = defaultStore;
477 ATH_MSG_DEBUG(
"Creating " << toolName <<
" associated with store \"" << store
480 const auto itr =
m_toolMap.find( store );
483 if (
p_toolSvc->retrieveTool(
"IOVSvcTool/" + toolName, ist,
this ).isFailure()) {
484 ATH_MSG_ERROR(
"Unable to create IOVSvcTool associated with store \""
486 return StatusCode::FAILURE;
490 return StatusCode::SUCCESS;
493 ATH_MSG_INFO(
"an IOVSvcTool already exists associated with store \""
496 return StatusCode::SUCCESS;
515 const std::string store = (storeName==
"default" ? defaultStore : storeName);
517 const auto itr =
m_toolMap.find( store );
520 ATH_MSG_INFO(
"No IOVSvcTool associated with store \"" << store
539 for (
const auto& [name, ist] :
m_toolMap) {
540 if (ist->holdsProxy( proxy )) {
554 for (
const auto& [name, ist] :
m_toolMap) {
555 if (ist->holdsProxy( clid, key )) {
578 std::string fullname, tname;
579 if (
p_CLIDSvc->getTypeNameOfID( clid, tname ).isFailure()) {
581 fullname += std::to_string(clid);
589 fullname += std::to_string(clid);
600std::vector<std::string>
603 auto keys =
m_toolMap | std::views::keys;
604 return std::vector<std::string>(keys.begin(), keys.end());
615 << ist->getStoreName() <<
"\"" );
616 ist->resetAllProxies();
625 const EventIDBase& now) {
627 const EventContext& ctx = Gaudi::Hive::currentContext();
629 ATH_MSG_DEBUG(
"createCondObj: id: " <<
id <<
" t: " << now <<
" valid: "
632 if (ccb->
valid(now)) {
633 if (msgLvl(MSG::DEBUG)) {
637 <<
" is still valid at " << now );
639 return StatusCode::SUCCESS;
642 IOVTime t(now.run_number(), now.lumi_block(),
643 now.time_stamp()*1000000000LL + now.time_stamp_ns_offset());
646 std::string sgKey =
id.key();
647 auto sep = sgKey.find(
'+');
648 if (sep != std::string::npos) {
649 sgKey.erase(0,sep+1);
652 std::unique_ptr<IOpaqueAddress> ioa;
655 if (
getRangeFromDB(
id.clid(), sgKey, t, range, tag, ioa).isFailure()) {
656 ATH_MSG_ERROR(
"unable to get range from db for time " << t <<
" clid "
657 <<
id.clid() <<
" " << sgKey );
658 return StatusCode::FAILURE;
663 EventIDRange eidRange(range);
668 <<
" IOA: " << ioa.get());
674 if (ccb->
range (eidRange.start(),
r) &&
675 eventIDMatch (
r.start(), eidRange.start()))
678 return StatusCode::SUCCESS;
682 if (ccb->
proxy() ==
nullptr) {
693 DataObject* dobj =
nullptr;
696 if (dp->store()->createObj(dp->loader(), ioa.get(), dobj).isFailure()) {
698 return StatusCode::FAILURE;
727 if (!
sc.isSuccess()) {
728 ATH_MSG_ERROR(
"unable to insert Object at " << v <<
" into CondCont "
729 << ccb->
id() <<
" for range " << eidRange );
730 return StatusCode::FAILURE;
#define ATH_CHECK
Evaluate an expression and check for errors.
uint32_t CLID
The Class ID type.
Abstract interface to IOVDbSvc to access IOVRange and tag information.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
static bool isOverlap(code_t code)
Helper to test whether a code is OVERLAP.
Base class for all conditions containers.
virtual StatusCode typelessInsert(const EventIDRange &r, void *obj, const EventContext &ctx)=0
Insert a new conditions object.
void setProxy(SG::DataProxy *)
Set the associated DataProxy.
@ MIXED
Mixed Run+lbn / timestamp container.
virtual StatusCode extendLastRange(const EventIDRange &newRange, const EventContext &ctx)=0
Extend the range of the last IOV.
virtual bool valid(const EventIDBase &t) const =0
Test to see if a given IOV time is mapped in the container.
KeyType keyType() const
Return the key type for this container.
virtual bool range(const EventIDBase &t, EventIDRange &r) const =0
Return the mapped validity range for an IOV time.
SG::DataProxy * proxy()
Return the associated DataProxy, if any.
const DataObjID & id() const
Return CLID/key corresponding to this container.
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
Abstract interface to IOVDbSvc to access IOVRange and tag information.
virtual bool dropObject(const std::string &key, const bool resetCache=false)=0
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
virtual StatusCode preLoadDataTAD(const SG::TransientAddress *, const std::string &storeName) override
supply a list of TADs whose data will be preloaded
std::map< std::string, IIOVSvcTool * > m_toolMap
virtual std::vector< std::string > getStoreNames() const override
virtual StatusCode createIOVTool(const std::string &storeName) override
ServiceHandle< StoreGateSvc > p_detStore
virtual StatusCode preLoadTAD(const SG::TransientAddress *, const std::string &storeName) override
supply a list of TADs whose proxies will be preloaded
IOVSvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode getRange(const CLID &clid, const std::string &key, IOVRange &io) const override
virtual StatusCode replaceProxy(SG::DataProxy *pOld, SG::DataProxy *pNew, const std::string &storeName) override
replace a registered DataProxy with a new version
ServiceHandle< IClassIDSvc > p_CLIDSvc
virtual void resetAllProxies() override
virtual StatusCode deregProxy(SG::DataProxy *proxy) override
Deregister a DataProxy with the service.
std::recursive_mutex m_lock
IIOVSvcTool * getTool(const std::string &storeName, bool createIF=true)
virtual StatusCode setRange(const CLID &clid, const std::string &key, IOVRange &io, const std::string &storeName) override
Update Range from dB.
virtual StatusCode getRangeFromDB(const CLID &clid, const std::string &key, IOVRange &range, std::string &tag, std::unique_ptr< IOpaqueAddress > &ioa, const EventIDBase &now) const override
Get IOVRange from db for current event.
ServiceHandle< StoreGateSvc > p_sgs
virtual StatusCode setRangeInDB(const CLID &clid, const std::string &key, const IOVRange &range, const std::string &tag) override
Set a particular IOVRange in db (and memory).
virtual StatusCode regProxy(SG::DataProxy *proxy, const std::string &key, const std::string &storeName) override
Subscribe method for DataProxy. key StoreGate key.
virtual StatusCode createCondObj(CondContBase *, const DataObjID &, const EventIDBase &) override
ServiceHandle< IToolSvc > p_toolSvc
virtual void ignoreProxy(const CLID &clid, const std::string &key, const std::string &storeName) override
ignore proxy
virtual StatusCode reinitialize() override
virtual StatusCode initialize() override
std::string fullProxyName(const SG::DataProxy *proxy) const
virtual StatusCode dropObjectFromDB(const CLID &clid, const std::string &key, const std::string &storeName) override
Drop the associated object from the db and trigger reload.
ServiceHandle< ICondSvc > p_condSvc
Basic time unit for IOVSvc.
void setRunEvent(uint32_t run, uint32_t event) noexcept
void setTimestamp(uint64_t timestamp) noexcept
T * Storable_cast(DataObject *pDObj, bool quiet=true, IRegisterTransient *irt=0, bool isConst=true)
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
int run(int argc, char *argv[])