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 if (detector_geometry_.empty())
50 else if (hcal_geometry_ != nullptr &&
52 EXCEPTION_RAISE(
53 "GeometryException",
54 "Attempting to run a single job with multiple geometries " +
55 detector_geometry_ + " and '" + rh.getDetectorName() + "'");
56 }
57 // make sure detector name has been set
58 if (detector_geometry_.empty())
59 EXCEPTION_RAISE("GeometryException",
60 "HcalGeometryProvider unable to get the name of the "
61 "detector from the RunHeader.");
62 }
63
64 private:
68 std::string detector_geometry_;
69 ldmx::HcalGeometry* hcal_geometry_;
70};
71
73 const std::string& name, const std::string& tagname,
74 const framework::config::Parameters& parameters,
75 framework::Process& process)
76 : framework::
77 ConditionsObjectProvider{ldmx::HcalGeometry::CONDITIONS_OBJECT_NAME,
78 tagname, parameters, process},
79 params_{parameters} {
80 hcal_geometry_ = 0;
81}
82
84 if (hcal_geometry_) delete hcal_geometry_;
85 hcal_geometry_ = 0;
86}
87
88std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
90 static const std::string keyname("detectors_valid");
91
92 if (!hcal_geometry_) {
94 (params_.exists("hcal_geometry"))
95 ? (params_.get<framework::config::Parameters>("hcal_geometry"))
96 : (params_);
97
98 // search through the subtrees
99 for (auto key : phex.keys()) {
102
103 if (!pver.exists(keyname)) {
104 ldmx_log(warn) << "No parameter " << keyname << " found in " << key;
105 // log strange situation and continue
106 continue;
107 }
108
109 std::vector<std::string> dets_valid =
110 pver.get<std::vector<std::string> >(keyname);
111 for (auto detregex : dets_valid) {
112 std::string regex(detregex);
113 if (regex.empty()) continue; // no empty regex allowed
114 if (regex[0] != '^') regex.insert(0, 1, '^');
115 if (regex.back() != '$') regex += '$';
116 regex_t reg;
117
118 int rv =
119 regcomp(&reg, regex.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
120 if (rv) {
121 char err[1024];
122 regerror(rv, &reg, err, 1024);
123 EXCEPTION_RAISE(
124 "GeometryException",
125 "Invalid detector regular expression : '" + regex + "' " + err);
126 }
127 int nmatch = regexec(&reg, detector_geometry_.c_str(), 0, 0, 0);
128 regfree(&reg);
129 if (!nmatch) {
130 hcal_geometry_ = new ldmx::HcalGeometry(pver);
131 break;
132 }
133 }
134 if (hcal_geometry_) break;
135 }
136 if (!hcal_geometry_) {
137 EXCEPTION_RAISE("GeometryException", "Unable to create HcalGeometry");
138 }
139 }
140
141 return std::make_pair(
142 hcal_geometry_,
143 framework::ConditionsIOV(context.getRun(), context.getRun(), true, true));
144}
145
146} // namespace hcal
147
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.