LDMX Software
TrigScintGeometryProvider.cxx
Go to the documentation of this file.
1#include <regex.h>
2
6#include "Framework/RunHeader.h"
7
14namespace trigscint {
15
17 public:
18 TrigScintGeometryProvider(const std::string& name, const std::string& tagname,
19 const framework::config::Parameters& parameters,
21
23
24 virtual std::pair<const framework::ConditionsObject*,
26 getCondition(const ldmx::EventHeader& context);
27
29
30 virtual void onNewRun(ldmx::RunHeader& rh) {
31 // Prefer the explicitly-configured detector (set via the python
32 // 'detector' parameter, robust for real data whose RunHeader may carry no
33 // detector name); otherwise fall back to the RunHeader (sim).
34 const std::string rh_det = rh.getDetectorName();
35 if (detector_geometry_.empty())
36 detector_geometry_ = rh_det;
37 else if (ts_geometry_ != nullptr && !rh_det.empty() &&
38 detector_geometry_ != rh_det) {
39 EXCEPTION_RAISE(
40 "GeometryException",
41 "Attempting to run a single job with multiple geometries " +
42 detector_geometry_ + " and '" + rh_det + "'");
43 }
44 if (detector_geometry_.empty())
45 EXCEPTION_RAISE("GeometryException",
46 "TrigScintGeometryProvider unable to get the detector "
47 "name from the RunHeader; set the 'detector' parameter.");
48 }
49
50 private:
52 std::string detector_geometry_;
53 ldmx::TrigScintGeometry* ts_geometry_;
54};
55
56TrigScintGeometryProvider::TrigScintGeometryProvider(
57 const std::string& name, const std::string& tagname,
58 const framework::config::Parameters& parameters,
59 framework::Process& process)
60 : framework::ConditionsObjectProvider{ldmx::TrigScintGeometry::
61 CONDITIONS_OBJECT_NAME,
62 tagname, parameters, process},
63 params_{parameters} {
64 ts_geometry_ = 0;
65 // optional explicit detector name (real data); empty => use RunHeader
66 detector_geometry_ = parameters.get<std::string>("detector", "");
67}
68
69TrigScintGeometryProvider::~TrigScintGeometryProvider() {
70 if (ts_geometry_) delete ts_geometry_;
71 ts_geometry_ = 0;
72}
73
74std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
76 static const std::string keyname("detectors_valid");
77
78 if (!ts_geometry_) {
80 (params_.exists("trig_scint_geometry"))
82 "trig_scint_geometry"))
83 : (params_);
84
85 for (auto key : pts.keys()) {
88
89 if (!pver.exists(keyname)) {
90 ldmx_log(warn) << "No parameter " << keyname << " found in " << key;
91 continue;
92 }
93
94 std::vector<std::string> dets_valid =
95 pver.get<std::vector<std::string> >(keyname);
96 for (auto detregex : dets_valid) {
97 std::string regex(detregex);
98 if (regex.empty()) continue;
99 if (regex[0] != '^') regex.insert(0, 1, '^');
100 if (regex.back() != '$') regex += '$';
101 regex_t reg;
102
103 int rv =
104 regcomp(&reg, regex.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
105 if (rv) {
106 char err[1024];
107 regerror(rv, &reg, err, 1024);
108 EXCEPTION_RAISE(
109 "GeometryException",
110 "Invalid detector regular expression : '" + regex + "' " + err);
111 }
112 int nmatch = regexec(&reg, detector_geometry_.c_str(), 0, 0, 0);
113 regfree(&reg);
114 if (!nmatch) {
115 ts_geometry_ = new ldmx::TrigScintGeometry(pver);
116 break;
117 }
118 }
119 if (ts_geometry_) break;
120 }
121 if (!ts_geometry_) {
122 EXCEPTION_RAISE("GeometryException",
123 "Unable to create TrigScintGeometry");
124 }
125 }
126
127 return std::make_pair(
128 ts_geometry_,
129 framework::ConditionsIOV(context.getRun(), context.getRun(), true, true));
130}
131
132} // namespace trigscint
133
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 a trigger-scintillator (module, bar) into a global bar-center position.
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
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
Bar-center positions of the trigger-scintillator modules.
virtual void onNewRun(ldmx::RunHeader &rh)
Callback for the ConditionsObjectProvider to take any necessary action when the processing of events ...
virtual void releaseConditionsObject(const framework::ConditionsObject *co)
Called by conditions system when done with a conditions object, appropriate point for cleanup.
virtual std::pair< const framework::ConditionsObject *, framework::ConditionsIOV > getCondition(const ldmx::EventHeader &context)
Pure virtual getCondition function.
All classes in the ldmx-sw project use this namespace.