Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
JSortHeaders.cc
Go to the documentation of this file.
1#include <unistd.h>
2#include <iostream>
3#include <iomanip>
4#include <string>
5
7
8#include "Jeep/JPrint.hh"
9#include "Jeep/JParser.hh"
10#include "Jeep/JMessage.hh"
11
12#include "JSupport/JSupport.hh"
15
16#include "JAAnet/JHead.hh"
17
18
19/**
20 * \file
21 * Example program for sorting Monte-Carlo files with compatible headers.
22 *
23 * \author bjung
24 */
25int main(int argc, char **argv)
26{
27 using namespace std;
28 using namespace JPP;
29
30 JMultipleFileScanner_t inputFiles;
31
32 string outputFile;
33 char wildcard;
34
35 int debug;
36
37 try {
38
39 JParser<> zap;
40
41 zap['f'] = make_field(inputFiles);
42 zap['o'] = make_field(outputFile) = "";
43 zap['w'] = make_field(wildcard) = '%';
44 zap['d'] = make_field(debug) = 1;
45
46 zap(argc, argv);
47 }
48 catch(const exception& error) {
49 FATAL(error.what() << endl);
50 }
51
52
53 const size_t pos = outputFile.find(wildcard);
54
55 if (!outputFile.empty() && pos == string::npos) {
56 FATAL("Valid wildcard must be specified (<" << outputFile << "> does not contain \'" << wildcard << "\').");
57 }
58
59
60 JEvtWeightFileScannerSet<> scanners(inputFiles);
61
62 const size_t Ndigits = to_string(scanners.size()).size();
63
64 for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
65
66 const size_t n = distance(scanners.begin(), scanner);
67
68 const JMultipleFileScanner_t& filelist = scanner->getFilelist();
69
70 NOTICE("Header type " << n << ":" << endl);
71 DEBUG (endl << scanner->getHeader() << endl);
72 NOTICE("========================" << endl <<
73 filelist <<
74 "========================" << endl << endl);
75
76 if (!outputFile.empty()) {
77
78 const string filename = string(outputFile).replace(pos, 1, MAKE_STRING(setfill('0') << setw(Ndigits) << n));
79
80 ofstream ofs(filename);
81
82 ofs << filelist;
83
84 ofs.close();
85 }
86 }
87
88 return 0;
89}
string outputFile
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
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)
ROOT TTree parameter settings of various packages.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Utility class to parse command line options.
Definition JParser.hh:1698
std::string to_string(const T &value)
Convert value to string.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition JPolint.hh:791
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
std::vector< filescanner_type >::iterator iterator
Auxiliary base class for list of file names.
const JMultipleFileScanner_t & getFilelist() const
Get file list.