Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JSortEvt.cc File Reference

Example program for sorting and 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 sorting and merging Monte-Carlo files with compatible headers.

Note: Already existing merged files will be overwritten.

Author
bjung

Definition in file JSortEvt.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JSortEvt.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 string identifier = scanners.getUniqueIdentifier(scanner);
76  const string name = string(outputFile).replace(pos, 1, identifier.c_str());
77 
78  NOTICE("Writing " << name << "..." << endl);
79 
80  JFileRecorder<typelist> out(name.c_str());
81 
82  out.open();
83 
84  const Head& head = getHeader(scanner->getFilename());
85 
86  out.put(head);
87 
88  out.put(JMeta(argc, argv));
89 
90  for (JMultipleFileScanner<JMeta> in(scanner->getFilelist()); in.hasNext(); ) {
91  out.put(*in.next());
92  }
93 
94  while (scanner->hasNext()) {
95 
96  const Evt* event = scanner->next();
97 
98  if (event != NULL) {
99 
100  STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl);
101  out.put(*event);
102 
103  } else {
104 
105  WARNING("Event " << scanner->getCounter() << " is empty; skip.");
106  }
107  }
108 
109  out.close();
110  }
111 
112  return 0;
113 }
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:1517
#define STATUS(A)
Definition: JMessage.hh:63
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
string outputFile
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Type list.
Definition: JTypeList.hh:22
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define NOTICE(A)
Definition: JMessage.hh:64
then awk string
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary base class for list of file names.
std::vector< filescanner_type >::iterator iterator
General purpose class for object reading from a list of file names.
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
then echo WARNING
Definition: JTuneHV.sh:91
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62