Jpp  18.0.0-rc.2
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 #include "JDAQ/JDAQEvaluator.hh"
12 #include "JDAQ/JDAQTimesliceIO.hh"
15 #include "JTools/JRange.hh"
17 #include "JSupport/JFileScanner.hh"
18 #include "JSupport/JTreeScanner.hh"
21 
22 
23 /**
24  * \file
25  * Support methods.
26  * \author mdejong
27  */
28 namespace JSUPPORT {}
29 namespace JPP { using namespace JSUPPORT; }
30 
31 namespace JSUPPORT {
32 
34 
35 
36  /**
37  * Type definition for frame index range.
38  */
40 
41  /**
42  * Type definition for DAQ UTC time range.
43  */
45 
46 
47  /**
48  * Get time duration of given UTC time range.
49  *
50  * \param utc UTC time range
51  * \return time duration [s]
52  */
53  inline double getTimeDuration(const JDAQUTCTimeRange& utc)
54  {
55  if (utc.is_valid())
56  return (utc.getUpperLimit().getTimeNanoSecond() -
57  utc.getLowerLimit().getTimeNanoSecond()) * 1.0e-9;
58  else
59  return 0.0;
60  }
61 
62 
63  /**
64  * Get run number for given file name of data taking run.
65  *
66  * \param file_name file name
67  * \return run number
68  */
69  template<class T>
70  inline int getRunNumber(const std::string& file_name)
71  {
72  JFileScanner<T> in(file_name.c_str());
73 
74  if (in.hasNext())
75  return in.next()->getRunNumber();
76  else
77  return -1;
78  }
79 
80 
81  /**
82  * Get range of frame indices.
83  *
84  * \param in TTree scanner
85  * \return frame index range
86  */
87  template<class T>
89  {
90  if (!in.empty())
91  return JFrameIndexRange(in.begin()->getFrameIndex(), in.rbegin()->getFrameIndex());
92  else
93  return JFrameIndexRange(0,0);
94  }
95 
96 
97  /**
98  * Get range of frame indices for given file name of data taking run.
99  *
100  * \param file_name file name
101  * \return frame index range
102  */
103  template<class T>
105  {
107 
108  TDirectory* dir = TDirectory::CurrentDirectory();
109 
110  if (isROOTFile(file_name.c_str())) {
111 
113 
114  return getFrameIndexRange(in);
115 
116  } else {
117 
118  JFileScanner<T> in(file_name.c_str());
119 
120  while (in.hasNext()) {
121  result.include(in.next()->getFrameIndex());
122  }
123  }
124 
125  if (dir != NULL) {
126  dir->cd(); // restore current working directory
127  }
128 
129  return result;
130  }
131 
132 
133  /**
134  * Get UTC time range.
135  *
136  * \return UTC time range
137  */
139  {
141  }
142 
143 
144  /**
145  * Get UTC time range.
146  *
147  * \param in TTree scanner
148  * \return UTC time range
149  */
150  template<class T>
152  {
153  if (!in.empty())
154  return JDAQUTCTimeRange(in.begin()->getTimesliceStart(), in.rbegin()->getTimesliceStart());
155  else
156  return getUTCTimeRange();
157  }
158 
159 
160  /**
161  * Get UTC time range for given file name of data taking run.
162  *
163  * \param file_name file name
164  * \return UTC time range
165  */
166  template<class T>
168  {
170 
171  TDirectory* dir = TDirectory::CurrentDirectory();
172 
173  if (isROOTFile(file_name.c_str())) {
174 
176 
177  result = getUTCTimeRange(in);
178 
179  } else {
180 
181  for (JFileScanner<T> in(file_name.c_str()); in.hasNext(); ) {
182  result.include(in.next()->getTimesliceStart());
183  }
184  }
185 
186  if (dir != NULL) {
187  dir->cd(); // restore current working directory
188  }
189 
190  return result;
191  }
192 
193 
194  /**
195  * Get UTC time range for given file name of data taking run.
196  * Get data taking live time.
197  *
198  * \param __begin begin of file list
199  * \param __end end of file list
200  * \return UTC time range
201  */
202  template<class T>
203  inline JDAQUTCTimeRange getUTCTimeRange(T __begin, T __end)
204  {
206 
207  for (T i = __begin; i != __end; ++i) {
208 
209  JDAQUTCTimeRange buffer = getUTCTimeRange<KM3NETDAQ::JDAQSummaryslice>(*i);
210 
211  if (buffer == getUTCTimeRange()) {
212  buffer = getUTCTimeRange<KM3NETDAQ::JDAQTimeslice>(*i);
213  }
214 
215  result.combine(buffer);
216  }
217 
218  return result;
219  }
220 
221 
222  /**
223  * Get data taking live time.
224  *
225  * \param file_name file name
226  * \return live time [s]
227  */
228  inline double getLivetime(const std::string& file_name)
229  {
230  using namespace KM3NETDAQ;
231  using namespace JTRIGGER;
232 
233  TDirectory* dir = TDirectory::CurrentDirectory();
234 
235  double livetime = 0.0;
236 
237  try {
238 
240 
241  if (parameters.writeSummary.prescale != 0) {
242 
244 
245  livetime = in.getEntries() * getFrameTime() * 1.0e-9 / parameters.writeSummary.prescale;
246  }
247  }
248  catch(const std::exception& error) {}
249 
250  if (dir != NULL) {
251  dir->cd(); // restore current working directory
252  }
253 
254  return livetime;
255  }
256 
257 
258  /**
259  * Get data taking live time.
260  *
261  * \param __begin begin of file list
262  * \param __end end of file list
263  * \return live time [s]
264  */
265  template<class T>
266  inline double getLivetime(T __begin, T __end)
267  {
268  double livetime = 0.0;
269 
270  for (T i = __begin; i != __end; ++i) {
271  livetime += getLivetime(*i);
272  }
273 
274  return livetime;
275  }
276 
277 
278  /**
279  * Get data taking live time.
280  *
281  * \param file_list file list
282  * \return live time [s]
283  */
284  inline double getLivetime(const JMultipleFileScanner_t& file_list)
285  {
286  return getLivetime(file_list.begin(), file_list.end());
287  }
288 }
289 
290 #endif
JDAQUTCTimeRange getUTCTimeRange()
Get UTC time range.
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
*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.
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
return result
Definition: JPolint.hh:764
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
then awk string
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:822
Auxiliary class to define a range between two values.
double getLivetime(const std::string &file_name)
Get data taking live time.
Object reading from file.
Definition: JFileScanner.hh:37
JFrameIndexRange getFrameIndexRange(JTreeScanner< T, KM3NETDAQ::JDAQEvaluator > &in)
Get range of frame indices.
static JRange< int, std::less< int > > DEFAULT_RANGE()
Default range.
Definition: JRange.hh:555
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] 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:46
Specifications of file name extensions.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.