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

Application for merging Monte-Carlo files. More...

#include <uuid/uuid.h>
#include <iostream>
#include <iomanip>
#include <string>
#include "km3net-dataformat/definitions/weightlist.hh"
#include "km3net-dataformat/offline/MultiHead.hh"
#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"
#include "JROOT/JRootFileWriter.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Application for merging Monte-Carlo files.

Author
bjung

Definition in file JMergeEvt.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file JMergeEvt.cc.

35 {
36  using namespace std;
37  using namespace JPP;
38 
39  typedef typename JTYPELIST<MultiHead, Head, JMeta, Evt>::typelist typelist;
40 
41  JMultipleFileScanner_t inputFiles;
42  string outputFile;
43 
44  int debug;
45 
46  try {
47 
48  JParser<> zap;
49 
50  zap['f'] = make_field(inputFiles);
51  zap['o'] = make_field(outputFile) = "merged.root";
52  zap['d'] = make_field(debug) = 1;
53 
54  zap(argc, argv);
55  }
56  catch(const exception& error) {
57  FATAL(error.what() << endl);
58  }
59 
60 
61  // Create set of files ordered based on header-info
62 
63  JEvtWeightFileScannerSet<> scanners(inputFiles);
64 
65 
66  // Create merged output for all compatible files
67 
69 
70  out.open();
71 
72  out.put(JMeta(argc, argv));
73 
74  JHead commonHeader = scanners.begin()->getHeader();
75 
76  MultiHead eventHeaders;
77 
78  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
79 
80  // Add header legacy information
81 
82  JHead header = scanner->getHeader();
83  header.createUUID(); // Ensure UUID is set
84 
85  Head head;
86  copy(header, head);
87 
88  eventHeaders.push_back(head);
89 
90  commonHeader = commonHeader.getMatch(header);
91 
92  // Add event-weight normalisations
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 
102  Evt copy = *event;
103 
104  uuid_copy(copy.header_uuid, header.UUID.uuid); // Copy UUID of corresponding header
105 
106  copy.w.resize(WEIGHTLIST_NORMALISATION+1); // Store event rate normalisation
107  copy.w.at(WEIGHTLIST_NORMALISATION) = scanner->getNormalisation();
108 
109  out.put(copy);
110 
111  } else {
112 
113  WARNING("Event " << scanner->getCounter() << " is empty; skip.");
114  }
115  }
116  }
117 
118  Head newHead;
119  copy(commonHeader, newHead);
120 
121  out.put(newHead);
122 
123  out.put(eventHeaders);
124 
125  out.close();
126 
127  return 0;
128 }
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:1514
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1256
#define STATUS(A)
Definition: JMessage.hh:63
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:42
string outputFile
void createUUID()
Create UUID if not already set.
Definition: JHead.hh:1287
Type list.
Definition: JTypeList.hh:22
JUUID UUID
Definition: JHead.hh:1567
uuid_t header_uuid
UUID of header containing the event-weight information.
Definition: Evt.hh:35
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Monte Carlo run header.
Definition: JHead.hh:1221
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
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
virtual void open(const char *file_name) override
Open file.
static const int WEIGHTLIST_NORMALISATION
Event rate normalisation.
Definition: weightlist.hh:16
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
uuid_t uuid
Definition: JUUID.hh:161
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