Jpp  15.0.1-rc.1-highqe
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"
20 
21 
22 /**
23  * \file
24  * Support methods.
25  * \author mdejong
26  */
27 namespace JSUPPORT {}
28 namespace JPP { using namespace JSUPPORT; }
29 
30 namespace JSUPPORT {
31 
33 
34 
35  /**
36  * Type definition for frame index range.
37  */
39 
40  /**
41  * Type definition for DAQ UTC time range.
42  */
44 
45 
46  /**
47  * Get time duration of given UTC time range.
48  *
49  * \param utc UTC time range
50  * \return time duration [s]
51  */
52  inline double getTimeDuration(const JDAQUTCTimeRange& utc)
53  {
54  if (utc.is_valid())
55  return (utc.getUpperLimit().getTimeNanoSecond() -
56  utc.getLowerLimit().getTimeNanoSecond()) * 1.0e-9;
57  else
58  return 0.0;
59  }
60 
61 
62  /**
63  * Get run number for given file name of data taking run.
64  *
65  * \param file_name file name
66  * \return run number
67  */
68  template<class T>
69  inline int getRunNumber(const std::string& file_name)
70  {
71  JFileScanner<T> in(file_name.c_str());
72 
73  if (in.hasNext())
74  return in.next()->getRunNumber();
75  else
76  return -1;
77  }
78 
79 
80  /**
81  * Get range of frame indices.
82  *
83  * \param in TTree scanner
84  * \return frame index range
85  */
86  template<class T>
88  {
89  if (!in.empty())
90  return JFrameIndexRange(in.begin()->getFrameIndex(), in.rbegin()->getFrameIndex());
91  else
92  return JFrameIndexRange(0,0);
93  }
94 
95 
96  /**
97  * Get range of frame indices for given file name of data taking run.
98  *
99  * \param file_name file name
100  * \return frame index range
101  */
102  template<class T>
103  inline JFrameIndexRange getFrameIndexRange(const std::string& file_name)
104  {
106 
107  TDirectory* dir = TDirectory::CurrentDirectory();
108 
109  if (isROOTFile(file_name.c_str())) {
110 
112 
113  return getFrameIndexRange(in);
114 
115  } else {
116 
117  JFileScanner<T> in(file_name.c_str());
118 
119  while (in.hasNext()) {
120  result.include(in.next()->getFrameIndex());
121  }
122  }
123 
124  if (dir != NULL) {
125  dir->cd(); // restore current working directory
126  }
127 
128  return result;
129  }
130 
131 
132  /**
133  * Get UTC time range.
134  *
135  * \return UTC time range
136  */
138  {
140  }
141 
142 
143  /**
144  * Get UTC time range.
145  *
146  * \param in TTree scanner
147  * \return UTC time range
148  */
149  template<class T>
151  {
152  if (!in.empty())
153  return JDAQUTCTimeRange(in.begin()->getTimesliceStart(), in.rbegin()->getTimesliceStart());
154  else
155  return getUTCTimeRange();
156  }
157 
158 
159  /**
160  * Get UTC time range for given file name of data taking run.
161  *
162  * \param file_name file name
163  * \return UTC time range
164  */
165  template<class T>
166  inline JDAQUTCTimeRange getUTCTimeRange(const std::string& file_name)
167  {
169 
170  TDirectory* dir = TDirectory::CurrentDirectory();
171 
172  if (isROOTFile(file_name.c_str())) {
173 
175 
176  result = getUTCTimeRange(in);
177 
178  } else {
179 
180  for (JFileScanner<T> in(file_name.c_str()); in.hasNext(); ) {
181  result.include(in.next()->getTimesliceStart());
182  }
183  }
184 
185  if (dir != NULL) {
186  dir->cd(); // restore current working directory
187  }
188 
189  return result;
190  }
191 
192 
193  /**
194  * Get UTC time range for given file name of data taking run.
195  * Get data taking live time.
196  *
197  * \param __begin begin of file list
198  * \param __end end of file list
199  * \return UTC time range
200  */
201  template<class T>
202  inline JDAQUTCTimeRange getUTCTimeRange(T __begin, T __end)
203  {
205 
206  for (T i = __begin; i != __end; ++i) {
207 
208  JDAQUTCTimeRange buffer = getUTCTimeRange<KM3NETDAQ::JDAQSummaryslice>(*i);
209 
210  if (buffer == getUTCTimeRange()) {
211  buffer = getUTCTimeRange<KM3NETDAQ::JDAQTimeslice>(*i);
212  }
213 
214  result.combine(buffer);
215  }
216 
217  return result;
218  }
219 
220 
221  /**
222  * Get data taking live time.
223  *
224  * \param file_name file name
225  * \return live time [s]
226  */
227  inline double getLivetime(const std::string& file_name)
228  {
229  using namespace KM3NETDAQ;
230  using namespace JTRIGGER;
231 
232  TDirectory* dir = TDirectory::CurrentDirectory();
233 
234  double livetime = 0.0;
235 
236  try {
237 
239 
240  if (parameters.writeSummary.prescale != 0) {
241 
243 
244  livetime = in.getEntries() * getFrameTime() * 1.0e-9 / parameters.writeSummary.prescale;
245  }
246  }
247  catch(const std::exception& error) {}
248 
249  if (dir != NULL) {
250  dir->cd(); // restore current working directory
251  }
252 
253  return livetime;
254  }
255 
256 
257  /**
258  * Get data taking live time.
259  *
260  * \param __begin begin of file list
261  * \param __end end of file list
262  * \return live time [s]
263  */
264  template<class T>
265  inline double getLivetime(T __begin, T __end)
266  {
267  double livetime = 0.0;
268 
269  for (T i = __begin; i != __end; ++i) {
270  livetime += getLivetime(*i);
271  }
272 
273  return livetime;
274  }
275 }
276 
277 #endif
static const JRange< int, std::less< int > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:568
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:398
*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:433
Data structure for UTC time.
Template definition for direct access of elements in ROOT TChain.
Definition: JTreeScanner.hh:91
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:727
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.
bool is_valid() const
Check validity of range.
Definition: JRange.hh:311
Normalisation of MUPAGE events.
Definition: JHead.hh:768
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:36
JFrameIndexRange getFrameIndexRange(JTreeScanner< T, KM3NETDAQ::JDAQEvaluator > &in)
Get range of frame indices.
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
Specifications of file name extensions.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.