Jpp  17.1.0
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;
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) = 1;
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 double T_ns = (total.getUpperLimit().getTimeNanoSecond() -
334  total.getLowerLimit().getTimeNanoSecond()) / numberOfFiles.total;
335 
336  for (double t1 = total.getLowerLimit().getTimeNanoSecond(); t1 < total.getUpperLimit().getTimeNanoSecond(); t1 += T_ns) {
337  ranges.push_back(JDAQUTCTimeRange(JDAQUTCExtended(t1), JDAQUTCExtended(t1 + T_ns)));
338  }
339  }
340 
341 
343 
344  JCopyMaster<JDAQTypes_t> master(inputFile, selection);
345 
346  const int width = (int) (log10(ranges.size() + 1) + 1);
347 
348  for (size_t i = 0; i != ranges.size(); ++i) {
349 
350  if (numberOfFiles.index == numberOfFiles.invalid || numberOfFiles.index == i) {
351 
352  const string file_name = MAKE_STRING(outputFile.substr(0,pos) << FILL(width,'0') << i << FILL() << outputFile.substr(pos+1));
353 
354  STATUS("Writing " << file_name << "... " << flush);
355 
356  master.open(file_name.c_str());
357 
358  master.put(JMeta(argc, argv));
359  master.put(getTriggerParameters(inputFile));
360 
361  master.copy(ranges[i]);
362 
363  master.close();
364 
365  STATUS("OK" << endl);
366  }
367  }
368 }
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:1500
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:66
string outputFile
Data structure for UTC time.
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
set_variable E_E log10(E_{fit}/E_{#mu})"
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:67
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:685
#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.