LDMX Software
Public Member Functions | Private Attributes | List of all members
ldmx::ElectronicsMap< ElectronicsID, DetID > Class Template Reference

ElectronicsMap. More...

#include <ElectronicsMap.h>

Public Member Functions

 ElectronicsMap (bool want_d2e=false)
 
void clear ()
 Remove all entries from the map.
 
void addEntry (ElectronicsID eid, DetID did)
 Add an entry to the map.
 
bool exists (ElectronicsID eid) const
 Tests if a given electronics id is in the map.
 
bool exists (DetID did) const
 Tests if a given detector id is in the map This method is slow O(N) if the map is not configured for detector id to electronics id.
 
DetID get (ElectronicsID eid) const
 Get the detector ID for this electronics ID.
 
ElectronicsID get (DetID did) const
 Get the electronics ID for this detector ID This method is slow O(N) if the map is not configured for detector id to electronics id.
 

Private Attributes

std::vector< DetectorID::RawValue > eid2did_
 Linear-time map for electronics (packed index) to raw detector id.
 
bool makeD2E_
 Flag to determine if did2eid should be filled (resource optimization)
 
std::map< DetectorID::RawValue, ElectronicsID > did2eid_
 Log(N) map for raw detector id to electronics id.
 

Detailed Description

template<class ElectronicsID, class DetID>
class ldmx::ElectronicsMap< ElectronicsID, DetID >

ElectronicsMap.

A class for efficient mapping between electronics IDs (using packed index techniques) and detector IDs which are arbitrarily formatted.

Template Parameters

in] ElectronicsID class of electronics ID

Template Parameters

in] DetID class of detector IDs

Definition at line 28 of file ElectronicsMap.h.

Constructor & Destructor Documentation

◆ ElectronicsMap()

template<class ElectronicsID , class DetID >
ldmx::ElectronicsMap< ElectronicsID, DetID >::ElectronicsMap ( bool  want_d2e = false)
inline

Definition at line 30 of file ElectronicsMap.h.

31 : eid2did_{ElectronicsID::MAX_INDEX, 0}, makeD2E_(want_d2e) {}
std::vector< DetectorID::RawValue > eid2did_
Linear-time map for electronics (packed index) to raw detector id.
bool makeD2E_
Flag to determine if did2eid should be filled (resource optimization)

Member Function Documentation

◆ addEntry()

template<class ElectronicsID , class DetID >
void ldmx::ElectronicsMap< ElectronicsID, DetID >::addEntry ( ElectronicsID  eid,
DetID  did 
)
inline

Add an entry to the map.

Definition at line 44 of file ElectronicsMap.h.

44 {
45 unsigned int index = eid.index();
46 if (index >= eid2did_.size()) {
47 EXCEPTION_RAISE("ElectronicsMapOverflow",
48 "Attempted to insert electronics with index " +
49 std::to_string(index) +
50 " which is larger than allowed in this map");
51 }
52 eid2did_[index] = did.raw();
53 if (makeD2E_) did2eid_.insert(std::make_pair(did.raw(), eid));
54 }
std::map< DetectorID::RawValue, ElectronicsID > did2eid_
Log(N) map for raw detector id to electronics id.

References ldmx::ElectronicsMap< ElectronicsID, DetID >::did2eid_, ldmx::ElectronicsMap< ElectronicsID, DetID >::eid2did_, and ldmx::ElectronicsMap< ElectronicsID, DetID >::makeD2E_.

◆ clear()

template<class ElectronicsID , class DetID >
void ldmx::ElectronicsMap< ElectronicsID, DetID >::clear ( )
inline

Remove all entries from the map.

Definition at line 36 of file ElectronicsMap.h.

36 {
37 eid2did_ = std::vector<DetectorID::RawValue>(ElectronicsID::MAX_INDEX, 0);
38 did2eid_.clear();
39 }

References ldmx::ElectronicsMap< ElectronicsID, DetID >::did2eid_, and ldmx::ElectronicsMap< ElectronicsID, DetID >::eid2did_.

◆ exists() [1/2]

template<class ElectronicsID , class DetID >
bool ldmx::ElectronicsMap< ElectronicsID, DetID >::exists ( DetID  did) const
inline

Tests if a given detector id is in the map This method is slow O(N) if the map is not configured for detector id to electronics id.

Definition at line 68 of file ElectronicsMap.h.

68 {
69 if (makeD2E_) {
70 return did2eid_.find(did.raw()) == did2eid_.end();
71 } else {
72 for (auto i : eid2did_) {
73 if (i == did.raw()) return true;
74 }
75 return false;
76 }
77 }

References ldmx::ElectronicsMap< ElectronicsID, DetID >::did2eid_, ldmx::ElectronicsMap< ElectronicsID, DetID >::eid2did_, and ldmx::ElectronicsMap< ElectronicsID, DetID >::makeD2E_.

◆ exists() [2/2]

template<class ElectronicsID , class DetID >
bool ldmx::ElectronicsMap< ElectronicsID, DetID >::exists ( ElectronicsID  eid) const
inline

Tests if a given electronics id is in the map.

Definition at line 59 of file ElectronicsMap.h.

59 {
60 return (eid.index() < eid2did_.size() && eid2did_[eid.index()] != 0);
61 }

References ldmx::ElectronicsMap< ElectronicsID, DetID >::eid2did_.

◆ get() [1/2]

template<class ElectronicsID , class DetID >
ElectronicsID ldmx::ElectronicsMap< ElectronicsID, DetID >::get ( DetID  did) const
inline

Get the electronics ID for this detector ID This method is slow O(N) if the map is not configured for detector id to electronics id.

Throws an exception on failure as there is no globally-defined invalid electronics

Definition at line 95 of file ElectronicsMap.h.

95 {
96 if (makeD2E_) {
97 auto itr = did2eid_.find(did.raw());
98 if (itr == did2eid_.end()) {
99 std::stringstream ss;
100 ss << "Unable to find mapping for det id " << did;
101 EXCEPTION_RAISE("ElectronicsMapNotFound", ss.str());
102 }
103 return itr->second;
104 } else {
105 for (unsigned int i = 0; i < eid2did_.size(); i++) {
106 if (eid2did_[i] == did.raw()) return ElectronicsID::idFromIndex(i);
107 }
108 std::stringstream ss;
109 ss << "Unable to find mapping for det id " << did;
110 EXCEPTION_RAISE("ElectronicsMapNotFound", ss.str());
111 }
112 }

References ldmx::ElectronicsMap< ElectronicsID, DetID >::did2eid_, ldmx::ElectronicsMap< ElectronicsID, DetID >::eid2did_, and ldmx::ElectronicsMap< ElectronicsID, DetID >::makeD2E_.

◆ get() [2/2]

template<class ElectronicsID , class DetID >
DetID ldmx::ElectronicsMap< ElectronicsID, DetID >::get ( ElectronicsID  eid) const
inline

Get the detector ID for this electronics ID.

Definition at line 82 of file ElectronicsMap.h.

82 {
83 if (eid.index() >= eid2did_.size())
84 return DetID();
85 else
86 return DetID(eid2did_[eid.index()]);
87 }

References ldmx::ElectronicsMap< ElectronicsID, DetID >::eid2did_.

Member Data Documentation

◆ did2eid_

template<class ElectronicsID , class DetID >
std::map<DetectorID::RawValue, ElectronicsID> ldmx::ElectronicsMap< ElectronicsID, DetID >::did2eid_
private

◆ eid2did_

template<class ElectronicsID , class DetID >
std::vector<DetectorID::RawValue> ldmx::ElectronicsMap< ElectronicsID, DetID >::eid2did_
private

◆ makeD2E_

template<class ElectronicsID , class DetID >
bool ldmx::ElectronicsMap< ElectronicsID, DetID >::makeD2E_
private

Flag to determine if did2eid should be filled (resource optimization)

Definition at line 122 of file ElectronicsMap.h.

Referenced by ldmx::ElectronicsMap< ElectronicsID, DetID >::addEntry(), ldmx::ElectronicsMap< ElectronicsID, DetID >::exists(), and ldmx::ElectronicsMap< ElectronicsID, DetID >::get().


The documentation for this class was generated from the following file: