LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
OpDetWaveform.h
Go to the documentation of this file.
1 
9 #ifndef OpDetWaveform_h
10 #define OpDetWaveform_h
11 
12 #include <cstdint> // for uint16_t
13 #include <functional> // so we can redefine less<> below
14 #include <limits>
15 #include <vector>
16 
17 namespace raw {
18 
19  // Define the types used
20  typedef short ADC_Count_t;
21  typedef unsigned int Channel_t;
22  typedef double TimeStamp_t;
23 
24  class OpDetWaveform : public std::vector<ADC_Count_t> {
25  private:
26  Channel_t fChannel;
27  TimeStamp_t fTimeStamp;
28 
29  public:
30  // Simple constructors/destructors.
31  // Just in case the user forgets to supply the default channel, use
32  // a garbage value to indicate that there's a problem.
33  // To save on memory reallocations, offer an option to specify the
34  // the initial memory allocation of the channel vector.
35  OpDetWaveform(TimeStamp_t time = std::numeric_limits<TimeStamp_t>::max(),
36  Channel_t chan = std::numeric_limits<Channel_t>::max(),
37  size_type len = 0)
38  : fChannel(chan), fTimeStamp(time)
39  {
40  this->reserve(len);
41  };
42 
43  OpDetWaveform(TimeStamp_t time, Channel_t chan, std::vector<uint16_t> const& rhs)
44  : std::vector<ADC_Count_t>(rhs.begin(), rhs.end()), fChannel(chan), fTimeStamp(time){};
45 
46  // Functions included for backwards compatability with previous data types
47  std::vector<ADC_Count_t>& Waveform() { return *this; }
48 
49  // Functions included for backwards compatability with previous data types
50  std::vector<ADC_Count_t> const& Waveform() const { return *this; }
51 
52  Channel_t ChannelNumber() const { return fChannel; }
53  TimeStamp_t TimeStamp() const { return fTimeStamp; }
54  void SetChannelNumber(Channel_t chan) { fChannel = chan; }
55  void SetTimeStamp(TimeStamp_t time) { fTimeStamp = time; }
56  };
57 }
58 
59 namespace raw {
60  inline bool operator<(const OpDetWaveform& lhs, const OpDetWaveform& rhs)
61  {
62  // Sort by channel, then time
63  if (lhs.ChannelNumber() < rhs.ChannelNumber()) return true;
64  if (lhs.ChannelNumber() > rhs.ChannelNumber()) return false;
65 
66  return (lhs.TimeStamp() < rhs.TimeStamp());
67  }
68 } // namespace raw
69 
70 // For no extra charge, include how to sort ChannelData*, just in
71 // case we want (for example) a std::set<ChannelData*>.
72 namespace std {
73  template <>
74  class less<raw::OpDetWaveform*> {
75  public:
76  bool operator()(const raw::OpDetWaveform* lhs, const raw::OpDetWaveform* rhs)
77  {
78  return (*lhs) < (*rhs);
79  }
80  };
81 }
82 
83 #endif
Channel_t ChannelNumber() const
Definition: OpDetWaveform.h:52
TimeStamp_t TimeStamp() const
Definition: OpDetWaveform.h:53
bool operator<(const OpDetWaveform &lhs, const OpDetWaveform &rhs)
Definition: OpDetWaveform.h:60
STL namespace.
double TimeStamp_t
us since 1970, based on TimeService
Definition: OpDetWaveform.h:22
Raw data description.
Definition: RawTypes.h:6
std::vector< ADC_Count_t > & Waveform()
Definition: OpDetWaveform.h:47
void SetTimeStamp(TimeStamp_t time)
Definition: OpDetWaveform.h:55
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
OpDetWaveform(TimeStamp_t time, Channel_t chan, std::vector< uint16_t > const &rhs)
Definition: OpDetWaveform.h:43
std::vector< ADC_Count_t > const & Waveform() const
Definition: OpDetWaveform.h:50
void SetChannelNumber(Channel_t chan)
Definition: OpDetWaveform.h:54
OpDetWaveform(TimeStamp_t time=std::numeric_limits< TimeStamp_t >::max(), Channel_t chan=std::numeric_limits< Channel_t >::max(), size_type len=0)
Definition: OpDetWaveform.h:35
TimeStamp_t fTimeStamp
On electronics time scale.
Definition: OpDetWaveform.h:27
bool operator()(const raw::OpDetWaveform *lhs, const raw::OpDetWaveform *rhs)
Definition: OpDetWaveform.h:76
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
short ADC_Count_t
Definition: OpDetWaveform.h:20
unsigned int Channel_t
Definition: OpDetWaveform.h:21