LDMX Software
Classes | Public Member Functions | Private Attributes | List of all members
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 ()
 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, ConditionsObjectProvider * > providerMap_
 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

◆ ~Conditions()

framework::Conditions::~Conditions ( )
inline

Class destructor.

Definition at line 53 of file Conditions.h.

53{ ; }

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 {
17 classname, objname, tagname, params, process_);
18
19 if (cop) {
20 std::string provides = cop->getConditionObjectName();
21 if (providerMap_.find(provides) != providerMap_.end()) {
22 EXCEPTION_RAISE(
23 "ConditionAmbiguityException",
24 "Multiple ConditonsObjectProviders configured to provide " +
25 provides);
26 }
27 providerMap_[provides] = cop;
28 } else {
29 EXCEPTION_RAISE("ConditionsException",
30 "No ConditionsObjectProvider for " + classname);
31 }
32}
be configured to load conditions objects from CSV files.
std::map< std::string, ConditionsObjectProvider * > providerMap_
Map of who provides which condition.
Definition Conditions.h:122
ConditionsObjectProvider * createConditionsObjectProvider(const std::string &classname, const std::string &objName, const std::string &tagname, const framework::config::Parameters &params, Process &process)
Make a conditions object provider.
static PluginFactory & getInstance()
Get the factory instance.

References framework::PluginFactory::createConditionsObjectProvider(), framework::ConditionsObjectProvider::getConditionObjectName(), framework::PluginFactory::getInstance(), process_, and providerMap_.

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 46 of file Conditions.cxx.

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

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 55 of file Conditions.cxx.

56 {
57 const ldmx::EventHeader& context = *(process_.getEventHeader());
58 auto cacheptr = cache_.find(condition_name);
59
60 if (cacheptr == cache_.end()) {
61 auto copptr = providerMap_.find(condition_name);
62
63 if (copptr == providerMap_.end()) {
64 EXCEPTION_RAISE("ConditionUnavailable",
65 "No provider is available for : " + condition_name);
66 }
67
68 std::pair<const ConditionsObject*, ConditionsIOV> cond =
69 copptr->second->getCondition(context);
70
71 if (!cond.first) {
72 EXCEPTION_RAISE(
73 "ConditionUnavailable",
74 "Null condition returned for requested item : " + condition_name);
75 }
76
77 // first request, create a cache entry
78 CacheEntry ce;
79 ce.iov = cond.second;
80 ce.obj = cond.first;
81 ce.provider = copptr->second;
82 cache_[condition_name] = ce;
83 return ce.obj;
84 } else {
86 if (cacheptr->second.iov.validForEvent(context))
87 return cacheptr->second.obj;
88 else {
89 // if not, we release the old object
90 cacheptr->second.provider->releaseConditionsObject(cacheptr->second.obj);
91 // now ask for a new one
92 std::pair<const ConditionsObject*, ConditionsIOV> cond =
93 cacheptr->second.provider->getCondition(context);
94
95 if (!cond.first) {
96 std::stringstream s;
97 s << "Unable to update condition '" << condition_name << "' for event "
98 << context.getEventNumber() << " run " << context.getRun();
99 if (context.isRealData())
100 s << " DATA";
101 else
102 s << " MC";
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 providerMap_.

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

◆ onNewRun()

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

Calls onNewRun for all ConditionsObjectProviders.

Definition at line 42 of file Conditions.cxx.

42 {
43 for (auto ptr : providerMap_) ptr.second->onNewRun(rh);
44}
void onNewRun(ldmx::RunHeader &)
Calls onNewRun for all ConditionsObjectProviders.

References providerMap_.

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

◆ onProcessEnd()

void framework::Conditions::onProcessEnd ( )

Calls onProcessEnd for all ConditionsObjectProviders.

Definition at line 38 of file Conditions.cxx.

38 {
39 for (auto ptr : providerMap_) ptr.second->onProcessEnd();
40}
void onProcessEnd()
Calls onProcessEnd for all ConditionsObjectProviders.

References providerMap_.

◆ onProcessStart()

void framework::Conditions::onProcessStart ( )

Calls onProcessStart for all ConditionsObjectProviders.

Definition at line 34 of file Conditions.cxx.

34 {
35 for (auto ptr : providerMap_) ptr.second->onProcessStart();
36}
void onProcessStart()
Calls onProcessStart for all ConditionsObjectProviders.

References providerMap_.

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

Member Data Documentation

◆ cache_

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

Conditions cache.

Definition at line 137 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().

◆ providerMap_

std::map<std::string, ConditionsObjectProvider*> framework::Conditions::providerMap_
private

Map of who provides which condition.

Definition at line 122 of file Conditions.h.

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


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