Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JSortEvt.cc
Go to the documentation of this file.
1#include <unistd.h>
2#include <iostream>
3#include <iomanip>
4#include <string>
5
8
9#include "Jeep/JPrint.hh"
10#include "Jeep/JParser.hh"
11#include "Jeep/JMessage.hh"
12#include "Jeep/JeepToolkit.hh"
13
14#include "JDAQ/JDAQEventIO.hh"
17
18#include "JSupport/JMeta.hh"
19#include "JSupport/JSupport.hh"
23
25
27
28#include "JAAnet/JHead.hh"
29
30#include "TTree.h"
31
32
33/**
34 * \file
35 * Example program for sorting and merging Monte-Carlo files with compatible headers.
36 *
37 * Note: Already existing merged files will be overwritten.
38 *
39 * \author bjung
40 */
41int main(int argc, char **argv)
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
Recording of objects on file according a format that follows from the file name extension.
General purpose messaging.
#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
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.
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
int main(int argc, char **argv)
Definition JSortEvt.cc:41
ROOT TTree parameter settings of various packages.
Auxiliary methods for handling file names, type names and environment.
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.
virtual void open(const char *file_name) override
Open 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
virtual void close() override
Close device.
virtual bool put(const T &object) override
Object output.
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.