AliRoot Core  a565103 (a565103)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompareDigitsOrClusters.C
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "AliMUONDataInterface.h"
3 #include "AliMUONVDigitStore.h"
4 #include "TTree.h"
5 #include "AliLog.h"
6 #include "TMath.h"
7 #include "Riostream.h"
8 #include "TKey.h"
9 #include "AliMUONVClusterStore.h"
10 
26 
27 using namespace std;
28 
29 template<class T>
30 T* Store(TFile& file, Long64_t event)
31 {
32  Bool_t ok = file.cd(Form("Event%lld",event));
33  if (!ok)
34  {
35  AliErrorGeneral("Store",Form("Cannot cd to Event%lld",event));
36  return 0x0;
37  }
38 
39  TObject* key = gDirectory->GetListOfKeys()->First();
40 
41  TTree* tree = static_cast<TTree*>(gDirectory->Get(key->GetName()));
42 
43  if (!tree)
44  {
45  AliErrorGeneral("Store",Form("Cannot get %s from file for event %lld",key->GetName(),event));
46  return 0x0;
47  }
48 
49  T* store = T::Create(*tree);
50 
51  if (!store)
52  {
53  AliErrorGeneral("Store","Cannot get store from tree");
54  return 0x0;
55  }
56 
57  store->Connect(*tree);
58 
59  tree->GetEntry(0);
60 
61  return store;
62 }
63 
64 template<class T>
65 Int_t Compare(const T& ds1, const T& ds2)
66 {
67  if ( ds1.GetSize() != ds2.GetSize() )
68  {
69  return 1;
70  }
71 
72  TIter next1(ds1.CreateIterator());
73  TIter next2(ds2.CreateIterator());
74 
75  TObject* d1;
76 
77  while ( ( d1 = next1()))
78  {
79  TObject* d2 = next2();
80  if ( d1->Compare(d2) ) return 2;
81  }
82 
83  return 0;
84 }
85 
86 TFile* Open(const char* filename, Long64_t& nevents)
87 {
88  TFile* file = TFile::Open(filename);
89  if (!file)
90  {
91  AliErrorGeneral("Open",Form("Cannot open file %s",filename));
92  return 0x0;
93  }
94  TIter next(file->GetListOfKeys());
95  TKey* key;
96 
97  nevents = 0;
98  while ( ( key = static_cast<TKey*>(next())))
99  {
100  if ( TString(key->GetName()).BeginsWith("Event") )
101  {
102  ++nevents;
103  }
104  }
105 
106  return file;
107 }
108 
109 void DumpSorted(const char* filename, Long64_t event, const AliMUONVStore& store)
110 {
112 
113  TIter next(store.CreateIterator());
114  TObject* object;
115  TList list;
116  list.SetOwner(kFALSE);
117 
118  while ( ( object = next() ) )
119  {
120  list.Add(object);
121  }
122 
123  list.Sort();
124 
125  std::ofstream out(Form("%s.%lld.txt",filename,event));
126 
127  std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
128  std::cout.rdbuf(out.rdbuf()); //redirect std::cout to filename
129 
130  list.Print();
131 
132  std::cout.rdbuf(coutbuf); //reset to standard output again
133 }
134 
135 template<class T>
136 Int_t Compare(const char* file1, const char* file2, Long64_t maxEvents=0)
137 {
138  Long64_t n1;
139  Long64_t n2;
140 
141  TFile* f1 = Open(file1,n1);
142  TFile* f2 = Open(file2,n2);
143 
144  if ( n1 != n2 )
145  {
146  AliWarningGeneral("CompareDigits",Form("file1 has %lld events while file2 has %lld ...",
147  n1,n2));
148  }
149 
150  if ( !maxEvents )
151  {
152  maxEvents = TMath::Min(n1,n2);
153  }
154 
155  Long64_t n = TMath::Min(maxEvents,n1);
156 
157  n = TMath::Min(n,n2);
158 
159  for ( Long64_t i = 0; i < n; ++i )
160  {
161  T* store1 = Store<T>(*f1,i);
162  if (!store1)
163  {
164  AliErrorGeneral("Compare",Form("Cannot get store from file1 for event %lld",i));
165  continue;
166  }
167  T* store2 = Store<T>(*f2,i);
168  if (!store2)
169  {
170  AliErrorGeneral("Compare",Form("Cannot get store from file2 for event %lld",i));
171  continue;
172  }
173 
174  if ( Compare<T>(*store1,*store2) )
175  {
176  AliErrorGeneral("Compare",Form("differ for event %lld",i));
177  DumpSorted("file1",i,*store1);
178  DumpSorted("file2",i,*store2);
179  }
180 
181  delete store1;
182  delete store2;
183  }
184 
185  return 0;
186 }
187 
188 Int_t CompareDigits(const char* file1, const char* file2, Long64_t maxEvents=0)
189 {
190  return Compare<AliMUONVDigitStore>(file1,file2,maxEvents);
191 }
192 
193 Int_t CompareClusters(const char* file1, const char* file2, Long64_t maxEvents=0)
194 {
195  return Compare<AliMUONVClusterStore>(file1,file2,maxEvents);
196 }
virtual TIterator * CreateIterator() const =0
Return an iterator to loop over the whole store.
TFile * Open(const char *filename, Long64_t &nevents)
Int_t CompareClusters(const char *file1, const char *file2, Long64_t maxEvents=0)
T * Store(TFile &file, Long64_t event)
void DumpSorted(const char *filename, Long64_t event, const AliMUONVStore &store)
Int_t Compare(const T &ds1, const T &ds2)
TTree * tree
Int_t CompareDigits(const char *file1, const char *file2, Long64_t maxEvents=0)
Base class for MUON data stores.
Definition: AliMUONVStore.h:22