LDMX Software
EcalGeometryProvider.cxx
Go to the documentation of this file.
1#include <regex.h>
2
6#include "Framework/RunHeader.h"
7
14namespace ecal {
15
17 public:
23 EcalGeometryProvider(const std::string& name, const std::string& tagname,
24 const framework::config::Parameters& parameters,
26
28 virtual ~EcalGeometryProvider();
29
36 virtual std::pair<const framework::ConditionsObject*,
38 getCondition(const ldmx::EventHeader& context);
39
45
46 virtual void onNewRun(ldmx::RunHeader& rh) {
47 // the configured detector wins (real data RunHeaders carry no detector)
48 const std::string rh_det = rh.getDetectorName();
49 if (detector_geometry_.empty())
50 detector_geometry_ = rh_det;
51 else if (ecal_geometry_ != nullptr && !rh_det.empty() &&
52 detector_geometry_ != rh_det) {
53 EXCEPTION_RAISE(
54 "GeometryException",
55 "Attempting to run a single job with multiple geometries " +
56 detector_geometry_ + " and '" + rh_det + "'");
57 }
58 // make sure detector name has been set
59 if (detector_geometry_.empty())
60 EXCEPTION_RAISE("GeometryException",
61 "EcalGeometryProvider unable to get the name of the "
62 "detector from the RunHeader; set the 'detector' "
63 "parameter.");
64 }
65
66 private:
68 std::vector<framework::config::Parameters> geometries_;
70 std::string detector_geometry_;
71 ldmx::EcalGeometry* ecal_geometry_;
72};
73
75 const std::string& name, const std::string& tagname,
76 const framework::config::Parameters& parameters,
77 framework::Process& process)
79 ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME, tagname, parameters,
80 process} {
82 parameters.get<std::vector<framework::config::Parameters>>("geometries");
83 // optional explicit detector name (real data), empty: use the RunHeader
84 detector_geometry_ = parameters.get<std::string>("detector", "");
85 ecal_geometry_ = 0;
86}
87
89 if (ecal_geometry_) delete ecal_geometry_;
90 ecal_geometry_ = 0;
91}
92
93std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
95 static const std::string keyname("detectors_valid");
96
97 if (!ecal_geometry_) {
98 // search through the subtrees
99 for (auto pver : geometries_) {
100 if (!pver.exists(keyname)) {
101 ldmx_log(warn) << "No parameter " << keyname
102 << " found one of the detector vesrsions.";
103 // log strange situation and continue
104 continue;
105 }
106
107 std::vector<std::string> dets_valid =
108 pver.get<std::vector<std::string>>(keyname);
109 for (auto detregex : dets_valid) {
110 std::string regex(detregex);
111 if (regex.empty()) continue; // no empty regex allowed
112 if (regex[0] != '^') regex.insert(0, 1, '^');
113 if (regex.back() != '$') regex += '$';
114 regex_t reg;
115
116 int rv =
117 regcomp(&reg, regex.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
118 if (rv) {
119 char err[1024];
120 regerror(rv, &reg, err, 1024);
121 EXCEPTION_RAISE(
122 "GeometryException",
123 "Invalid detector regular expression : '" + regex + "' " + err);
124 }
125 int nmatch = regexec(&reg, detector_geometry_.c_str(), 0, 0, 0);
126 regfree(&reg);
127 if (!nmatch) {
128 ecal_geometry_ = new ldmx::EcalGeometry(pver);
129 break;
130 }
131 }
132 if (ecal_geometry_) break;
133 }
134 if (!ecal_geometry_) {
135 EXCEPTION_RAISE("GeometryException", "Unable to create EcalGeometry");
136 }
137 }
138
139 return std::make_pair(
140 ecal_geometry_,
141 framework::ConditionsIOV(context.getRun(), context.getRun(), true, true));
142}
143
144} // namespace ecal
145
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 translates raw positions of ECal module hits into cells in a hexagonal readout.
Class that provides header information about an event such as event number and timestamp.
be configured to load conditions objects from CSV files.
virtual ~EcalGeometryProvider()
Destructor.
EcalGeometryProvider(const std::string &name, const std::string &tagname, const framework::config::Parameters &parameters, framework::Process &process)
Class constructor.
virtual std::pair< const framework::ConditionsObject *, framework::ConditionsIOV > getCondition(const ldmx::EventHeader &context)
Provides access to the EcalGeometry or EcalTriggerGeometry.
std::string detector_geometry_
Geometry as last used.
std::vector< framework::config::Parameters > geometries_
parameters for the various geometry versions we can support
virtual void releaseConditionsObject(const framework::ConditionsObject *co)
Take no action on release, as the object is permanently owned by the Provider.
virtual void onNewRun(ldmx::RunHeader &rh)
Callback for the ConditionsObjectProvider to take any necessary action when the processing of events ...
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
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
Translation between real-space positions and cell IDs within the ECal.
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
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.