Jpp  debug
the software that should make you happy
JSortEvt.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <string>
4 
7 
8 #include "Jeep/JPrint.hh"
9 #include "Jeep/JParser.hh"
10 #include "Jeep/JMessage.hh"
11 #include "Jeep/JeepToolkit.hh"
12 
13 #include "JDAQ/JDAQEventIO.hh"
14 #include "JDAQ/JDAQTimesliceIO.hh"
16 
17 #include "JSupport/JMeta.hh"
18 #include "JSupport/JSupport.hh"
22 
24 
25 #include "JReconstruction/JEvt.hh"
26 
27 #include "JAAnet/JHead.hh"
28 
29 
30 /**
31  * \file
32  * Example program for sorting and merging Monte-Carlo files with compatible headers.
33  *
34  * Note: Already existing merged files will be overwritten.
35  *
36  * \author bjung
37  */
38 int main(int argc, char **argv)
39 {
40  using namespace std;
41  using namespace JPP;
42 
44 
45  JMultipleFileScanner_t inputFiles;
46  string outputFile;
47 
48  char wildcard;
49 
50  int debug;
51 
52  try {
53 
54  JParser<> zap;
55 
56  zap['f'] = make_field(inputFiles);
57  zap['o'] = make_field(outputFile) = "%.merged.root";
58  zap['w'] = make_field(wildcard) = '%';
59  zap['d'] = make_field(debug) = 1;
60 
61  zap(argc, argv);
62  }
63  catch(const exception& error) {
64  FATAL(error.what() << endl);
65  }
66 
67  const size_t pos = outputFile.find(wildcard);
68 
69  if (pos == string::npos) {
70  FATAL("Valid wildcard must be specified (<" << outputFile << "> does not contain \'" << wildcard << "\').");
71  }
72 
73 
74  // Create set of files ordered based on header-info
75 
76  JEvtWeightFileScannerSet<> scanners(inputFiles);
77 
78 
79  // Create merged output for all compatible files
80 
81  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
82 
83  const string identifier = scanners.getUniqueIdentifier(scanner);
84  const string name = string(outputFile).replace(pos, 1, identifier.c_str());
85 
86  NOTICE("Writing " << name << "..." << endl);
87 
88  JFileRecorder<typelist> out(name.c_str());
89 
90  out.open();
91 
92  const Head& head = getHeader(scanner->getFilename());
93 
94  out.put(head);
95 
96  out.put(JMeta(argc, argv));
97 
98  for (JMultipleFileScanner<JMeta> in(scanner->getFilelist()); in.hasNext(); ) {
99  out.put(*in.next());
100  }
101 
102  while (scanner->hasNext()) {
103 
104  const Evt* event = scanner->next();
105 
106  if (event != NULL) {
107 
108  STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl);
109  out.put(*event);
110 
111  } else {
112 
113  WARNING("Event " << scanner->getCounter() << " is empty; skip.");
114  }
115  }
116 
118 
119  io >> out;
120 
121  out.close();
122  }
123 
124  return 0;
125 }
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:69
#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:2158
I/O formatting auxiliaries.
int main(int argc, char **argv)
Definition: JSortEvt.cc:38
ROOT TTree parameter settings of various packages.
Auxiliary methods for handling file names, type names and environment.
Data structure for set of track fit results.
virtual bool put(const T &object)=0
Object output.
Utility class to parse command line options.
Definition: JParser.hh:1714
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.
virtual bool hasNext() override
Check availability of next element.
@ 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.
Definition: JSTDTypes.hh:14
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.
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
std::string getUniqueIdentifier(const_iterator p) const
Get unique identifier for a file-scanner contained within this set of event-weighter-associated file-...
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72
Auxiliary base class for list of file names.