LDMX Software
EcalDetectorMap.cxx
2
3#include <sstream>
4
7
8namespace ecal {
9
11 public:
12 EcalDetectorMapLoader(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 cell_map_ = parameters.getParameter<std::string>("cell_map");
20 motherboard_map_ = parameters.getParameter<std::string>("motherboard_map");
21 layer_map_ = parameters.getParameter<std::string>("layer_map");
22 }
23
24 virtual std::pair<const framework::ConditionsObject*,
27 if (!the_map_) {
28 the_map_ = new EcalDetectorMap(cell_map_, motherboard_map_, layer_map_,
29 want_d2e_);
30 }
31
32 return std::make_pair(
33 the_map_, framework::ConditionsIOV(context.getRun(), context.getRun(),
34 true, true));
35 }
36
42
43 private:
44 EcalDetectorMap* the_map_;
45 std::string cell_map_;
46 std::string motherboard_map_;
47 std::string layer_map_;
48 bool want_d2e_;
49};
50
51EcalDetectorMap::EcalDetectorMap(const std::string& cell_map,
52 const std::string& motherboard_map,
53 const std::string& layer_map, bool want_d2e)
54 : framework::ConditionsObject(CONDITIONS_OBJECT_NAME),
55 ldmx::ElectronicsMap<ldmx::EcalElectronicsID, ldmx::EcalID>(want_d2e) {
56 conditions::StreamCSVLoader scell(cell_map);
57 this->loadCellMap(scell);
58 conditions::StreamCSVLoader smb(motherboard_map);
59 this->loadMotherboardMap(smb);
60 conditions::StreamCSVLoader slayer(layer_map);
61 this->loadLayerMap(slayer);
62 this->buildElectronicsMap();
63}
64
66 cells_.clear();
67 while (loader.nextRow()) {
69 ci.module_cellid = loader.getInteger("CELLID");
70 ci.rocid = loader.getInteger("ROCID");
71 ci.roc_elink_number = loader.getInteger("ROC_ELINK_NUMBER");
72 ci.roc_elink_channel = loader.getInteger("ROC_ELINK_CHANNEL");
73 cells_.push_back(ci);
74 }
75}
76
78 elinks_.clear();
79 while (loader.nextRow()) {
81 mli.motherboard_type = loader.getInteger("MOTHERBOARD_TYPE");
82 mli.module = loader.getInteger("MODULE");
83 mli.rocid = loader.getInteger("ROCID");
84 mli.roc_elink_number = loader.getInteger("ROC_ELINK_NUMBER");
85 mli.polarfire_elink = loader.getInteger("POLARFIRE_ELINK");
86 elinks_.push_back(mli);
87 }
88}
89
91 layers_.clear();
92 while (loader.nextRow()) {
94 mpl.motherboard_type = loader.getInteger("MOTHERBOARD_TYPE");
95 mpl.layer = loader.getInteger("LAYER");
96 mpl.daq_opticallink = loader.getInteger("OLINK");
97 layers_.push_back(mpl);
98 }
99}
100
102 this->clear(); // empty the electronics map
103 // loop over optical links
104 for (auto olink : layers_) {
105 for (auto elink : elinks_) {
106 // select only matching motherboard types
107 if (elink.motherboard_type != olink.motherboard_type) continue;
108
109 for (auto cell : cells_) {
110 // select only cells which are associated with the appropriate elink
111 if (elink.rocid != cell.rocid ||
112 elink.roc_elink_number != cell.roc_elink_number)
113 continue;
114
115 // now, we have only cells which are relevant
116 ldmx::EcalID precisionId(olink.layer, elink.module, cell.module_cellid);
117 ldmx::EcalElectronicsID elecId(olink.daq_opticallink,
118 elink.polarfire_elink,
119 cell.roc_elink_channel);
120
121 if (this->exists(elecId)) {
122 std::stringstream ss;
123 ss << "Two different mappings for electronics channel " << elecId;
124 EXCEPTION_RAISE("DuplicateMapping", ss.str());
125 }
126 this->addEntry(elecId, precisionId);
127 }
128 }
129 }
130}
131
132} // namespace ecal
133DECLARE_CONDITIONS_PROVIDER_NS(ecal, EcalDetectorMapLoader);
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 which contains logic for how the detector items connect to and relate with the reconstruction c...
Class that provides header information about an event such as event number and timestamp.
be configured to load conditions objects from CSV files.
Class which parses a CSV file and provides the rows one at a time to a user The parser ignores any li...
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.
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 Ecal connect to each other.
void loadCellMap(conditions::GeneralCSVLoader &loader)
import cell map from the provided CSV loader
void loadMotherboardMap(conditions::GeneralCSVLoader &loader)
import motherboard map from the provided CSV loader
static constexpr const char * CONDITIONS_OBJECT_NAME
The name of the EID <-> DetID map for the ECal.
EcalDetectorMap(const std::string &cell_map, const std::string &motherboard_map, const std::string &layer_map, bool want_d2e)
Default constructor which builds the necessary maps.
void buildElectronicsMap()
build the electronics map from loaded maps
void loadLayerMap(conditions::GeneralCSVLoader &loader)
import layer map from the provided CSV loader
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
Identifies a location in the Ecal readout chain.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
void addEntry(ldmx::EcalElectronicsID eid, ldmx::EcalID did)
Add an entry to the map.
bool exists(ldmx::EcalElectronicsID 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
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45
Table of per-module cell information.
int rocid
hgcroc id on the module (which of the six)
int module_cellid
precision information
Table of per-motherboard connections information.
int roc_elink_number
hgcroc link id on the module (which of the two)
Table of per-layer motherboard layouts.
int daq_opticallink
mother global optical link number