Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintChain.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <set>
6 #include <memory>
7 #include <string.h>
8 
9 #include "TError.h"
10 #include "TROOT.h"
11 #include "TFile.h"
12 #include "TKey.h"
13 #include "TTree.h"
14 #include "TChain.h"
15 
16 #include "JSystem/JGlob.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 namespace {
23 
24  /**
25  * Auxiliary data structure for TChain.
26  */
27  struct JChain :
28  public std::unique_ptr<TChain>
29  {
30  /**
31  * Default constructor.
32  */
33  JChain()
34  {}
35 
36  /**
37  * Constructor.
38  *
39  * \param name name of TTree
40  */
41  JChain(const char* const name) :
42  std::unique_ptr<TChain>(new TChain(name))
43  {}
44 
45  /**
46  * Less-than operator for TChain.
47  *
48  * \param first first TChain
49  * \param second second TChain
50  * \return true if name of first TChain is less than that of second; else false
51  */
52  friend inline bool operator<(const JChain& first, const JChain& second)
53  {
54  return strcmp(first->GetName(), second->GetName()) < 0;
55  }
56  };
57 }
58 
59 
60 /**
61  * \file
62  *
63  * Auxiliary program to print ROOT TChain information.
64  * \author mdejong
65  */
66 int main(int argc, char **argv)
67 {
68  using namespace std;
69  using namespace JPP;
70 
71  vector<string> inputFile;
72  int debug;
73 
74  try {
75 
76  JParser<> zap("Auxiliary program to print ROOT TChain information.");
77 
78  zap['f'] = make_field(inputFile);
79  zap['d'] = make_field(debug) = 1;
80 
81  zap(argc, argv);
82  }
83  catch(const exception &error) {
84  FATAL(error.what() << endl);
85  }
86 
87  gErrorIgnoreLevel = kFatal;
88 
89  inputFile = getFilenames(inputFile);
90 
91  set<JChain> buffer;
92 
93  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
94 
95  TFile* file = TFile::Open(file_name->c_str());
96 
97  if (file != NULL) {
98 
99  TIter iter(file->GetListOfKeys(), kIterBackward);
100 
101  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
102 
103  TKey* p = dynamic_cast<TKey*>(file->GetListOfKeys()->Before(key));
104 
105  if (p == NULL || strcmp(key->GetName(), p->GetName()) != 0) { // select last key
106 
107  TTree* tree = dynamic_cast<TTree*>(key->ReadObj());
108 
109  if (tree != NULL) {
110  buffer.insert(JChain(tree->GetName()));
111  }
112  }
113  }
114 
115  file->Close();
116 
117  delete file;
118  }
119  }
120 
121  for (auto& chain : buffer) {
122 
123  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
124  chain->Add(file_name->c_str());
125  }
126 
127  cout << setw(24) << left << chain->GetName() << ' '
128  << setw(10) << right << chain->GetEntries() << endl;
129  }
130 }
Utility class to parse command line options.
Definition: JParser.hh:1711
int main(int argc, char *argv[])
Definition: Main.cc:15
then usage $script[< detector identifier >< run range >]< QA/QCfile > nExample script to produce data quality plots nWhen a detector identifier and run range are data are downloaded from the database nand subsequently stored in the given QA QC file
Definition: JDataQuality.sh:19
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1816
static JGlob getFilenames
Function object to get list of files for given pattern.
Definition: JGlob.hh:123
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
General purpose messaging.
then fatal The output file must have the wildcard in the name
Definition: JCanberra.sh:31
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
int debug
debug level
File list.