LDMX Software
HcalGeometryProvider.cxx
Go to the documentation of this file.
1#include <regex.h>
2#include <sys/types.h>
3
7#include "Framework/RunHeader.h"
8
16namespace hcal {
17
19 public:
25 HcalGeometryProvider(const std::string& name, const std::string& tagname,
26 const framework::config::Parameters& parameters,
28
30 virtual ~HcalGeometryProvider();
31
38 virtual std::pair<const framework::ConditionsObject*,
40 getCondition(const ldmx::EventHeader& context);
41
47
48 virtual void onNewRun(ldmx::RunHeader& rh) {
49 if (detectorGeometry_.empty())
51 else if (hcalGeometry_ != nullptr &&
53 EXCEPTION_RAISE(
54 "GeometryException",
55 "Attempting to run a single job with multiple geometries " +
56 detectorGeometry_ + " and '" + rh.getDetectorName() + "'");
57 }
58 // make sure detector name has been set
59 if (detectorGeometry_.empty())
60 EXCEPTION_RAISE("GeometryException",
61 "HcalGeometryProvider unable to get the name of the "
62 "detector from the RunHeader.");
63 }
64
65 private:
69 std::string detectorGeometry_;
70 ldmx::HcalGeometry* hcalGeometry_;
71};
72
74 const std::string& name, const std::string& tagname,
75 const framework::config::Parameters& parameters,
76 framework::Process& process)
77 : framework::
78 ConditionsObjectProvider{ldmx::HcalGeometry::CONDITIONS_OBJECT_NAME,
79 tagname, parameters, process},
80 params_{parameters} {
81 hcalGeometry_ = 0;
82}
83
85 if (hcalGeometry_) delete hcalGeometry_;
86 hcalGeometry_ = 0;
87}
88
89std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
91 static const std::string KEYNAME("detectors_valid");
92
93 if (!hcalGeometry_) {
95 (params_.exists("HcalGeometry"))
97 "HcalGeometry"))
98 : (params_);
99
100 // search through the subtrees
101 for (auto key : phex.keys()) {
104
105 if (!pver.exists(KEYNAME)) {
106 ldmx_log(warn) << "No parameter " << KEYNAME << " found in " << key;
107 // log strange situation and continue
108 continue;
109 }
110
111 std::vector<std::string> dets_valid =
112 pver.getParameter<std::vector<std::string> >(KEYNAME);
113 for (auto detregex : dets_valid) {
114 std::string regex(detregex);
115 if (regex.empty()) continue; // no empty regex allowed
116 if (regex[0] != '^') regex.insert(0, 1, '^');
117 if (regex.back() != '$') regex += '$';
118 regex_t reg;
119
120 int rv =
121 regcomp(&reg, regex.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
122 if (rv) {
123 char err[1024];
124 regerror(rv, &reg, err, 1024);
125 EXCEPTION_RAISE(
126 "GeometryException",
127 "Invalid detector regular expression : '" + regex + "' " + err);
128 }
129 int nmatch = regexec(&reg, detectorGeometry_.c_str(), 0, 0, 0);
130 regfree(&reg);
131 if (!nmatch) {
132 hcalGeometry_ = new ldmx::HcalGeometry(pver);
133 break;
134 }
135 }
136 if (hcalGeometry_) break;
137 }
138 if (!hcalGeometry_) {
139 EXCEPTION_RAISE("GeometryException", "Unable to create HcalGeometry");
140 }
141 }
142
143 return std::make_pair(
144 hcalGeometry_,
145 framework::ConditionsIOV(context.getRun(), context.getRun(), true, true));
146}
147
148} // namespace hcal
149
150DECLARE_CONDITIONS_PROVIDER_NS(hcal, HcalGeometryProvider);
Base class for provider of conditions information like pedestals, gains, electronics maps,...
#define DECLARE_CONDITIONS_PROVIDER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that provides header information about an event such as event number and timestamp.
Class that translates HCal ID into positions of strip hits.
be configured to load conditions objects from CSV files.
Class which defines the run/event/type range for which a given condition is valid,...
Base class for all providers of conditions objects.
const Process & process() const
Get the process handle.
Base class for all conditions objects, very simple.
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
std::vector< std::string > keys() const
Get a list of the keys available.
Definition Parameters.h:130
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
bool exists(const std::string &name) const
Check to see if a parameter exists.
Definition Parameters.h:71
virtual ~HcalGeometryProvider()
Destructor.
virtual void releaseConditionsObject(const framework::ConditionsObject *co)
Take no action on release, as the object is permanently owned by the Provider.
virtual std::pair< const framework::ConditionsObject *, framework::ConditionsIOV > getCondition(const ldmx::EventHeader &context)
Provides access to the HcalGeometry.
virtual void onNewRun(ldmx::RunHeader &rh)
Callback for the ConditionsObjectProvider to take any necessary action when the processing of events ...
framework::config::Parameters params_
Handle to the parameters, needed for future use during get condition.
std::string detectorGeometry_
Geometry as last used.
HcalGeometryProvider(const std::string &name, const std::string &tagname, const framework::config::Parameters &parameters, framework::Process &process)
Class constructor.
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
Implementation of HCal strip readout.
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:54
const std::string & getDetectorName() const
Definition RunHeader.h:77
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45