4 #include "TInterpreter.h"
5 #include "TBranchClones.h"
6 #include "TBranchElement.h"
7 #include "AliTPCTrackHits.h"
8 #include "AliTRDtrackHits.h"
12 void ConvertToNewIO(const char* name)
14 // AliLoader::SetDebug();
15 AliConfig* conf = AliConfig::Instance();
16 TClass* detclass = AliDetector::Class();
18 Bool_t skipit = kFALSE;
20 TBranch* branches[100];
23 AliRunLoader* rl = AliRunLoader::Open("galiceNewIO.root","Event","recreate");
24 rl->SetCompressionLevel(2);
25 rl->SetNumberOfEventsPerFile(100);
31 outAliRun = new AliRun("OutgAlice","Output gAlice");
39 outAliRun->SetRunLoader(rl);
41 TFile* infile = TFile::Open(name);
45 ::Error("ConvertToNewIO.C","Can not open input file %s",name);
49 AliRun* inAliRun = (AliRun*)infile->Get("gAlice");
53 ::Error("ConvertToNewIO.C","Can not find gAlice in input file");
57 // inAliRun->GetEvent(0);
59 TObjArray* modules = inAliRun->Modules();
62 ::Error("ConvertToNewIO.C","Can not get array with modules from AliRun");
68 while ((object = next()))
70 module = dynamic_cast<AliModule*>(object);
72 ::Error("ConvertToNewIO.C","Can not cast module %#x ",object);
77 outAliRun->AddModule(module);
79 TClass* modclass = module->IsA();
80 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
83 ::Info("ConvertToNewIO.C"," Adding %s to RL.",det->GetName());
84 conf->Add(det,"Event");
89 TParticle* particleBuffer = new TParticle();
90 /***************************************************/
91 /**** Event to Event **************/
92 /***************************************************/
94 TTree* treeE = (TTree*)infile->Get("TE");
97 ::Error("ConvertToNewIO.C","Can not get TreeE from AliRun");
102 AliHeader* inheader = new AliHeader();
103 treeE->SetBranchAddress("Header",&inheader);
105 Int_t nevents = (Int_t)treeE->GetEntries();
106 for (Int_t i = 0; i<nevents; i++)
108 ::Info("ConvertToNewIO.C","Converting Event %d.",i);
109 rl->SetEventNumber(i);
111 /*****************************************/
113 /*****************************************/
115 ::Info("ConvertToNewIO.C","Copying Header");
116 AliHeader* outheader = rl->GetHeader();
119 outheader->SetEvent(inheader->GetEvent());
120 outheader->SetNvertex(inheader->GetNvertex());
121 outheader->SetNprimary(inheader->GetNprimary());
122 outheader->SetNtrack(inheader->GetNtrack());
123 outheader->SetRun(inheader->GetRun());
124 outheader->SetEventNrInRun(inheader->GetEventNrInRun());
125 outheader->SetStack(inheader->Stack());
126 outheader->SetGenEventHeader(inheader->GenEventHeader());
129 /*****************************************/
130 /* K I N E M A T I C S */
131 /*****************************************/
132 ::Info("ConvertToNewIO.C","Copying Kinematics.");
133 TString treeKname("TreeK");
135 TTree* treeK = (TTree*)infile->Get(treeKname);
138 if (treeK->GetEntries() > 0)
140 //I do this gimnastics to set directory correctly, without changing NewIO code
141 //only for this purpose
142 rl->LoadKinematics("update");
144 rl->GetEventFolder()->Remove(rl->TreeK());
147 treeK->SetBranchAddress("Particles",&particleBuffer);
148 ::Info("ConvertToNewIO.C","Cloning TreeK ...");
149 TTree* tk = treeK->CloneTree();
150 ::Info("ConvertToNewIO.C","Cloning TreeK ... Done");
151 tk->SetName(AliRunLoader::fgkKineContainerName);
152 rl->GetEventFolder()->Add(tk);
153 rl->WriteKinematics("OVERWRITE");
154 rl->UnloadKinematics();
158 Info("ConvertToNewIO.C","Kinematics Tree is Empty");
163 Error("ConvertToNewIO.C","Could not find Kinematics tree named %s",treeKname.Data());
166 /*****************************************/
167 /* T R A C K R E F E R E N C E S */
168 /*****************************************/
169 ::Info("ConvertToNewIO.C","Copying Track Refs.");
170 TString treeTRname("TreeTR");
172 TTree* treeTR = (TTree*)infile->Get(treeTRname);
175 if (treeTR->GetEntries() > 0)
179 while ((object = next()))
181 module = dynamic_cast<AliModule*>(object);
183 ::Error("ConvertToNewIO.C","Can not cast module %#x ",object);
187 TClass* modclass = module->IsA();
188 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
191 TClonesArray* trbuffer = new TClonesArray("AliTrackReference", 100);
192 treeTR->SetBranchAddress(det->GetName(),&trbuffer);
196 //I do this gimnastics to set directory correctly, without changing NewIO code
197 //only for this purpose
198 rl->LoadTrackRefs("update");
199 rl->MakeTrackRefsContainer();
200 rl->GetEventFolder()->Remove(rl->TreeTR());
203 ::Info("ConvertToNewIO.C","Cloning TreeTR ...");
204 TTree* tr = treeTR->CloneTree();
205 ::Info("ConvertToNewIO.C","Cloning TreeTR ... Done");
207 tr->SetName(AliRunLoader::fgkTrackRefsContainerName);
208 rl->GetEventFolder()->Add(tr);
209 rl->WriteTrackRefs("OVERWRITE");
210 rl->UnloadTrackRefs();
214 Info("ConvertToNewIO.C","Track References Tree is Empty");
219 Error("ConvertToNewIO.C","Could not find Track Refs tree named %s",treeTRname.Data());
223 /*****************************************/
225 /*****************************************/
226 ::Info("ConvertToNewIO.C","Copying Hits.");
227 TString treeHname("TreeH");
229 TTree* treeH = (TTree*)infile->Get(treeHname);
233 if (treeH->GetEntries() > 0)
235 TObjArray* lob = treeH->GetListOfBranches();
236 TObjArray* loaders = new TObjArray();
237 TIter nextnewmodule(outAliRun->Modules());
239 while ((module = (AliModule*)nextnewmodule()))
241 TClass* modclass = module->IsA();
242 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
243 TClonesArray* ca = 0;
246 AliLoader* loader = det->GetLoader();
249 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
253 TString mask(det->GetName());
255 loader->LoadHits("update");
256 loader->MakeTree("H");
257 loaders->Add(loader);
258 for(Int_t b=0; b<lob->GetEntries();b++)
260 TBranch* branch = (TBranch*)lob->At(b);
261 TString bname(branch->GetName());//
262 if ( bname.BeginsWith(det->GetName()) )
264 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
265 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
266 TString contname(branch->GetClassName());
268 Int_t splitlvl = branch->GetSplitLevel();
269 // if (splitlvl) splitlvl = 99;
271 if( contname.CompareTo("TClonesArray") == 0)
273 TBranchElement* belem = (TBranchElement*)branch;
274 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
276 ca = new TClonesArray(belem->GetClonesName());
277 pbuf[nbranches] = ca;
279 branch->SetAddress(&(pbuf[nbranches]));
280 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
282 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
283 branches[nbranches] = loader->TreeH()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
288 TClass* bcl = gROOT->GetClass(branch->GetClassName());
291 ::Error("ConvertToNewIO.C","Can not get TClass object of class named %s",branch->GetClassName());
294 pbuf[nbranches] = bcl->New();
295 ::Info("ConvertToNewIO.C","Dumping buffer:");
296 ((TObject*)pbuf[nbranches])->Dump();
297 ::Info("ConvertToNewIO.C","Setting Adress:");
298 branch->SetAddress(&(pbuf[nbranches]));
299 ::Info("ConvertToNewIO.C","Creating branch SpliLvl = %d",splitlvl);
300 branches[nbranches] =loader->TreeH()->Branch(branch->GetName(),branch->GetClassName(),&(pbuf[nbranches]),4000,splitlvl);
304 }//loop over branches
305 }//if module is detector
306 }//while loop over modules
307 Int_t nentr = (Int_t)treeH->GetEntries();
308 ::Info("ConvertToNewIO.C","Copying Hits . Number of entries %d ... ",nentr);
310 // ::Info("ConvertToNewIO.C","Getting event:");
312 Int_t nl = loaders->GetEntries();
313 for (Int_t e = 0; e < nentr; e++)
318 for (Int_t l = 0; l < nbranches; l++)
320 // printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
321 branches[l]->SetAddress(&(pbuf[l]));
324 for (Int_t l = 0; l < nl; l++)
326 AliLoader* loader = (AliLoader*)loaders->At(l);
327 // printf("Filling %s\n",loader->GetName());
328 loader->TreeH()->Fill();
338 ::Info("ConvertToNewIO.C","Copying Hits ... Done");
339 for (Int_t l = 0; l < nl; l++)
341 AliLoader* loader = (AliLoader*)loaders->At(l);
342 loader->WriteHits("OVERWRITE");
343 loader->UnloadHits();
346 for (Int_t l = 0; l < nbranches; l++)
348 delete (TObject*)pbuf[l];
352 else //tree has any entries
354 Info("ConvertToNewIO.C","Hits Tree is Empty");
359 ::Warning("ConvertToNewIO.C","Could not get TreeH from in AliRun.");
363 /*****************************************/
365 /*****************************************/
366 ::Info("ConvertToNewIO.C","Copying S Digits.");
367 TString treeSname("TreeS");
369 TTree* treeS = (TTree*)infile->Get(treeSname);
372 if (treeS->GetEntries() > 0)
374 TObjArray* lob = treeS->GetListOfBranches();
375 TObjArray* loaders = new TObjArray();
376 TIter nextnewmodule(outAliRun->Modules());
378 while ((module = (AliModule*)nextnewmodule()))
380 TClass* modclass = module->IsA();
381 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
382 TClonesArray* ca = 0;
385 AliLoader* loader = det->GetLoader();
388 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
392 TString mask(det->GetName());
394 loader->LoadSDigits("update");
395 loader->MakeTree("S");
396 loaders->Add(loader);
397 for(Int_t b=0; b<lob->GetEntries();b++)
399 TBranch* branch = (TBranch*)lob->At(b);
400 TString bname(branch->GetName());//
401 if ( bname.BeginsWith(det->GetName()) )
404 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
405 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
406 TString contname(branch->GetClassName());
408 Int_t splitlvl = branch->GetSplitLevel();
409 // if (splitlvl) splitlvl = 99;
411 if ( contname.CompareTo("TClonesArray") == 0)
413 TBranchElement* belem = (TBranchElement*)branch;
414 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
416 ca = new TClonesArray(belem->GetClonesName());
417 pbuf[nbranches] = ca;
419 branch->SetAddress(&(pbuf[nbranches]));
420 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
422 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
423 branches[nbranches] = loader->TreeS()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
428 TClass* bcl = gROOT->GetClass(branch->GetClassName());
431 ::Error("ConvertToNewIO.C","Can not get TClass object of class named %s",branch->GetClassName());
434 pbuf[nbranches] = bcl->New();
435 ::Info("ConvertToNewIO.C","Dumping buffer:");
436 ((TObject*)pbuf[nbranches])->Dump();
437 ::Info("ConvertToNewIO.C","Setting Adress:");
438 branch->SetAddress(&(pbuf[nbranches]));
439 ::Info("ConvertToNewIO.C","Creating branch SpliLvl = %d",splitlvl);
440 branches[nbranches] =loader->TreeS()->Branch(branch->GetName(),branch->GetClassName(),&(pbuf[nbranches]),4000,splitlvl);
444 }//loop over branches
445 }//if module is detector
446 }//while loop over modules
447 Int_t nentr = (Int_t)treeS->GetEntries();
448 ::Info("ConvertToNewIO.C","Copying SDigits. Number of entries %d ... ",nentr);
450 // ::Info("ConvertToNewIO.C","Getting event:");
452 Int_t nl = loaders->GetEntries();
453 for (Int_t e = 0; e < nentr; e++)
458 for (Int_t l = 0; l < nbranches; l++)
460 // printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
461 branches[l]->SetAddress(&(pbuf[l]));
464 for (Int_t l = 0; l < nl; l++)
466 AliLoader* loader = (AliLoader*)loaders->At(l);
467 // printf("Filling %s\n",loader->GetName());
468 loader->TreeS()->Fill();
478 ::Info("ConvertToNewIO.C","Copying SDigits ... Done");
479 for (Int_t l = 0; l < nl; l++)
481 AliLoader* loader = (AliLoader*)loaders->At(l);
482 loader->WriteSDigits("OVERWRITE");
483 loader->UnloadSDigits();
486 for (Int_t l = 0; l < nbranches; l++)
488 delete (TObject*)pbuf[l];
492 else //tree has any entries
494 ::Info("ConvertToNewIO.C","S Digits Tree is Empty");
499 ::Warning("ConvertToNewIO.C","Could not get TreeS from AliRun.");
503 /*****************************************/
505 /*****************************************/
506 ::Info("ConvertToNewIO.C","Copying Digits.");
507 TString treeDname("TreeD");
509 TTree* treeD = (TTree*)infile->Get(treeDname);
512 if (treeD->GetEntries() > 0)
515 TObjArray* lob = treeD->GetListOfBranches();
516 TObjArray* loaders = new TObjArray();
517 TIter nextnewmodule(outAliRun->Modules());
519 while ((module = (AliModule*)nextnewmodule()))
521 TClass* modclass = module->IsA();
522 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
523 TClonesArray* ca = 0;
526 AliLoader* loader = det->GetLoader();
529 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
533 TString mask(det->GetName());
535 loader->LoadDigits("update");
536 loader->MakeTree("D");
537 loaders->Add(loader);
538 for(Int_t b=0; b<lob->GetEntries();b++)
540 TBranch* branch = (TBranch*)lob->At(b);
541 TString bname(branch->GetName());//
542 if ( bname.BeginsWith(det->GetName()) )
545 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
546 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
547 TString contname(branch->GetClassName());
549 Int_t splitlvl = branch->GetSplitLevel();
550 // if (splitlvl) splitlvl = 99;
552 if ( contname.CompareTo("TClonesArray") == 0)
554 TBranchElement* belem = (TBranchElement*)branch;
555 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
557 ca = new TClonesArray(belem->GetClonesName());
558 pbuf[nbranches] = ca;
560 branch->SetAddress(&(pbuf[nbranches]));
561 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
563 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
564 branches[nbranches] = loader->TreeD()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
569 TClass* bcl = gROOT->GetClass(branch->GetClassName());
572 ::Error("ConvertToNewIO.C","Can not get TClass object of class named %s",branch->GetClassName());
575 pbuf[nbranches] = bcl->New();
576 ::Info("ConvertToNewIO.C","Dumping buffer:");
577 ((TObject*)pbuf[nbranches])->Dump();
578 ::Info("ConvertToNewIO.C","Setting Adress:");
579 branch->SetAddress(&(pbuf[nbranches]));
580 ::Info("ConvertToNewIO.C","Creating branch SpliLvl = %d",splitlvl);
581 branches[nbranches] =loader->TreeD()->Branch(branch->GetName(),branch->GetClassName(),&(pbuf[nbranches]),4000,splitlvl);
585 }//loop over branches
586 }//if module is detector
587 }//while loop over modules
588 Int_t nentr = (Int_t)treeD->GetEntries();
589 ::Info("ConvertToNewIO.C","Copying Digits. Number of entries %d ... ",nentr);
591 // ::Info("ConvertToNewIO.C","Getting event:");
593 Int_t nl = loaders->GetEntries();
594 for (Int_t e = 0; e < nentr; e++)
599 for (Int_t l = 0; l < nbranches; l++)
601 // printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
602 branches[l]->SetAddress(&(pbuf[l]));
605 for (Int_t l = 0; l < nl; l++)
607 AliLoader* loader = (AliLoader*)loaders->At(l);
608 // printf("Filling %s\n",loader->GetName());
609 loader->TreeD()->Fill();
619 ::Info("ConvertToNewIO.C","Copying Digits ... Done");
620 for (Int_t l = 0; l < nl; l++)
622 AliLoader* loader = (AliLoader*)loaders->At(l);
623 loader->WriteDigits("OVERWRITE");
624 loader->UnloadDigits();
628 else //tree has any entries
630 Info("ConvertToNewIO.C","S Digits Tree is Empty");
635 ::Warning("ConvertToNewIO.C","Could not get TreeD from in AliRun.");
638 for (Int_t l = 0; l < nbranches; l++)
640 delete (TObject*)pbuf[l];
644 /*****************************************/
645 /* R e c P o i n t s */
646 /*****************************************/
647 ::Info("ConvertToNewIO.C","Copying RecPoints.");
648 TString treeRname("TreeR");
650 TTree* treeR = (TTree*)infile->Get(treeRname);
653 if (treeR->GetEntries() > 0)
655 TObjArray* lob = treeR->GetListOfBranches();
656 TObjArray* loaders = new TObjArray();
657 TIter nextnewmodule(outAliRun->Modules());
659 while ((module = (AliModule*)nextnewmodule()))
661 TClass* modclass = module->IsA();
662 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
663 TClonesArray* ca = 0;
666 AliLoader* loader = det->GetLoader();
669 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
673 TString mask(det->GetName());
675 loader->LoadRecPoints("update");
676 loader->MakeTree("R");
677 loaders->Add(loader);
678 for(Int_t b=0; b<lob->GetEntries();b++)
680 TBranch* branch = (TBranch*)lob->At(b);
681 TString bname(branch->GetName());//
682 if ( bname.BeginsWith(det->GetName()) )
685 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
686 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
687 TString contname(branch->GetClassName());
689 Int_t splitlvl = branch->GetSplitLevel();
690 // if (splitlvl) splitlvl = 99;
692 if ( contname.CompareTo("TClonesArray") == 0)
694 TBranchElement* belem = (TBranchElement*)branch;
695 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
697 ca = new TClonesArray(belem->GetClonesName());
698 pbuf[nbranches] = ca;
700 branch->SetAddress(&(pbuf[nbranches]));
701 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
703 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
704 branches[nbranches] = loader->TreeR()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
709 TClass* bcl = gROOT->GetClass(branch->GetClassName());
712 ::Error("ConvertToNewIO.C","Can not get TClass object of class named %s",branch->GetClassName());
715 pbuf[nbranches] = bcl->New();
716 ::Info("ConvertToNewIO.C","Dumping buffer:");
717 ((TObject*)pbuf[nbranches])->Dump();
718 ::Info("ConvertToNewIO.C","Setting Adress:");
719 branch->SetAddress(&(pbuf[nbranches]));
720 ::Info("ConvertToNewIO.C","Creating branch SpliLvl = %d",splitlvl);
721 branches[nbranches] =loader->TreeR()->Branch(branch->GetName(),branch->GetClassName(),&(pbuf[nbranches]),4000,splitlvl);
725 }//loop over branches
726 }//if module is detector
727 }//while loop over modules
728 Int_t nentr = (Int_t)treeR->GetEntries();
729 ::Info("ConvertToNewIO.C","Copying RecPoints. Number of entries %d ... ",nentr);
731 // ::Info("ConvertToNewIO.C","Getting event:");
733 Int_t nl = loaders->GetEntries();
734 for (Int_t e = 0; e < nentr; e++)
739 for (Int_t l = 0; l < nbranches; l++)
741 // printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
742 branches[l]->SetAddress(&(pbuf[l]));
745 for (Int_t l = 0; l < nl; l++)
747 AliLoader* loader = (AliLoader*)loaders->At(l);
748 // printf("Filling %s\n",loader->GetName());
749 loader->TreeR()->Fill();
759 ::Info("ConvertToNewIO.C","Copying RecPoints ... Done");
760 for (Int_t l = 0; l < nl; l++)
762 AliLoader* loader = (AliLoader*)loaders->At(l);
763 loader->WriteRecPoints("OVERWRITE");
764 loader->UnloadRecPoints();
767 for (Int_t l = 0; l < nbranches; l++)
769 delete (TObject*)pbuf[l];//delete branches buffers
773 else //tree has any entries
775 Info("ConvertToNewIO.C","Rec Points Tree is Empty");
780 ::Warning("ConvertToNewIO.C","Could not get TreeR from in AliRun.");
784 }//end of loop over events
786 /***************************************************/
787 /**** Run to Run *************/
788 /***************************************************/
790 rl->WriteHeader("OVERWRITE");
793 TGeometry* geo = inAliRun->GetGeometry();
798 rl->WriteRunLoader();
800 ::Info("ConvertToNewIO.C","Done");