LDMX Software
HcalDetectorMap.cxx
2
3#include <algorithm>
4#include <sstream>
5
6#include "Conditions/GeneralCSVLoader.h"
9
10namespace hcal {
11
13 public:
14 HcalDetectorMapLoader(const std::string& name, const std::string& tagname,
15 const framework::config::Parameters& parameters,
18 tagname, parameters, process),
19 the_map_{nullptr} {
20 want_d2e_ = parameters.get<bool>("want_d2e");
21 connections_table_ = parameters.get<std::string>("connections_table");
22 }
23
24 virtual std::pair<const framework::ConditionsObject*,
27 if (!the_map_) {
28 the_map_ = new HcalDetectorMap(connections_table_, want_d2e_);
29 }
30
31 return std::make_pair(
32 the_map_, framework::ConditionsIOV(context.getRun(), context.getRun(),
33 true, true));
34 }
35
41
42 private:
43 HcalDetectorMap* the_map_;
44 std::string connections_table_;
45 bool want_d2e_;
46};
47
48HcalDetectorMap::HcalDetectorMap(const std::string& connections_table,
49 bool want_d2e)
50 : framework::ConditionsObject(CONDITIONS_OBJECT_NAME),
51 ldmx::ElectronicsMap<ldmx::HcalElectronicsID, ldmx::HcalDigiID>(
52 want_d2e) {
53 this->clear();
54 conditions::StreamCSVLoader csv(connections_table);
55 while (csv.nextRow()) {
56 // explicit table (e.g. ESA26): elink and detector ID fields given directly
57 const auto& cols{csv.columnNames()};
58 if (std::find(cols.begin(), cols.end(), "Section") != cols.end()) {
59 ldmx::HcalElectronicsID eid(csv.getInteger("Polarfire"),
60 csv.getInteger("Elink"),
61 csv.getInteger("Channel"));
62 ldmx::HcalDigiID did(csv.getInteger("Section"), csv.getInteger("Layer"),
63 csv.getInteger("Strip"), csv.getInteger("End"));
64 if (this->exists(eid)) {
65 std::stringstream ss;
66 ss << "Two different mappings for electronics channel " << eid;
67 EXCEPTION_RAISE("DuplicateMapping", ss.str());
68 }
69 this->addEntry(eid, did);
70 continue;
71 }
82 int polarfire = csv.getInteger("Polarfire");
83 int hgcroc = csv.getInteger("HGCROC");
84 int chan = csv.getInteger("Channel");
85
106 int link = 2 * hgcroc; // link count starts from 0
107 if (chan >= 36) {
108 link += 1;
109 chan -= 36;
110 }
111
112 // one quadbar groups 4 strips and each quadbar is connected to 2 CMBs - one
113 // in each end
114 int end = csv.getInteger("CMB") % 2;
115 if (end == 0)
116 end = 1; // negative end (?)
117 else
118 end = 0; // positive end (?)
119
120 // The Bar field in the map represents a numbering *within a quadbar* not
121 // the strip number.
122 //
123 // This gives correct range for the strip numbers [0,7] and [0,11] but the
124 // actual order of the quadbars has to be checked
125
126 auto quad_bar{csv.getInteger("QuadBar")};
127 auto bar_number{csv.getInteger("Bar")};
128 // Strip = (4 - Bar) + 4 * (QuadBar - 1)
129 // QuadBar starts at 1 so we need to subtract to get first value
130 // to be zero
131 auto strip{(bar_number - 1) +
132 4 * (quad_bar - 1)}; // This is flipped from the original
133 if (csv.getInteger("Plane") % 2 == 1)
134 strip = (4 - bar_number) +
135 4 * (quad_bar - 1); // Plane 2 is backward by mistake
136 ldmx::HcalDigiID detid(0 /*section - only one section during test beam*/,
137 csv.getInteger("Plane") /*layer_*/, strip /*strip*/,
138 end /*end*/);
139 ldmx::HcalElectronicsID eleid(polarfire /*polarfire fpga*/, link /*elink*/,
140 chan /*channel*/);
141
142 if (this->exists(eleid)) {
143 std::stringstream ss;
144 ss << "Two different mappings for electronics channel " << eleid;
145 EXCEPTION_RAISE("DuplicateMapping", ss.str());
146 }
147 this->addEntry(eleid, detid);
148 }
149}
150
151} // namespace hcal
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 which contains logic for how the detector items connect to and relate with the reconstruction c...
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.
std::vector< std::string > columnNames() const
Get the column names.
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.
ConditionsObjectProvider(const std::string &objname, const std::string &tagname, const framework::config::Parameters &parameters, Process &process)
Class constructor.
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
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
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)
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.