First version of writing aod files. Reader for aod files. AliAOD::fParticles chnged...
[u/mrichter/AliRoot.git] / ANALYSIS / AliReaderAOD.cxx
CommitLineData
dd2b6810 1#include "AliReaderAOD.h"
2
3ClassImp(AliReaderAOD)
4
5#include <TError.h>
6#include <TFile.h>
7#include <TTree.h>
8#include "AliAOD.h"
9
10Int_t AliReaderAOD::WriteAOD(AliReader* reader, const char* outfilename, Bool_t /*multcheck*/)
11{
12//reads tracks from runs and writes them to file
13 ::Info("AliReaderAOD::Write","________________________________________________________");
14 ::Info("AliReaderAOD::Write","________________________________________________________");
15 ::Info("AliReaderAOD::Write","________________________________________________________");
16
17 if (reader == 0x0)
18 {
19 ::Error("AliReaderAOD::Write","Input Reader is NULL");
20 return -1;
21 }
22 TFile *outfile = TFile::Open(outfilename,"recreate");
23 if (outfile == 0x0)
24 {
25 ::Error("AliReaderAOD::Write","Can not open output file %s",outfilename);
26 return -1;
27 }
28
29 TTree *tree = new TTree("TAOD","Tree with tracks");
30
31 TBranch *recbranch = 0x0, *simbranch = 0x0;
32
33 AliAOD* eventsim = new AliAOD();
34 AliAOD* eventrec = new AliAOD;
35
36 eventsim->SetParticleClassName("AliAODParticle");
37 eventrec->SetParticleClassName("AliAODParticle");
38
39 if (reader->ReadsSim()) simbranch = tree->Branch("simulated","AliAOD",&eventsim,32000,99);
40 if (reader->ReadsRec()) recbranch = tree->Branch("reconstructed","AliAOD",&eventrec,32000,99);
41
42 reader->Rewind();
43 while (reader->Next() == kFALSE)
44 {
45
46 if (reader->ReadsSim())
47 {
48 eventsim = reader->GetEventSim();
49// simbranch->SetAddress(&eventsim);
50 }
51
52 if (reader->ReadsRec())
53 {
54 eventrec = reader->GetEventRec();
55// recbranch->SetAddress(&eventrec);
56 }
57 tree->Fill();
58 tree->Print();
59 }
60
61 ::Info("AliReaderAOD::Write","Written %d events",tree->GetEntries());
62 outfile->cd();
63 tree->Write();
64 delete tree;
65 delete outfile;
66 return 0;
67}
68