]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/CopyAli.C
Added protection against occasional non-LED STANDALONE runs
[u/mrichter/AliRoot.git] / PHOS / CopyAli.C
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // name: CopyAli.C
4 // date: 17.3.2002
5 // last update: 21.3.2002
6 // author: Jiri Chudoba
7 // version: 1.0
8 //
9 // description: 
10 //    copy some alice objects from 1 file to another
11 //
12 // ToDo: 
13 //    add support for more events in 1 file
14 //
15 //
16 // Note:
17 //    copied objects are not deleted, I assume that the root
18 //    session is exited after this copy
19 //
20 // Example:
21 //     aliroot -b -q CopyAli.C\("galice.root","TreeK.root",0,1,1,1\)
22 //
23 // History:
24 //
25 // 21.3.02 - first version
26 //
27 ////////////////////////////////////////////////////////////////////////
28
29 #if !defined(__CINT__) || defined(__MAKECINT__)
30 #include "iostream.h"
31 #include "TTree.h"
32 #include "TBranch.h"
33 #include "TDirectory.h"
34 #include "TFile.h"
35 #include "AliRun.h"
36 #include "TParticle.h"
37 #include "AliHeader.h"
38 #include "TGeometry.h"
39 #include "TObjArray.h"
40 #include "TString.h"
41 #endif
42
43 void CopyAli(TString fnOrig="rfio:galice.root", TString fnNew="galice_new.root",Int_t iEvent = 0, Bool_t copygAlice=kTRUE,Bool_t copyTreeK = kFALSE) 
44 {
45
46   TFile *fileOrig = TFile::Open(fnOrig);
47   if (!fileOrig->IsOpen()) {
48     cerr<<"Cannot open input file "<<fnOrig.Data()<<endl;
49     return;
50   }
51 //  AliRun *gAlice;
52   if (gAlice) {delete gAlice; gAlice = 0;}  
53   gAlice = (AliRun*)(fileOrig->Get("gAlice"));
54   if (!gAlice) {
55     cerr<<"Cannot read gAlice from the input file"<<endl;
56     return;
57   }
58
59   Int_t nAllTracks = gAlice->GetEvent(iEvent);
60   cout<<"nAllTracks = "<<nAllTracks<<endl;
61
62 // Open the new file
63
64   TFile *fileNew = TFile::Open(fnNew,"update");
65   if (!fileNew->IsOpen()) {
66     cerr<<"Cannot open output file "<<fnNew.Data()<<endl;
67     return;
68   }
69   if (copygAlice) {
70     cout<<"Copy gAlice: ";
71     gAlice->Write();
72     cout<<"done"<<endl;
73
74     TTree *treeE  = gAlice->TreeE();
75     if (!treeE) {
76       cerr<<"No TreeE found for event "<<iEvent<<endl;
77       return;
78     }      
79     cout<<"Copy TreeE: ";
80     AliHeader *header = new AliHeader();
81     treeE->SetBranchAddress("Header", &header);
82     treeE->SetBranchStatus("*",1);
83     TTree *treeENew =  treeE->CloneTree();
84     treeENew->Write();
85     cout<<"done"<<endl;
86
87     cout<<"Copy AliceGeom: ";
88     TGeometry *AliceGeom = static_cast<TGeometry*>(fileOrig->Get("AliceGeom"));
89     if (!AliceGeom) {
90       cerr<<"AliceGeom was not found in the input file "<<fnNew.Data()<<endl;
91       return;
92     }
93     AliceGeom->Write();
94     cout<<"done"<<endl;
95   }
96       
97
98   if (copyTreeK) {
99     cout<<"Copy TreeK: ";
100     TTree *treeK  = gAlice->TreeK();
101     if (!treeK) {
102       cerr<<"No TreeK found for event "<<iEvent<<endl;
103       return;
104     }
105     TParticle *particle = new TParticle();
106     treeK->SetBranchAddress("Particles",&particle);
107     treeK->SetBranchStatus("*",1);
108     TTree *treeKNew =  treeK->CloneTree();
109     treeKNew->Write();
110     cout<<"done"<<endl;
111   }
112
113  
114   delete gAlice;
115   gAlice = 0;
116   fileNew->Close();
117   fileOrig->Close();
118   delete fileNew;
119   delete fileOrig;
120 }