Jpp  19.1.0
the software that should make you happy
JSupportToolkit.hh
Go to the documentation of this file.
1 #ifndef __JSUPPORT__JSUPPORTTOOLKIT__
2 #define __JSUPPORT__JSUPPORTTOOLKIT__
3 
4 #include <string>
5 #include <exception>
6 
7 #include "TDirectory.h"
8 
10 
11 #include "JDAQ/JDAQEvaluator.hh"
13 #include "JDAQ/JDAQTimesliceIO.hh"
15 #include "JDAQ/JSupport.hh"
17 #include "JTools/JRange.hh"
19 #include "JSupport/JFileScanner.hh"
20 #include "JSupport/JTreeScanner.hh"
23 
24 
25 /**
26  * \file
27  * Support methods.
28  * \author mdejong
29  */
30 namespace JSUPPORT {}
31 namespace JPP { using namespace JSUPPORT; }
32 
33 namespace JSUPPORT {
34 
36 
37 
38  /**
39  * Type definition for frame index range.
40  */
42 
43  /**
44  * Type definition for DAQ UTC time range.
45  */
47 
48 
49  /**
50  * Get time duration of given UTC time range.
51  *
52  * \param utc UTC time range
53  * \return time duration [s]
54  */
55  inline double getTimeDuration(const JDAQUTCTimeRange& utc)
56  {
57  if (utc.is_valid())
58  return (utc.getUpperLimit().getTimeNanoSecond() -
59  utc.getLowerLimit().getTimeNanoSecond()) * 1.0e-9;
60  else
61  return 0.0;
62  }
63 
64 
65  /**
66  * Get run number for given file name of data taking run.
67  *
68  * \param file_name file name
69  * \return run number
70  */
71  template<class T>
72  inline int getRunNumber(const std::string& file_name)
73  {
74  JFileScanner<T> in(file_name.c_str());
75 
76  if (in.hasNext())
77  return in.next()->getRunNumber();
78  else
79  return -1;
80  }
81 
82 
83  /**
84  * Get range of frame indices.
85  *
86  * \param in TTree scanner
87  * \return frame index range
88  */
89  template<class T>
91  {
92  if (!in.empty())
93  return JFrameIndexRange(in.begin()->getFrameIndex(), in.rbegin()->getFrameIndex());
94  else
95  return JFrameIndexRange(0,0);
96  }
97 
98 
99  /**
100  * Get range of frame indices for given file name of data taking run.
101  *
102  * \param file_name file name
103  * \return frame index range
104  */
105  template<class T>
106  inline JFrameIndexRange getFrameIndexRange(const std::string& file_name)
107  {
109 
110  TDirectory* dir = TDirectory::CurrentDirectory();
111 
112  if (isROOTFile(file_name.c_str())) {
113 
115 
116  return getFrameIndexRange(in);
117 
118  } else {
119 
120  JFileScanner<T> in(file_name.c_str());
121 
122  while (in.hasNext()) {
123  result.include(in.next()->getFrameIndex());
124  }
125  }
126 
127  if (dir != NULL) {
128  dir->cd(); // restore current working directory
129  }
130 
131  return result;
132  }
133 
134 
135  /**
136  * Get UTC time range.
137  *
138  * \return UTC time range
139  */
141  {
143  }
144 
145 
146  /**
147  * Get UTC time range.
148  *
149  * \param in TTree scanner
150  * \return UTC time range
151  */
152  template<class T>
154  {
155  if (!in.empty())
156  return JDAQUTCTimeRange(in.begin()->getTimesliceStart(), in.rbegin()->getTimesliceStart());
157  else
158  return getUTCTimeRange();
159  }
160 
161 
162  /**
163  * Get UTC time range for given file name of data taking run.
164  *
165  * \param file_name file name
166  * \return UTC time range
167  */
168  template<class T>
169  inline JDAQUTCTimeRange getUTCTimeRange(const std::string& file_name)
170  {
172 
173  TDirectory* dir = TDirectory::CurrentDirectory();
174 
175  if (isROOTFile(file_name.c_str())) {
176 
178 
179  result = getUTCTimeRange(in);
180 
181  } else {
182 
183  for (JFileScanner<T> in(file_name.c_str()); in.hasNext(); ) {
184  result.include(in.next()->getTimesliceStart());
185  }
186  }
187 
188  if (dir != NULL) {
189  dir->cd(); // restore current working directory
190  }
191 
192  return result;
193  }
194 
195 
196  /**
197  * Get UTC time range for given file name of data taking run.
198  * Get data taking live time.
199  *
200  * \param __begin begin of file list
201  * \param __end end of file list
202  * \return UTC time range
203  */
204  template<class T>
205  inline JDAQUTCTimeRange getUTCTimeRange(T __begin, T __end)
206  {
208 
209  for (T i = __begin; i != __end; ++i) {
210 
211  JDAQUTCTimeRange buffer = getUTCTimeRange<KM3NETDAQ::JDAQSummaryslice>(*i);
212 
213  if (buffer == getUTCTimeRange()) {
214  buffer = getUTCTimeRange<KM3NETDAQ::JDAQTimeslice>(*i);
215  }
216 
217  result.combine(buffer);
218  }
219 
220  return result;
221  }
222 
223 
224  /**
225  * Get data taking live time.
226  *
227  * \param file_name file name
228  * \return live time [s]
229  */
230  inline double getLivetime(const std::string& file_name)
231  {
232  using namespace KM3NETDAQ;
233  using namespace JTRIGGER;
234 
235  TDirectory* dir = TDirectory::CurrentDirectory();
236 
237  double livetime = 0.0;
238 
239  try {
240 
241  const JTriggerParameters parameters = getTriggerParameters(file_name);
242 
243  if (parameters.writeSummary.prescale != 0) {
244 
245  JTreeScanner<JDAQSummaryslice> in(file_name);
246 
247  livetime = in.getEntries() * getFrameTime() * 1.0e-9 / parameters.writeSummary.prescale;
248  }
249  }
250  catch(const std::exception& error) {}
251 
252  if (dir != NULL) {
253  dir->cd(); // restore current working directory
254  }
255 
256  return livetime;
257  }
258 
259 
260  /**
261  * Get data taking live time.
262  *
263  * \param __begin begin of file list
264  * \param __end end of file list
265  * \return live time [s]
266  */
267  template<class T>
268  inline double getLivetime(T __begin, T __end)
269  {
270  double livetime = 0.0;
271 
272  for (T i = __begin; i != __end; ++i) {
273  livetime += getLivetime(*i);
274  }
275 
276  return livetime;
277  }
278 
279 
280  /**
281  * Get data taking live time.
282  *
283  * \param file_list file list
284  * \return live time [s]
285  */
286  inline double getLivetime(const JMultipleFileScanner_t& file_list)
287  {
288  return getLivetime(file_list.begin(), file_list.end());
289  }
290 }
291 
292 #endif
ROOT TTree parameter settings.
Specifications of file name extensions.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Auxiliary class to define a range between two values.
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.
Object reading from file.
Definition: JFileScanner.hh:39
Auxiliary interface for direct access of elements in ROOT TChain.
Template definition for direct access of elements in ROOT TChain.
bool is_valid() const
Check validity of range.
Definition: JRange.hh:311
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
static JRange< int, std::less< int > > DEFAULT_RANGE()
Default range.
Definition: JRange.hh:555
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
long long int prescale
Definition: JPrescaler.hh:96
Data structure for all trigger parameters.
JPrescaler writeSummary
write JDAQSummaryslice
Data structure for UTC time.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Support classes and methods for experiment specific I/O.
Definition: JDataWriter.cc:38
double getTimeDuration(const JDAQUTCTimeRange &utc)
Get time duration of given UTC time range.
JTOOLS::JRange< JDAQUTCExtended > JDAQUTCTimeRange
Type definition for DAQ UTC time range.
JDAQUTCTimeRange getUTCTimeRange(T __begin, T __end)
Get UTC time range for given file name of data taking run.
bool isROOTFile(const char *file_name)
Check file format.
double getLivetime(const JMultipleFileScanner_t &file_list)
Get data taking live time.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
int getRunNumber(const std::string &file_name)
Get run number for given file name of data taking run.
JFrameIndexRange getFrameIndexRange(const std::string &file_name)
Get range of frame indices for given file name of data taking run.
JTOOLS::JRange< int > JFrameIndexRange
Type definition for frame index range.
Auxiliary classes and methods for triggering.
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Normalisation of MUPAGE events.
Definition: JHead.hh:835
Auxiliary base class for list of file names.