LDMX Software
Conditions.cxx
2
3#include <sstream>
4
6#include "Framework/Process.h"
7
8namespace framework {
9
10Conditions::Conditions(Process& p) : process_{p} {}
11
13 const std::string& classname, const std::string& objname,
14 const std::string& tagname, const framework::config::Parameters& params) {
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}
33
35 for (auto ptr : providerMap_) ptr.second->onProcessStart();
36}
37
39 for (auto ptr : providerMap_) ptr.second->onProcessEnd();
40}
41
43 for (auto ptr : providerMap_) ptr.second->onNewRun(rh);
44}
45
47 const std::string& condition_name) const {
48 auto cacheptr = cache_.find(condition_name);
49 if (cacheptr == cache_.end())
50 return ConditionsIOV();
51 else
52 return cacheptr->second.iov;
53}
54
56 const std::string& condition_name) {
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}
111
112} // namespace framework
Container and caching class for conditions information.
Class which provides a singleton module factory that creates EventProcessor objects.
Class which represents the process under execution.
Class which defines the run/event/type range for which a given condition is valid,...
Base class for all providers of conditions objects.
virtual void onProcessStart()
Callback for the ConditionsObjectProvider to take any necessary action when the processing of events ...
const std::string & getConditionObjectName() const
Get the list of conditions objects available from this provider.
Base class for all conditions objects, very simple.
Process & process_
Handle to the Process.
Definition Conditions.h:119
std::map< std::string, CacheEntry > cache_
Conditions cache.
Definition Conditions.h:137
std::map< std::string, ConditionsObjectProvider * > providerMap_
Map of who provides which condition.
Definition Conditions.h:122
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),...
void onProcessEnd()
Calls onProcessEnd for all ConditionsObjectProviders.
ConditionsIOV getConditionIOV(const std::string &condition_name) const
Access the IOV for the given condition.
Conditions(Process &)
Constructor.
void onProcessStart()
Calls onProcessStart 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.
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.
Class which represents the process under execution.
Definition Process.h:36
const ldmx::EventHeader * getEventHeader() const
Get the pointer to the current event header, if defined.
Definition Process.h:68
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
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
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:57
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45
An entry to store an already loaded conditions object.
Definition Conditions.h:127
ConditionsObjectProvider * provider
Provider that gave us the conditions object.
Definition Conditions.h:131
const ConditionsObject * obj
Const pointer to the retrieved conditions object.
Definition Conditions.h:133
ConditionsIOV iov
Interval Of Validity for this entry in the cache.
Definition Conditions.h:129