EUDAQ
 All Classes Namespaces Files Functions Variables Pages
Clusters.hh
1 #ifndef EUDAQ_INCLUDED_Clusters
2 #define EUDAQ_INCLUDED_Clusters
3 
4 #include "eudaq/Exception.hh"
5 
6 namespace eudaq {
7 
8  class Clusters {
9  public:
10  Clusters(std::pair<int, int> pos, int eve) {
11  m_x.push_back(pos.first);
12  m_y.push_back(pos.second);
13  m_event = eve;
14  };
15  Clusters(){};
16  Clusters(std::istream &in) : m_event(-1) { read(in); }
17  void read(std::istream &in);
18  void SetEventNum(int eve);
19  int EventNum() const { return m_event; }
20  uint64_t EventTimestamp() const { return m_timestamp; }
21  int NumClusters() const { return m_x.size(); }
22  int ClusterX(int i) const { return m_x[i]; }
23  int ClusterY(int i) const { return m_y[i]; }
24  int ClusterA(int i) const { return m_a[i]; }
25 
26  private:
27  int m_event;
28  uint64_t m_timestamp;
29  std::vector<int> m_x, m_y, m_a;
30  };
31 
32  inline void Clusters::read(std::istream &in) {
33  int lastevent = m_event;
34  std::string line;
35  std::getline(in, line);
36  if (in.eof())
37  return;
38  std::istringstream str(line);
39  str >> m_event;
40  if (m_event <= lastevent)
41  EUDAQ_THROW("Bad data file: event " + eudaq::to_string(m_event) + " <= " +
42  eudaq::to_string(lastevent));
43  int nclust = -1;
44  str >> nclust;
45  m_timestamp = 0;
46  str >> m_timestamp;
47 
48  if (nclust < 0)
49  return;
50  m_x.resize(nclust);
51  m_y.resize(nclust);
52  m_a.resize(nclust);
53  for (int i = 0; i < nclust; ++i) {
54  std::getline(in, line);
55  std::istringstream str(line);
56  str >> m_x[i];
57  str >> m_y[i];
58  str >> m_a[i];
59  }
60  if (in.eof())
61  EUDAQ_THROW("Bad data file: unexpected end of file");
62  }
63 }
64 
65 #endif // EUDAQ_INCLUDED_Clusters
Definition: Clusters.hh:8
std::string to_string(const T &x, int digits=0)
Definition: Utils.hh:54