Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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"
15#include "JDAQ/JSupport.hh"
16
18#include "JTools/JRange.hh"
19
25
26#include "JLang/JTypeList.hh"
27
28
29/**
30 * \file
31 * Support methods.
32 * \author mdejong
33 */
34namespace JSUPPORT {}
35namespace JPP { using namespace JSUPPORT; }
36
37namespace JSUPPORT {
38
40 using JLANG::JType;
41
42
43 /**
44 * Type definition for frame index range.
45 */
47
48 /**
49 * Type definition for DAQ UTC time range.
50 */
52
53
54 /**
55 * Get time duration of given UTC time range.
56 *
57 * \param utc UTC time range
58 * \return time duration [s]
59 */
60 inline double getTimeDuration(const JDAQUTCTimeRange& utc)
61 {
62 if (utc.is_valid())
63 return (utc.getUpperLimit().getTimeNanoSecond() -
64 utc.getLowerLimit().getTimeNanoSecond()) * 1.0e-9;
65 else
66 return 0.0;
67 }
68
69
70 /**
71 * Get run number for given file name of data taking run.
72 *
73 * \param file_name file name
74 * \return run number
75 */
76 template<class T>
77 inline int getRunNumber(const std::string& file_name)
78 {
79 JFileScanner<T> in(file_name.c_str());
80
81 if (in.hasNext())
82 return in.next()->getRunNumber();
83 else
84 return -1;
85 }
86
87
88 /**
89 * Get range of frame indices.
90 *
91 * \param in TTree scanner
92 * \return frame index range
93 */
94 template<class T>
96 {
97 if (!in.empty())
98 return JFrameIndexRange(in.begin()->getFrameIndex(), in.rbegin()->getFrameIndex());
99 else
100 return JFrameIndexRange(0,0);
101 }
102
103
104 /**
105 * Get range of frame indices for given file name of data taking run.
106 *
107 * \param file_name file name
108 * \return frame index range
109 */
110 template<class T>
111 inline JFrameIndexRange getFrameIndexRange(const std::string& file_name)
112 {
114
115 TDirectory* dir = TDirectory::CurrentDirectory();
116
117 if (isROOTFile(file_name.c_str())) {
118
120
121 return getFrameIndexRange(in);
122
123 } else {
124
125 JFileScanner<T> in(file_name.c_str());
126
127 while (in.hasNext()) {
128 result.include(in.next()->getFrameIndex());
129 }
130 }
131
132 if (dir != NULL) {
133 dir->cd(); // restore current working directory
134 }
135
136 return result;
137 }
138
139
140 /**
141 * Get UTC time range.
142 *
143 * \return UTC time range
144 */
149
150
151 /**
152 * Get UTC time range.
153 *
154 * \param in TTree scanner
155 * \return UTC time range
156 */
157 template<class T>
159 {
160 if (!in.empty())
161 return JDAQUTCTimeRange(in.begin()->getTimesliceStart(), in.rbegin()->getTimesliceStart());
162 else
163 return getUTCTimeRange();
164 }
165
166
167 /**
168 * Get UTC time range for given file name of data taking run.
169 *
170 * \param file_name file name
171 * \return UTC time range
172 */
173 template<class T>
174 inline JDAQUTCTimeRange getUTCTimeRange(const std::string& file_name)
175 {
177
178 TDirectory* dir = TDirectory::CurrentDirectory();
179
180 if (isROOTFile(file_name.c_str())) {
181
183
185
186 } else {
187
188 for (JFileScanner<T> in(file_name.c_str()); in.hasNext(); ) {
189 result.include(in.next()->getTimesliceStart());
190 }
191 }
192
193 if (dir != NULL) {
194 dir->cd(); // restore current working directory
195 }
196
197 return result;
198 }
199
200
201 /**
202 * Auxiliary class to extract UTC time range for list of data types.
203 */
204 template<class JTypelist_t>
206 public JDAQUTCTimeRange
207 {
208 /**
209 * Constructor.
210 *
211 * \param file_name file name
212 */
216 {
217 using namespace JPP;
218
220 }
221
222
223 /**
224 * Process internal file for given data type.
225 *
226 * \param type data type
227 */
228 template<class T>
229 void operator()(const JType<T>& type)
230 {
232
233 if (buffer != getUTCTimeRange()) {
234 this->combine(buffer);
235 }
236 }
237
238 private:
239 std::string file_name;
240 };
241
242
243 /**
244 * Get UTC time range for given file names of data taking runs.
245 *
246 * \param __begin begin of file list
247 * \param __end end of file list
248 * \return UTC time range
249 */
250 template<class T>
251 inline JDAQUTCTimeRange getUTCTimeRange(T __begin, T __end)
252 {
253 using namespace JPP;
254
256
257 for (T i = __begin; i != __end; ++i) {
258
262 KM3NETDAQ::JDAQTimesliceL1>::typelist> buffer(*i);
263
264 result.combine(buffer);
265 }
266
267 return result;
268 }
269
270
271 /**
272 * Get data taking live time.
273 *
274 * \param file_name file name
275 * \return live time [s]
276 */
277 inline double getLivetime(const std::string& file_name)
278 {
279 using namespace KM3NETDAQ;
280 using namespace JTRIGGER;
281
282 TDirectory* dir = TDirectory::CurrentDirectory();
283
284 double livetime = 0.0;
285
286 try {
287
288 const JTriggerParameters parameters = getTriggerParameters(file_name);
289
290 if (parameters.writeSummary.prescale != 0) {
291
292 JTreeScanner<JDAQSummaryslice> in(file_name);
293
294 livetime = in.getEntries() * getFrameTime() * 1.0e-9 / parameters.writeSummary.prescale;
295 }
296 }
297 catch(const std::exception& error) {}
298
299 if (dir != NULL) {
300 dir->cd(); // restore current working directory
301 }
302
303 return livetime;
304 }
305
306
307 /**
308 * Get data taking live time.
309 *
310 * \param __begin begin of file list
311 * \param __end end of file list
312 * \return live time [s]
313 */
314 template<class T>
315 inline double getLivetime(T __begin, T __end)
316 {
317 double livetime = 0.0;
318
319 for (T i = __begin; i != __end; ++i) {
320 livetime += getLivetime(*i);
321 }
322
323 return livetime;
324 }
325
326
327 /**
328 * Get data taking live time.
329 *
330 * \param file_list file list
331 * \return live time [s]
332 */
333 inline double getLivetime(const JMultipleFileScanner_t& file_list)
334 {
335 return getLivetime(file_list.begin(), file_list.end());
336 }
337}
338
339#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.
Object reading from file.
Auxiliary interface for direct access of elements in ROOT TChain.
Template definition for direct access of elements in ROOT TChain.
Range of values.
Definition JRange.hh:42
bool is_valid() const
Check validity of range.
Definition JRange.hh:311
static JRange< int, std::less< int > > DEFAULT_RANGE()
Definition JRange.hh:555
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
range_type & combine(const range_type &range)
Combine ranges.
Definition JRange.hh:432
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.
void for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Definition JTypeList.hh:414
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Support classes and methods for experiment specific I/O.
double getTimeDuration(const JDAQUTCTimeRange &utc)
Get time duration of given UTC time range.
JTOOLS::JRange< JDAQUTCExtended > JDAQUTCTimeRange
Type definition for DAQ UTC time range.
double getLivetime(const std::string &file_name)
Get data taking live time.
bool isROOTFile(const char *file_name)
Check file format.
JDAQUTCTimeRange getUTCTimeRange()
Get UTC time range.
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.
JTOOLS::JRange< int > JFrameIndexRange
Type definition for frame index range.
JFrameIndexRange getFrameIndexRange(JTreeScannerInterface< T, KM3NETDAQ::JDAQEvaluator > &in)
Get range of frame indices.
return result
Definition JPolint.hh:862
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
virtual const pointer_type & next() override
Get next element.
virtual bool hasNext() override
Check availability of next element.
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
Auxiliary class for a type holder.
Definition JType.hh:19
Auxiliary base class for list of file names.
Auxiliary class to extract UTC time range for list of data types.
void operator()(const JType< T > &type)
Process internal file for given data type.
JMultiplexDAQUTCTimeRange(const std::string &file_name)
Constructor.
Timeslice data structure for L1 data.
Timeslice data structure for L2 data.
Timeslice data structure for SN data.