Jpp  19.1.0
the software that should make you happy
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

◆ main()

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 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define WARNING(A)
Definition: JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Data structure for set of track fit results.
Utility class to parse command line options.
Definition: JParser.hh:1698
Object writing to file.
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
@ RIGHT
Definition: JTwosome.hh:18
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
std::vector< filescanner_type >::iterator iterator
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72
Auxiliary base class for list of file names.