1 void addObjectAndUpdateAOD(const char *fileName = "AliAOD.root") {
2 // This little macro takes an already created AOD file and adds
4 // You need write access to the AOD file, which is generally not
5 // the case for AOD files available on the GRID/on CAF.
6 // Be aware that if something breaks (lost connection, node goes
7 // down, ...) the content of the file will be essentially lost,
9 // WITH THIS UPDATE PROCEDURE YOU HAVE THE POWER TO DESTROY DATA!
11 // To read back this data (including the newly updated branch), have
12 // a look at $ALICE_ROOT/STEER/ReadAOD.C and add one line
13 // TClonesArray *esdTracks =
14 // (TClonesArray*)ev->GetList()->FindObject("esdTracks");
16 // ev->ReadFromTree(aodTree);
18 // esdTracks will be 'filled' correctly after each call of
19 // aodTree->GetEvent(nEv);
23 // open input file and get the TTree
24 TFile inFile(fileName, "UPDATE");
26 TTree *aodTree = (TTree*)inFile.Get("aodTree");
27 AliAODEvent *ev = new AliAODEvent();
28 ev->ReadFromTree(aodTree);
30 // add new information to the list (we use AliESDtracks as an example)
31 TClonesArray *tracks = new TClonesArray("AliESDtrack", 0);
32 ev->AddObject(tracks); // add new object to the list
34 // define a unique name
35 const char *name = "esdTracks";
36 tracks->SetName(name); // set this name to be the name of the TClonesArray
37 // create the new branch
38 TBranch *newBranch = aodTree->Branch(name, &tracks); // the branch gets the same name
41 Int_t nEvent = aodTree->GetEntries();
43 for(Int_t iEv = 0; iEv < nEvent; iEv++) {
46 // read events (only necessary if you want to access the old data)
47 aodTree->GetEvent(nEv);
50 tracks->Delete(); // for each event delete old entries of new TClonesArray
52 Int_t nTracks = gRandom->Rndm() * 50; // randomize size of TClonesArray (just for this example)
53 tracks->Expand(nTracks); // expand container (just for speed)
56 TClonesArray &rTracks = *tracks;
57 for (Int_t iTr = 0; iTr< nTracks; iTr++) {
58 new(rTracks[iTr]) AliESDtrack();
61 // fill the new branch
65 // (over)write the tree (to the same file!)
67 aodTree->Write("", TObject::kOverwrite);