LDMX Software
HcalGeometryProvider.cxx
Go to the documentation of this file.
1#include <regex.h>
2
6#include "Framework/RunHeader.h"
7
15namespace hcal {
16
18 public:
24 HcalGeometryProvider(const std::string& name, const std::string& tagname,
25 const framework::config::Parameters& parameters,
27
29 virtual ~HcalGeometryProvider();
30
37 virtual std::pair<const framework::ConditionsObject*,
39 getCondition(const ldmx::EventHeader& context);
40
46
47 virtual void onNewRun(ldmx::RunHeader& rh) {
48 // the configured detector wins (real data RunHeaders carry no detector)
49 const std::string rh_det = rh.getDetectorName();
50 if (detector_geometry_.empty())
51 detector_geometry_ = rh_det;
52 else if (hcal_geometry_ != nullptr && !rh_det.empty() &&
53 detector_geometry_ != rh_det) {
54 EXCEPTION_RAISE(
55 "GeometryException",
56 "Attempting to run a single job with multiple geometries " +
57 detector_geometry_ + " and '" + rh_det + "'");
58 }
59 // make sure detector name has been set
60 if (detector_geometry_.empty())
61 EXCEPTION_RAISE("GeometryException",
62 "HcalGeometryProvider unable to get the name of the "
63 "detector from the RunHeader; set the 'detector' "
64 "parameter.");
65 }
66
67 private:
71 std::string detector_geometry_;
72 ldmx::HcalGeometry* hcal_geometry_;
73};
74
76 const std::string& name, const std::string& tagname,
77 const framework::config::Parameters& parameters,
78 framework::Process& process)
79 : framework::
80 ConditionsObjectProvider{ldmx::HcalGeometry::CONDITIONS_OBJECT_NAME,
81 tagname, parameters, process},
82 params_{parameters} {
83 // optional explicit detector name (real data), empty: use the RunHeader
84 detector_geometry_ = parameters.get<std::string>("detector", "");
85 hcal_geometry_ = 0;
86}
87
89 if (hcal_geometry_) delete hcal_geometry_;
90 hcal_geometry_ = 0;
91}
92
93std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
95 static const std::string keyname("detectors_valid");
96
97 if (!hcal_geometry_) {
99 (params_.exists("hcal_geometry"))
100 ? (params_.get<framework::config::Parameters>("hcal_geometry"))
101 : (params_);
102
103 // search through the subtrees
104 for (auto key : phex.keys()) {
107
108 if (!pver.exists(keyname)) {
109 ldmx_log(warn) << "No parameter " << keyname << " found in " << key;
110 // log strange situation and continue
111 continue;
112 }
113
114 std::vector<std::string> dets_valid =
115 pver.get<std::vector<std::string> >(keyname);
116 for (auto detregex : dets_valid) {
117 std::string regex(detregex);
118 if (regex.empty()) continue; // no empty regex allowed
119 if (regex[0] != '^') regex.insert(0, 1, '^');
120 if (regex.back() != '$') regex += '$';
121 regex_t reg;
122
123 int rv =
124 regcomp(&reg, regex.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
125 if (rv) {
126 char err[1024];
127 regerror(rv, &reg, err, 1024);
128 EXCEPTION_RAISE(
129 "GeometryException",
130 "Invalid detector regular expression : '" + regex + "' " + err);
131 }
132 int nmatch = regexec(&reg, detector_geometry_.c_str(), 0, 0, 0);
133 regfree(&reg);
134 if (!nmatch) {
135 hcal_geometry_ = new ldmx::HcalGeometry(pver);
136 break;
137 }
138 }
139 if (hcal_geometry_) break;
140 }
141 if (!hcal_geometry_) {
142 EXCEPTION_RAISE("GeometryException", "Unable to create HcalGeometry");
143 }
144 }
145
146 return std::make_pair(
147 hcal_geometry_,
148 framework::ConditionsIOV(context.getRun(), context.getRun(), true, true));
149}
150
151} // namespace hcal
152
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:34
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
std::vector< std::string > keys() const
Get a list of the keys available.
Definition Parameters.h:131
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
bool exists(const std::string &name) const
Check to see if a parameter exists.
Definition Parameters.h:60
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:68
const std::string & getDetectorName() const
Definition RunHeader.h:99
All classes in the ldmx-sw project use this namespace.