Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMergeEvt.cc File Reference

Example program for merging Monte-Carlo files with compatible headers. More...

#include <iostream>
#include <iomanip>
#include <string>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JeepToolkit.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.hh"
#include "JAAnet/JHead.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program for merging Monte-Carlo files with compatible headers.

Note: Already existing merged files will be overwritten.

Author
bjung

Definition in file JMergeEvt.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JMergeEvt.cc.

31 {
32  using namespace std;
33  using namespace JPP;
34 
35  typedef typename JTYPELIST<Head, JMeta, Evt>::typelist typelist;
36 
37  JMultipleFileScanner_t inputFiles;
38  string outputFile;
39 
40  char wildcard;
41 
42  int debug;
43 
44  try {
45 
46  JParser<> zap;
47 
48  zap['f'] = make_field(inputFiles);
49  zap['o'] = make_field(outputFile) = "%.merged.root";
50  zap['w'] = make_field(wildcard) = '%';
51  zap['d'] = make_field(debug) = 1;
52 
53  zap(argc, argv);
54  }
55  catch(const exception& error) {
56  FATAL(error.what() << endl);
57  }
58 
59  const size_t pos = outputFile.find(wildcard);
60 
61  if (pos == string::npos) {
62  FATAL("Valid wildcard must be specified (<" << outputFile << "> does not contain \'" << wildcard << "\').");
63  }
64 
65 
66  // Create set of files ordered based on header-info
67 
68  JEvtWeightFileScannerSet<> scanners(inputFiles);
69 
70 
71  // Create merged output for all compatible files
72 
73  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
74 
75  const JHead& header = scanner->getHeader();
76 
77  const string identifier = scanners.getUniqueIdentifier(scanner);
78  const string buffer = string(outputFile).replace(pos, 1, identifier.c_str());
79 
80  NOTICE("Writing " << buffer << "..." << endl);
81 
82  JFileRecorder<typelist> out(buffer.c_str());
83 
84  out.open();
85 
86  Head head;
87  copy(header, head);
88  out.put(head);
89 
90  out.put(JMeta(argc, argv));
91 
92  for (JMultipleFileScanner<JMeta> in(scanner->getFilelist()); in.hasNext(); ) {
93  out.put(*in.next());
94  }
95 
96  while (scanner->hasNext()) {
97 
98  const Evt* event = scanner->next();
99 
100  if (event != NULL) {
101 
102  STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl);
103  out.put(*event);
104 
105  } else {
106 
107  WARNING("Event " << scanner->getCounter() << " is empty; skip.");
108  }
109  }
110 
111  out.close();
112  }
113 
114  return 0;
115 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1500
#define WARNING(A)
Definition: JMessage.hh:65
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1146
#define STATUS(A)
Definition: JMessage.hh:63
string outputFile
std::vector< value_type >::iterator iterator
Type list.
Definition: JTypeList.hh:22
#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
Monte Carlo run header.
Definition: JHead.hh:1113
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:67
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary base class for list of file names.
General purpose class for object reading from a list of file names.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
virtual void open(const char *file_name) override
Open file.
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
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:41
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19