LDMX Software
Conditions.cxx
2
3#include <sstream>
4
7#include "Framework/Exception/Exception.h"
8#include "Framework/Process.h"
9
10namespace framework {
11
12Conditions::Conditions(Process& p) : process_{p} {}
13
15 for (auto& [name, entry] : cache_) {
16 if (entry.obj_ && entry.provider_) {
17 entry.provider_->releaseConditionsObject(entry.obj_);
18 entry.obj_ = nullptr;
19 }
20 }
21}
22
24 const std::string& classname, const std::string& objname,
25 const std::string& tagname, const framework::config::Parameters& params) {
26 auto cop = ConditionsObjectProvider::Factory::get().make(
27 classname, objname, tagname, params, process_);
28 if (not cop) {
29 EXCEPTION_RAISE("UnableToCreate",
30 "No ConditionsObjectProvider for " + classname);
31 }
32
33 std::string provides = cop.value()->getConditionObjectName();
34 if (provider_map_.find(provides) != provider_map_.end()) {
35 EXCEPTION_RAISE(
36 "ConditionAmbiguityException",
37 "Multiple ConditonsObjectProviders configured to provide " + provides);
38 }
39 provider_map_[provides] = cop.value();
40}
41
43 for (auto ptr : provider_map_) ptr.second->onProcessStart();
44}
45
47 for (auto ptr : provider_map_) ptr.second->onProcessEnd();
48}
49
51 for (auto ptr : provider_map_) ptr.second->onNewRun(rh);
52}
53
55 const std::string& condition_name) const {
56 auto cacheptr = cache_.find(condition_name);
57 if (cacheptr == cache_.end()) {
58 return ConditionsIOV();
59 } else {
60 return cacheptr->second.iov_;
61 }
62}
63
65 const std::string& condition_name) {
66 const ldmx::EventHeader& context = *(process_.getEventHeader());
67 auto cacheptr = cache_.find(condition_name);
68
69 if (cacheptr == cache_.end()) {
70 auto copptr = provider_map_.find(condition_name);
71
72 if (copptr == provider_map_.end()) {
73 EXCEPTION_RAISE("ConditionUnavailable",
74 "No provider is available for : " + condition_name);
75 }
76
77 std::pair<const ConditionsObject*, ConditionsIOV> cond =
78 copptr->second->getCondition(context);
79
80 if (!cond.first) {
81 EXCEPTION_RAISE(
82 "ConditionUnavailable",
83 "Null condition returned for requested item : " + condition_name);
84 }
85
86 // first request, create a cache entry
87 CacheEntry ce;
88 ce.iov_ = cond.second;
89 ce.obj_ = cond.first;
90 ce.provider_ = copptr->second;
91 cache_[condition_name] = ce;
92 return ce.obj_;
93 } else {
94 // if still valid, we return what we have
95 if (cacheptr->second.iov_.validForEvent(context)) {
96 return cacheptr->second.obj_;
97 } else {
98 // if not, we release the old object
99 cacheptr->second.provider_->releaseConditionsObject(
100 cacheptr->second.obj_);
101 cacheptr->second.obj_ = nullptr;
102 // now ask for a new one
103 std::pair<const ConditionsObject*, ConditionsIOV> cond =
104 cacheptr->second.provider_->getCondition(context);
105
106 if (!cond.first) {
107 std::stringstream s;
108 s << "Unable to update condition '" << condition_name << "' for event "
109 << context.getEventNumber() << " run " << context.getRun();
110 if (context.isRealData()) {
111 s << " DATA";
112 } else {
113 s << " MC";
114 }
115 EXCEPTION_RAISE("ConditionUnavailable", s.str());
116 }
117 cacheptr->second.iov_ = cond.second;
118 cacheptr->second.obj_ = cond.first;
119 return cond.first;
120 }
121 }
122}
123
124} // namespace framework
Base class for provider of conditions information like pedestals, gains, electronics maps,...
Container and caching class for conditions information.
Class that provides header information about an event such as event number and timestamp.
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:118
std::map< std::string, CacheEntry > cache_
Conditions cache.
Definition Conditions.h:137
std::map< std::string, std::shared_ptr< ConditionsObjectProvider > > provider_map_
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.
~Conditions()
Class destructor.
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:34
const ldmx::EventHeader * getEventHeader() const
Get the pointer to the current event header, if defined.
Definition Process.h:66
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
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:68
All classes in the ldmx-sw project use this namespace.
An entry to store an already loaded conditions object.
Definition Conditions.h:127
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
std::shared_ptr< ConditionsObjectProvider > provider_
Provider that gave us the conditions object.
Definition Conditions.h:131