Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintMeta.cc File Reference

Auxiliary program to print Jpp meta data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TNamed.h"
#include "TKey.h"
#include "TRegexp.h"
#include "JLang/JLangToolkit.hh"
#include "JLang/JObjectMultiplexer.hh"
#include "Jeep/JeepToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print Jpp meta data.

Author
mdejong

Definition in file JPrintMeta.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 39 of file JPrintMeta.cc.

40 {
41  using namespace std;
42  using namespace JPP;
43 
44  string inputFile;
45  JLimit_t numberOfEvents;
46  string application;
47  string option;
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Auxiliary program to print Jpp meta data.");
53 
54  zap['f'] = make_field(inputFile);
55  zap['n'] = make_field(numberOfEvents) = JLimit::max();
56  zap['A'] = make_field(application) = "";
57  zap['O'] = make_field(option) = plain_t, single_t, json_t;
58  zap['d'] = make_field(debug) = 1;
59 
60  zap(argc, argv);
61  }
62  catch(const exception &error) {
63  FATAL(error.what() << endl);
64  }
65 
66  cout.tie(&cerr);
67 
68  if (application != "") {
69 
70  TFile* in = TFile::Open(inputFile.c_str(), "exists");
71 
72  if (in != NULL && in->IsOpen()) {
73 
74  const TRegexp regexp(application.c_str());
75 
76  TIter iter(in->GetListOfKeys());
77 
78  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
79 
80  const TString tag(key->GetName());
81 
82  if (tag.Index(regexp) != -1) {
83 
84  TNamed* named = dynamic_cast<TNamed*>(key->ReadObj());
85 
86  if (named != NULL) {
87  cout << named->GetName() << "[" << key->GetCycle() << "] " << named->GetTitle() << endl;
88  }
89  }
90  }
91 
92  in->Close();
93 
94  } else {
95 
96  ERROR("Error opening file: " << inputFile << endl);
97  }
98 
99  } else {
100 
101  JMultipleFileScanner<JMetaTypes_t> in(inputFile, numberOfEvents);
102 
103  JObjectMultiplexer<JMetaTypes_t> abc(in);
104 
105  if (option == single_t) {
106  cout << "[" << endl;
107  }
108 
109  while (abc.hasNext()) {
110 
111  JMeta* meta = abc.next();
112 
113  if (option == plain_t) {
114 
115  cout << *meta << endl;
116 
117  } else if (option == single_t ||
118  option == json_t) {
119 
120  cout << "[" << double_quote((*meta)[application_t]) << ", {" << endl;
121 
122  for (JMeta::const_iterator i = meta->begin(); i != meta->end(); ++i) {
123  if (i->first != application_t) {
124  cout << double_quote(i->first) << " : " << double_quote(i->second) << (i->first != meta->rbegin()->first ? "," : "") << endl;
125  }
126  }
127  cout << "}]";
128 
129  if (abc.hasNext()) {
130  cout << ",";
131  }
132 
133  cout << endl;
134  }
135  }
136 
137  if (option == single_t) {
138  cout << "]" << endl;
139  }
140  }
141 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Utility class to parse command line options.
Definition: JParser.hh:1410
static const char *const application_t
Definition of meta data parameters.
Definition: JMeta.hh:59
std::string double_quote(const std::string &value)
Quote string.
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:214
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
#define ERROR(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:59
#define FATAL(A)
Definition: JMessage.hh:65