16#include "GaudiKernel/MsgStream.h"
21std::string CondContBase::s_cleanerSvcName =
"Athena::ConditionsCleanerSvc";
64 if (newRange.
m_range.start().isTimeStamp()) {
68 EventIDBase eid = ctx.eventID();
69 if (ctx.hasExtension()) {
70 EventIDBase::number_type conditionsRun =
72 if (conditionsRun != EventIDBase::UNDEFNUM) {
73 eid.set_run_number (conditionsRun);
94 if (oldRange.
m_range.stop().isTimeStamp()) {
96 EventIDBase oldId = oldRange.
m_range.stop();
97 EventIDBase newId = newRange.
m_range.start();
98 newRange.
m_range = EventIDRange (EventIDBase (newId.run_number(),
101 oldId.time_stamp_ns_offset(),
103 newId.bunch_crossing_id()),
120 if (oldRange.
m_range.start().isTimeStamp()) {
122 EventIDBase oldId = oldRange.
m_range.start();
123 EventIDBase newId = newRange.
m_range.stop();
125 EventIDBase (newId.run_number(),
126 newId.event_number(),
128 oldId.time_stamp_ns_offset(),
130 newId.bunch_crossing_id()));
181 range.m_range = EventIDRange (
range.m_range.start(),
210 return StatusCode::Category::message (code);
319size_t CondContBase::trim (
const std::vector<key_type>& runLbnKeys,
const std::vector<key_type>& TSKeys)
333 for (
const typename CondContSet::value_type& ent :
m_condSet.range()) {
339 size_t ntrim=tsmap_nc->trim (TSKeys,
true);
344 size_t outerTrimmed=
m_condSet.trim(runLbnKeys);
348 return nTrimmed+outerTrimmed;
413 std::shared_ptr<CondContSet::IPayloadDeleter> payloadDeleter,
446 CondContSet::payload_unique_ptr t,
447 const EventContext& ctx)
449 EventIDBase start =
r.start();
450 EventIDBase stop =
r.stop();
455 if (start.run_number() == EventIDBase::UNDEFNUM ||
456 stop.run_number() == EventIDBase::UNDEFNUM)
459 msg << MSG::ERROR <<
"CondContBase::insertBase: "
460 <<
"Run part of range invalid in mixed container."
462 return StatusCode::FAILURE;
468 else if (start.isTimeStamp() && stop.isTimeStamp()) {
474 msg << MSG::ERROR <<
"CondContBase::insertBase: "
475 <<
"Timestamp key used in non-timestamp container."
477 return StatusCode::FAILURE;
484 else if (start.run_number() != EventIDBase::UNDEFNUM &&
485 stop.run_number() != EventIDBase::UNDEFNUM)
492 msg << MSG::ERROR <<
"CondContBase::insertBase: "
493 <<
"Run/LBN key used in non-Run/LBN container."
495 return StatusCode::FAILURE;
504 msg << MSG::ERROR <<
"CondContBase::insertBase: EventIDRange " <<
r
505 <<
" is neither fully RunEvent nor TimeStamp"
507 return StatusCode::FAILURE;
510 CondContSet::EmplaceResult reslt =
511 m_condSet.emplace( RangeKey(
r, start_key, stop_key),
516 if (reslt == CondContSet::EmplaceResult::DUPLICATE)
520 else if (reslt == CondContSet::EmplaceResult::EXTENDED)
524 else if (reslt == CondContSet::EmplaceResult::OVERLAP) {
539 const EventContext& ctx)
543 if (!t.isRunLumi()) {
545 msg << MSG::ERROR <<
"CondContBase::erase: "
546 <<
"Non-Run/LBN key used in Run/LBN container."
548 return StatusCode::FAILURE;
553 if (!t.isTimeStamp()) {
555 msg << MSG::ERROR <<
"CondContBase::erase: "
556 <<
"Non-Timestamp key used in timestamp container."
558 return StatusCode::FAILURE;
567 return StatusCode::SUCCESS;
583 const EventContext& ctx)
590 if (!newRange.start().isRunLumi()) {
592 msg << MSG::ERROR <<
"CondContBase::extendLastRange: "
593 <<
"Non-Run/LBN range used in Run/LBN container."
595 return StatusCode::FAILURE;
601 if (!newRange.start().isTimeStamp()) {
603 msg << MSG::ERROR <<
"CondContBase::extendLastRange: "
604 <<
"Non-timestamp range used in timestamp container."
606 return StatusCode::FAILURE;
613 return StatusCode::FAILURE;
620 return StatusCode::SUCCESS;
622 return StatusCode::FAILURE;
637 EventIDRange
const**
r)
const
639 const void* ptr =
nullptr;
646 msg << MSG::ERROR <<
"CondContBase::findBase: "
647 <<
"Non-Run/LBN key used in Run/LBN container."
654 if (!t.isTimeStamp()) [[
unlikely]] {
656 msg << MSG::ERROR <<
"CondContBase::findBase: "
657 <<
"Non-timestamp key used in timestamp container."
670 CondContSet::const_iterator
it =
m_condSet.find (key);
671 if (it && key < it->
first.m_stop) {
673 *
r = &
it->first.m_range;
706 return std::vector<CondContBase*> (
m_deps.begin(),
m_deps.end());
716void CondContBase::setCleanerSvcName (
const std::string& name)
718 s_cleanerSvcName = name;
729 msg << MSG::ERROR <<
"CondCont<T>::insert: Not most-derived class; "
730 <<
"CLID used: " << usedCLID
731 <<
"; container CLID: " <<
m_clid
750 return m_id.fullKey();
763 ost <<
"id: " <<
id() <<
" proxy: " <<
proxy() <<
" ["
764 <<
entries() <<
"] entries" << std::endl;
765 forEach ([&] (
const CondContSet::value_type& ent)
766 { ost << ent.first.m_range <<
" " << ent.second << std::endl; });
773std::vector<EventIDRange>
776 std::vector<EventIDRange>
r;
779 forEach ([&] (
const CondContSet::value_type& ent)
780 {
r.push_back (ent.first.m_range); });
809 const EventContext& ctx)
812 CondContSet::payload_unique_ptr (obj,
delfcn()),
827 const EventIDRange*
rp =
nullptr;
843 const EventContext& ctx)
861 const EventContext& ctx)
880 std::shared_ptr<CondContSet::IPayloadDeleter> payloadDeleter,
883 std::move(payloadDeleter), capacity)
904 std::shared_ptr<CondContSet::IPayloadDeleter> payloadDeleter,
921 ost <<
"id: " <<
id() <<
" proxy: " <<
proxy() <<
" ["
923 forEach ([&] (
const CondContSet::value_type& ent)
927 if (tsmap->empty()) {
928 ost << ent.first.m_range <<
" (empty tsmap)" << std::endl;
931 for (
const CondContSet::value_type& ent2 : tsmap->range()) {
932 ost << ent2.first.m_range <<
" " << ent2.second << std::endl;
945 forEach ([&] (
const CondContSet::value_type& ent) {
948 nent += tsmap->size();
957std::vector<EventIDRange>
960 std::vector<EventIDRange>
r;
963 forEach ([&] (
const CondContSet::value_type& ent)
967 for (
const CondContSet::value_type& ent2 : tsmap->range()) {
968 r.push_back (ent2.first.m_range);
997 const EventContext& ctx)
1015 const EventIDRange*
rp =
nullptr;
1033 const EventContext& )
1036 msg << MSG::ERROR <<
"CondContMixedBase::erase: "
1037 <<
"erase() is not implemented for mixed containers."
1039 return StatusCode::FAILURE;
1057 const EventContext& )
1060 msg << MSG::ERROR <<
"CondContMixedBase::extendLastRange: "
1061 <<
"extendLastRange() is not implemented for mixed containers."
1063 return StatusCode::FAILURE;
1084 CondContBase::CondContSet::payload_unique_ptr t,
1085 const EventContext& ctx)
1090 const EventIDRange*
range =
nullptr;
1098 if (
r.start().isTimeStamp() ) {
1104 StatusCode
sc = StatusCode::SUCCESS;
1107 if (
r.start().run_number() !=
range->start().run_number() ||
1108 r.stop().run_number() !=
range->stop().run_number() ||
1109 r.start().lumi_block() !=
range->start().lumi_block() ||
1110 r.stop().lumi_block() !=
range->stop().lumi_block())
1116 bool extended =
false;
1117 if (tsmap->size() == 1) {
1118 CondContSet::const_iterator elt = tsmap->find (start_key);
1120 if (elt->first.m_start == start_key &&
1121 elt->first.m_stop == stop_key)
1139 tsmap->updateRanges ([&] (
RangeKey& k)
1140 { EventIDBase start = k.m_range.start();
1141 EventIDBase stop = k.m_range.stop();
1142 stop.set_run_number(
r.stop().run_number());
1143 stop.set_lumi_block(
r.stop().lumi_block());
1144 k.m_range = EventIDRange (start, stop);
1154 msg << MSG::ERROR <<
"CondContMixedBase::insertMixed: "
1155 <<
"Run+lbn part of new range doesn't match existing range, "
1156 <<
"or can't extend. "
1157 <<
"New: " <<
r <<
"; existing: " << *
range
1159 return StatusCode::FAILURE;
1164 auto newmap = std::make_unique<CondContSet>
1166 tsmap = newmap.get();
1168 if (
sc.isFailure()) {
1171 else if (Category::isDuplicate (
sc)) {
1177 CondContSet::EmplaceResult reslt =
1178 tsmap->emplace (
RangeKey(
r, start_key, stop_key),
1179 std::move(t),
false, ctx );
1181 if (reslt == CondContSet::EmplaceResult::OVERLAP) {
1184 else if (Category::isExtended (
sc)) {
1187 else if (reslt == CondContSet::EmplaceResult::DUPLICATE)
1191 else if (reslt == CondContSet::EmplaceResult::EXTENDED)
1211 EventIDRange
const**
r)
const
1213 if (!t.isTimeStamp()) {
1215 msg << MSG::ERROR <<
"CondContMixedBase::findMixed: "
1216 <<
"No valid timestamp in key used with mixed container."
1221 auto dostall = []() { CxxUtils::stall();
return true; };
1222 const void* ptr =
nullptr;
1223 CondContSet::const_iterator it;
1226 if (!ptr)
return nullptr;
1230 it = tsmap->find (key);
1232 if (it && key < it->first.m_stop) {
1234 *
r = &it->first.m_range;
Hold mappings of ranges to condition objects.
CondContStatusCode
Define extended status codes used by CondCont.
uint32_t CLID
The Class ID type.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Define macros for attributes used to control the static checker.
Interface for RCU service.
EventIDBase::number_type conditionsRun() const
Status code category for ContCont.
StatusCode::code_t code_t
static bool isOverlap(code_t code)
Helper to test whether a code is OVERLAP.
virtual const char * name() const override
Name of the category.
virtual bool isSuccess(code_t code) const override
Is code considered success?
virtual std::string message(code_t code) const override
Description for code within this category.
static bool isExtended(code_t code)
Helper to test whether a code is EXTENDED.
static bool isDuplicate(code_t code)
Helper to test whether a code is DUPLICATE.
void quiescent(const EventContext &ctx)
Mark that this thread is no longer accessing data from this container.
CLID m_clid
CLID of the most-derived CondCont.
void insertError(CLID usedCLID) const
Helper to report an error due to using a base class for insertion.
void forEach(const FUNC &func) const
Call func on each entry in the container.
CondContSet::Updater_t Updater_t
size_t nInserts() const
Return the number times an item was inserted into the map.
void setProxy(SG::DataProxy *)
Set the associated DataProxy.
size_t maxSize() const
Return the maximum size of the map.
KeyType
Type of key used for this container.
@ SINGLE
Either TIMESTAMP or RUNLBN, but nothing's been put in the container yet, so we don't know which one.
@ MIXED
Mixed Run+lbn / timestamp container.
@ TIMESTAMP
Container uses timestamp keys.
@ RUNLBN
Container uses run+lbn keys.
std::string title() const
Description of this container to use for MsgStream.
void clear()
Remove all entries in the container.
std::atomic< KeyType > m_keyType
Key type of this container.
const void * findBase(const EventIDBase &t, EventIDRange const **r) const
Internal lookup function.
CondContSet m_condSet
Set of mapped objects.
static std::string s_cleanerSvcName ATLAS_THREAD_SAFE
Name of the global conditions cleaner service.
delete_function * delfcn() const
Return the deletion function for this container.
StatusCode eraseBase(const EventIDBase &t, const EventContext &ctx)
Erase the first element not less than t.
ServiceHandle< Athena::IConditionsCleanerSvc > m_cleanerSvc
Handle to the cleaner service.
void addDep(CondContBase *dep)
Declare another conditions container that depends on this one.
static key_type keyFromTimestamp(const EventIDBase &b)
Make a timestamp key from an EventIDBase.
static key_type keyFromRunLBN(const EventIDBase &b)
Make a run+lbn key from an EventIDBase.
virtual size_t entries() const
Return the number of conditions objects in the container.
DataObjID m_id
CLID+key for this container.
CxxUtils::ConcurrentRangeMap< RangeKey, key_type, void, Compare, Athena::RCUUpdater > CondContSet
StatusCode inserted(const EventContext &ctx)
Tell the cleaner that a new object was added to the container.
KeyType keyType() const
Return the key type for this container.
CondContBase(Athena::IRCUSvc &rcusvc, KeyType keytype, CLID clid, const DataObjID &id, SG::DataProxy *proxy, std::shared_ptr< CondContSet::IPayloadDeleter > payloadDeleter, size_t capacity)
Internal constructor.
CLID clid() const
Return the CLID of the most-derived CondCont.
StatusCode extendLastRangeBase(const EventIDRange &newRange, const EventContext &ctx)
Extend the range of the last IOV.
StatusCode insertBase(const EventIDRange &r, CondContSet::payload_unique_ptr t, const EventContext &ctx)
Insert a new conditions object.
uint64_t key_type
Type used to store an IOV time internally.
SG::DataProxy * m_proxy
Associated DataProxy.
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.
virtual size_t trim(const std::vector< key_type > &runLbnKeys, const std::vector< key_type > &TSKeys)
Remove unused entries from the front of the list.
void print() const
Dump the container to cout.
const DataObjID & id() const
Return CLID/key corresponding to this container.
CondContSet::delete_function delete_function
std::vector< CondContBase * > getDeps()
Return the list of conditions containers that depend on this one.
virtual void list(std::ostream &ost) const =0
Dump the container contents for debugging.
CxxUtils::ConcurrentPtrSet< CondContBase, CxxUtils::SimpleUpdater > DepSet
Other conditions dependencies that depend on this one, as inferred by addDependency calls.
delete_function * payloadDelfcn() const
Return the payload deletion function for this container.
virtual void list(std::ostream &ost) const override final
Dump the container contents for debugging.
const void * findMixed(const EventIDBase &t, EventIDRange const **r) const
Internal lookup function.
virtual std::vector< EventIDRange > ranges() const override final
Return all IOV validity ranges defined in this container.
virtual StatusCode typelessInsert(const EventIDRange &r, void *obj, const EventContext &ctx) override final
Insert a new conditions object.
virtual StatusCode erase(const EventIDBase &t, const EventContext &ctx) override final
Erase the first element not less than t.
virtual StatusCode extendLastRange(const EventIDRange &newRange, const EventContext &ctx) override final
Extend the range of the last IOV.
virtual size_t entries() const override final
Return the number of conditions objects in the container.
Athena::IRCUSvc & m_rcusvc
Need to remember the RCU svc here in order to pass it to the TS maps.
std::shared_ptr< CondContSet::IPayloadDeleter > m_payloadDeleter
Deletion object for actual payload objects.
std::mutex m_mutex
Mutex for insertions.
StatusCode insertMixed(const EventIDRange &r, CondContBase::CondContSet::payload_unique_ptr t, const EventContext &ctx)
Insert a new conditions object.
CondContMixedBase(Athena::IRCUSvc &rcusvc, CLID clid, const DataObjID &id, SG::DataProxy *proxy, std::shared_ptr< CondContSet::IPayloadDeleter > payloadDeleter, size_t capacity)
Internal constructor.
virtual bool range(const EventIDBase &t, EventIDRange &r) const override final
Return the mapped validity range for an IOV time.
CondContSingleBase(Athena::IRCUSvc &rcusvc, CLID clid, const DataObjID &id, SG::DataProxy *proxy, std::shared_ptr< CondContSet::IPayloadDeleter > payloadDeleter, size_t capacity)
Internal constructor.
virtual bool range(const EventIDBase &t, EventIDRange &r) const override final
Return the mapped validity range for an IOV time.
virtual void list(std::ostream &ost) const override final
Dump the container contents for debugging.
virtual std::vector< EventIDRange > ranges() const override final
Return all IOV validity ranges defined in this container.
virtual StatusCode typelessInsert(const EventIDRange &r, void *obj, const EventContext &ctx) override final
Insert a new conditions object.
virtual StatusCode extendLastRange(const EventIDRange &newRange, const EventContext &ctx) override final
Extend the range of the last IOV.
virtual StatusCode erase(const EventIDBase &t, const EventContext &ctx) override final
Erase the first element not less than t.
CondContBase::key_type key_type
DataProxy provides the registry services for StoreGate.
singleton-like access to IMessageSvc via open function and helper
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
IMessageSvc * getMessageSvc(bool quiet=false)
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
::StatusCode StatusCode
StatusCode definition for legacy code.
int extendRange(RangeKey &range, const RangeKey &newRange) const
Possibly extend an existing range at the end.
int overlap(const EventContext &ctx, const RangeKey &oldRange, RangeKey &newRange) const
Test if two ranges overlap, and adjust if needed.
Range object to store in ConcurrentRangeMap.
key_type m_start
Packed start time.
key_type m_stop
Packed stop time.
EventIDRange m_range
Original range object.