17#include "GaudiKernel/MsgStream.h"
22std::string CondContBase::s_cleanerSvcName =
"Athena::ConditionsCleanerSvc";
65 if (newRange.
m_range.start().isTimeStamp()) {
69 EventIDBase eid = ctx.eventID();
70 if (ctx.hasExtension()) {
71 EventIDBase::number_type conditionsRun =
73 if (conditionsRun != EventIDBase::UNDEFNUM) {
74 eid.set_run_number (conditionsRun);
95 if (oldRange.
m_range.stop().isTimeStamp()) {
97 EventIDBase oldId = oldRange.
m_range.stop();
98 EventIDBase newId = newRange.
m_range.start();
99 newRange.
m_range = EventIDRange (EventIDBase (newId.run_number(),
100 newId.event_number(),
102 oldId.time_stamp_ns_offset(),
104 newId.bunch_crossing_id()),
121 if (oldRange.
m_range.start().isTimeStamp()) {
123 EventIDBase oldId = oldRange.
m_range.start();
124 EventIDBase newId = newRange.
m_range.stop();
126 EventIDBase (newId.run_number(),
127 newId.event_number(),
129 oldId.time_stamp_ns_offset(),
131 newId.bunch_crossing_id()));
182 range.m_range = EventIDRange (
range.m_range.start(),
211 return StatusCode::Category::message (code);
265 return isExtended (code.getCode());
320size_t CondContBase::trim (
const std::vector<key_type>& runLbnKeys,
const std::vector<key_type>& TSKeys)
340 size_t ntrim=tsmap_nc->trim (TSKeys,
true);
345 size_t outerTrimmed=
m_condSet.trim(runLbnKeys);
349 return nTrimmed+outerTrimmed;
414 std::shared_ptr<CondContSet::IPayloadDeleter> payloadDeleter,
448 const EventContext& ctx )
450 EventIDBase start =
r.start();
451 EventIDBase stop =
r.stop();
456 if (start.run_number() == EventIDBase::UNDEFNUM ||
457 stop.run_number() == EventIDBase::UNDEFNUM)
460 msg << MSG::ERROR <<
"CondContBase::insertBase: "
461 <<
"Run part of range invalid in mixed container."
463 return StatusCode::FAILURE;
469 else if (start.isTimeStamp() && stop.isTimeStamp()) {
475 msg << MSG::ERROR <<
"CondContBase::insertBase: "
476 <<
"Timestamp key used in non-timestamp container."
478 return StatusCode::FAILURE;
485 else if (start.run_number() != EventIDBase::UNDEFNUM &&
486 stop.run_number() != EventIDBase::UNDEFNUM)
493 msg << MSG::ERROR <<
"CondContBase::insertBase: "
494 <<
"Run/LBN key used in non-Run/LBN container."
496 return StatusCode::FAILURE;
505 msg << MSG::ERROR <<
"CondContBase::insertBase: EventIDRange " <<
r
506 <<
" is neither fully RunEvent nor TimeStamp"
508 return StatusCode::FAILURE;
517 if (reslt == CondContSet::EmplaceResult::DUPLICATE)
521 else if (reslt == CondContSet::EmplaceResult::EXTENDED)
525 else if (reslt == CondContSet::EmplaceResult::OVERLAP) {
540 const EventContext& ctx )
544 if (!t.isRunLumi()) {
546 msg << MSG::ERROR <<
"CondContBase::erase: "
547 <<
"Non-Run/LBN key used in Run/LBN container."
549 return StatusCode::FAILURE;
554 if (!t.isTimeStamp()) {
556 msg << MSG::ERROR <<
"CondContBase::erase: "
557 <<
"Non-Timestamp key used in timestamp container."
559 return StatusCode::FAILURE;
568 return StatusCode::SUCCESS;
584 const EventContext& ctx )
591 if (!newRange.start().isRunLumi()) {
593 msg << MSG::ERROR <<
"CondContBase::extendLastRange: "
594 <<
"Non-Run/LBN range used in Run/LBN container."
596 return StatusCode::FAILURE;
602 if (!newRange.start().isTimeStamp()) {
604 msg << MSG::ERROR <<
"CondContBase::extendLastRange: "
605 <<
"Non-timestamp range used in timestamp container."
607 return StatusCode::FAILURE;
614 return StatusCode::FAILURE;
621 return StatusCode::SUCCESS;
623 return StatusCode::FAILURE;
638 EventIDRange
const**
r)
const
640 const void* ptr =
nullptr;
647 msg << MSG::ERROR <<
"CondContBase::findBase: "
648 <<
"Non-Run/LBN key used in Run/LBN container."
657 msg << MSG::ERROR <<
"CondContBase::findBase: "
658 <<
"Non-timestamp key used in timestamp container."
672 if (it && key < it->
first.m_stop) {
674 *
r = &
it->first.m_range;
707 return std::vector<CondContBase*> (
m_deps.begin(),
m_deps.end());
717void CondContBase::setCleanerSvcName (
const std::string& name)
719 s_cleanerSvcName = name;
730 msg << MSG::ERROR <<
"CondCont<T>::insert: Not most-derived class; "
731 <<
"CLID used: " << usedCLID
732 <<
"; container CLID: " <<
m_clid
751 return m_id.fullKey();
764 ost <<
"id: " <<
id() <<
" proxy: " <<
proxy() <<
" ["
765 <<
entries() <<
"] entries" << std::endl;
767 { ost << ent.first.m_range <<
" " << ent.second << std::endl; });
774std::vector<EventIDRange>
777 std::vector<EventIDRange>
r;
781 {
r.push_back (ent.first.m_range); });
810 const EventContext& ctx )
828 const EventIDRange*
rp =
nullptr;
844 const EventContext& ctx )
862 const EventContext& ctx )
881 std::shared_ptr<CondContSet::IPayloadDeleter> payloadDeleter,
884 std::move(payloadDeleter), capacity)
905 std::shared_ptr<CondContSet::IPayloadDeleter> payloadDeleter,
922 ost <<
"id: " <<
id() <<
" proxy: " <<
proxy() <<
" ["
924 forEach ([&] (
const CondContSet::value_type& ent)
928 if (tsmap->
empty()) {
929 ost << ent.first.m_range <<
" (empty tsmap)" << std::endl;
932 for (
const CondContSet::value_type& ent2 : tsmap->
range()) {
933 ost << ent2.first.m_range <<
" " << ent2.second << std::endl;
946 forEach ([&] (
const CondContSet::value_type& ent) {
949 nent += tsmap->
size();
958std::vector<EventIDRange>
961 std::vector<EventIDRange>
r;
964 forEach ([&] (
const CondContSet::value_type& ent)
968 for (
const CondContSet::value_type& ent2 : tsmap->
range()) {
969 r.push_back (ent2.first.m_range);
998 const EventContext& ctx )
1016 const EventIDRange*
rp =
nullptr;
1034 const EventContext& )
1037 msg << MSG::ERROR <<
"CondContMixedBase::erase: "
1038 <<
"erase() is not implemented for mixed containers."
1040 return StatusCode::FAILURE;
1058 const EventContext& )
1061 msg << MSG::ERROR <<
"CondContMixedBase::extendLastRange: "
1062 <<
"extendLastRange() is not implemented for mixed containers."
1064 return StatusCode::FAILURE;
1086 const EventContext& ctx )
1089 std::lock_guard<std::mutex> lock (
m_mutex);
1091 const EventIDRange*
range =
nullptr;
1099 if (
r.start().isTimeStamp() ) {
1105 StatusCode
sc = StatusCode::SUCCESS;
1108 if (
r.start().run_number() !=
range->start().run_number() ||
1109 r.stop().run_number() !=
range->stop().run_number() ||
1110 r.start().lumi_block() !=
range->start().lumi_block() ||
1111 r.stop().lumi_block() !=
range->stop().lumi_block())
1117 bool extended =
false;
1118 if (tsmap->size() == 1) {
1119 CondContSet::const_iterator elt = tsmap->find (start_key);
1121 if (elt->first.m_start == start_key &&
1122 elt->first.m_stop == stop_key)
1140 tsmap->updateRanges ([&] (
RangeKey& k)
1141 { EventIDBase start = k.m_range.start();
1142 EventIDBase stop = k.m_range.stop();
1143 stop.set_run_number(
r.stop().run_number());
1144 stop.set_lumi_block(
r.stop().lumi_block());
1145 k.m_range = EventIDRange (start, stop);
1155 msg << MSG::ERROR <<
"CondContMixedBase::insertMixed: "
1156 <<
"Run+lbn part of new range doesn't match existing range, "
1157 <<
"or can't extend. "
1158 <<
"New: " <<
r <<
"; existing: " << *
range
1160 return StatusCode::FAILURE;
1165 auto newmap = std::make_unique<CondContSet>
1167 tsmap = newmap.get();
1169 if (
sc.isFailure()) {
1172 else if (Category::isDuplicate (
sc)) {
1178 CondContSet::EmplaceResult reslt =
1179 tsmap->emplace (
RangeKey(
r, start_key, stop_key),
1180 std::move(t),
false, ctx );
1182 if (reslt == CondContSet::EmplaceResult::OVERLAP) {
1185 else if (Category::isExtended (
sc)) {
1188 else if (reslt == CondContSet::EmplaceResult::DUPLICATE)
1192 else if (reslt == CondContSet::EmplaceResult::EXTENDED)
1212 EventIDRange
const**
r)
const
1214 if (!t.isTimeStamp()) {
1216 msg << MSG::ERROR <<
"CondContMixedBase::findMixed: "
1217 <<
"No valid timestamp in key used with mixed container."
1223 const void* ptr =
nullptr;
1224 CondContSet::const_iterator it;
1227 if (!ptr)
return nullptr;
1231 it = tsmap->
find (key);
1233 if (it && key < it->first.m_stop) {
1235 *
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.
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.
StatusCode insertBase(const EventIDRange &r, CondContSet::payload_unique_ptr t, const EventContext &ctx=Gaudi::Hive::currentContext())
Insert a new conditions object.
CLID m_clid
CLID of the most-derived CondCont.
StatusCode extendLastRangeBase(const EventIDRange &newRange, const EventContext &ctx=Gaudi::Hive::currentContext())
Extend the range of the last IOV.
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.
StatusCode eraseBase(const EventIDBase &t, const EventContext &ctx=Gaudi::Hive::currentContext())
Erase the first element not less than t.
delete_function * delfcn() const
Return the deletion function for this container.
void quiescent(const EventContext &ctx=Gaudi::Hive::currentContext())
Mark that this thread is no longer accessing data from this container.
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.
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.
StatusCode insertMixed(const EventIDRange &r, CondContBase::CondContSet::payload_unique_ptr t, const EventContext &ctx=Gaudi::Hive::currentContext())
Insert a new conditions object.
virtual size_t entries() const override final
Return the number of conditions objects in the container.
virtual StatusCode erase(const EventIDBase &t, const EventContext &ctx=Gaudi::Hive::currentContext()) override final
Erase the first element not less than t.
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.
virtual StatusCode typelessInsert(const EventIDRange &r, void *obj, const EventContext &ctx=Gaudi::Hive::currentContext()) override final
Insert a new conditions object.
std::mutex m_mutex
Mutex for insertions.
virtual StatusCode extendLastRange(const EventIDRange &newRange, const EventContext &ctx=Gaudi::Hive::currentContext()) override final
Extend the range of the last IOV.
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.
virtual StatusCode erase(const EventIDBase &t, const EventContext &ctx=Gaudi::Hive::currentContext()) override final
Erase the first element not less than t.
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 StatusCode extendLastRange(const EventIDRange &newRange, const EventContext &ctx=Gaudi::Hive::currentContext()) override final
Extend the range of the last IOV.
virtual StatusCode typelessInsert(const EventIDRange &r, void *obj, const EventContext &ctx=Gaudi::Hive::currentContext()) override final
Insert a new conditions object.
virtual std::vector< EventIDRange > ranges() const override final
Return all IOV validity ranges defined in this container.
CondContBase::key_type key_type
std::pair< RangeKey, const void * > value_type
std::unique_ptr< void, DeletePayload > payload_unique_ptr
const_iterator_range range() const
Return a range that can be used to iterate over the container.
bool empty() const
Test if the map is empty.
const value_type * const_iterator
EmplaceResult emplace(const RANGE &range, payload_unique_ptr ptr, bool tryExtend=false, const typename Updater_t::Context_t &ctx=Updater_t::defaultContext())
Add a new element to the map.
const_iterator find(const key_query_type &key) const
Search for the first item less than or equal to KEY.
void erase(const key_query_type &key, const typename Updater_t::Context_t &ctx=Updater_t::defaultContext())
Erase the first item less than or equal to KEY.
size_t size() const
Return the current number of elements in the map.
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.
void stall()
Emit stall instruction for use in a spin loop.
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.