EUDAQ
 All Classes Namespaces Files Functions Variables Pages
StandardEvent.hh
1 #ifndef EUDAQ_INCLUDED_StandardEvent
2 #define EUDAQ_INCLUDED_StandardEvent
3 
4 #include "eudaq/Event.hh"
5 #include <vector>
6 #include <string>
7 
8 namespace eudaq {
9 
10  class DLLEXPORT StandardPlane : public Serializable {
11  public:
12  enum FLAGS {
13  FLAG_ZS = 0x1, // Data are zero suppressed
14  FLAG_NEEDCDS =
15  0x2, // CDS needs to be calculated (data is 2 or 3 raw frames)
16  FLAG_NEGATIVE = 0x4, // Signal polarity is negative
17  FLAG_ACCUMULATE = 0x8, // Multiple frames should be accumulated for output
18 
19  FLAG_WITHPIVOT = 0x10000, // Include before/after pivot boolean per pixel
20  FLAG_WITHSUBMAT = 0x20000, // Include Submatrix ID per pixel
21  FLAG_DIFFCOORDS =
22  0x40000 // Each frame can have different coordinates (in ZS mode)
23  };
24  typedef double pixel_t;
25  typedef double coord_t;
26  StandardPlane(unsigned id, const std::string &type,
27  const std::string &sensor = "");
29  StandardPlane();
30  void Serialize(Serializer &) const;
31  void SetSizeRaw(unsigned w, unsigned h, unsigned frames = 1, int flags = 0);
32  void SetSizeZS(unsigned w, unsigned h, unsigned npix, unsigned frames = 1,
33  int flags = 0);
34 
35  template <typename T>
36  void SetPixel(unsigned index, unsigned x, unsigned y, T pix,
37  bool pivot = false, unsigned frame = 0) {
38  SetPixelHelper(index, x, y, (double)pix, pivot, frame);
39  }
40  template <typename T>
41  void SetPixel(unsigned index, unsigned x, unsigned y, T pix,
42  unsigned frame) {
43  SetPixelHelper(index, x, y, (double)pix, false, frame);
44  }
45  template <typename T>
46  void PushPixel(unsigned x, unsigned y, T pix, bool pivot = false,
47  unsigned frame = 0) {
48  PushPixelHelper(x, y, (double)pix, pivot, frame);
49  }
50  template <typename T>
51  void PushPixel(unsigned x, unsigned y, T pix, unsigned frame) {
52  PushPixelHelper(x, y, (double)pix, false, frame);
53  }
54 
55  void SetPixelHelper(unsigned index, unsigned x, unsigned y, double pix,
56  bool pivot, unsigned frame);
57  void PushPixelHelper(unsigned x, unsigned y, double pix, bool pivot,
58  unsigned frame);
59  double GetPixel(unsigned index, unsigned frame) const;
60  double GetPixel(unsigned index) const;
61  double GetX(unsigned index, unsigned frame) const;
62  double GetX(unsigned index) const;
63  double GetY(unsigned index, unsigned frame) const;
64  double GetY(unsigned index) const;
65  bool GetPivot(unsigned index, unsigned frame = 0) const;
66  void SetPivot(unsigned index, unsigned frame, bool PivotFlag);
67  // defined for short, int, double
68  template <typename T> std::vector<T> GetPixels() const {
69  SetupResult();
70  std::vector<T> result(m_result_pix->size());
71  for (size_t i = 0; i < result.size(); ++i) {
72  result[i] = static_cast<T>((*m_result_pix)[i] * Polarity());
73  }
74  return result;
75  }
76  const std::vector<coord_t> &XVector(unsigned frame) const;
77  const std::vector<coord_t> &XVector() const;
78  const std::vector<coord_t> &YVector(unsigned frame) const;
79  const std::vector<coord_t> &YVector() const;
80  const std::vector<pixel_t> &PixVector(unsigned frame) const;
81  const std::vector<pixel_t> &PixVector() const;
82 
83  void SetXSize(unsigned x);
84  void SetYSize(unsigned y);
85  void SetTLUEvent(unsigned ev);
86  void SetPivotPixel(unsigned p);
87  void SetFlags(FLAGS flags);
88 
89  unsigned ID() const;
90  const std::string &Type() const;
91  const std::string &Sensor() const;
92  unsigned XSize() const;
93  unsigned YSize() const;
94  unsigned NumFrames() const;
95  unsigned TotalPixels() const;
96  unsigned HitPixels(unsigned frame) const;
97  unsigned HitPixels() const;
98  unsigned TLUEvent() const;
99  unsigned PivotPixel() const;
100 
101  int GetFlags(int f) const;
102  bool NeedsCDS() const;
103  int Polarity() const;
104 
105  void Print(std::ostream &) const;
106 
107  private:
108  const std::vector<pixel_t> &
109  GetFrame(const std::vector<std::vector<pixel_t>> &v, unsigned f) const;
110  void SetupResult() const;
111 
112  std::string m_type, m_sensor;
113  unsigned m_id, m_tluevent;
114  unsigned m_xsize, m_ysize;
115  unsigned m_flags, m_pivotpixel;
116  std::vector<std::vector<pixel_t>> m_pix;
117  std::vector<std::vector<coord_t>> m_x, m_y;
118  std::vector<std::vector<bool>> m_pivot;
119  std::vector<unsigned> m_mat;
120 
121  mutable const std::vector<pixel_t> *m_result_pix;
122  mutable const std::vector<coord_t> *m_result_x, *m_result_y;
123 
124  mutable std::vector<pixel_t> m_temp_pix;
125  mutable std::vector<coord_t> m_temp_x, m_temp_y;
126  };
127 
128  class DLLEXPORT StandardEvent : public Event {
129  EUDAQ_DECLARE_EVENT(StandardEvent);
130 
131  public:
132  StandardEvent(unsigned run = 0, unsigned evnum = 0,
133  uint64_t timestamp = NOTIMESTAMP);
134  StandardEvent(const Event &);
136  void SetTimestamp(uint64_t);
137 
138  StandardPlane &AddPlane(const StandardPlane &);
139  size_t NumPlanes() const;
140  const StandardPlane &GetPlane(size_t i) const;
141  StandardPlane &GetPlane(size_t i);
142  virtual void Serialize(Serializer &) const;
143  virtual void Print(std::ostream &) const;
144 
145  // void SetSlowPara(std::string name, double value){slowpara[name] = value;};
146  // std::map<std::string, double> GetSlowPara()const {return slowpara;};
147  private:
148  std::vector<StandardPlane> m_planes;
149  // std::map<std::string, double> slowpara;
150  };
151 
152  inline std::ostream &operator<<(std::ostream &os, const StandardPlane &pl) {
153  pl.Print(os);
154  return os;
155  }
156  inline std::ostream &operator<<(std::ostream &os, const StandardEvent &ev) {
157  ev.Print(os);
158  return os;
159  }
160 
161 } // namespace eudaq
162 
163 #endif // EUDAQ_INCLUDED_StandardEvent
Definition: TLUEvent.hh:10
Definition: Serializer.hh:156
Definition: Serializable.hh:13
Definition: StandardEvent.hh:10
Definition: StandardEvent.hh:128
Definition: Serializer.hh:19
Definition: Event.hh:38