Snapshot.h
Go to the documentation of this file.
1 /**
2  * \file Snapshot.h
3  *
4  * \ingroup Snapshot
5  *
6  * \brief Class def header for a class Snapshot
7  *
8  * @author kterao
9  */
10 
11 /** \addtogroup Snapshot
12 
13  @{*/
14 #ifndef IOVDATA_SNAPSHOT_H
15 #define IOVDATA_SNAPSHOT_H
16 
17 #include <algorithm>
18 #include <vector>
19 #include "IOVTimeStamp.h"
20 #include "ChData.h"
21 #include <sstream>
22 #include "IOVDataError.h"
23 #include "IOVDataConstants.h"
24 
25 namespace lariov {
26 
27  /**
28  \class Snapshot
29  */
30  template <class T>
31  class Snapshot {
32 
33  public:
34 
35  /// Default constructor
37  fStart(0,0), fEnd(0,0) {}
38 
39  /// Default destructor
41 
42  void Clear();
43 
44  const IOVTimeStamp& Start() const {return fStart;}
45  const IOVTimeStamp& End() const {return fEnd;}
46  void SetIoV(const IOVTimeStamp& start, const IOVTimeStamp& end);
47 
48  bool IsValid(const IOVTimeStamp& ts) const;
49 
50  size_t NChannels() const {return fData.size();}
51 
52  const std::vector<T>& Data() const {return fData;}
53 
54 
55 
56  /// Only included with class if T has base class ChData
57  template< class U = T,
59  bool HasChannel(unsigned int ch) const {
60 
61  typename std::vector<T>::const_iterator it = std::lower_bound(fData.begin(), fData.end(), ch);
62  if ( it == fData.end() || it->Channel() != ch) {
63  return false;
64  }
65  else return true;
66  }
67 
68  template< class U = T,
69  typename std::enable_if<std::is_base_of<ChData, U>::value, int>::type = 0>
70  const T& GetRow(unsigned int ch) const {
71 
72  typename std::vector<T>::const_iterator it = std::lower_bound(fData.begin(), fData.end(), ch);
73 
74  if ( it == fData.end() || it->Channel() != ch ) {
75  std::string msg("Channel not found: ");
76  msg += std::to_string(ch);
77  throw IOVDataError(msg);
78  }
79 
80  return *it;
81  }
82 
83  template< class U = T,
84  typename std::enable_if<std::is_base_of<ChData, U>::value, int>::type = 0>
85  void AddOrReplaceRow(const T& data) {
86  typename std::vector<T>::iterator it = std::lower_bound(fData.begin(), fData.end(), data.Channel());
87  if (it == fData.end() || data.Channel() != it->Channel() ) {
88  bool sort = ( !(fData.empty()) && data < fData.back());
89  fData.push_back(data);
90  if (sort) std::sort(fData.begin(), fData.end());
91  }
92  else {
93  *it = data;
94  }
95  }
96 
97  private:
98 
101  std::vector<T> fData;
102  };
103 
104  //=============================================
105  // Class implementation
106  //=============================================
107  template <class T>
109  fData.clear();
112  }
113 
114  template <class T>
115  void Snapshot<T>::SetIoV(const IOVTimeStamp& start, const IOVTimeStamp& end) {
116  if (start >= end) {
117  throw IOVDataError("Called Snapshot::SetIoV with start timestamp >= end timestamp!");
118  }
119 
120  fStart = start;
121  fEnd = end;
122  }
123 
124  template <class T>
125  bool Snapshot<T>::IsValid(const IOVTimeStamp& ts) const {
126  return (ts >= fStart && ts < fEnd);
127  }
128 
129 }//end namespace lariov
130 #endif
131 /** @} */ // end of doxygen group
132 
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
intermediate_table::iterator iterator
void SetStamp(unsigned long stamp, unsigned int substamp=0)
Definition: IOVTimeStamp.h:41
void msg(const char *fmt,...)
Definition: message.cpp:107
~Snapshot()
Default destructor.
Definition: Snapshot.h:40
std::string string
Definition: nybbler.cc:12
std::vector< T > fData
Definition: Snapshot.h:101
void AddOrReplaceRow(const T &data)
Definition: Snapshot.h:85
IOVTimeStamp fEnd
Definition: Snapshot.h:100
bool HasChannel(unsigned int ch) const
Only included with class if T has base class ChData.
Definition: Snapshot.h:59
intermediate_table::const_iterator const_iterator
const T & GetRow(unsigned int ch) const
Definition: Snapshot.h:70
Class def header for a class IOVTimeStamp.
unsigned long SubStamp() const
Definition: IOVTimeStamp.h:38
IOVTimeStamp fStart
Definition: Snapshot.h:99
Snapshot()
Default constructor.
Definition: Snapshot.h:36
size_t NChannels() const
Definition: Snapshot.h:50
const IOVTimeStamp & Start() const
Definition: Snapshot.h:44
Filters for channels, events, etc.
void SetIoV(const IOVTimeStamp &start, const IOVTimeStamp &end)
Definition: Snapshot.h:115
const IOVTimeStamp & End() const
Definition: Snapshot.h:45
unsigned long Stamp() const
Definition: IOVTimeStamp.h:37
const std::vector< T > & Data() const
Definition: Snapshot.h:52
Collection of exception classes for IOVData.
Class def header for a class ChData.
static IOVTimeStamp MaxTimeStamp()
bool IsValid(const IOVTimeStamp &ts) const
Definition: Snapshot.h:125
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34