Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "JSupport/JMeta.hh"
14 #include "JSupport/JSupport.hh"
18 
19 #include "JAAnet/JHead.hh"
20 
21 
22 /**
23  * \file
24  * Example program for sorting and merging Monte-Carlo files with compatible headers.
25  *
26  * Note: Already existing merged files will be overwritten.
27  *
28  * \author bjung
29  */
30 int main(int argc, char **argv)
31 {
32  using namespace std;
33  using namespace JPP;
34 
35  typedef typename JTYPELIST<Head, JMeta, Evt>::typelist typelist;
36 
37  JMultipleFileScanner_t inputFiles;
38  string outputFile;
39 
40  char wildcard;
41 
42  int debug;
43 
44  try {
45 
46  JParser<> zap;
47 
48  zap['f'] = make_field(inputFiles);
49  zap['o'] = make_field(outputFile) = "%.merged.root";
50  zap['w'] = make_field(wildcard) = '%';
51  zap['d'] = make_field(debug) = 1;
52 
53  zap(argc, argv);
54  }
55  catch(const exception& error) {
56  FATAL(error.what() << endl);
57  }
58 
59  const size_t pos = outputFile.find(wildcard);
60 
61  if (pos == string::npos) {
62  FATAL("Valid wildcard must be specified (<" << outputFile << "> does not contain \'" << wildcard << "\').");
63  }
64 
65 
66  // Create set of files ordered based on header-info
67 
68  JEvtWeightFileScannerSet<> scanners(inputFiles);
69 
70 
71  // Create merged output for all compatible files
72 
73  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
74 
75  const string identifier = scanners.getUniqueIdentifier(scanner);
76  const string name = string(outputFile).replace(pos, 1, identifier.c_str());
77 
78  NOTICE("Writing " << name << "..." << endl);
79 
80  JFileRecorder<typelist> out(name.c_str());
81 
82  out.open();
83 
84  const Head& head = getHeader(scanner->getFilename());
85 
86  out.put(head);
87 
88  out.put(JMeta(argc, argv));
89 
90  for (JMultipleFileScanner<JMeta> in(scanner->getFilelist()); in.hasNext(); ) {
91  out.put(*in.next());
92  }
93 
94  while (scanner->hasNext()) {
95 
96  const Evt* event = scanner->next();
97 
98  if (event != NULL) {
99 
100  STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl);
101  out.put(*event);
102 
103  } else {
104 
105  WARNING("Event " << scanner->getCounter() << " is empty; skip.");
106  }
107  }
108 
109  out.close();
110  }
111 
112  return 0;
113 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
std::string getUniqueIdentifier(const_iterator p) const
Get unique identifier for a file-scanner contained within this set of event-weighter-associated file-...
#define STATUS(A)
Definition: JMessage.hh:63
Recording of objects on file according a format that follows from the file name extension.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
string outputFile
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Type list.
Definition: JTypeList.hh:22
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Auxiliary methods for handling file names, type names and environment.
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
then awk string
General purpose messaging.
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Auxiliary base class for list of file names.
std::vector< filescanner_type >::iterator iterator
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
virtual void open(const char *file_name) override
Open file.
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
then echo WARNING
Definition: JTuneHV.sh:91
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62