Jpp  18.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintMeta.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TNamed.h"
8 #include "TKey.h"
9 #include "TRegexp.h"
10 
11 #include "JLang/JLangToolkit.hh"
13 #include "Jeep/JeepToolkit.hh"
14 #include "JSon/JSon.hh"
15 
17 #include "JSupport/JMeta.hh"
18 #include "JSupport/JSupport.hh"
19 
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 namespace {
24 
25  /**
26  * Print options.
27  */
28  static const char* plain_t = "plain"; //!< plain text
29  static const char* json_t = "JSON"; //!< JSON format
30 }
31 
32 /**
33  * \file
34  * Auxiliary program to print Jpp meta data.
35  * \author mdejong
36  */
37 int main(int argc, char **argv)
38 {
39  using namespace std;
40  using namespace JPP;
41 
42  string inputFile;
43  JLimit_t numberOfEvents;
44  string application;
45  string option;
46  vector<string> key;
47  int debug;
48 
49  try {
50 
51  JParser<> zap("Auxiliary program to print Jpp meta data.");
52 
53  zap['f'] = make_field(inputFile);
54  zap['n'] = make_field(numberOfEvents) = JLimit::max();
55  zap['A'] = make_field(application) = "";
56  zap['O'] = make_field(option) = plain_t, json_t;
57  zap['k'] = make_field(key, "possible values: "
58  << GITrelease_t << ", "
59  << SVNrelease_t << ", "
60  << ROOTrelease_t << ", "
61  << namespace_t << ", "
62  << command_t << ", "
64  zap['d'] = make_field(debug) = 1;
65 
66  zap(argc, argv);
67  }
68  catch(const exception &error) {
69  FATAL(error.what() << endl);
70  }
71 
72 
73  if (application != "") {
74 
75  TFile* in = TFile::Open(inputFile.c_str(), "exists");
76 
77  if (in != NULL && in->IsOpen()) {
78 
79  const TRegexp regexp(application.c_str());
80 
81  TIter iter(in->GetListOfKeys());
82 
83  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
84 
85  const TString tag(key->GetName());
86 
87  if (tag.Contains(regexp)) {
88 
89  TNamed* named = dynamic_cast<TNamed*>(key->ReadObj());
90 
91  if (named != NULL) {
92  cout << named->GetName() << "[" << key->GetCycle() << "] " << named->GetTitle() << endl;
93  }
94  }
95  }
96 
97  in->Close();
98 
99  } else {
100 
101  ERROR("Error opening file: " << inputFile << endl);
102  }
103 
104  } else {
105 
106  JMultipleFileScanner<JMetaTypes_t> in(inputFile, numberOfEvents);
108 
109  json js;
110 
111  while (abc.hasNext()) {
112 
113  JMeta* meta = abc.next();
114 
115  if (option == plain_t) {
116 
117  if (key.empty()) {
118 
119  cout << (*meta) << endl;
120 
121  } else {
122 
123  for (const auto& i : key) {
124  cout << ' ' << (*meta)[i];
125  }
126  cout << endl;
127  }
128 
129  } else if (option == json_t) {
130 
131  js += json(*meta);
132  }
133  }
134 
135  if (option == json_t) {
136  cout << setw(4) << js << endl;
137  }
138  }
139 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1514
static const char *const GITrelease_t
GIT release.
Definition: JMeta.hh:60
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Auxiliary class for multiplexing object iterators.
static const char *const ROOTrelease_t
ROOT release.
Definition: JMeta.hh:61
static const char *const SVNrelease_t
SVN release.
Definition: JMeta.hh:59
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
#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 ERROR(A)
Definition: JMessage.hh:66
virtual const pointer_type & next() override
Get next element.
virtual bool hasNext() override
Check availability of next element.
General purpose messaging.
static const char *const system_t
system information
Definition: JMeta.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
static const char *const namespace_t
name space
Definition: JMeta.hh:62
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
nlohmann::json json
static const char *const command_t
Linux command.
Definition: JMeta.hh:63
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
int debug
debug level