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 (detector_geometry_.empty())
51 else if (hcal_geometry_ != nullptr &&
53 EXCEPTION_RAISE(
54 "GeometryException",
55 "Attempting to run a single job with multiple geometries " +
56 detector_geometry_ + " and '" + rh.getDetectorName() + "'");
57 }
58 // make sure detector name has been set
59 if (detector_geometry_.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 detector_geometry_;
70 ldmx::HcalGeometry* hcal_geometry_;
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 hcal_geometry_ = 0;
82}
83
85 if (hcal_geometry_) delete hcal_geometry_;
86 hcal_geometry_ = 0;
87}
88
89std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
91 static const std::string keyname("detectors_valid");
92
93 if (!hcal_geometry_) {
95 (params_.exists("HcalGeometry"))
96 ? (params_.get<framework::config::Parameters>("HcalGeometry"))
97 : (params_);
98
99 // search through the subtrees
100 for (auto key : phex.keys()) {
103
104 if (!pver.exists(keyname)) {
105 ldmx_log(warn) << "No parameter " << keyname << " found in " << key;
106 // log strange situation and continue
107 continue;
108 }
109
110 std::vector<std::string> dets_valid =
111 pver.get<std::vector<std::string> >(keyname);
112 for (auto detregex : dets_valid) {
113 std::string regex(detregex);
114 if (regex.empty()) continue; // no empty regex allowed
115 if (regex[0] != '^') regex.insert(0, 1, '^');
116 if (regex.back() != '$') regex += '$';
117 regex_t reg;
118
119 int rv =
120 regcomp(&reg, regex.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
121 if (rv) {
122 char err[1024];
123 regerror(rv, &reg, err, 1024);
124 EXCEPTION_RAISE(
125 "GeometryException",
126 "Invalid detector regular expression : '" + regex + "' " + err);
127 }
128 int nmatch = regexec(&reg, detector_geometry_.c_str(), 0, 0, 0);
129 regfree(&reg);
130 if (!nmatch) {
131 hcal_geometry_ = new ldmx::HcalGeometry(pver);
132 break;
133 }
134 }
135 if (hcal_geometry_) break;
136 }
137 if (!hcal_geometry_) {
138 EXCEPTION_RAISE("GeometryException", "Unable to create HcalGeometry");
139 }
140 }
141
142 return std::make_pair(
143 hcal_geometry_,
144 framework::ConditionsIOV(context.getRun(), context.getRun(), true, true));
145}
146
147} // namespace hcal
148
Base class for provider of conditions information like pedestals, gains, electronics maps,...
#define DECLARE_CONDITIONS_PROVIDER(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:29
std::vector< std::string > keys() const
Get a list of the keys available.
Definition Parameters.h:134
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
bool exists(const std::string &name) const
Check to see if a parameter exists.
Definition Parameters.h:63
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 ...
std::string detector_geometry_
Geometry as last used.
framework::config::Parameters params_
Handle to the parameters, needed for future use during get condition.
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:57
const std::string & getDetectorName() const
Definition RunHeader.h:80
All classes in the ldmx-sw project use this namespace.