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);
30 outAliRun = new AliRun("OutgAlice","Output gAlice");
38 outAliRun->SetRunLoader(rl);
40 TFile* infile = TFile::Open(name);
44 ::Error("ConvertToNewIO.C","Can not open input file %s",name);
48 AliRun* inAliRun = (AliRun*)infile->Get("gAlice");
52 ::Error("ConvertToNewIO.C","Can not find gAlice in input file");
56 // inAliRun->GetEvent(0);
58 TObjArray* modules = inAliRun->Modules();
61 ::Error("ConvertToNewIO.C","Can not get array with modules from AliRun");
66 while ((module = (AliModule*)next()))
68 outAliRun->AddModule(module);
70 TClass* modclass = module->IsA();
71 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
74 ::Info("ConvertToNewIO.C"," Adding %s to RL.",det->GetName());
75 conf->Add(det,"Event");
80 TParticle* particleBuffer = new TParticle();
81 /***************************************************/
82 /**** Event to Event **************/
83 /***************************************************/
85 TTree* treeE = (TTree*)infile->Get("TE");
88 ::Error("ConvertToNewIO.C","Can not get TreeE from AliRun");
93 AliHeader* inheader = new AliHeader();
94 treeE->SetBranchAddress("Header",&inheader);
96 Int_t nevents = (Int_t)treeE->GetEntries();
97 for (Int_t i = 0; i<nevents; i++)
99 ::Info("ConvertToNewIO.C","Converting Event %d.",i);
100 rl->SetEventNumber(i);
102 /*****************************************/
104 /*****************************************/
106 ::Info("ConvertToNewIO.C","Copying Header");
107 AliHeader* outheader = rl->GetHeader();
110 outheader->SetEvent(inheader->GetEvent());
111 outheader->SetNvertex(inheader->GetNvertex());
112 outheader->SetNprimary(inheader->GetNprimary());
113 outheader->SetNtrack(inheader->GetNtrack());
114 outheader->SetRun(inheader->GetRun());
115 outheader->SetEventNrInRun(inheader->GetEventNrInRun());
116 outheader->SetStack(inheader->Stack());
117 outheader->SetGenEventHeader(inheader->GenEventHeader());
120 /*****************************************/
121 /* K I N E M A T I C S */
122 /*****************************************/
123 ::Info("ConvertToNewIO.C","Copying Kinematics.");
124 TString treeKname("TreeK");
126 TTree* treeK = (TTree*)infile->Get(treeKname);
129 if (treeK->GetEntries() > 0)
131 //I do this gimnastics to set directory correctly, without changing NewIO code
132 //only for this purpose
133 rl->LoadKinematics("update");
135 rl->GetEventFolder()->Remove(rl->TreeK());
138 treeK->SetBranchAddress("Particles",&particleBuffer);
139 ::Info("ConvertToNewIO.C","Cloning TreeK ...");
140 TTree* tk = treeK->CloneTree();
141 ::Info("ConvertToNewIO.C","Cloning TreeK ... Done");
142 tk->SetName(AliRunLoader::fgkKineContainerName);
143 rl->GetEventFolder()->Add(tk);
144 rl->WriteKinematics("OVERWRITE");
145 rl->UnloadKinematics();
149 Info("ConvertToNewIO.C","Kinematics Tree is Empty");
154 Error("ConvertToNewIO.C","Could not find Kinematics tree named %s",treeKname.Data());
157 /*****************************************/
158 /* T R A C K R E F E R E N C E S */
159 /*****************************************/
160 ::Info("ConvertToNewIO.C","Copying Track Refs.");
161 TString treeTRname("TreeTR");
163 TTree* treeTR = (TTree*)infile->Get(treeTRname);
166 if (treeTR->GetEntries() > 0)
169 while ((module = (AliModule*)next()))
171 TClass* modclass = module->IsA();
172 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
175 TClonesArray* trbuffer = new TClonesArray("AliTrackReference", 100);
176 treeTR->SetBranchAddress(det->GetName(),&trbuffer);
180 //I do this gimnastics to set directory correctly, without changing NewIO code
181 //only for this purpose
182 rl->LoadTrackRefs("update");
183 rl->MakeTrackRefsContainer();
184 rl->GetEventFolder()->Remove(rl->TreeTR());
187 ::Info("ConvertToNewIO.C","Cloning TreeTR ...");
188 TTree* tr = treeTR->CloneTree();
189 ::Info("ConvertToNewIO.C","Cloning TreeTR ... Done");
191 tr->SetName(AliRunLoader::fgkTrackRefsContainerName);
192 rl->GetEventFolder()->Add(tr);
193 rl->WriteTrackRefs("OVERWRITE");
194 rl->UnloadTrackRefs();
198 Info("ConvertToNewIO.C","Track References Tree is Empty");
203 Error("ConvertToNewIO.C","Could not find Track Refs tree named %s",treeTRname.Data());
207 /*****************************************/
209 /*****************************************/
210 ::Info("ConvertToNewIO.C","Copying Hits.");
211 TString treeHname("TreeH");
213 TTree* treeH = (TTree*)infile->Get(treeHname);
217 if (treeH->GetEntries() > 0)
219 TObjArray* lob = treeH->GetListOfBranches();
220 TObjArray* loaders = new TObjArray();
221 TIter nextnewmodule(outAliRun->Modules());
223 while ((module = (AliModule*)nextnewmodule()))
225 TClass* modclass = module->IsA();
226 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
227 TClonesArray* ca = 0;
230 AliLoader* loader = det->GetLoader();
233 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
237 TString mask(det->GetName());
239 loader->LoadHits("update");
240 loader->MakeTree("H");
241 loaders->Add(loader);
242 for(Int_t b=0; b<lob->GetEntries();b++)
244 TBranch* branch = (TBranch*)lob->At(b);
245 TString bname(branch->GetName());//
246 if ( bname.BeginsWith(det->GetName()) )
248 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
249 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
250 TString contname(branch->GetClassName());
252 Int_t splitlvl = branch->GetSplitLevel();
253 // if (splitlvl) splitlvl = 99;
255 if( contname.CompareTo("TClonesArray") == 0)
257 TBranchElement* belem = (TBranchElement*)branch;
258 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
260 ca = new TClonesArray(belem->GetClonesName());
261 pbuf[nbranches] = ca;
263 branch->SetAddress(&(pbuf[nbranches]));
264 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
266 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
267 branches[nbranches] = loader->TreeH()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
272 TClass* bcl = gROOT->GetClass(branch->GetClassName());
273 pbuf[nbranches] = bcl->New();
274 ::Info("ConvertToNewIO.C","Dumping buffer:");
275 ((TObject*)pbuf[nbranches])->Dump();
276 ::Info("ConvertToNewIO.C","Setting Adress:");
277 branch->SetAddress(&(pbuf[nbranches]));
278 ::Info("ConvertToNewIO.C","Creating branch SpliLvl = %d",splitlvl);
279 branches[nbranches] =loader->TreeH()->Branch(branch->GetName(),branch->GetClassName(),&(pbuf[nbranches]),4000,splitlvl);
283 }//loop over branches
284 }//if module is detector
285 }//while loop over modules
286 Int_t nentr = (Int_t)treeH->GetEntries();
287 ::Info("ConvertToNewIO.C","Copying Hits . Number of entries %d ... ",nentr);
289 // ::Info("ConvertToNewIO.C","Getting event:");
291 Int_t nl = loaders->GetEntries();
292 for (Int_t e = 0; e < nentr; e++)
297 for (Int_t l = 0; l < nbranches; l++)
299 // printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
300 branches[l]->SetAddress(&(pbuf[l]));
303 for (Int_t l = 0; l < nl; l++)
305 AliLoader* loader = (AliLoader*)loaders->At(l);
306 // printf("Filling %s\n",loader->GetName());
307 loader->TreeH()->Fill();
317 ::Info("ConvertToNewIO.C","Copying Hits ... Done");
318 for (Int_t l = 0; l < nl; l++)
320 AliLoader* loader = (AliLoader*)loaders->At(l);
321 loader->WriteHits("OVERWRITE");
322 loader->UnloadHits();
325 for (Int_t l = 0; l < nbranches; l++)
327 delete (TObject*)pbuf[l];
331 else //tree has any entries
333 Info("ConvertToNewIO.C","Hits Tree is Empty");
338 ::Warning("ConvertToNewIO.C","Could not get TreeH from in AliRun.");
342 /*****************************************/
344 /*****************************************/
345 ::Info("ConvertToNewIO.C","Copying S Digits.");
346 TString treeSname("TreeS");
348 TTree* treeS = (TTree*)infile->Get(treeSname);
351 if (treeS->GetEntries() > 0)
353 TObjArray* lob = treeS->GetListOfBranches();
354 TObjArray* loaders = new TObjArray();
355 TIter nextnewmodule(outAliRun->Modules());
357 while ((module = (AliModule*)nextnewmodule()))
359 TClass* modclass = module->IsA();
360 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
361 TClonesArray* ca = 0;
364 AliLoader* loader = det->GetLoader();
367 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
371 TString mask(det->GetName());
373 loader->LoadSDigits("update");
374 loader->MakeTree("S");
375 loaders->Add(loader);
376 for(Int_t b=0; b<lob->GetEntries();b++)
378 TBranch* branch = (TBranch*)lob->At(b);
379 TString bname(branch->GetName());//
380 if ( bname.BeginsWith(det->GetName()) )
383 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
384 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
385 TString contname(branch->GetClassName());
387 Int_t splitlvl = branch->GetSplitLevel();
388 // if (splitlvl) splitlvl = 99;
390 if ( contname.CompareTo("TClonesArray") == 0)
392 TBranchElement* belem = (TBranchElement*)branch;
393 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
395 ca = new TClonesArray(belem->GetClonesName());
396 pbuf[nbranches] = ca;
398 branch->SetAddress(&(pbuf[nbranches]));
399 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
401 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
402 branches[nbranches] = loader->TreeS()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
407 TClass* bcl = gROOT->GetClass(branch->GetClassName());
408 pbuf[nbranches] = bcl->New();
409 ::Info("ConvertToNewIO.C","Dumping buffer:");
410 ((TObject*)pbuf[nbranches])->Dump();
411 ::Info("ConvertToNewIO.C","Setting Adress:");
412 branch->SetAddress(&(pbuf[nbranches]));
413 ::Info("ConvertToNewIO.C","Creating branch SpliLvl = %d",splitlvl);
414 branches[nbranches] =loader->TreeS()->Branch(branch->GetName(),branch->GetClassName(),&(pbuf[nbranches]),4000,splitlvl);
418 }//loop over branches
419 }//if module is detector
420 }//while loop over modules
421 Int_t nentr = (Int_t)treeS->GetEntries();
422 ::Info("ConvertToNewIO.C","Copying SDigits. Number of entries %d ... ",nentr);
424 // ::Info("ConvertToNewIO.C","Getting event:");
426 Int_t nl = loaders->GetEntries();
427 for (Int_t e = 0; e < nentr; e++)
432 for (Int_t l = 0; l < nbranches; l++)
434 // printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
435 branches[l]->SetAddress(&(pbuf[l]));
438 for (Int_t l = 0; l < nl; l++)
440 AliLoader* loader = (AliLoader*)loaders->At(l);
441 // printf("Filling %s\n",loader->GetName());
442 loader->TreeS()->Fill();
452 ::Info("ConvertToNewIO.C","Copying SDigits ... Done");
453 for (Int_t l = 0; l < nl; l++)
455 AliLoader* loader = (AliLoader*)loaders->At(l);
456 loader->WriteSDigits("OVERWRITE");
457 loader->UnloadSDigits();
460 for (Int_t l = 0; l < nbranches; l++)
462 delete (TObject*)pbuf[l];
466 else //tree has any entries
468 Info("ConvertToNewIO.C","S Digits Tree is Empty");
473 ::Warning("ConvertToNewIO.C","Could not get TreeS from in AliRun.");
477 /*****************************************/
479 /*****************************************/
480 ::Info("ConvertToNewIO.C","Copying Digits.");
481 TString treeDname("TreeD");
483 TTree* treeD = (TTree*)infile->Get(treeDname);
486 if (treeD->GetEntries() > 0)
489 TObjArray* lob = treeD->GetListOfBranches();
490 TObjArray* loaders = new TObjArray();
491 TIter nextnewmodule(outAliRun->Modules());
493 while ((module = (AliModule*)nextnewmodule()))
495 TClass* modclass = module->IsA();
496 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
497 TClonesArray* ca = 0;
500 AliLoader* loader = det->GetLoader();
503 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
507 TString mask(det->GetName());
509 loader->LoadDigits("update");
510 loader->MakeTree("D");
511 loaders->Add(loader);
512 for(Int_t b=0; b<lob->GetEntries();b++)
514 TBranch* branch = (TBranch*)lob->At(b);
515 TString bname(branch->GetName());//
516 if ( bname.BeginsWith(det->GetName()) )
519 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
520 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
521 TString contname(branch->GetClassName());
523 Int_t splitlvl = branch->GetSplitLevel();
524 // if (splitlvl) splitlvl = 99;
526 if ( contname.CompareTo("TClonesArray") == 0)
528 TBranchElement* belem = (TBranchElement*)branch;
529 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
531 ca = new TClonesArray(belem->GetClonesName());
532 pbuf[nbranches] = ca;
534 branch->SetAddress(&(pbuf[nbranches]));
535 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
537 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
538 branches[nbranches] = loader->TreeD()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
543 TClass* bcl = gROOT->GetClass(branch->GetClassName());
544 pbuf[nbranches] = bcl->New();
545 ::Info("ConvertToNewIO.C","Dumping buffer:");
546 ((TObject*)pbuf[nbranches])->Dump();
547 ::Info("ConvertToNewIO.C","Setting Adress:");
548 branch->SetAddress(&(pbuf[nbranches]));
549 ::Info("ConvertToNewIO.C","Creating branch SpliLvl = %d",splitlvl);
550 branches[nbranches] =loader->TreeD()->Branch(branch->GetName(),branch->GetClassName(),&(pbuf[nbranches]),4000,splitlvl);
554 }//loop over branches
555 }//if module is detector
556 }//while loop over modules
557 Int_t nentr = (Int_t)treeD->GetEntries();
558 ::Info("ConvertToNewIO.C","Copying Digits. Number of entries %d ... ",nentr);
560 // ::Info("ConvertToNewIO.C","Getting event:");
562 Int_t nl = loaders->GetEntries();
563 for (Int_t e = 0; e < nentr; e++)
568 for (Int_t l = 0; l < nbranches; l++)
570 // printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
571 branches[l]->SetAddress(&(pbuf[l]));
574 for (Int_t l = 0; l < nl; l++)
576 AliLoader* loader = (AliLoader*)loaders->At(l);
577 // printf("Filling %s\n",loader->GetName());
578 loader->TreeD()->Fill();
588 ::Info("ConvertToNewIO.C","Copying Digits ... Done");
589 for (Int_t l = 0; l < nl; l++)
591 AliLoader* loader = (AliLoader*)loaders->At(l);
592 loader->WriteDigits("OVERWRITE");
593 loader->UnloadDigits();
597 else //tree has any entries
599 Info("ConvertToNewIO.C","S Digits Tree is Empty");
604 ::Warning("ConvertToNewIO.C","Could not get TreeD from in AliRun.");
607 for (Int_t l = 0; l < nbranches; l++)
609 delete (TObject*)pbuf[l];
613 /*****************************************/
614 /* R e c P o i n t s */
615 /*****************************************/
616 ::Info("ConvertToNewIO.C","Copying RecPoints.");
617 TString treeRname("TreeR");
619 TTree* treeR = (TTree*)infile->Get(treeRname);
622 if (treeR->GetEntries() > 0)
624 TObjArray* lob = treeR->GetListOfBranches();
625 TObjArray* loaders = new TObjArray();
626 TIter nextnewmodule(outAliRun->Modules());
628 while ((module = (AliModule*)nextnewmodule()))
630 TClass* modclass = module->IsA();
631 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
632 TClonesArray* ca = 0;
635 AliLoader* loader = det->GetLoader();
638 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
642 TString mask(det->GetName());
644 loader->LoadRecPoints("update");
645 loader->MakeTree("R");
646 loaders->Add(loader);
647 for(Int_t b=0; b<lob->GetEntries();b++)
649 TBranch* branch = (TBranch*)lob->At(b);
650 TString bname(branch->GetName());//
651 if ( bname.BeginsWith(det->GetName()) )
654 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
655 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
656 TString contname(branch->GetClassName());
658 Int_t splitlvl = branch->GetSplitLevel();
659 // if (splitlvl) splitlvl = 99;
661 if ( contname.CompareTo("TClonesArray") == 0)
663 TBranchElement* belem = (TBranchElement*)branch;
664 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
666 ca = new TClonesArray(belem->GetClonesName());
667 pbuf[nbranches] = ca;
669 branch->SetAddress(&(pbuf[nbranches]));
670 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
672 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
673 branches[nbranches] = loader->TreeR()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
678 TClass* bcl = gROOT->GetClass(branch->GetClassName());
679 pbuf[nbranches] = bcl->New();
680 ::Info("ConvertToNewIO.C","Dumping buffer:");
681 ((TObject*)pbuf[nbranches])->Dump();
682 ::Info("ConvertToNewIO.C","Setting Adress:");
683 branch->SetAddress(&(pbuf[nbranches]));
684 ::Info("ConvertToNewIO.C","Creating branch SpliLvl = %d",splitlvl);
685 branches[nbranches] =loader->TreeR()->Branch(branch->GetName(),branch->GetClassName(),&(pbuf[nbranches]),4000,splitlvl);
689 }//loop over branches
690 }//if module is detector
691 }//while loop over modules
692 Int_t nentr = (Int_t)treeR->GetEntries();
693 ::Info("ConvertToNewIO.C","Copying RecPoints. Number of entries %d ... ",nentr);
695 // ::Info("ConvertToNewIO.C","Getting event:");
697 Int_t nl = loaders->GetEntries();
698 for (Int_t e = 0; e < nentr; e++)
703 for (Int_t l = 0; l < nbranches; l++)
705 // printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
706 branches[l]->SetAddress(&(pbuf[l]));
709 for (Int_t l = 0; l < nl; l++)
711 AliLoader* loader = (AliLoader*)loaders->At(l);
712 // printf("Filling %s\n",loader->GetName());
713 loader->TreeR()->Fill();
723 ::Info("ConvertToNewIO.C","Copying RecPoints ... Done");
724 for (Int_t l = 0; l < nl; l++)
726 AliLoader* loader = (AliLoader*)loaders->At(l);
727 loader->WriteRecPoints("OVERWRITE");
728 loader->UnloadRecPoints();
731 for (Int_t l = 0; l < nbranches; l++)
733 delete (TObject*)pbuf[l];//delete branches buffers
737 else //tree has any entries
739 Info("ConvertToNewIO.C","Rec Points Tree is Empty");
744 ::Warning("ConvertToNewIO.C","Could not get TreeR from in AliRun.");
748 }//end of loop over events
750 /***************************************************/
751 /**** Run to Run *************/
752 /***************************************************/
754 rl->WriteHeader("OVERWRITE");
757 TGeometry* geo = inAliRun->GetGeometry();
762 rl->WriteRunLoader();
764 ::Info("ConvertToNewIO.C","Done");