DuneChannelInfo.h
Go to the documentation of this file.
1 // DuneChannelInfo.h
2 
3 // David Adams
4 // June 2019
5 //
6 // Channel info for dataprep in DUNE.
7 
8 #ifndef DuneChannelInfo_H
9 #define DuneChannelInfo_H
10 
12 #include <sstream>
13 #include <memory>
14 
16 
17 public:
18 
20  using Index = AdcIndex;
21 
26 
27  static Index badChannel() { return -1u; }
28  static Index badIndex() { return -1u; }
29  static const DuneChannelInfo& badChannelInfo() {
30  static DuneChannelInfo bci;
31  return bci;
32  }
33 
34  // Reset to no channel.
35  void clear() {
36  channel = badChannel();
37  fembID = badIndex();
38  fembChannel = badIndex();
39  channelStatus = badIndex();
40  }
41 
42  // Default ctor.
43  DuneChannelInfo() = default;
44 
45  // Ctor from components.
46  DuneChannelInfo(Index a_channel, Index a_fembID, Index a_fembChannel, Index a_channelStatus)
47  : channel(a_channel), fembID(a_fembID), fembChannel(a_fembChannel),
48  channelStatus(a_channelStatus) { }
49 
50  // Is this valid info?
51  bool isValid() const { return channel != badIndex(); }
52 
53  // Order two channel info objects.
54  bool operator<(const DuneChannelInfo& rhs) {
55  if ( channel < rhs.channel ) return true;
56  return false;
57  }
58 
59  // Compare two channel info objects.
60  bool operator==(const DuneChannelInfo& rhs) const {
61  if ( channel != rhs.channel ) return false;
62  if ( fembID != rhs.fembID ) return false;
63  if ( fembChannel != rhs.fembChannel ) return false;
64  if ( channelStatus != rhs.channelStatus ) return false;
65  return true;
66  }
67 
68  bool operator!=(const DuneChannelInfo& rhs) const {
69  return ! (*this == rhs);
70  }
71 
72  // Return the channel number as a string.
74  std::ostringstream ssout;
75  ssout << channel;
76  return ssout.str();
77  }
78 
79  // Return femb as ID-chan.
80  // opt = 0: Return RRR.
81  // 1: Return RRR-SSS
82  // 2: if SSS==0, return RRR, otherwise RRR-SSS.
83  std::string fembString(Index wid =2, Index wch =3) const {
84  std::string sid = std::to_string(fembID);
85  while ( sid.size() < wid ) sid = "0" + sid;
86  std::string sch = std::to_string(fembChannel);
87  while ( sch.size() < wch ) sch = "0" + sch;
88  return sid + "-" + sch;
89  }
90 
91 };
92 
93 #endif
std::string string
Definition: nybbler.cc:12
bool operator!=(const DuneChannelInfo &rhs) const
bool isValid() const
std::string channelString() const
bool operator==(const DuneChannelInfo &rhs) const
DuneChannelInfo()=default
static Index badChannel()
unsigned int AdcIndex
Definition: AdcTypes.h:15
static Index badIndex()
DuneChannelInfo(Index a_channel, Index a_fembID, Index a_fembChannel, Index a_channelStatus)
unsigned int AdcChannel
Definition: AdcTypes.h:50
bool operator<(const DuneChannelInfo &rhs)
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
AdcChannel Channel
std::string fembString(Index wid=2, Index wch=3) const
static const DuneChannelInfo & badChannelInfo()