Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JMergeEvt.cc File Reference

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

#include <uuid/uuid.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <deque>
#include <queue>
#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 "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JMultiHead.hh"
#include "JReconstruction/JEvt.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.hh"
#include "JSupport/JMonteCarloFileSupportkit.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, mdejong

Definition in file JMergeEvt.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 90 of file JMergeEvt.cc.

91{
92 using namespace std;
93 using namespace JPP;
94 using namespace KM3NETDAQ;
95
97
98
99 JMultipleFileScanner_t inputFiles;
101
102 int debug;
103
104 try {
105
106 JParser<> zap;
107
108 zap['f'] = make_field(inputFiles);
109 zap['o'] = make_field(outputFile) = "merged.root";
110 zap['d'] = make_field(debug) = 1;
111
112 zap(argc, argv);
113 }
114 catch(const exception& error) {
115 FATAL(error.what() << endl);
116 }
117
118
119 outputFile.open();
120
121 outputFile.put(JMeta(argc, argv));
122
123 // Create set of filescanners ordered based on header-info
124
125 JEvtWeightFileScannerSet<> scanners(inputFiles);
126
127 if (scanners.empty()) {
128 FATAL("File scanner set is empty");
129 }
130
131 // Merge multi-headers and obtain common header
132
133 const JHead& firstHeader = scanners.begin()->getHeader();
134 JHead commonHeader = firstHeader;
135 JMultiHead eventHeaders = getMultiHeader(inputFiles);
136
137 eventHeaders.merge(firstHeader);
138
139 for (JEvtWeightFileScannerSet<>::iterator scanner = next(scanners.begin()); scanner != scanners.end(); ++scanner) {
140
141 JHead header = scanner->getHeader();
142 commonHeader = commonHeader.getMatch(header);
143
144 eventHeaders.insert(header);
145 }
146
147 eventHeaders.merge();
148
149 outputFile.put(static_cast<const MultiHead&>(eventHeaders));
150
151 {
152 Head buffer;
153
154 copy(commonHeader, buffer);
155
156 outputFile.put(buffer);
157 }
158
159
161
163
164 for (JEvtWeightFileScannerSet<>::iterator i = scanners.begin(); i != scanners.end(); ++i) {
165 in.push_back(JTreeScanner_t(i->getFilelist()));
166 }
167
168 counter_type number_of_events = 0;
169
170 for (const auto& i : in) {
171 number_of_events += i.getEntries();
172 }
173
174
175 // Update event-weight normalisations
176
177 auto getEvt = [eventHeaders, scanners](const entry_type& top) {
178
179 Evt out = top.evt;
180
181 if (out.w.size() <= WEIGHTLIST_NORMALISATION) {
182 out.w.resize(WEIGHTLIST_NORMALISATION + 1, 0.0);
183 }
184
185 const JUUID headerUUID = (uuid_is_null(out.header_uuid) == 0 ? // is valid
186 eventHeaders.getHeaderUUID(out) : scanners[top.index].getHeader().UUID);
187
188 out.w[WEIGHTLIST_NORMALISATION] = eventHeaders.getNormalisation(headerUUID);
189
190 uuid_copy(out.header_uuid, headerUUID.uuid);
191
192 return out;
193 };
194
195
196 priority_queue<entry_type, deque<entry_type> > buffer; // multiplex
197
198 for (size_t i = 0; i != in.size(); ++i) {
199
200 if (in[i].hasNext()) {
201
202 buffer.push({i, *in[i].next()});
203
204 --number_of_events;
205 }
206 }
207
208 while (number_of_events != 0) { // process
209
210 STATUS("event: " << setw(10) << number_of_events << '\r'); DEBUG(endl);
211
212 const entry_type& top = buffer.top();
213
214 outputFile.put(getEvt(top));
215
216 if (in[top.index].hasNext()) {
217
218 buffer.push({top.index, *in[top.index].next()});
219
220 --number_of_events;
221 }
222
223 buffer.pop();
224 }
225
226 while (!buffer.empty()) { // flush
227
228 const entry_type& top = buffer.top();
229
230 outputFile.put(getEvt(top));
231
232 buffer.pop();
233 }
234
236
237 io >> outputFile;
238
239 outputFile.close();
240
241 return 0;
242}
string outputFile
#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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Monte Carlo run header.
Definition JHead.hh:1236
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.
Base class for JTreeScanner.
Template definition for direct access of elements in ROOT TChain.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
JEvt getEvt(const JHead &header, const JModel &model)
Get event.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Long64_t counter_type
Type definition for counter.
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
bool insert(const JHead &header)
Insert the given header.
Definition JMultiHead.hh:69
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 data structure to convert model to 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.
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