Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintChain.cc File Reference

Auxiliary program to print ROOT TChain information. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <set>
#include <memory>
#include <string.h>
#include "TError.h"
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TTree.h"
#include "TChain.h"
#include "JSystem/JGlob.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 ROOT TChain information.

Author
mdejong

Definition in file JPrintChain.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 66 of file JPrintChain.cc.

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:1514
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
static JGlob getFilenames
Function object to get list of files for given pattern.
Definition: JGlob.hh:127
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level