QwAnalysis
QwTrackingDump.cc File Reference
#include <vector>
#include <TFile.h>
#include <TTree.h>
#include <TKey.h>
#include "QwLog.h"
+ Include dependency graph for QwTrackingDump.cc:

Go to the source code of this file.

Functions

Int_t main (Int_t argc, Char_t *argv[])
 

Function Documentation

Int_t main ( Int_t  argc,
Char_t *  argv[] 
)

Definition at line 13 of file QwTrackingDump.cc.

References QwLog::endl(), QwError, QwMessage, and QwWarning.

14 {
15  if (argc < 1) {
16  QwError << "Please specify a filename." << QwLog::endl;
17  return 1;
18  }
19 
20  // Fill list of trees we are interested in
21  std::vector< TString > treelist;
22  treelist.push_back("hit_tree");
23  treelist.push_back("event_tree");
24 
25  // Fill list of branches we are interested in
26  std::vector< std::pair< TString, TObject* > > branchlist;
27  branchlist.push_back(std::pair< TString, TObject* > ("hits",(TObject*)0));
28  branchlist.push_back(std::pair< TString, TObject* > ("events",(TObject*)0));
29 
30  // Open the file
31  TString name = TString(argv[1]);
32  TFile* file = new TFile(name);
33 
34  // Look for all trees
35  for (size_t tree = 0; tree < treelist.size(); tree++) {
36  // Get object and check whether it is a tree
37  TObject* object = file->Get(treelist.at(tree));
38  if (! object) {
39  QwWarning << "No key " << treelist.at(tree) << QwLog::endl;
40  continue;
41  }
42  if (! object->InheritsFrom("TTree")) {
43  QwWarning << "Object " << treelist.at(tree) << " is not a tree" << QwLog::endl;
44  continue;
45  }
46  TTree* thistree = dynamic_cast<TTree*>(object);
47  if (! thistree) {
48  QwWarning << "No tree " << treelist.at(tree) << QwLog::endl;
49  continue;
50  }
51  Int_t nevents = thistree->GetEntries();
52  QwMessage << "Number of entries in " << treelist.at(tree) << ": "
53  << nevents << QwLog::endl;
54 
55  // Set up the branches
56  for (size_t branch = 0; branch < branchlist.size(); branch++) {
57  if (thistree->FindBranch(branchlist.at(branch).first)) {
58  thistree->SetBranchAddress(branchlist.at(branch).first,
59  &branchlist.at(branch).second);
60  } else {
61  QwWarning << "No branch " << branchlist.at(branch).first << " "
62  << "in tree " << treelist.at(tree)
63  << QwLog::endl;
64  }
65  }
66 
67  // Loop over all events
68  for (Int_t event = 0; event < nevents; event++) {
69  QwMessage << "Event " << event << QwLog::endl;
70  thistree->GetEntry(event);
71  for (size_t branch = 0; branch < branchlist.size(); branch++) {
72  if (branchlist.at(branch).second)
73  branchlist.at(branch).second->Print();
74  }
75  }
76  }
77 
78  // Close file
79  file->Close();
80 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function: