ROOT logo
addObjectDuringAODCreation() {

  // add an object to an aod and write it

  TFile *aodFile = TFile::Open("addAOD.root", "RECREATE");

    // create an AliAOD object 
  AliAODEvent *aod = new AliAODEvent();
  aod->CreateStdContent();
  
  // add new information, we use AliESDtracks for now
  TClonesArray *tracks = new TClonesArray("AliESDtrack", 0);
  aod->AddObject(tracks);

  // go to the file
  aodFile->cd();
  
  // create the tree
  TTree *aodTree = new TTree("aodTree", "AliAOD tree");
  aodTree->Branch(aod->GetList());

  for (Int_t iEvent = 0; iEvent < 10; ++iEvent) {
    // add (part of) standard information
    AliAODHeader *header = aod->GetHeader();

    tracks->Delete(); // delete old objects
    tracks->Expand(iEvent+5/* just to make it a different number each time*/); // expand container (just for speed)
    
    // fill TClonesArray
    TClonesArray &rTracks = *tracks;
    for (Int_t i = 0; i< iEvent+5; i++) {
      new(rTracks[i]) AliESDtrack();
    }

    // fill the tree for this event
    aodTree->Fill();
  } // end of event loop

  aodTree->GetUserInfo()->Add(aod);

  // write the tree to the specified file
  aodFile = aodTree->GetCurrentFile();
  aodFile->cd();
  aodTree->Write();



}
 addObjectDuringAODCreation.C:1
 addObjectDuringAODCreation.C:2
 addObjectDuringAODCreation.C:3
 addObjectDuringAODCreation.C:4
 addObjectDuringAODCreation.C:5
 addObjectDuringAODCreation.C:6
 addObjectDuringAODCreation.C:7
 addObjectDuringAODCreation.C:8
 addObjectDuringAODCreation.C:9
 addObjectDuringAODCreation.C:10
 addObjectDuringAODCreation.C:11
 addObjectDuringAODCreation.C:12
 addObjectDuringAODCreation.C:13
 addObjectDuringAODCreation.C:14
 addObjectDuringAODCreation.C:15
 addObjectDuringAODCreation.C:16
 addObjectDuringAODCreation.C:17
 addObjectDuringAODCreation.C:18
 addObjectDuringAODCreation.C:19
 addObjectDuringAODCreation.C:20
 addObjectDuringAODCreation.C:21
 addObjectDuringAODCreation.C:22
 addObjectDuringAODCreation.C:23
 addObjectDuringAODCreation.C:24
 addObjectDuringAODCreation.C:25
 addObjectDuringAODCreation.C:26
 addObjectDuringAODCreation.C:27
 addObjectDuringAODCreation.C:28
 addObjectDuringAODCreation.C:29
 addObjectDuringAODCreation.C:30
 addObjectDuringAODCreation.C:31
 addObjectDuringAODCreation.C:32
 addObjectDuringAODCreation.C:33
 addObjectDuringAODCreation.C:34
 addObjectDuringAODCreation.C:35
 addObjectDuringAODCreation.C:36
 addObjectDuringAODCreation.C:37
 addObjectDuringAODCreation.C:38
 addObjectDuringAODCreation.C:39
 addObjectDuringAODCreation.C:40
 addObjectDuringAODCreation.C:41
 addObjectDuringAODCreation.C:42
 addObjectDuringAODCreation.C:43
 addObjectDuringAODCreation.C:44
 addObjectDuringAODCreation.C:45
 addObjectDuringAODCreation.C:46
 addObjectDuringAODCreation.C:47
 addObjectDuringAODCreation.C:48
 addObjectDuringAODCreation.C:49