Jpp  18.0.1-rc.2
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 "JAAnet/JHead.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.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 31 of file JMergeEvt.cc.

32 {
33  using namespace std;
34  using namespace JPP;
35 
36  typedef typename JTYPELIST<JAAnetTypes_t, JMetaTypes_t>::typelist typelist;
37 
38  JMultipleFileScanner_t inputFiles;
40 
41  int debug;
42 
43  try {
44 
45  JParser<> zap;
46 
47  zap['f'] = make_field(inputFiles);
48  zap['o'] = make_field(outputFile) = "merged.root";
49  zap['d'] = make_field(debug) = 1;
50 
51  zap(argc, argv);
52  }
53  catch(const exception& error) {
54  FATAL(error.what() << endl);
55  }
56 
57 
58  // Create set of files ordered based on header-info
59 
60  JEvtWeightFileScannerSet<> scanners(inputFiles);
61 
62  // Create merged output for all compatible files
63 
64  outputFile.open();
65 
66  outputFile.put(JMeta(argc, argv));
67 
68  JHead commonHeader = scanners.begin()->getHeader();
69 
70  MultiHead eventHeaders;
71 
72  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
73 
74  // Add header legacy information
75 
76  JHead header = scanner->getHeader();
77  header.createUUID(); // Ensure UUID is set
78 
79  Head head;
80  copy(header, head);
81 
82  eventHeaders.push_back(head);
83 
84  commonHeader = commonHeader.getMatch(header);
85 
86  // Add event-weight normalisations
87 
88  while (scanner->hasNext()) {
89 
90  const Evt* event = scanner->next();
91 
92  if (event != NULL) {
93 
94  STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl);
95 
96  Evt out = *event;
97 
98  uuid_copy(out.header_uuid, header.UUID.uuid);
99 
100  if (out.w.size() <= WEIGHTLIST_NORMALISATION) {
101  out.w.resize(WEIGHTLIST_NORMALISATION + 1, 0.0);
102  }
103 
104  out.w[WEIGHTLIST_NORMALISATION] = scanner->getNormalisation(*event);
105 
106  outputFile.put(out);
107 
108  } else {
109 
110  WARNING("Event " << scanner->getCounter() << " is empty; skip.");
111  }
112  }
113  }
114 
115  Head newHead;
116  copy(commonHeader, newHead);
117 
118  outputFile.put(newHead);
119 
120  for (JMultipleFileScanner<MultiHead> in(inputFiles); in.hasNext(); ) {
121 
122  const MultiHead& multiHead = *in.next();
123 
124  eventHeaders.join(multiHead);
125  }
126 
127  outputFile.put(eventHeaders);
128 
129  JMultipleFileScanner<JMetaTypes_t> io(inputFiles);
130 
131  io >> outputFile;
132 
133  outputFile.close();
134 
135  return 0;
136 }
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
General purpose class for object reading from a list of file names.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
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 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