Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JMergeEvt.cc
Go to the documentation of this file.
1#include <uuid/uuid.h>
2#include <iostream>
3#include <iomanip>
4#include <string>
5
7
11
12#include "JDAQ/JDAQEventIO.hh"
15
17
18#include "Jeep/JPrint.hh"
19#include "Jeep/JParser.hh"
20#include "Jeep/JMessage.hh"
21
22#include "JAAnet/JHead.hh"
23#include "JAAnet/JMultiHead.hh"
24
26
27#include "JSupport/JMeta.hh"
28#include "JSupport/JSupport.hh"
33
34
35/**
36 * \file
37 * Application for merging Monte-Carlo files.
38 *
39 * \author bjung
40 */
41int main(int argc, char **argv)
42{
43 using namespace std;
44 using namespace JPP;
45 using namespace KM3NETDAQ;
46
48
49
50 JMultipleFileScanner_t inputFiles;
52
53 int debug;
54
55 try {
56
57 JParser<> zap;
58
59 zap['f'] = make_field(inputFiles);
60 zap['o'] = make_field(outputFile) = "merged.root";
61 zap['d'] = make_field(debug) = 1;
62
63 zap(argc, argv);
64 }
65 catch(const exception& error) {
66 FATAL(error.what() << endl);
67 }
68
69
70 outputFile.open();
71
72 outputFile.put(JMeta(argc, argv));
73
74 // Create set of filescanners ordered based on header-info
75
76 JEvtWeightFileScannerSet<> scanners(inputFiles);
77
78 JHead commonHeader = scanners.begin()->getHeader();
79
80 // Merge multi-headers
81
82 JMultiHead eventHeaders = getMultiHeader(inputFiles);
83
84 for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
85
86 JHead header = scanner->getHeader();
87 header.createUUID(); // Ensure UUID is set
88
89 commonHeader = commonHeader.getMatch(header);
90
91 eventHeaders.merge(header);
92
93 // Add event-weight normalisations
94
95 while (scanner->hasNext()) {
96
97 STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl);
98
99 const Evt* event = scanner->next();
100
101 Evt out = *event;
102
103 // Update event-weight normalisation
104
105 if (out.w.size() <= WEIGHTLIST_NORMALISATION) {
106 out.w.resize(WEIGHTLIST_NORMALISATION + 1, 0.0);
107 }
108
109 const JUUID headerUUID = (uuid_is_null(event->header_uuid) == 0 ? // is valid
110 eventHeaders.getHeaderUUID(*event) : header.UUID);
111
112 out.w[WEIGHTLIST_NORMALISATION] = eventHeaders.getNormalisation(headerUUID);
113
114 uuid_copy(out.header_uuid, headerUUID.uuid);
115
116 outputFile.put(out);
117 }
118 }
119
120 Head newHead;
121 copy(commonHeader, newHead);
122
123 outputFile.put(newHead);
124
125 outputFile.put(static_cast<const MultiHead&>(eventHeaders));
126
128
129 io >> outputFile;
130
131 outputFile.close();
132
133 return 0;
134}
string outputFile
Recording of objects on file according a format that follows from the file name extension.
int main(int argc, char **argv)
Definition JMergeEvt.cc:41
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
ROOT I/O of application specific meta data.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
ROOT TTree parameter settings of various packages.
Monte Carlo run header.
Definition JHead.hh:1236
void createUUID()
Create UUID if not already set.
Definition JHead.hh:1301
const JHead & getHeader() const
Get header.
Definition JHead.hh:1270
JHead getMatch(const JHead &header) const
Get matching fields.
Definition JHead.hh:1410
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.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
@ RIGHT
Definition JTwosome.hh:18
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JMultiHead getMultiHeader(const JMultipleFileScanner_t &file_list)
Get multi-header corresponding to a given file list.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
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
uuid_t header_uuid
UUID of header containing the event-weight information.
Definition Evt.hh:35
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
Auxiliary data structure to store multiple headers and bookkeep event-weight normalisations.
Definition JMultiHead.hh:39
void merge(const JHead &header)
Merge the given header into this object.
Definition JMultiHead.hh:56
double getNormalisation(const JUUID &UUID) const
Get normalisation for given header UUID.
JUUID getHeaderUUID(const Evt &event) const
Get the header UUID corresponding to the given event.
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
Simple wrapper for UUID.
Definition JUUID.hh:24
uuid_t uuid
Definition JUUID.hh:172
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.
static const int WEIGHTLIST_NORMALISATION
Event rate normalisation.
Definition weightlist.hh:16