]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/ReadFlatESD.C
Merge branch 'master' into flatdev
[u/mrichter/AliRoot.git] / HLT / global / ReadFlatESD.C
1 /**
2  * >> Testing Macro to read FlatESDEvent from output file <<
3  **
4  * Primary Authors : Sergey Gorbunov, Jochen Thaeder, Chiara Zampolli
5  *
6  * Usage:
7  *  aliroot -b -l -q LoadLibs.C ReadFlatESD.C++
8  *
9  **************************************************************************/
10
11 #if !defined(__CINT__) || defined(__MAKECINT__)
12 #include "AliESDEvent.h"
13 #include "AliESD.h"
14 #include "AliESDfriend.h"
15 #include <TFile.h>
16 #include <TTree.h>
17 #include <TSystem.h>
18 #include "./AliFlatESDEvent.h"
19 #include "./AliFlatESDTrack.h"
20 #include "./AliFlatTPCCluster.h"
21 #include "./AliFlatExternalTrackParam.h"
22 #include "Riostream.h"
23 #endif   
24
25 void ReadFlatESD(const char* filename="outFlatESD.root") {
26
27   ifstream is(filename, std::ifstream::binary | std::ifstream::in);
28   if (is){
29     is.seekg (0, is.end);
30     int length = is.tellg();
31     is.seekg (0, is.beg);
32     char * buffer = new char [length];
33     
34     std::cout << "Reading " << length << " characters... ";
35     
36     is.read (buffer,length);
37     if (is)
38       std::cout << "all characters read successfully." << endl;
39     else
40       std::cout << "error: only " << is.gcount() << " could be read";
41     is.close();
42     
43     // ...buffer contains the entire file...
44     
45     char *curr = buffer;
46     char *endBuff = buffer+length;
47     int iEvent = 0;
48     while( curr < endBuff ){
49       AliFlatESDEvent *flatEsd = reinterpret_cast<AliFlatESDEvent *>(curr);
50       cout<<"Reading event "<<iEvent<<":"<<endl;
51       cout<<"vtx SPD: "<<(Bool_t) flatEsd->GetPrimaryVertexSPD()
52           <<" vtx tracks: "<<(Bool_t) flatEsd->GetPrimaryVertexTracks() 
53           <<" ntracks: "<<flatEsd->GetNumberOfTracks()
54           <<" nV0's: "<<flatEsd->GetNumberOfV0s()
55           <<endl;
56       curr=curr+ flatEsd->GetSize();
57       iEvent++;
58     }
59
60     delete[] buffer;
61   }
62   else {
63     cout << "File could not be read" << endl;
64   }
65   return;
66 }