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) {
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}
30
32 for (auto ptr : provider_map_) ptr.second->onProcessStart();
33}
34
36 for (auto ptr : provider_map_) ptr.second->onProcessEnd();
37}
38
40 for (auto ptr : provider_map_) ptr.second->onNewRun(rh);
41}
42
44 const std::string& condition_name) const {
45 auto cacheptr = cache_.find(condition_name);
46 if (cacheptr == cache_.end()) {
47 return ConditionsIOV();
48 } else {
49 return cacheptr->second.iov_;
50 }
51}
52
54 const std::string& condition_name) {
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}
111
112} // namespace framework
Base class for provider of conditions information like pedestals, gains, electronics maps,...
Container and caching class for conditions information.
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 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:138
std::map< std::string, std::shared_ptr< ConditionsObjectProvider > > provider_map_
Map of who provides which condition.
Definition Conditions.h:123
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.
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.
An entry to store an already loaded conditions object.
Definition Conditions.h:128
const ConditionsObject * obj_
Const pointer to the retrieved conditions object.
Definition Conditions.h:134
ConditionsIOV iov_
Interval Of Validity for this entry in the cache.
Definition Conditions.h:130
std::shared_ptr< ConditionsObjectProvider > provider_
Provider that gave us the conditions object.
Definition Conditions.h:132