Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
47  std::vector<JDAQSuperFrame>()
48  {}
49 
50 
51  /**
52  * Constructor.
53  *
54  * \param chronometer DAQ chronometer
55  */
56  JDAQTimeslice(const JDAQChronometer& chronometer) :
58  JDAQTimesliceHeader(chronometer),
59  std::vector<JDAQSuperFrame>()
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(6) << frame->size();
189 
190  if (!lpr) {
191 
192  if (!frame->empty()) {
193 
194  out << ' ' << setw(10) << frame-> begin()->getT();
195  out << " ... ";
196  out << ' ' << setw(10) << frame->rbegin()->getT();
197  }
198 
199  out << endl;
200 
201  } else {
202 
203  out << endl;
204 
205  int n = 1;
206 
207  for (JDAQFrame::const_iterator hit = frame->begin(); hit != frame->end(); ++hit, ++n) {
208  out << setw(2) << (int) hit->getPMT() << ' ' << setw(8) << hit->getT() << (n%10 == 0 ? '\n' : ' ');
209  }
210 
211  out << endl;
212  }
213  }
214 
215  return out;
216  }
217 
218 
220  };
221 
222 
223  /**
224  * Equal operator for DAQ time slices.
225  *
226  * \param first time slice
227  * \param second time slice
228  * \result true if first time slice equal to second; else false
229  */
230  inline bool operator==(const JDAQTimeslice& first,
231  const JDAQTimeslice& second)
232  {
233  return (first.getDAQTimesliceHeader() == second.getDAQTimesliceHeader() &&
234  static_cast<const std::vector<JDAQSuperFrame>&>(first) == static_cast<const std::vector<JDAQSuperFrame>&>(second));
235  }
236 
237 
238  /**
239  * Not-equal operator for DAQ time slices.
240  *
241  * \param first time slice
242  * \param second time slice
243  * \result true if first time slice not equal to second; else false
244  */
245  inline bool operator!=(const JDAQTimeslice& first,
246  const JDAQTimeslice& second)
247  {
248  return !(first == second);
249  }
250 
251 
252  /**
253  * Timeslice data structure for L0 data.
254  */
256 
257 
258  /**
259  * Timeslice data structure for L1 data.
260  */
262 
263 
264  /**
265  * Timeslice data structure for L2 data.
266  */
268 
269 
270  /**
271  * Timeslice data structure for SN data.
272  */
274 
275 
276  /**
277  * Print DAQ Timeslice.
278  *
279  * \param out output stream
280  * \param timeslice timeslice
281  * \return output stream
282  */
283  inline std::ostream& operator<<(std::ostream& out, const JDAQTimeslice& timeslice)
284  {
285  return timeslice.print(out, getDAQLongprint());
286  }
287 }
288 
289 #endif
void clear()
Clear data.
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
Interface for binary output.
JDAQTimeslice(const JDAQChronometer &chronometer)
Constructor.
Auxiliary class for a DAQ type holder.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
friend JWriter & operator<<(JWriter &, const JDAQTimeslice &)
Write DAQ time slice to output.
JDAQTimeslice()
Default constructor.
friend size_t getSizeof()
Definition of method to get size of data type.
JDAQTimeslice & operator=(const JDAQTimeslice &timeslice)
Assignment operator.
Timeslice data structure for L1 data.
const JDAQTimesliceHeader & getDAQTimesliceHeader() const
Get DAQ time slice header.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
virtual ~JDAQTimeslice()
Virtual destructor.
JDAQTimeslice & add(const JDAQTimeslice &timeslice)
Add another timeslice.
Hit data structure.
Definition: JDAQHit.hh:34
const_iterator begin() const
Definition: JDAQFrame.hh:136
Timeslice data structure for L2 data.
const JDAQChronometer & getDAQChronometer() const
Get DAQ chronometer.
Data time slice.
std::ostream & print(std::ostream &out, const bool lpr=false) const
Print DAQ Timeslice.
void setDAQChronometer(const JDAQChronometer &chronometer)
Set DAQ chronometer.
Timeslice data structure for SN data.
Interface for binary input.
alias put_queue eval echo n
Definition: qlib.csh:19
friend JReader & operator>>(JReader &, JDAQTimeslice &)
Read DAQ time slice from input.
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
bool & getDAQLongprint()
Get DAQ print option.
Definition: JDAQPrint.hh:15
ClassDef(JDAQTimeslice, 4)
Data frame of one optical module.
JDAQSuperFrame & add(const JDAQSuperFrame &super_frame)
Add data from same optical module.
Timeslice data structure for L0 data.
const_iterator end() const
Definition: JDAQFrame.hh:137