Jpp - 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"
14 #include "JTools/JRange.hh"
16 #include "JSupport/JFileScanner.hh"
17 #include "JSupport/JTreeScanner.hh"
19 
20 
21 /**
22  * \file
23  * Support methods.
24  * \author mdejong
25  */
26 namespace JSUPPORT {}
27 namespace JPP { using namespace JSUPPORT; }
28 
29 namespace JSUPPORT {
30 
32 
33 
34  /**
35  * Type definition for frame index range.
36  */
38 
39  /**
40  * Type definition for DAQ UTC time range.
41  */
43 
44 
45  /**
46  * Get time duration of given UTC time range.
47  *
48  * \param utc UTC time range
49  * \return time duration [s]
50  */
51  inline double getTimeDuration(const JDAQUTCTimeRange& utc)
52  {
53  if (utc.is_valid())
54  return (utc.getUpperLimit().getTimeNanoSecond() -
55  utc.getLowerLimit().getTimeNanoSecond()) * 1.0e-9;
56  else
57  return 0.0;
58  }
59 
60 
61  /**
62  * Get run number for given file name of data taking run.
63  *
64  * \param file_name file name
65  * \return run number
66  */
67  template<class T>
68  inline int getRunNumber(const std::string& file_name)
69  {
70  JFileScanner<T> in(file_name.c_str());
71 
72  if (in.hasNext())
73  return in.next()->getRunNumber();
74  else
75  return -1;
76  }
77 
78 
79  /**
80  * Get range of frame indices.
81  *
82  * \param in TTree scanner
83  * \return frame index range
84  */
85  template<class T>
87  {
88  if (!in.empty())
89  return JFrameIndexRange(in.begin()->getFrameIndex(), in.rbegin()->getFrameIndex());
90  else
91  return JFrameIndexRange(0,0);
92  }
93 
94 
95  /**
96  * Get range of frame indices for given file name of data taking run.
97  *
98  * \param file_name file name
99  * \return frame index range
100  */
101  template<class T>
102  inline JFrameIndexRange getFrameIndexRange(const std::string& file_name)
103  {
105 
106  TDirectory*& dir = TDirectory::CurrentDirectory();
107 
108  if (isROOTFile(file_name.c_str())) {
109 
111 
112  return getFrameIndexRange(in);
113 
114  } else {
115 
116  JFileScanner<T> in(file_name.c_str());
117 
118  while (in.hasNext()) {
119  result.include(in.next()->getFrameIndex());
120  }
121  }
122 
123  if (dir != NULL) {
124  dir->cd(); // restore current working directory
125  }
126 
127  return result;
128  }
129 
130 
131  /**
132  * Get UTC time range.
133  *
134  * \param in TTree scanner
135  * \return UTC time range
136  */
137  template<class T>
139  {
140  if (!in.empty())
141  return JDAQUTCTimeRange(in.begin()->getTimesliceStart(), in.rbegin()->getTimesliceStart());
142  else
144  }
145 
146 
147  /**
148  * Get UTC time range for given file name of data taking run.
149  *
150  * \param file_name file name
151  * \return UTC time range
152  */
153  template<class T>
154  inline JDAQUTCTimeRange getUTCTimeRange(const std::string& file_name)
155  {
157 
158  TDirectory*& dir = TDirectory::CurrentDirectory();
159 
160  if (isROOTFile(file_name.c_str())) {
161 
163 
164  result = getUTCTimeRange(in);
165 
166  } else {
167 
168  for (JFileScanner<T> in(file_name.c_str()); in.hasNext(); ) {
169  result.include(in.next()->getTimesliceStart());
170  }
171  }
172 
173  if (dir != NULL) {
174  dir->cd(); // restore current working directory
175  }
176 
177  return result;
178  }
179 
180 
181  /**
182  * Get UTC time range for given file name of data taking run.
183  * Get data taking live time.
184  *
185  * \param __begin begin of file list
186  * \param __end end of file list
187  * \return UTC time range
188  */
189  template<class T>
190  inline JDAQUTCTimeRange getUTCTimeRange(T __begin, T __end)
191  {
193 
194  for (T i = __begin; i != __end; ++i) {
195  result.combine(getUTCTimeRange<KM3NETDAQ::JDAQSummaryslice>(*i));
196  }
197 
198  return result;
199  }
200 
201 
202  /**
203  * Get data taking live time.
204  *
205  * \param file_name file name
206  * \return live time [s]
207  */
208  inline double getLivetime(const std::string& file_name)
209  {
210  using namespace KM3NETDAQ;
211  using namespace JTRIGGER;
212 
213  TDirectory*& dir = TDirectory::CurrentDirectory();
214 
215  double livetime = 0.0;
216 
217  try {
218 
220 
221  if (parameters.writeSummary.prescale != 0) {
222 
224 
225  livetime = in.getEntries() * getFrameTime() * 1.0e-9 / parameters.writeSummary.prescale;
226  }
227  }
228  catch(const std::exception& error) {}
229 
230  if (dir != NULL) {
231  dir->cd(); // restore current working directory
232  }
233 
234  return livetime;
235  }
236 
237 
238  /**
239  * Get data taking live time.
240  *
241  * \param __begin begin of file list
242  * \param __end end of file list
243  * \return live time [s]
244  */
245  template<class T>
246  inline double getLivetime(T __begin, T __end)
247  {
248  double livetime = 0.0;
249 
250  for (T i = __begin; i != __end; ++i) {
251  livetime += getLivetime(*i);
252  }
253 
254  return livetime;
255  }
256 }
257 
258 #endif
static const JRange< int, std::less< int > > DEFAULT_RANGE
Default range.
Definition: JRange.hh:568
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
JDAQUTCTimeRange getUTCTimeRange(JTreeScanner< T, KM3NETDAQ::JDAQEvaluator > &in)
Get UTC time range.
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:38
Specifications of file name extensions.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.