All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChannelToWireMap.h
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Geometry/details/ChannelToWireMap.h
3  * @brief Channel-to-wire mapping data structure.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date October 16, 2019
6  * @see `icarusalg/Geometry/details/ChannelToWireMap.cxx`
7  */
8 
9 #ifndef ICARUSALG_GEOMETRY_DETAILS_CHANNELTOWIREMAP_H
10 #define ICARUSALG_GEOMETRY_DETAILS_CHANNELTOWIREMAP_H
11 
12 // LArSoft libraries
14 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
15 
16 // C/C++ standard libraries
17 #include <vector>
18 #include <cassert>
19 #include <utility> // std::pair<>
20 
21 
22 // -----------------------------------------------------------------------------
23 // --- icarus::details::ChannelToWireMap
24 // -----------------------------------------------------------------------------
25 namespace icarus::details { class ChannelToWireMap; }
26 /**
27  * @brief Mapping of ROP channels into wires.
28  *
29  * For each readout plane, we store its first channel (the last one can be
30  * found from the next ROP), and for all wire planes after the first one,
31  * the first channel that is shared (with the previous plane, that is) and
32  * the first channel on that plane that is not shared.
33  */
35 
36  public:
38 
39  /// First channel in ROP.
41  unsigned int nChannels = 0U;
42  readout::ROPID ropid; ///< ID of the ROP we cover.
43 
44  /// Compares with a channel ID (std::less<>).
45  struct Compare {
46  template <typename A, typename B>
47  constexpr bool operator() (A const& a, B const& b) const
48  { return cmp(a, b); }
49 
50  static constexpr raw::ChannelID_t channelOf(raw::ChannelID_t channel)
51  { return channel; }
52  static constexpr raw::ChannelID_t channelOf
53  (ChannelsInROPStruct const& data)
54  { return data.firstChannel; }
55 
56  template <typename A, typename B>
57  static constexpr bool cmp(A const& a, B const& b)
58  { return channelOf(a) < channelOf(b); }
59 
60  }; // struct Compare
61 
62  ChannelsInROPStruct() = default;
65  readout::ROPID const& ropid
66  )
67  : firstChannel(firstChannel)
68  , nChannels(nChannels)
69  , ropid(ropid)
70  {}
71 
72  /// Returns if `channel` is not in a lower ROP than this one.
73  constexpr bool isChannelAbove(raw::ChannelID_t channel) const
74  { return (channel >= firstChannel); }
75 
76  /// Strict ordering according to the first channel in ROP.
77  constexpr bool operator< (ChannelsInROPStruct const& other) const
78  { return Compare{}(*this, other); }
79 
80  }; // struct ChannelsInROPStruct
81 
82  /// Returns data of the ROP including `channel`, `nullptr` if none.
83  ChannelsInROPStruct const* find(raw::ChannelID_t channel) const;
84 
85  /// Returns data of the ROP `ropid`, `nullptr` if none.
86  ChannelsInROPStruct const* find(readout::ROPID const& ropid) const;
87 
88  /// Returns the ID of the first invalid channel (the last channel, plus 1).
90 
91  /// Returns the number of mapped channels.
92  unsigned int nChannels() const
93  { return endChannel() - raw::ChannelID_t{0}; }
94 
95  /// Adds the next ROP with its first channel ID
96  /// (must be larger than previous).
97  void addROP(
98  readout::ROPID const& rid,
99  raw::ChannelID_t firstROPchannel, unsigned int nChannels
100  )
101  {
102  assert(
103  fROPfirstChannel.empty()
104  || (firstROPchannel > fROPfirstChannel.back().firstChannel)
105  );
106  fROPfirstChannel.emplace_back(firstROPchannel, nChannels, rid);
107  }
108 
109  /// Sets the ID of the channels after the last valid one.
110  void setEndChannel(raw::ChannelID_t channel) { fEndChannel = channel; }
111 
112  /// Resets the data of the map to like just constructed.
113  void clear();
114 
115  private:
116 
117  /// Collection of channel ROP channel information, sorted by first channel.
118  std::vector<ChannelsInROPStruct> fROPfirstChannel;
119 
120  raw::ChannelID_t fEndChannel = 0; ///< ID of the first invalid channel.
121 
122 }; // class icarus::details::ChannelToWireMap
123 
124 
125 #endif // ICARUSALG_GEOMETRY_DETAILS_CHANNELTOWIREMAP_H
void setEndChannel(raw::ChannelID_t channel)
Sets the ID of the channels after the last valid one.
readout::ROPID ropid
ID of the ROP we cover.
Classes identifying readout-related concepts.
constexpr bool operator()(A const &a, B const &b) const
process_name gaushit a
ChannelsInROPStruct const * find(raw::ChannelID_t channel) const
Returns data of the ROP including channel, nullptr if none.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
Mapping of ROP channels into wires.
constexpr bool isChannelAbove(raw::ChannelID_t channel) const
Returns if channel is not in a lower ROP than this one.
constexpr bool operator<(ChannelsInROPStruct const &other) const
Strict ordering according to the first channel in ROP.
void clear()
Resets the data of the map to like just constructed.
static constexpr bool cmp(A const &a, B const &b)
raw::ChannelID_t fEndChannel
ID of the first invalid channel.
Class identifying a set of planes sharing readout channels.
static constexpr raw::ChannelID_t channelOf(raw::ChannelID_t channel)
raw::ChannelID_t firstChannel
First channel in ROP.
unsigned int nChannels() const
Returns the number of mapped channels.
raw::ChannelID_t endChannel() const
Returns the ID of the first invalid channel (the last channel, plus 1).
Compares with a channel ID (std::less&lt;&gt;).
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
float A
Definition: dedx.py:137
ChannelsInROPStruct(raw::ChannelID_t firstChannel, unsigned int nChannels, readout::ROPID const &ropid)
std::vector< ChannelsInROPStruct > fROPfirstChannel
Collection of channel ROP channel information, sorted by first channel.
void addROP(readout::ROPID const &rid, raw::ChannelID_t firstROPchannel, unsigned int nChannels)