Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JDAQSplit.cc File Reference

Auxiliary program to split data. More...

#include <string>
#include <iostream>
#include <iomanip>
#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 data.

Author
mdejong

Definition in file JDAQSplit.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 203 of file JDAQSplit.cc.

204 {
205  using namespace std;
206  using namespace JPP;
207 
208  typedef vector<JDAQUTCTimeRange> ranges_type;
209 
210  std::string inputFile;
211  std::string outputFile;
212  size_t numberOfFiles;
213  ranges_type ranges;
214  JROOTClassSelection selection = getROOTClassSelection<JDAQTypes_t>();
215  int debug;
216 
217  try {
218 
219  JParser<> zap("Auxiliary program to split data.");
220 
221  zap['f'] = make_field(inputFile);
222  zap['o'] = make_field(outputFile);
223  zap['N'] = make_field(numberOfFiles) = 0;
224  zap['r'] = make_field(ranges) = JPARSER::initialised();
225  zap['C'] = make_field(selection,
226  "Precede name of data structure by a '+' or '-' "
227  "to add or remove data types in the output, respectively."
228  "\nROOT wildcards are accepted.") = JPARSER::initialised();
229  zap['d'] = make_field(debug) = 1;
230 
231  zap(argc, argv);
232  }
233  catch(const exception& error) {
234  FATAL(error.what() << endl);
235  }
236 
237 
238  if (numberOfFiles == 0 && ranges.empty()) {
239  FATAL("Invalid splitting " << numberOfFiles << '/' << ranges.size() << endl);
240  }
241 
242  const size_t pos = outputFile.find(WILDCARD);
243 
244  if (pos == string::npos) {
245  FATAL("Output file name " << outputFile << " does not contain wild card '" << WILDCARD << "'" << endl);
246  }
247 
248  const JDAQUTCTimeRange total = getUTCTimeRange<JDAQSummaryslice>(inputFile);
249 
250  if (!total.is_valid()) {
251  FATAL("No (valid) summary data in input file " << inputFile << ' ' << total << endl);
252  }
253 
254  NOTICE("Total time range " << total << endl);
255 
256  if (ranges.empty()) {
257 
258  const double length = (total.getUpperLimit().getTimeNanoSecond() -
259  total.getLowerLimit().getTimeNanoSecond()) / numberOfFiles;
260 
261  for (double t1 = total.getLowerLimit().getTimeNanoSecond(); t1 < total.getUpperLimit().getTimeNanoSecond(); t1 += length) {
262  ranges.push_back(JDAQUTCTimeRange(JDAQUTCExtended(t1), JDAQUTCExtended(t1 + length)));
263  }
264  }
265 
266 
268 
269  JCopyMaster<JDAQTypes_t> master(inputFile, selection);
270 
271  const int width = (int) (log10(ranges.size() + 1) + 1);
272 
273  for (size_t i = 0; i != ranges.size(); ++i) {
274 
275  const string file_name = MAKE_STRING(outputFile.substr(0,pos) << FILL(width,'0') << i << FILL() << outputFile.substr(pos+1));
276 
277  STATUS("Writing " << file_name << endl);
278 
279  master.open(file_name.c_str());
280 
281  master.put(getTriggerParameters(inputFile));
282 
283  master.copy(ranges[i]);
284 
285  master.close();
286  }
287 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary class for ROOT class selection.
then echo Test string reversed by master(hit< return > to continue)." JProcess -c "JEcho" -rC fi if (( 1 ))
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
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
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:327
#define FATAL(A)
Definition: JMessage.hh:67
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.