Fix
[u/mrichter/AliRoot.git] / PHOS / CopyAli.C
CommitLineData
8f62fbbb 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"
8f62fbbb 38#include "TObjArray.h"
39#include "TString.h"
40#endif
41
42void CopyAli(TString fnOrig="rfio:galice.root", TString fnNew="galice_new.root",Int_t iEvent = 0, Bool_t copygAlice=kTRUE,Bool_t copyTreeK = kFALSE)
43{
44
45 TFile *fileOrig = TFile::Open(fnOrig);
46 if (!fileOrig->IsOpen()) {
47 cerr<<"Cannot open input file "<<fnOrig.Data()<<endl;
48 return;
49 }
50// AliRun *gAlice;
51 if (gAlice) {delete gAlice; gAlice = 0;}
52 gAlice = (AliRun*)(fileOrig->Get("gAlice"));
53 if (!gAlice) {
54 cerr<<"Cannot read gAlice from the input file"<<endl;
55 return;
56 }
57
58 Int_t nAllTracks = gAlice->GetEvent(iEvent);
59 cout<<"nAllTracks = "<<nAllTracks<<endl;
60
61// Open the new file
62
63 TFile *fileNew = TFile::Open(fnNew,"update");
64 if (!fileNew->IsOpen()) {
65 cerr<<"Cannot open output file "<<fnNew.Data()<<endl;
66 return;
67 }
68 if (copygAlice) {
69 cout<<"Copy gAlice: ";
70 gAlice->Write();
71 cout<<"done"<<endl;
72
73 TTree *treeE = gAlice->TreeE();
74 if (!treeE) {
75 cerr<<"No TreeE found for event "<<iEvent<<endl;
76 return;
77 }
78 cout<<"Copy TreeE: ";
79 AliHeader *header = new AliHeader();
80 treeE->SetBranchAddress("Header", &header);
81 treeE->SetBranchStatus("*",1);
82 TTree *treeENew = treeE->CloneTree();
83 treeENew->Write();
84 cout<<"done"<<endl;
85
8f62fbbb 86 if (copyTreeK) {
87 cout<<"Copy TreeK: ";
88 TTree *treeK = gAlice->TreeK();
89 if (!treeK) {
90 cerr<<"No TreeK found for event "<<iEvent<<endl;
91 return;
92 }
93 TParticle *particle = new TParticle();
94 treeK->SetBranchAddress("Particles",&particle);
95 treeK->SetBranchStatus("*",1);
96 TTree *treeKNew = treeK->CloneTree();
97 treeKNew->Write();
98 cout<<"done"<<endl;
99 }
100
101
102 delete gAlice;
103 gAlice = 0;
104 fileNew->Close();
105 fileOrig->Close();
106 delete fileNew;
107 delete fileOrig;
108}