check_proxy.C
Go to the documentation of this file.
1 // This macro loads a CAF with regular Reflex-based StandardRecord and with
2 // SRProxy. It recurses through all branches in every event checking for
3 // differences and printing a message if it finds any. Run me with cafe.
4 
5 #include "TFile.h"
6 #include "TTree.h"
7 
10 
11 void check_proxy(std::string fname, std::string fname2 = "", int N = -1)
12 {
13  // CAn either compare two files, or one file against itself
14  if(fname2.empty()) fname2 = fname;
15 
16  TFile* f = TFile::Open(fname.c_str());
17  assert(!f->IsZombie());
18  TTree* recTree = (TTree*)f->Get("recTree");
19  assert(recTree);
20 
21  TFile* f2 = TFile::Open(fname2.c_str());
22  assert(!f2->IsZombie());
23 
24  // This is the logic from SpectrumLoader than also handles multitree flatcafs
25  TDirectory* dir = 0;
26  TTree* tr = 0;
27 
28  TObject* obj = f2->Get("recTree");
29  assert(obj);
30  if(obj->ClassName() == std::string("TTree")){
31  tr = (TTree*)obj;
32  }
33  else{
34  dir = (TDirectory*)obj;
35  tr = (TTree*)dir->Get("rec");
36  assert(tr);
37  }
38 
39  const caf::CAFType type = caf::GetCAFType(dir, tr);
40 
41  // Read one directly via dictionary
43  recTree->SetBranchAddress("rec", &sr);
44 
45  // And the other via proxy
46  long i;
47  caf::SRProxy srProxy(dir, tr, "rec", i, 0);
48 
49  if(N < 0 || N > recTree->GetEntries()) N = recTree->GetEntries();
50  for(i = 0; i < N; ++i){
51  std::cout << i << " / " << N << std::endl;
52 
53  recTree->GetEntry(i);
54 
55  if(type != caf::kFlatMultiTree) tr->LoadTree(i);
56 
57  srProxy.CheckEquals(*sr);
58  }
59 }
60 
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
Float_t f2
void check_proxy(std::string fname, std::string fname2="", int N=-1)
Definition: check_proxy.C:11
CAFType GetCAFType(const TDirectory *dir, TTree *tr)
void CheckEquals(const caf::StandardRecord &sr) const
Definition: SRProxy.cxx:4292
caf::StandardRecord * sr
OStream cout
Definition: OStream.cxx:6
The StandardRecord is the primary top-level object in the Common Analysis File trees.
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
enum BeamMode string