LDMX Software
hcal::HcalGeometryProvider Class Reference

Public Member Functions

 HcalGeometryProvider (const std::string &name, const std::string &tagname, const framework::config::Parameters &parameters, framework::Process &process)
 Class constructor.
 
virtual ~HcalGeometryProvider ()
 Destructor.
 
virtual std::pair< const framework::ConditionsObject *, framework::ConditionsIOV > getCondition (const ldmx::EventHeader &context)
 Provides access to the HcalGeometry.
 
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 starts for a given run.
 
- Public Member Functions inherited from framework::ConditionsObjectProvider
 DECLARE_FACTORY (ConditionsObjectProvider, std::shared_ptr< ConditionsObjectProvider >, const std::string &, const std::string &, const framework::config::Parameters &, Process &)
 declare that we have a factory for these types of classes
 
 ConditionsObjectProvider (const std::string &objname, const std::string &tagname, const framework::config::Parameters &parameters, Process &process)
 Class constructor.
 
virtual ~ConditionsObjectProvider ()=default
 Class destructor.
 
virtual void onProcessStart ()
 Callback for the ConditionsObjectProvider to take any necessary action when the processing of events starts.
 
virtual void onProcessEnd ()
 Callback for the ConditionsObjectProvider to take any necessary action when the processing of events finishes, such as closing database connections.
 
const std::string & getConditionObjectName () const
 Get the list of conditions objects available from this provider.
 
const std::string & getTagName () const
 Access the tag name.
 

Private Attributes

framework::config::Parameters params_
 Handle to the parameters, needed for future use during get condition.
 
std::string detector_geometry_
 Geometry as last used.
 
ldmx::HcalGeometry * hcal_geometry_
 

Additional Inherited Members

- Protected Member Functions inherited from framework::ConditionsObjectProvider
std::pair< const ConditionsObject *, ConditionsIOV > requestParentCondition (const std::string &name, const ldmx::EventHeader &context)
 Request another condition needed to construct this condition.
 
const Process & process () const
 Get the process handle.
 
- Protected Attributes inherited from framework::ConditionsObjectProvider
logging::logger the_log_
 The logger for this ConditionsObjectProvider.
 

Detailed Description

Definition at line 17 of file HcalGeometryProvider.cxx.

Constructor & Destructor Documentation

◆ HcalGeometryProvider()

hcal::HcalGeometryProvider::HcalGeometryProvider ( const std::string & name,
const std::string & tagname,
const framework::config::Parameters & parameters,
framework::Process & process )

Class constructor.

Parameters
parameters– uses the "hcal_geometry" section to configure the HcalGeometry

Definition at line 75 of file HcalGeometryProvider.cxx.

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}
const Process & process() const
Get the process handle.
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
std::string detector_geometry_
Geometry as last used.
framework::config::Parameters params_
Handle to the parameters, needed for future use during get condition.
static constexpr const char * CONDITIONS_OBJECT_NAME
Conditions object: The name of the python configuration calling this class (Hcal/python/HcalGeometry....

References detector_geometry_, and framework::config::Parameters::get().

◆ ~HcalGeometryProvider()

hcal::HcalGeometryProvider::~HcalGeometryProvider ( )
virtual

Destructor.

Definition at line 88 of file HcalGeometryProvider.cxx.

88 {
89 if (hcal_geometry_) delete hcal_geometry_;
90 hcal_geometry_ = 0;
91}

Member Function Documentation

◆ getCondition()

std::pair< const framework::ConditionsObject *, framework::ConditionsIOV > hcal::HcalGeometryProvider::getCondition ( const ldmx::EventHeader & context)
virtual

Provides access to the HcalGeometry.

Note
Currently, these are assumed to be valid for all time, but this behavior could be changed. Users should not cache the pointer between events

Implements framework::ConditionsObjectProvider.

Definition at line 94 of file HcalGeometryProvider.cxx.

94 {
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()) {
105 framework::config::Parameters pver =
106 phex.get<framework::config::Parameters>(key);
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}
Class which defines the run/event/type range for which a given condition is valid,...
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
bool exists(const std::string &name) const
Check to see if a parameter exists.
Definition Parameters.h:60
int getRun() const
Return the run number.
Definition EventHeader.h:84
Implementation of HCal strip readout.

References detector_geometry_, framework::config::Parameters::exists(), framework::config::Parameters::get(), ldmx::EventHeader::getRun(), framework::config::Parameters::keys(), and params_.

◆ onNewRun()

virtual void hcal::HcalGeometryProvider::onNewRun ( ldmx::RunHeader & )
inlinevirtual

Callback for the ConditionsObjectProvider to take any necessary action when the processing of events starts for a given run.

Reimplemented from framework::ConditionsObjectProvider.

Definition at line 47 of file HcalGeometryProvider.cxx.

47 {
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 }

References detector_geometry_, and ldmx::RunHeader::getDetectorName().

◆ releaseConditionsObject()

virtual void hcal::HcalGeometryProvider::releaseConditionsObject ( const framework::ConditionsObject * co)
inlinevirtual

Take no action on release, as the object is permanently owned by the Provider.

Reimplemented from framework::ConditionsObjectProvider.

Definition at line 45 of file HcalGeometryProvider.cxx.

45{}

Member Data Documentation

◆ detector_geometry_

std::string hcal::HcalGeometryProvider::detector_geometry_
private

Geometry as last used.

Definition at line 71 of file HcalGeometryProvider.cxx.

Referenced by getCondition(), HcalGeometryProvider(), and onNewRun().

◆ hcal_geometry_

ldmx::HcalGeometry* hcal::HcalGeometryProvider::hcal_geometry_
private

Definition at line 72 of file HcalGeometryProvider.cxx.

◆ params_

framework::config::Parameters hcal::HcalGeometryProvider::params_
private

Handle to the parameters, needed for future use during get condition.

Definition at line 69 of file HcalGeometryProvider.cxx.

Referenced by getCondition().


The documentation for this class was generated from the following file: