Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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;
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 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1514
then echo Test string reversed by master(hit< return > to continue)." $DIR/JProcess -c "$DIR/JEcho" -rC fi if (( 1 ))
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary class for ROOT class selection.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
string outputFile
Data structure for UTC time.
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
set_variable E_E log10(E_{fit}/E_{#mu})"
double getTimeDifference(const JDAQChronometer &first, const JDAQChronometer &second)
Get time difference between two chronometers.
#define NOTICE(A)
Definition: JMessage.hh:64
then awk string
Range of values.
Definition: JRange.hh:38
JTOOLS::JRange< JDAQUTCExtended > JDAQUTCTimeRange
Type definition for DAQ UTC time range.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
JRange< T, JComparator_t > combine(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Combine ranges.
Definition: JRange.hh:676
#define FATAL(A)
Definition: JMessage.hh:67
do echo n Creating graphics for string $STRING for((FLOOR=$FIRST_FLOOR;$FLOOR<=$LAST_FLOOR;FLOOR+=1))
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
int debug
debug level