LDMX Software
EcalGeometryProvider.cxx
Go to the documentation of this file.
1#include <regex.h>
2#include <sys/types.h>
3
7#include "Framework/RunHeader.h"
8
15namespace ecal {
16
18 public:
24 EcalGeometryProvider(const std::string& name, const std::string& tagname,
25 const framework::config::Parameters& parameters,
27
29 virtual ~EcalGeometryProvider();
30
37 virtual std::pair<const framework::ConditionsObject*,
39 getCondition(const ldmx::EventHeader& context);
40
46
47 virtual void onNewRun(ldmx::RunHeader& rh) {
48 if (detectorGeometry_.empty())
50 else if (ecalGeometry_ != nullptr &&
52 EXCEPTION_RAISE(
53 "GeometryException",
54 "Attempting to run a single job with multiple geometries " +
55 detectorGeometry_ + " and '" + rh.getDetectorName() + "'");
56 }
57 // make sure detector name has been set
58 if (detectorGeometry_.empty())
59 EXCEPTION_RAISE("GeometryException",
60 "EcalGeometryProvider unable to get the name of the "
61 "detector from the RunHeader.");
62 }
63
64 private:
66 std::vector<framework::config::Parameters> geometries_;
68 std::string detectorGeometry_;
69 ldmx::EcalGeometry* ecalGeometry_;
70};
71
73 const std::string& name, const std::string& tagname,
74 const framework::config::Parameters& parameters,
75 framework::Process& process)
77 ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME, tagname, parameters,
78 process} {
80 parameters.getParameter<std::vector<framework::config::Parameters>>(
81 "geometries");
82 ecalGeometry_ = 0;
83}
84
86 if (ecalGeometry_) delete ecalGeometry_;
87 ecalGeometry_ = 0;
88}
89
90std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
92 static const std::string KEYNAME("detectors_valid");
93
94 if (!ecalGeometry_) {
95 // search through the subtrees
96 for (auto pver : geometries_) {
97 if (!pver.exists(KEYNAME)) {
98 ldmx_log(warn) << "No parameter " << KEYNAME
99 << " found one of the detector vesrsions.";
100 // log strange situation and continue
101 continue;
102 }
103
104 std::vector<std::string> dets_valid =
105 pver.getParameter<std::vector<std::string>>(KEYNAME);
106 for (auto detregex : dets_valid) {
107 std::string regex(detregex);
108 if (regex.empty()) continue; // no empty regex allowed
109 if (regex[0] != '^') regex.insert(0, 1, '^');
110 if (regex.back() != '$') regex += '$';
111 regex_t reg;
112
113 int rv =
114 regcomp(&reg, regex.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
115 if (rv) {
116 char err[1024];
117 regerror(rv, &reg, err, 1024);
118 EXCEPTION_RAISE(
119 "GeometryException",
120 "Invalid detector regular expression : '" + regex + "' " + err);
121 }
122 int nmatch = regexec(&reg, detectorGeometry_.c_str(), 0, 0, 0);
123 regfree(&reg);
124 if (!nmatch) {
125 ecalGeometry_ = new ldmx::EcalGeometry(pver);
126 break;
127 }
128 }
129 if (ecalGeometry_) break;
130 }
131 if (!ecalGeometry_) {
132 EXCEPTION_RAISE("GeometryException", "Unable to create EcalGeometry");
133 }
134 }
135
136 return std::make_pair(
137 ecalGeometry_,
138 framework::ConditionsIOV(context.getRun(), context.getRun(), true, true));
139}
140
141} // namespace ecal
142
143DECLARE_CONDITIONS_PROVIDER_NS(ecal, EcalGeometryProvider);
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 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 detectorGeometry_
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:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
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:54
const std::string & getDetectorName() const
Definition RunHeader.h:77
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45