Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JSortEvt.cc File Reference

Example program for sorting and merging Monte-Carlo files with compatible headers. More...

#include <unistd.h>
#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"
#include "TTree.h"

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 41 of file JSortEvt.cc.

42{
43 using namespace std;
44 using namespace JPP;
45
47
48 JMultipleFileScanner_t inputFiles;
49 string outputFile;
50
51 char wildcard;
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['w'] = make_field(wildcard) = '%';
62 zap['d'] = make_field(debug) = 1;
63
64 zap(argc, argv);
65 }
66 catch(const exception& error) {
67 FATAL(error.what() << endl);
68 }
69
70
71 TTree::SetMaxTreeSize(1000000000000LL); // Set maximum tree size to 1TB
72
73 const size_t pos = outputFile.find(wildcard);
74
75 if (pos == string::npos) {
76 FATAL("Valid wildcard must be specified (<" << outputFile << "> does not contain \'" << wildcard << "\').");
77 }
78
79
80 // Create set of files ordered based on header-info
81
82 JEvtWeightFileScannerSet<> scanners(inputFiles);
83
84
85 // Create merged output for all compatible files
86
87 const size_t Ndigits = to_string(scanners.size()).size();
88
89 for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
90
91 const size_t Nfile = distance(scanners.begin(), scanner);
92
93 const string filename = string(outputFile).replace(pos, 1, MAKE_STRING(setfill('0') << setw(Ndigits) << Nfile));
94
95 NOTICE("Writing " << filename << "..." << endl);
96
97 if (scanner->getFilelist().size() == 1 &&
98 symlink(scanner->getFilename().c_str(), filename.c_str()) == 0) {
99 continue;
100 }
101
102 JFileRecorder<typelist> out(filename.c_str());
103
104 out.open();
105
106 const Head& head = getHeader(scanner->getFilename());
107
108 out.put(head);
109
110 out.put(JMeta(argc, argv));
111
112 while (scanner->hasNext()) {
113
114 const Evt* event = scanner->next();
115
116 if (event != NULL) {
117
118 STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl);
119 out.put(*event);
120
121 } else {
122
123 WARNING("Event " << scanner->getCounter() << " is empty; skip.");
124 }
125 }
126
128
129 io >> out;
130
131 out.close();
132 }
133
134 return 0;
135}
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:72
#define WARNING(A)
Definition JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
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.
std::string to_string(const T &value)
Convert value to string.
@ 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.
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.