Jpp  debug
the software that should make you happy
JDAQTimeslice.hh
Go to the documentation of this file.
1 #ifndef __JDAQTIMESLICE__
2 #define __JDAQTIMESLICE__
3 
4 #include <ostream>
5 #include <iomanip>
6 #include <vector>
7 #include <map>
8 
15 
16 
17 /**
18  * \author mdejong
19  */
20 
21 namespace KM3NETDAQ {
22 
23  class JDAQEvent;
24  class JDAQSummaryslice;
25 
26 
27  /**
28  * Data time slice.
29  */
30  class JDAQTimeslice :
31  public JDAQPreamble,
32  public JDAQTimesliceHeader,
33  public std::vector<JDAQSuperFrame>
34  {
35  public:
36 
37  friend size_t getSizeof(const JDAQTimeslice&);
39  friend JWriter& operator<<(JWriter&, const JDAQTimeslice&);
40 
41  /**
42  * Default constructor.
43  */
48  {}
49 
50 
51  /**
52  * Constructor.
53  *
54  * \param chronometer DAQ chronometer
55  */
56  JDAQTimeslice(const JDAQChronometer& chronometer) :
58  JDAQTimesliceHeader(chronometer),
60  {}
61 
62 
63  /**
64  * Constructor.
65  *
66  * \param event DAQ event
67  * \param snapshot use shapshot hits (else use triggered hits)
68  */
69  JDAQTimeslice(const JDAQEvent& event,
70  const bool snapshot = true);
71 
72 
73  /**
74  * Constructor.
75  *
76  * \param event DAQ event
77  * \param summary summary
78  * \param snapshot use shapshot hits (else use triggered hits)
79  */
80  JDAQTimeslice(const JDAQEvent& event,
81  const JDAQSummaryslice& summary,
82  const bool snapshot = true);
83 
84 
85  /**
86  * Virtual destructor.
87  */
88  virtual ~JDAQTimeslice()
89  {
90  clear();
91  }
92 
93 
94  /**
95  * Clear data.
96  */
97  void clear()
98  {
99  for (iterator i = this->begin(); i != this->end(); ++i) {
100  i->clear();
101  }
102 
104  }
105 
106 
107  /**
108  * Assignment operator.
109  *
110  * \param timeslice timeslice
111  * \return this timeslice
112  */
114  {
115  clear();
116 
118 
119  for (const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
120  push_back(*i);
121  }
122 
123  return *this;
124  }
125 
126 
127  /**
128  * Add another timeslice.
129  *
130  * \param timeslice timeslice
131  * \return this timeslice
132  */
133  JDAQTimeslice& add(const JDAQTimeslice& timeslice)
134  {
135  using namespace std;
136 
138 
139  for (const_iterator i = this->begin(); i != this->end(); ++i) {
140  buffer[i->getModuleIdentifier()] = distance(static_cast<const JDAQTimeslice&>(*this).begin(),i);
141  }
142 
143  for (JDAQTimeslice::const_iterator i = timeslice.begin(); i != timeslice.end(); ++i) {
144 
145  map<JDAQModuleIdentifier, int>::const_iterator p = buffer.find(i->getModuleIdentifier());
146 
147  if (p != buffer.end()) {
148 
149  JDAQSuperFrame& frame = this->at(p->second);
150 
151  frame.add(*i);
152 
153  sort(frame.begin(), frame.end());
154 
155  } else {
156 
157  this->push_back(*i);
158  }
159  }
160 
161  return *this;
162  }
163 
164 
165  /**
166  * Print DAQ Timeslice.
167  *
168  * \param out output stream
169  * \param lpr long print
170  * \return output stream
171  */
172  std::ostream& print(std::ostream& out, const bool lpr = false) const
173  {
174  using namespace std;
175 
176  out << this->ClassName() << endl;
177  out << dynamic_cast<const JDAQPreamble&> (*this) << endl;
178  out << dynamic_cast<const JDAQChronometer&>(*this) << endl;
179 
180  for (JDAQTimeslice::const_iterator frame = this->begin(); frame != this->end(); ++frame) {
181 
182  out << ' ' << setw(10) << frame->getModuleID();
183  out << ' ' << setw(6) << frame->getLength();
184  out << ' ' << setw(6) << frame->getDataType();
185  out << ' ' << setw(6) << frame->getTimesliceStart();
186  out << ' ' << setw(8) << setfill('0') << hex << frame->getStatus() << dec << setfill(' ');
187  out << '|' << setw(8) << setfill('0') << hex << frame->getFIFOStatus() << dec << setfill(' ');
188  out << ' ' << setw(2) << frame->getUDPNumberOfReceivedPackets();
189  out << '/' << setw(2) << frame->getUDPMaximalSequenceNumber();
190  out << ' ' << setw(6) << frame->size();
191 
192  if (!lpr) {
193 
194  if (!frame->empty()) {
195 
196  out << ' ' << setw(10) << frame-> begin()->getT();
197  out << " ... ";
198  out << ' ' << setw(10) << frame->rbegin()->getT();
199  }
200 
201  out << endl;
202 
203  } else {
204 
205  out << endl;
206 
207  int n = 1;
208 
209  for (JDAQFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit, ++n) {
210  out << setw(2) << (int) hit->getPMT() << ' '
211  << setw(8) << (int) hit->getT() << ' '
212  << setw(3) << (int) hit->getToT() << (n%10 == 0 ? '\n' : ' ');
213  }
214 
215  out << endl;
216  }
217  }
218 
219  return out;
220  }
221 
222 
224  };
225 
226 
227  /**
228  * Equal operator for DAQ time slices.
229  *
230  * \param first time slice
231  * \param second time slice
232  * \result true if first time slice equal to second; else false
233  */
234  inline bool operator==(const JDAQTimeslice& first,
235  const JDAQTimeslice& second)
236  {
237  return (first.getDAQTimesliceHeader() == second.getDAQTimesliceHeader() &&
238  static_cast<const std::vector<JDAQSuperFrame>&>(first) == static_cast<const std::vector<JDAQSuperFrame>&>(second));
239  }
240 
241 
242  /**
243  * Not-equal operator for DAQ time slices.
244  *
245  * \param first time slice
246  * \param second time slice
247  * \result true if first time slice not equal to second; else false
248  */
249  inline bool operator!=(const JDAQTimeslice& first,
250  const JDAQTimeslice& second)
251  {
252  return !(first == second);
253  }
254 
255 
256  /**
257  * Timeslice data structure for L0 data.
258  */
260 
261 
262  /**
263  * Timeslice data structure for L1 data.
264  */
266 
267 
268  /**
269  * Timeslice data structure for L2 data.
270  */
272 
273 
274  /**
275  * Timeslice data structure for SN data.
276  */
278 
279 
280  /**
281  * Print DAQ Timeslice.
282  *
283  * \param out output stream
284  * \param timeslice timeslice
285  * \return output stream
286  */
287  inline std::ostream& operator<<(std::ostream& out, const JDAQTimeslice& timeslice)
288  {
289  return timeslice.print(out, getDAQLongprint());
290  }
291 }
292 
293 #endif
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Interface for binary input.
Interface for binary output.
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
const_iterator end() const
Definition: JDAQFrame.hh:166
const_iterator begin() const
Definition: JDAQFrame.hh:165
Hit data structure.
Definition: JDAQHit.hh:35
friend size_t getSizeof()
Definition of method to get size of data type.
Data frame of one optical module.
JDAQSuperFrame & add(const JDAQSuperFrame &super_frame)
Add data from same optical module.
const JDAQTimesliceHeader & getDAQTimesliceHeader() const
Get DAQ time slice header.
JDAQTimeslice & add(const JDAQTimeslice &timeslice)
Add another timeslice.
void clear()
Clear data.
friend JWriter & operator<<(JWriter &, const JDAQTimeslice &)
Write DAQ time slice to output.
JDAQTimeslice()
Default constructor.
JDAQTimeslice(const JDAQChronometer &chronometer)
Constructor.
std::ostream & print(std::ostream &out, const bool lpr=false) const
Print DAQ Timeslice.
virtual ~JDAQTimeslice()
Virtual destructor.
JDAQTimeslice & operator=(const JDAQTimeslice &timeslice)
Assignment operator.
friend JReader & operator>>(JReader &, JDAQTimeslice &)
Read DAQ time slice from input.
ClassDef(JDAQTimeslice, 4)
const int n
Definition: JPolint.hh:786
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
bool & getDAQLongprint()
Get DAQ print option.
Definition: JDAQPrint.hh:15
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
Definition: JSTDTypes.hh:14
Timeslice data structure for L0 data.
ClassDef(JDAQTimesliceL0, 1)
Timeslice data structure for L1 data.
ClassDef(JDAQTimesliceL1, 1)
Timeslice data structure for L2 data.
ClassDef(JDAQTimesliceL2, 1)
Timeslice data structure for SN data.
ClassDef(JDAQTimesliceSN, 1)
Auxiliary class for a DAQ type holder.