LDMX Software
HcalDetectorMap.cxx
2
3#include <sstream>
4
7
8namespace hcal {
9
11 public:
12 HcalDetectorMapLoader(const std::string& name, const std::string& tagname,
13 const framework::config::Parameters& parameters,
16 tagname, parameters, process),
17 the_map_{nullptr} {
18 want_d2e_ = parameters.getParameter<bool>("want_d2e");
19 connections_table_ =
20 parameters.getParameter<std::string>("connections_table");
21 }
22
23 virtual std::pair<const framework::ConditionsObject*,
26 if (!the_map_) {
27 the_map_ = new HcalDetectorMap(connections_table_, want_d2e_);
28 }
29
30 return std::make_pair(
31 the_map_, framework::ConditionsIOV(context.getRun(), context.getRun(),
32 true, true));
33 }
34
40
41 private:
42 HcalDetectorMap* the_map_;
43 std::string connections_table_;
44 bool want_d2e_;
45};
46
47HcalDetectorMap::HcalDetectorMap(const std::string& connections_table,
48 bool want_d2e)
49 : framework::ConditionsObject(CONDITIONS_OBJECT_NAME),
50 ldmx::ElectronicsMap<ldmx::HcalElectronicsID, ldmx::HcalDigiID>(
51 want_d2e) {
52 this->clear();
53 conditions::StreamCSVLoader csv(connections_table);
54 while (csv.nextRow()) {
65 int polarfire = csv.getInteger("Polarfire");
66 int hgcroc = csv.getInteger("HGCROC");
67 int chan = csv.getInteger("Channel");
68
89 int link = 2 * hgcroc; // link count starts from 0
90 if (chan >= 36) {
91 link += 1;
92 chan -= 36;
93 }
94
95 // one quadbar groups 4 strips and each quadbar is connected to 2 CMBs - one
96 // in each end
97 int end = csv.getInteger("CMB") % 2;
98 if (end == 0)
99 end = 1; // negative end (?)
100 else
101 end = 0; // positive end (?)
102
103 // The Bar field in the map represents a numbering *within a quadbar* not
104 // the strip number.
105 //
106 // This gives correct range for the strip numbers [0,7] and [0,11] but the
107 // actual order of the quadbars has to be checked
108
109 auto QuadBar{csv.getInteger("QuadBar")};
110 auto BarNumber{csv.getInteger("Bar")};
111 // Strip = (4 - Bar) + 4 * (QuadBar - 1)
112 // QuadBar starts at 1 so we need to subtract to get first value
113 // to be zero
114 auto strip{(BarNumber - 1) +
115 4 * (QuadBar - 1)}; // This is flipped from the original
116 if (csv.getInteger("Plane") % 2 == 1)
117 strip = (4 - BarNumber) +
118 4 * (QuadBar - 1); // Plane 2 is backward by mistake
119 ldmx::HcalDigiID detid(0 /*section - only one section during test beam*/,
120 csv.getInteger("Plane") /*layer*/, strip /*strip*/,
121 end /*end*/);
122 ldmx::HcalElectronicsID eleid(polarfire /*polarfire fpga*/, link /*elink*/,
123 chan /*channel*/);
124
125 if (this->exists(eleid)) {
126 std::stringstream ss;
127 ss << "Two different mappings for electronics channel " << eleid;
128 EXCEPTION_RAISE("DuplicateMapping", ss.str());
129 }
130 this->addEntry(eleid, detid);
131 }
132}
133
134} // namespace hcal
135DECLARE_CONDITIONS_PROVIDER_NS(hcal, HcalDetectorMapLoader);
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 provides header information about an event such as event number and timestamp.
Class which contains logic for how the detector items connect to and relate with the reconstruction c...
be configured to load conditions objects from CSV files.
bool nextRow()
Advance to next row if possible.
int getInteger(const std::string &colname, bool ignore_case=true) const
Get the value for the given column in the current row as an integer.
Specialization of the GeneralCSVLoader for loading from a file/stream.
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
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)
Pure virtual getCondition function.
Class which provides various information about how the parts of the Hcal connect to each other.
HcalDetectorMap(const std::string &connections_table, bool want_d2e)
Default constructor which builds the necessary maps.
static constexpr const char * CONDITIONS_OBJECT_NAME
The name of the EID <-> DetID map for the ECal.
void addEntry(ldmx::HcalElectronicsID eid, ldmx::HcalDigiID did)
Add an entry to the map.
bool exists(ldmx::HcalElectronicsID eid) const
Tests if a given electronics id is in the map.
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
Extension of HcalAbstractID providing access to HCal digi information.
Definition HcalDigiID.h:13
Identifies a location in the Hcal readout chain.
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45