Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
inherit instead of wrap, makes using the det map simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeichlersmith committed Nov 30, 2021
1 parent 921f55b commit b4df5e5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 78 deletions.
72 changes: 38 additions & 34 deletions include/Ecal/EcalDetectorMap.h
Original file line number Diff line number Diff line change
@@ -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 <vector>

#include "Framework/ConditionsObject.h"
#include "Conditions/GeneralCSVLoader.h"
#include <vector>
#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<ldmx::EcalElectronicsID, ldmx::EcalID> {
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);
Expand All @@ -71,8 +75,8 @@ class EcalDetectorMap : public framework::ConditionsObject {
void buildElectronicsMap();

/// the full electronics map
ldmx::ElectronicsMap<ldmx::EcalElectronicsID,ldmx::EcalID> emap_;
ldmx::ElectronicsMap<ldmx::EcalElectronicsID, ldmx::EcalID> emap_;

/**
* Table of per-module cell information
*/
Expand Down Expand Up @@ -120,7 +124,7 @@ class EcalDetectorMap : public framework::ConditionsObject {
std::vector<MotherboardsPerLayer> layers_;
};

}
} // namespace ecal

#endif // ECAL_ECALDETECTORMAP_H_
#endif // ECAL_ECALDETECTORMAP_H_

88 changes: 45 additions & 43 deletions src/Ecal/EcalDetectorMap.cxx
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
#include "Ecal/EcalDetectorMap.h"
#include "Framework/EventHeader.h"
#include "Framework/ConditionsObjectProvider.h"

#include <sstream>

#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<std::string>("cell_map");
motherboardMap_=parameters.getParameter<std::string>("motherboard_map");
layerMap_=parameters.getParameter<std::string>("layer_map");
tagname, parameters, process),
theMap_{0} {
want_d2e_ = parameters.getParameter<bool>("want_d2e");
cellMap_ = parameters.getParameter<std::string>("cell_map");
motherboardMap_ = parameters.getParameter<std::string>("motherboard_map");
layerMap_ = parameters.getParameter<std::string>("layer_map");
}

virtual std::pair<const framework::ConditionsObject*,
framework::ConditionsIOV>
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_);
Expand All @@ -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
Expand All @@ -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<ldmx::EcalElectronicsID, ldmx::EcalID>(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);
}
}
Expand All @@ -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);
2 changes: 1 addition & 1 deletion src/Ecal/EcalRawDecoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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>(EcalDetectorMap::CONDITIONS_OBJECT_NAME).emap()};
auto detmap{getCondition<EcalDetectorMap>(EcalDetectorMap::CONDITIONS_OBJECT_NAME)};
ldmx::HgcrocDigiCollection digis;
for (auto const& [eid_raw, digi] : eid_to_samples) {
// TODO: This checking of existence should be temporary,
Expand Down

0 comments on commit b4df5e5

Please sign in to comment.