diff --git a/include/Ecal/EcalDetectorMap.h b/include/Ecal/EcalDetectorMap.h index 833ef7d..7cea227 100644 --- a/include/Ecal/EcalDetectorMap.h +++ b/include/Ecal/EcalDetectorMap.h @@ -1,64 +1,68 @@ /** * @file EcalDetectorMap.h - * @brief Class which contains logic for how the detector items connect to and relate with the reconstruction cells + * @brief Class which contains logic for how the detector items connect to and + * relate with the reconstruction cells * @author Jeremiah Mans, University of Minnesota */ #ifndef ECAL_ECALDETECTORMAP_H_ #define ECAL_ECALDETECTORMAP_H_ -#include "DetDescr/EcalID.h" -#include "DetDescr/EcalElectronicsID.h" -#include "Tools/ElectronicsMap.h" +#include -#include "Framework/ConditionsObject.h" #include "Conditions/GeneralCSVLoader.h" -#include +#include "DetDescr/EcalElectronicsID.h" +#include "DetDescr/EcalID.h" +#include "Framework/ConditionsObject.h" +#include "Tools/ElectronicsMap.h" namespace ecal { -/** - * \brief Class which provides various information about how the parts of the Ecal connect to each other. +/** + * \brief Class which provides various information about how the parts of the + * Ecal connect to each other. * - * The class is loaded from three tables, currently in the form of CSV objects, + * The class is loaded from three tables, currently in the form of CSV objects, * using the EcalDetectorMapLoader declared and defined in the source. - * - * CellMap gives the information for a single Ecal module and has the following columns - * CELLID -- EcalDetectorID cell id - * ROCID -- which ROC on the module + * + * CellMap gives the information for a single Ecal module and has the following + * columns CELLID -- EcalDetectorID cell id ROCID -- which ROC on the module * ROC_ELINK_NUMBER -- which elink on the ROC (0/1) * ROC_ELINK_CHANNEL -- which channel on the elink (0-35) * - * MotherboardMap gives information about how the modules plug into a given type of motherboard - * ROCID -- which ROC on the module - * ROC_ELINK_NUMBER -- which elink on the ROC (0/1) - * MODULE -- which module on the layer - * POLARFIRE_ELINK -- elink input number on the Polarfire - * MOTHERBOARD_TYPE -- what type of motherboard is this + * MotherboardMap gives information about how the modules plug into a given type + * of motherboard ROCID -- which ROC on the module ROC_ELINK_NUMBER -- which + * elink on the ROC (0/1) MODULE -- which module on the layer POLARFIRE_ELINK -- + * elink input number on the Polarfire MOTHERBOARD_TYPE -- what type of + * motherboard is this * - * LayerMap gives information about how the motherboards are used on the various layers - * LAYER -- layer number - * MOTHERBOARD_TYPE - * OLINK -- DAQ optical link number + * LayerMap gives information about how the motherboards are used on the various + * layers LAYER -- layer number MOTHERBOARD_TYPE OLINK -- DAQ optical link + * number + * + * We inherit from two classes: (1) the ConditionsObject because we are a + * conditions object and (2) from the ElectronicsMap template because we + * are a electronics map. */ -class EcalDetectorMap : public framework::ConditionsObject { +class EcalDetectorMap + : public framework::ConditionsObject, + public ldmx::ElectronicsMap { public: /// The name of the EID <-> DetID map for the ECal static constexpr const char* CONDITIONS_OBJECT_NAME{"EcalDetectorMap"}; /** * Default constructor which builds the necessary maps. + * + * @param[in] want_d2e true if we want to build a reverse mapping + * Building a reverse (detector->electronics) map takes extra time + * and memory so it should be off by default. */ - EcalDetectorMap(); + EcalDetectorMap(bool want_d2e); /// Provider which loads the map friend class EcalDetectorMapLoader; - /** - * access the electronics map - */ - const auto& emap() const { return emap_; } - private: /// import cell map from the provided CSV loader void loadCellMap(conditions::GeneralCSVLoader& loader); @@ -71,8 +75,8 @@ class EcalDetectorMap : public framework::ConditionsObject { void buildElectronicsMap(); /// the full electronics map - ldmx::ElectronicsMap emap_; - + ldmx::ElectronicsMap emap_; + /** * Table of per-module cell information */ @@ -120,7 +124,7 @@ class EcalDetectorMap : public framework::ConditionsObject { std::vector layers_; }; -} +} // namespace ecal -#endif // ECAL_ECALDETECTORMAP_H_ +#endif // ECAL_ECALDETECTORMAP_H_ diff --git a/src/Ecal/EcalDetectorMap.cxx b/src/Ecal/EcalDetectorMap.cxx index 129f8f8..aab2e56 100644 --- a/src/Ecal/EcalDetectorMap.cxx +++ b/src/Ecal/EcalDetectorMap.cxx @@ -1,29 +1,31 @@ #include "Ecal/EcalDetectorMap.h" -#include "Framework/EventHeader.h" -#include "Framework/ConditionsObjectProvider.h" + #include +#include "Framework/ConditionsObjectProvider.h" +#include "Framework/EventHeader.h" + namespace ecal { class EcalDetectorMapLoader : public framework::ConditionsObjectProvider { public: - EcalDetectorMapLoader(const std::string& name, - const std::string& tagname, + EcalDetectorMapLoader(const std::string& name, const std::string& tagname, const framework::config::Parameters& parameters, framework::Process& process) : ConditionsObjectProvider(EcalDetectorMap::CONDITIONS_OBJECT_NAME, - tagname, parameters, process), theMap_{0} { - cellMap_=parameters.getParameter("cell_map"); - motherboardMap_=parameters.getParameter("motherboard_map"); - layerMap_=parameters.getParameter("layer_map"); + tagname, parameters, process), + theMap_{0} { + want_d2e_ = parameters.getParameter("want_d2e"); + cellMap_ = parameters.getParameter("cell_map"); + motherboardMap_ = parameters.getParameter("motherboard_map"); + layerMap_ = parameters.getParameter("layer_map"); } virtual std::pair getCondition(const ldmx::EventHeader& context) { - if (!theMap_) { - theMap_=new EcalDetectorMap(); + theMap_ = new EcalDetectorMap(want_d2e_); conditions::StreamCSVLoader scell(cellMap_); theMap_->loadCellMap(scell); conditions::StreamCSVLoader smb(motherboardMap_); @@ -33,12 +35,12 @@ class EcalDetectorMapLoader : public framework::ConditionsObjectProvider { theMap_->buildElectronicsMap(); } - - return std::make_pair(theMap_, - framework::ConditionsIOV( - context.getRun(), context.getRun(), true, true)); + + return std::make_pair( + theMap_, framework::ConditionsIOV(context.getRun(), context.getRun(), + true, true)); } - + /** * Take no action on release, as the object is permanently owned by the * Provider @@ -50,33 +52,34 @@ class EcalDetectorMapLoader : public framework::ConditionsObjectProvider { std::string cellMap_; std::string motherboardMap_; std::string layerMap_; + bool want_d2e_; }; -EcalDetectorMap::EcalDetectorMap() : framework::ConditionsObject(CONDITIONS_OBJECT_NAME) { -} +EcalDetectorMap::EcalDetectorMap(bool want_d2e) + : framework::ConditionsObject(CONDITIONS_OBJECT_NAME), + ldmx::ElectronicsMap(want_d2e) {} void EcalDetectorMap::loadCellMap(conditions::GeneralCSVLoader& loader) { cells_.clear(); while (loader.nextRow()) { CellInformation ci; - ci.module_cellid=loader.getInteger("CELLID"); - ci.rocid=loader.getInteger("ROCID"); - ci.roc_elink_number=loader.getInteger("ROC_ELINK_NUMBER"); - ci.roc_elink_channel=loader.getInteger("ROC_ELINK_CHANNEL"); + ci.module_cellid = loader.getInteger("CELLID"); + ci.rocid = loader.getInteger("ROCID"); + ci.roc_elink_number = loader.getInteger("ROC_ELINK_NUMBER"); + ci.roc_elink_channel = loader.getInteger("ROC_ELINK_CHANNEL"); cells_.push_back(ci); } } - void EcalDetectorMap::loadMotherboardMap(conditions::GeneralCSVLoader& loader) { elinks_.clear(); while (loader.nextRow()) { MotherboardLinksInformation mli; - mli.motherboard_type=loader.getInteger("MOTHERBOARD_TYPE"); - mli.module=loader.getInteger("MODULE"); - mli.rocid=loader.getInteger("ROCID"); - mli.roc_elink_number=loader.getInteger("ROC_ELINK_NUMBER"); - mli.polarfire_elink=loader.getInteger("POLARFIRE_ELINK"); + mli.motherboard_type = loader.getInteger("MOTHERBOARD_TYPE"); + mli.module = loader.getInteger("MODULE"); + mli.rocid = loader.getInteger("ROCID"); + mli.roc_elink_number = loader.getInteger("ROC_ELINK_NUMBER"); + mli.polarfire_elink = loader.getInteger("POLARFIRE_ELINK"); elinks_.push_back(mli); } } @@ -85,44 +88,43 @@ void EcalDetectorMap::loadLayerMap(conditions::GeneralCSVLoader& loader) { layers_.clear(); while (loader.nextRow()) { MotherboardsPerLayer mpl; - mpl.motherboard_type=loader.getInteger("MOTHERBOARD_TYPE"); - mpl.layer=loader.getInteger("LAYER"); - mpl.daq_opticallink=loader.getInteger("OLINK"); + mpl.motherboard_type = loader.getInteger("MOTHERBOARD_TYPE"); + mpl.layer = loader.getInteger("LAYER"); + mpl.daq_opticallink = loader.getInteger("OLINK"); layers_.push_back(mpl); } } - - void EcalDetectorMap::buildElectronicsMap() { - using namespace ldmx; - emap_.clear(); // empty the electronics map + this->clear(); // empty the electronics map // loop over optical links for (auto olink : layers_) { for (auto elink : elinks_) { // select only matching motherboard types - if (elink.motherboard_type!=olink.motherboard_type) continue; + if (elink.motherboard_type != olink.motherboard_type) continue; for (auto cell : cells_) { // select only cells which are associated with the appropriate elink - if (elink.rocid != cell.rocid || elink.roc_elink_number != cell.roc_elink_number) continue; + if (elink.rocid != cell.rocid || + elink.roc_elink_number != cell.roc_elink_number) + continue; // now, we have only cells which are relevant - EcalID precisionId(olink.layer, elink.module, cell.module_cellid); - EcalElectronicsID elecId(olink.daq_opticallink, elink.polarfire_elink, cell.roc_elink_channel); + ldmx::EcalID precisionId(olink.layer, elink.module, cell.module_cellid); + ldmx::EcalElectronicsID elecId(olink.daq_opticallink, + elink.polarfire_elink, + cell.roc_elink_channel); if (emap_.exists(elecId)) { std::stringstream ss; ss << "Two different mappings for electronics channel " << elecId; - EXCEPTION_RAISE( - "DuplicateMapping", - ss.str()); + EXCEPTION_RAISE("DuplicateMapping", ss.str()); } - emap_.addEntry(elecId,precisionId); + this->addEntry(elecId, precisionId); } } } } -} +} // namespace ecal DECLARE_CONDITIONS_PROVIDER_NS(ecal, EcalDetectorMapLoader); diff --git a/src/Ecal/EcalRawDecoder.cxx b/src/Ecal/EcalRawDecoder.cxx index 31cd3a6..579d877 100644 --- a/src/Ecal/EcalRawDecoder.cxx +++ b/src/Ecal/EcalRawDecoder.cxx @@ -47,7 +47,7 @@ void EcalRawDecoder::produce(framework::Event& event) { * unpacking of individual samples; however, we still need * to translate electronic IDs into detector IDs. */ - auto detmap{getCondition(EcalDetectorMap::CONDITIONS_OBJECT_NAME).emap()}; + auto detmap{getCondition(EcalDetectorMap::CONDITIONS_OBJECT_NAME)}; ldmx::HgcrocDigiCollection digis; for (auto const& [eid_raw, digi] : eid_to_samples) { // TODO: This checking of existence should be temporary,