LDMX Software
framework::Conditions Class Reference

Container and cache for conditions and conditions providers. More...

#include <Conditions.h>

Classes

struct  CacheEntry
 An entry to store an already loaded conditions object. More...
 

Public Member Functions

 Conditions (Process &)
 Constructor.
 
 ~Conditions ()=default
 Class destructor.
 
const ConditionsObjectgetConditionPtr (const std::string &condition_name)
 Primary request action for a conditions object If the object is in the cache and still valid (IOV), the cached object will be returned.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Primary request action for a conditions object If the object is in the cache and still valid (IOV), the cached object will be returned.
 
ConditionsIOV getConditionIOV (const std::string &condition_name) const
 Access the IOV for the given condition.
 
void onProcessStart ()
 Calls onProcessStart for all ConditionsObjectProviders.
 
void onProcessEnd ()
 Calls onProcessEnd for all ConditionsObjectProviders.
 
void onNewRun (ldmx::RunHeader &)
 Calls onNewRun for all ConditionsObjectProviders.
 
void createConditionsObjectProvider (const std::string &classname, const std::string &instancename, const std::string &tagname, const framework::config::Parameters &params)
 Create a ConditionsObjectProvider given the information.
 

Private Attributes

Processprocess_
 Handle to the Process.
 
std::map< std::string, std::shared_ptr< ConditionsObjectProvider > > provider_map_
 Map of who provides which condition.
 
std::map< std::string, CacheEntrycache_
 Conditions cache.
 

Detailed Description

Container and cache for conditions and conditions providers.

Definition at line 43 of file Conditions.h.

Constructor & Destructor Documentation

◆ Conditions()

framework::Conditions::Conditions ( Process & p)

Constructor.

Definition at line 10 of file Conditions.cxx.

10: process_{p} {}
Process & process_
Handle to the Process.
Definition Conditions.h:119

Member Function Documentation

◆ createConditionsObjectProvider()

void framework::Conditions::createConditionsObjectProvider ( const std::string & classname,
const std::string & instancename,
const std::string & tagname,
const framework::config::Parameters & params )

Create a ConditionsObjectProvider given the information.

Definition at line 12 of file Conditions.cxx.

14 {
15 auto cop = ConditionsObjectProvider::Factory::get().make(
16 classname, objname, tagname, params, process_);
17 if (not cop) {
18 EXCEPTION_RAISE("UnableToCreate",
19 "No ConditionsObjectProvider for " + classname);
20 }
21
22 std::string provides = cop.value()->getConditionObjectName();
23 if (provider_map_.find(provides) != provider_map_.end()) {
24 EXCEPTION_RAISE(
25 "ConditionAmbiguityException",
26 "Multiple ConditonsObjectProviders configured to provide " + provides);
27 }
28 provider_map_[provides] = cop.value();
29}
std::map< std::string, std::shared_ptr< ConditionsObjectProvider > > provider_map_
Map of who provides which condition.
Definition Conditions.h:123

References process_, and provider_map_.

Referenced by framework::Process::Process().

◆ getCondition()

template<class T >
const T & framework::Conditions::getCondition ( const std::string & condition_name)
inline

Primary request action for a conditions object If the object is in the cache and still valid (IOV), the cached object will be returned.

If it is not in the cache, or is out of date, the ConditionsObjectProvider::getCondition method will be called to provide the object.

See also
getConditionPtr
Template Parameters
Ttype to cast condition object to
Parameters
[in]condition_namename of condition to retrieve
Returns
const reference to conditions object

Definition at line 83 of file Conditions.h.

83 {
84 return dynamic_cast<const T&>(*getConditionPtr(condition_name));
85 }
const ConditionsObject * getConditionPtr(const std::string &condition_name)
Primary request action for a conditions object If the object is in the cache and still valid (IOV),...

References getConditionPtr().

Referenced by framework::EventProcessor::getCondition().

◆ getConditionIOV()

ConditionsIOV framework::Conditions::getConditionIOV ( const std::string & condition_name) const

Access the IOV for the given condition.

Parameters
[in]condition_namename of condition to get IOV for
Returns
Interval Of Validity for the input condition name

Definition at line 43 of file Conditions.cxx.

44 {
45 auto cacheptr = cache_.find(condition_name);
46 if (cacheptr == cache_.end()) {
47 return ConditionsIOV();
48 } else {
49 return cacheptr->second.iov_;
50 }
51}
std::map< std::string, CacheEntry > cache_
Conditions cache.
Definition Conditions.h:138

References cache_.

Referenced by framework::ConditionsObjectProvider::requestParentCondition().

◆ getConditionPtr()

const ConditionsObject * framework::Conditions::getConditionPtr ( const std::string & condition_name)

Primary request action for a conditions object If the object is in the cache and still valid (IOV), the cached object will be returned.

If it is not in the cache, or is out of date, the ConditionsObjectProvider::getCondition method will be called to provide the object.

Exceptions
Exceptionif condition object or provider for that object is not found.
Parameters
[in]condition_namename of condition to retrieve
Returns
pointer to conditions object with input name

if still valid, we return what we have

Definition at line 53 of file Conditions.cxx.

54 {
55 const ldmx::EventHeader& context = *(process_.getEventHeader());
56 auto cacheptr = cache_.find(condition_name);
57
58 if (cacheptr == cache_.end()) {
59 auto copptr = provider_map_.find(condition_name);
60
61 if (copptr == provider_map_.end()) {
62 EXCEPTION_RAISE("ConditionUnavailable",
63 "No provider is available for : " + condition_name);
64 }
65
66 std::pair<const ConditionsObject*, ConditionsIOV> cond =
67 copptr->second->getCondition(context);
68
69 if (!cond.first) {
70 EXCEPTION_RAISE(
71 "ConditionUnavailable",
72 "Null condition returned for requested item : " + condition_name);
73 }
74
75 // first request, create a cache entry
76 CacheEntry ce;
77 ce.iov_ = cond.second;
78 ce.obj_ = cond.first;
79 ce.provider_ = copptr->second;
80 cache_[condition_name] = ce;
81 return ce.obj_;
82 } else {
84 if (cacheptr->second.iov_.validForEvent(context)) {
85 return cacheptr->second.obj_;
86 } else {
87 // if not, we release the old object
88 cacheptr->second.provider_->releaseConditionsObject(
89 cacheptr->second.obj_);
90 // now ask for a new one
91 std::pair<const ConditionsObject*, ConditionsIOV> cond =
92 cacheptr->second.provider_->getCondition(context);
93
94 if (!cond.first) {
95 std::stringstream s;
96 s << "Unable to update condition '" << condition_name << "' for event "
97 << context.getEventNumber() << " run " << context.getRun();
98 if (context.isRealData()) {
99 s << " DATA";
100 } else {
101 s << " MC";
102 }
103 EXCEPTION_RAISE("ConditionUnavailable", s.str());
104 }
105 cacheptr->second.iov_ = cond.second;
106 cacheptr->second.obj_ = cond.first;
107 return cond.first;
108 }
109 }
110}
const ldmx::EventHeader * getEventHeader() const
Get the pointer to the current event header, if defined.
Definition Process.h:68
Provides header information an event such as event number and timestamp.
Definition EventHeader.h:44
int getRun() const
Return the run number.
Definition EventHeader.h:84
bool isRealData() const
Is this a real data event?
int getEventNumber() const
Return the event number.
Definition EventHeader.h:78

References cache_, framework::Process::getEventHeader(), ldmx::EventHeader::getEventNumber(), ldmx::EventHeader::getRun(), framework::Conditions::CacheEntry::iov_, ldmx::EventHeader::isRealData(), framework::Conditions::CacheEntry::obj_, process_, framework::Conditions::CacheEntry::provider_, and provider_map_.

Referenced by getCondition(), and framework::ConditionsObjectProvider::requestParentCondition().

◆ onNewRun()

void framework::Conditions::onNewRun ( ldmx::RunHeader & rh)

Calls onNewRun for all ConditionsObjectProviders.

Definition at line 39 of file Conditions.cxx.

39 {
40 for (auto ptr : provider_map_) ptr.second->onNewRun(rh);
41}

References provider_map_.

Referenced by framework::Process::newRun().

◆ onProcessEnd()

void framework::Conditions::onProcessEnd ( )

Calls onProcessEnd for all ConditionsObjectProviders.

Definition at line 35 of file Conditions.cxx.

35 {
36 for (auto ptr : provider_map_) ptr.second->onProcessEnd();
37}

References provider_map_.

◆ onProcessStart()

void framework::Conditions::onProcessStart ( )

Calls onProcessStart for all ConditionsObjectProviders.

Definition at line 31 of file Conditions.cxx.

31 {
32 for (auto ptr : provider_map_) ptr.second->onProcessStart();
33}

References provider_map_.

Referenced by framework::Process::run().

Member Data Documentation

◆ cache_

std::map<std::string, CacheEntry> framework::Conditions::cache_
private

Conditions cache.

Definition at line 138 of file Conditions.h.

Referenced by getConditionIOV(), and getConditionPtr().

◆ process_

Process& framework::Conditions::process_
private

Handle to the Process.

Definition at line 119 of file Conditions.h.

Referenced by createConditionsObjectProvider(), and getConditionPtr().

◆ provider_map_

std::map<std::string, std::shared_ptr<ConditionsObjectProvider> > framework::Conditions::provider_map_
private

Map of who provides which condition.

Definition at line 123 of file Conditions.h.

Referenced by createConditionsObjectProvider(), getConditionPtr(), onNewRun(), onProcessEnd(), and onProcessStart().


The documentation for this class was generated from the following files: