Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
JSortHeaders.cc File Reference

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

#include <unistd.h>
#include <iostream>
#include <iomanip>
#include <string>
#include "km3net-dataformat/offline/Head.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.hh"
#include "JAAnet/JHead.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

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

Author
bjung

Definition in file JSortHeaders.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 25 of file JSortHeaders.cc.

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
#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
#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.
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.