Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
242 
243  if (parameters.writeSummary.prescale != 0) {
244 
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
JDAQUTCTimeRange getUTCTimeRange()
Get UTC time range.
JFrameIndexRange getFrameIndexRange(JTreeScannerInterface< T, KM3NETDAQ::JDAQEvaluator > &in)
Get range of frame indices.
JTOOLS::JRange< int > JFrameIndexRange
Type definition for frame index range.
Data structure for all trigger parameters.
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
range_type & include(argument_type x)
Include given value to range.
Definition: JRange.hh:397
Auxiliary interface for direct access of elements in ROOT TChain.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
range_type & combine(const range_type &range)
Combine ranges.
Definition: JRange.hh:432
Data structure for UTC time.
Template definition for direct access of elements in ROOT TChain.
ROOT TTree parameter settings.
bool isROOTFile(const char *file_name)
Check file format.
long long int prescale
Definition: JPrescaler.hh:96
double getTimeDuration(const JDAQUTCTimeRange &utc)
Get time duration of given UTC time range.
JPrescaler writeSummary
write JDAQSummaryslice
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
do set_variable OUTPUT_DIRECTORY $WORKDIR T
int getRunNumber(const std::string &file_name)
Get run number for given file name of data taking run.
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
JTOOLS::JRange< JDAQUTCExtended > JDAQUTCTimeRange
Type definition for DAQ UTC time range.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
bool is_valid() const
Check validity of range.
Definition: JRange.hh:311
Auxiliary base class for list of file names.
Normalisation of MUPAGE events.
Definition: JHead.hh:835
Auxiliary class to define a range between two values.
double getLivetime(const std::string &file_name)
Get data taking live time.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Object reading from file.
Definition: JFileScanner.hh:37
static JRange< int, std::less< int > > DEFAULT_RANGE()
Default range.
Definition: JRange.hh:555
Specifications of file name extensions.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.