Jpp  debug
the software that should make you happy
Functions
JDAQSplit.cc File Reference

Auxiliary program to split DAQ data into multiple output files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDAQ/JDAQEvaluator.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "JSupport/JSingleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JTriggerParametersSupportkit.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JSupportToolkit.hh"
#include "JROOT/JROOTClassSelector.hh"
#include "JLang/JSinglePointer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to split DAQ data into multiple output files.

Author
mdejong

Definition in file JDAQSplit.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 271 of file JDAQSplit.cc.

272 {
273  using namespace std;
274  using namespace JPP;
275 
276  typedef vector<JDAQUTCTimeRange> ranges_type;
277 
278  std::string inputFile;
279  std::string outputFile;
280  JSplit numberOfFiles;
281  ranges_type ranges;
282  JROOTClassSelection selection = getROOTClassSelection<JDAQTypes_t>();
283  int debug;
284 
285  try {
286 
287  JParser<> zap("Auxiliary program to split DAQ data into multiple output files.");
288 
289  zap['f'] = make_field(inputFile);
290  zap['o'] = make_field(outputFile);
291  zap['N'] = make_field(numberOfFiles) = JPARSER::initialised();
292  zap['r'] = make_field(ranges,
293  "UTC time range(s)") = JPARSER::initialised();
294  zap['C'] = make_field(selection,
295  "Precede name of data structure by a '+' or '-' "
296  "to add or remove data types in the output, respectively."
297  "\nROOT wildcards are accepted.") = JPARSER::initialised();
298  zap['d'] = make_field(debug) = 2;
299 
300  zap(argc, argv);
301  }
302  catch(const exception& error) {
303  FATAL(error.what() << endl);
304  }
305 
306 
307  if ((numberOfFiles.total == 0 && ranges.empty()) ||
308  (numberOfFiles.total != 0 && !ranges.empty())) {
309  FATAL("Invalid splitting " << numberOfFiles << ' ' << ranges.size() << "; use either option -N or -r." << endl);
310  }
311 
312  const size_t pos = outputFile.find(WILDCARD);
313 
314  if (pos == string::npos) {
315  FATAL("Output file name " << outputFile << " does not contain wild card '" << WILDCARD << "'" << endl);
316  }
317 
318  const JDAQUTCTimeRange total = combine(getUTCTimeRange<JDAQSummaryslice>(inputFile),
319  getUTCTimeRange<JDAQEvent> (inputFile));
320 
321  if (!total.is_valid()) {
322  FATAL("No (valid) summary or event data in input file " << inputFile << ' ' << total << endl);
323  }
324 
325  NOTICE("Total UTC time range " << total << endl);
326 
327  if (!ranges.empty()) {
328 
329  sort(ranges.begin(), ranges.end(), compare);
330 
331  } else {
332 
333  const long double T_ns = ((long double) JDAQUTCExtended::getTick() + 1.0e9l * (long double) getTimeDifference(total.getLowerLimit(), total.getUpperLimit())) / (long double) numberOfFiles.total;
334 
335  for (long double t1 = total.getLowerLimit().getTimeNanoSecond(); t1 < (long double) total.getUpperLimit().getTimeNanoSecond(); t1 += T_ns) {
336  ranges.push_back(JDAQUTCTimeRange(JDAQUTCExtended(t1), JDAQUTCExtended(t1 + T_ns)));
337  }
338  }
339 
340 
342 
343  JCopyMaster<JDAQTypes_t> master(inputFile, selection);
344 
345  const int width = (int) (log10(ranges.size() + 1) + 1);
346 
347  for (size_t i = 0; i != ranges.size(); ++i) {
348 
349  if (numberOfFiles.index == numberOfFiles.invalid || numberOfFiles.index == i) {
350 
351  const string file_name = MAKE_STRING(outputFile.substr(0,pos) << FILL(width,'0') << i << FILL() << outputFile.substr(pos+1));
352 
353  STATUS("Writing " << file_name << ' ' << ranges[i] << "... " << flush);
354 
355  master.open(file_name.c_str());
356 
357  master.put(JMeta(argc, argv));
358  master.put(getTriggerParameters(inputFile));
359 
360  master.copy(ranges[i]);
361 
362  master.close();
363 
364  STATUS("OK" << endl);
365  }
366  }
367 }
string outputFile
#define STATUS(A)
Definition: JMessage.hh:63
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
Utility class to parse command line options.
Definition: JParser.hh:1714
Range of values.
Definition: JRange.hh:42
bool is_valid() const
Check validity of range.
Definition: JRange.hh:311
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
Data structure for UTC time.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JTOOLS::JRange< JDAQUTCExtended > JDAQUTCTimeRange
Type definition for DAQ UTC time range.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
JRange< T, JComparator_t > combine(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Combine ranges.
Definition: JRange.hh:676
for(int i=n/2;i !=0 &&p !=this->end();--i,++p)
Definition: JPolint.hh:788
static const char WILDCARD
Definition: JDAQTags.hh:56
double getTimeDifference(const JDAQChronometer &first, const JDAQChronometer &second)
Get time difference between two chronometers.
Definition: JSTDTypes.hh:14
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:330
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:84
Auxiliary class for ROOT class selection.
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72