Jpp  19.0.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 "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "JReconstruction/JEvt.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 38 of file JSortEvt.cc.

39 {
40  using namespace std;
41  using namespace JPP;
42 
44 
45  JMultipleFileScanner_t inputFiles;
46  string outputFile;
47 
48  char wildcard;
49 
50  int debug;
51 
52  try {
53 
54  JParser<> zap;
55 
56  zap['f'] = make_field(inputFiles);
57  zap['o'] = make_field(outputFile) = "%.merged.root";
58  zap['w'] = make_field(wildcard) = '%';
59  zap['d'] = make_field(debug) = 1;
60 
61  zap(argc, argv);
62  }
63  catch(const exception& error) {
64  FATAL(error.what() << endl);
65  }
66 
67  const size_t pos = outputFile.find(wildcard);
68 
69  if (pos == string::npos) {
70  FATAL("Valid wildcard must be specified (<" << outputFile << "> does not contain \'" << wildcard << "\').");
71  }
72 
73 
74  // Create set of files ordered based on header-info
75 
76  JEvtWeightFileScannerSet<> scanners(inputFiles);
77 
78 
79  // Create merged output for all compatible files
80 
81  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
82 
83  const string identifier = scanners.getUniqueIdentifier(scanner);
84  const string name = string(outputFile).replace(pos, 1, identifier.c_str());
85 
86  NOTICE("Writing " << name << "..." << endl);
87 
88  JFileRecorder<typelist> out(name.c_str());
89 
90  out.open();
91 
92  const Head& head = getHeader(scanner->getFilename());
93 
94  out.put(head);
95 
96  out.put(JMeta(argc, argv));
97 
98  for (JMultipleFileScanner<JMeta> in(scanner->getFilelist()); in.hasNext(); ) {
99  out.put(*in.next());
100  }
101 
102  while (scanner->hasNext()) {
103 
104  const Evt* event = scanner->next();
105 
106  if (event != NULL) {
107 
108  STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl);
109  out.put(*event);
110 
111  } else {
112 
113  WARNING("Event " << scanner->getCounter() << " is empty; skip.");
114  }
115  }
116 
118 
119  io >> out;
120 
121  out.close();
122  }
123 
124  return 0;
125 }
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:1711
#define WARNING(A)
Definition: JMessage.hh:65
#define STATUS(A)
Definition: JMessage.hh:63
string outputFile
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
#define NOTICE(A)
Definition: JMessage.hh:64
then fatal The output file must have the wildcard in the name
Definition: JCanberra.sh:31
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary base class for list of file names.
std::vector< filescanner_type >::iterator iterator
Data structure for set of track fit results.
General purpose class for object reading from a list of file names.
then fatal The output file must have the wildcard in the e g root fi 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:48
virtual void open(const char *file_name) override
Open file.
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
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