]> git.uio.no Git - u/mrichter/AliRoot.git/blame - macros/ConvertToNewIO.C
Classed moved form libJETANMC to libJETAN.
[u/mrichter/AliRoot.git] / macros / ConvertToNewIO.C
CommitLineData
88cb7938 1#ifndef __MAKECINT__
2 #ifndef __CINT__
3 #include "alles.h"
4 #include "TInterpreter.h"
5 #include "TBranchClones.h"
6 #include "TBranchElement.h"
7 #include "AliTPCTrackHits.h"
8 #include "AliTRDtrackHits.h"
9 #endif
10#endif
11
12void ConvertToNewIO(const char* name)
13{
14// AliLoader::SetDebug();
15 AliConfig* conf = AliConfig::Instance();
16 TClass* detclass = AliDetector::Class();
17 void* buff;
18 Bool_t skipit = kFALSE;
19 void * pbuf[100];
20 TBranch* branches[100];
21 Int_t nbranches = 0;
22
23 AliRunLoader* rl = AliRunLoader::Open("galiceNewIO.root","Event","recreate");
24 rl->SetCompressionLevel(2);
8eed56ee 25 rl->SetNumberOfEventsPerFile(100);
26
88cb7938 27 AliRun* outAliRun;
28
29 if (gAlice == 0x0)
30 {
31 outAliRun = new AliRun("OutgAlice","Output gAlice");
32 }
33 else
34 {
35 outAliRun = gAlice;
36 }
37 gAlice = 0x0;
38
39 outAliRun->SetRunLoader(rl);
40
41 TFile* infile = TFile::Open(name);
42
43 if (infile == 0x0)
44 {
45 ::Error("ConvertToNewIO.C","Can not open input file %s",name);
46 return;
47 }
48
49 AliRun* inAliRun = (AliRun*)infile->Get("gAlice");
50
51 if(inAliRun == 0x0)
52 {
53 ::Error("ConvertToNewIO.C","Can not find gAlice in input file");
54 return;
55 }
56 gAlice = inAliRun;
57// inAliRun->GetEvent(0);
58
59 TObjArray* modules = inAliRun->Modules();
60 if (modules == 0x0)
61 {
62 ::Error("ConvertToNewIO.C","Can not get array with modules from AliRun");
63 return;
64 }
65 TIter next(modules);
66 AliModule* module;
8eed56ee 67 TObject * object;
68 while ((object = next()))
88cb7938 69 {
8eed56ee 70 module = dynamic_cast<AliModule*>(object);
71 if (module == 0x0) {
72 ::Error("ConvertToNewIO.C","Can not cast module %#x ",object);
73 object->Dump();
74 continue;
75 }
76
88cb7938 77 outAliRun->AddModule(module);
78
79 TClass* modclass = module->IsA();
80 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
81 if (det)
82 {
83 ::Info("ConvertToNewIO.C"," Adding %s to RL.",det->GetName());
84 conf->Add(det,"Event");
85 rl->AddLoader(det);
86 }
87 }
88
89 TParticle* particleBuffer = new TParticle();
90 /***************************************************/
91 /**** Event to Event **************/
92 /***************************************************/
93
94 TTree* treeE = (TTree*)infile->Get("TE");
95 if (treeE == 0x0)
96 {
97 ::Error("ConvertToNewIO.C","Can not get TreeE from AliRun");
98 return;
99 }
100 rl->MakeTree("E");
101
102 AliHeader* inheader = new AliHeader();
103 treeE->SetBranchAddress("Header",&inheader);
104
105 Int_t nevents = (Int_t)treeE->GetEntries();
106 for (Int_t i = 0; i<nevents; i++)
107 {
108 ::Info("ConvertToNewIO.C","Converting Event %d.",i);
109 rl->SetEventNumber(i);
110 treeE->GetEvent(i);
111 /*****************************************/
112 /* H E A D E R */
113 /*****************************************/
114
115 ::Info("ConvertToNewIO.C","Copying Header");
116 AliHeader* outheader = rl->GetHeader();
117
118
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());
127 rl->TreeE()->Fill();
128
129 /*****************************************/
130 /* K I N E M A T I C S */
131 /*****************************************/
132 ::Info("ConvertToNewIO.C","Copying Kinematics.");
133 TString treeKname("TreeK");
134 treeKname+=i;
135 TTree* treeK = (TTree*)infile->Get(treeKname);
136 if (treeK)
137 {
138 if (treeK->GetEntries() > 0)
139 {
140 //I do this gimnastics to set directory correctly, without changing NewIO code
141 //only for this purpose
142 rl->LoadKinematics("update");
143 rl->MakeTree("K");
144 rl->GetEventFolder()->Remove(rl->TreeK());
145 delete rl->TreeK();
146
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();
155 }
156 else
157 {
158 Info("ConvertToNewIO.C","Kinematics Tree is Empty");
159 }
160 }
161 else
162 {
163 Error("ConvertToNewIO.C","Could not find Kinematics tree named %s",treeKname.Data());
164 }
165 delete treeK;
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");
171 treeTRname+=i;
172 TTree* treeTR = (TTree*)infile->Get(treeTRname);
173 if (treeTR)
174 {
175 if (treeTR->GetEntries() > 0)
176 {
177 next.Reset();
8eed56ee 178 TObject * object;
179 while ((object = next()))
88cb7938 180 {
8eed56ee 181 module = dynamic_cast<AliModule*>(object);
182 if (module == 0x0) {
183 ::Error("ConvertToNewIO.C","Can not cast module %#x ",object);
184 object->Dump();
185 continue;
186 }
88cb7938 187 TClass* modclass = module->IsA();
188 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
189 if (det)
190 {
191 TClonesArray* trbuffer = new TClonesArray("AliTrackReference", 100);
192 treeTR->SetBranchAddress(det->GetName(),&trbuffer);
193 }
194 }
195
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());
201 delete rl->TreeTR();
202
203 ::Info("ConvertToNewIO.C","Cloning TreeTR ...");
204 TTree* tr = treeTR->CloneTree();
205 ::Info("ConvertToNewIO.C","Cloning TreeTR ... Done");
206
207 tr->SetName(AliRunLoader::fgkTrackRefsContainerName);
208 rl->GetEventFolder()->Add(tr);
209 rl->WriteTrackRefs("OVERWRITE");
210 rl->UnloadTrackRefs();
211 }
212 else
213 {
214 Info("ConvertToNewIO.C","Track References Tree is Empty");
215 }
216 }
217 else
218 {
219 Error("ConvertToNewIO.C","Could not find Track Refs tree named %s",treeTRname.Data());
220 }
221 delete treeTR;
222
223 /*****************************************/
224 /* H I T S */
225 /*****************************************/
226 ::Info("ConvertToNewIO.C","Copying Hits.");
227 TString treeHname("TreeH");
228 treeHname+=i;
229 TTree* treeH = (TTree*)infile->Get(treeHname);
230
231 if (treeH)
232 {
233 if (treeH->GetEntries() > 0)
234 {
235 TObjArray* lob = treeH->GetListOfBranches();
236 TObjArray* loaders = new TObjArray();
237 TIter nextnewmodule(outAliRun->Modules());
238
239 while ((module = (AliModule*)nextnewmodule()))
240 {
241 TClass* modclass = module->IsA();
242 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
243 TClonesArray* ca = 0;
244 if (det)
245 {
246 AliLoader* loader = det->GetLoader();
247 if (loader == 0x0)
248 {
249 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
250 continue;
251 }
252
253 TString mask(det->GetName());
254
255 loader->LoadHits("update");
256 loader->MakeTree("H");
257 loaders->Add(loader);
258 for(Int_t b=0; b<lob->GetEntries();b++)
259 {
260 TBranch* branch = (TBranch*)lob->At(b);
261 TString bname(branch->GetName());//
262 if ( bname.BeginsWith(det->GetName()) )
263 {
264 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
265 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
266 TString contname(branch->GetClassName());
267
268 Int_t splitlvl = branch->GetSplitLevel();
269 // if (splitlvl) splitlvl = 99;
270
271 if( contname.CompareTo("TClonesArray") == 0)
272 {
273 TBranchElement* belem = (TBranchElement*)branch;
274 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
275
276 ca = new TClonesArray(belem->GetClonesName());
277 pbuf[nbranches] = ca;
278
279 branch->SetAddress(&(pbuf[nbranches]));
280 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
281
282 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
283 branches[nbranches] = loader->TreeH()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
284 nbranches++;
285 }
286 else
287 {
288 TClass* bcl = gROOT->GetClass(branch->GetClassName());
8eed56ee 289 if (bcl == 0x0)
290 {
291 ::Error("ConvertToNewIO.C","Can not get TClass object of class named %s",branch->GetClassName());
292 continue;
293 }
88cb7938 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);
301 nbranches++;
302 }
303 }
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);
309
310// ::Info("ConvertToNewIO.C","Getting event:");
311// nentr = 100;
312 Int_t nl = loaders->GetEntries();
313 for (Int_t e = 0; e < nentr; e++)
314 {
315 printf("%d\r",e);
316 treeH->GetEntry(e);
317
318 for (Int_t l = 0; l < nbranches; l++)
319 {
320// printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
321 branches[l]->SetAddress(&(pbuf[l]));
322 }
323
324 for (Int_t l = 0; l < nl; l++)
325 {
326 AliLoader* loader = (AliLoader*)loaders->At(l);
327// printf("Filling %s\n",loader->GetName());
328 loader->TreeH()->Fill();
329 }
330 #ifndef __MAKECINT__
331 #ifndef __CINT__
332 fflush(0);
333 #endif
334 #endif
335 }
336 printf("\n");
337
338 ::Info("ConvertToNewIO.C","Copying Hits ... Done");
339 for (Int_t l = 0; l < nl; l++)
340 {
341 AliLoader* loader = (AliLoader*)loaders->At(l);
342 loader->WriteHits("OVERWRITE");
343 loader->UnloadHits();
344 }
345 delete loaders;
346 for (Int_t l = 0; l < nbranches; l++)
347 {
348 delete (TObject*)pbuf[l];
349 }
350 nbranches = 0;
351 }
352 else //tree has any entries
353 {
354 Info("ConvertToNewIO.C","Hits Tree is Empty");
355 }
356 }
357 else //treeH
358 {
359 ::Warning("ConvertToNewIO.C","Could not get TreeH from in AliRun.");
360 }
361 delete treeH;
362
363 /*****************************************/
364 /* S D i g i t s */
365 /*****************************************/
366 ::Info("ConvertToNewIO.C","Copying S Digits.");
367 TString treeSname("TreeS");
368 treeSname+=i;
369 TTree* treeS = (TTree*)infile->Get(treeSname);
370 if (treeS)
371 {
372 if (treeS->GetEntries() > 0)
373 {
374 TObjArray* lob = treeS->GetListOfBranches();
375 TObjArray* loaders = new TObjArray();
376 TIter nextnewmodule(outAliRun->Modules());
377
378 while ((module = (AliModule*)nextnewmodule()))
379 {
380 TClass* modclass = module->IsA();
381 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
382 TClonesArray* ca = 0;
383 if (det)
384 {
385 AliLoader* loader = det->GetLoader();
386 if (loader == 0x0)
387 {
388 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
389 continue;
390 }
391
392 TString mask(det->GetName());
393
394 loader->LoadSDigits("update");
395 loader->MakeTree("S");
396 loaders->Add(loader);
397 for(Int_t b=0; b<lob->GetEntries();b++)
398 {
399 TBranch* branch = (TBranch*)lob->At(b);
400 TString bname(branch->GetName());//
401 if ( bname.BeginsWith(det->GetName()) )
402 {
403
404 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
405 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
406 TString contname(branch->GetClassName());
407
408 Int_t splitlvl = branch->GetSplitLevel();
409 // if (splitlvl) splitlvl = 99;
410
411 if ( contname.CompareTo("TClonesArray") == 0)
412 {
413 TBranchElement* belem = (TBranchElement*)branch;
414 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
415
416 ca = new TClonesArray(belem->GetClonesName());
417 pbuf[nbranches] = ca;
418
419 branch->SetAddress(&(pbuf[nbranches]));
420 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
421
422 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
423 branches[nbranches] = loader->TreeS()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
424 nbranches++;
425 }
426 else
427 {
428 TClass* bcl = gROOT->GetClass(branch->GetClassName());
8eed56ee 429 if (bcl == 0x0)
430 {
431 ::Error("ConvertToNewIO.C","Can not get TClass object of class named %s",branch->GetClassName());
432 continue;
433 }
88cb7938 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);
441 nbranches++;
442 }
443 }
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);
449
450// ::Info("ConvertToNewIO.C","Getting event:");
451// nentr = 100;
452 Int_t nl = loaders->GetEntries();
453 for (Int_t e = 0; e < nentr; e++)
454 {
455 printf("%d\r",e);
456 treeS->GetEntry(e);
457
458 for (Int_t l = 0; l < nbranches; l++)
459 {
460// printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
461 branches[l]->SetAddress(&(pbuf[l]));
462 }
463
464 for (Int_t l = 0; l < nl; l++)
465 {
466 AliLoader* loader = (AliLoader*)loaders->At(l);
467// printf("Filling %s\n",loader->GetName());
468 loader->TreeS()->Fill();
469 }
470 #ifndef __MAKECINT__
471 #ifndef __CINT__
472 fflush(0);
473 #endif
474 #endif
475 }
476 printf("\n");
477
478 ::Info("ConvertToNewIO.C","Copying SDigits ... Done");
479 for (Int_t l = 0; l < nl; l++)
480 {
481 AliLoader* loader = (AliLoader*)loaders->At(l);
482 loader->WriteSDigits("OVERWRITE");
483 loader->UnloadSDigits();
484 }
485 delete loaders;
486 for (Int_t l = 0; l < nbranches; l++)
487 {
488 delete (TObject*)pbuf[l];
489 }
490 nbranches = 0;
491 }
492 else //tree has any entries
493 {
8eed56ee 494 ::Info("ConvertToNewIO.C","S Digits Tree is Empty");
88cb7938 495 }
496 }
497 else //treeS
498 {
8eed56ee 499 ::Warning("ConvertToNewIO.C","Could not get TreeS from AliRun.");
88cb7938 500 }
501 delete treeS;
502
503 /*****************************************/
504 /* D i g i t s */
505 /*****************************************/
506 ::Info("ConvertToNewIO.C","Copying Digits.");
507 TString treeDname("TreeD");
508 treeDname+=i;
509 TTree* treeD = (TTree*)infile->Get(treeDname);
510 if (treeD)
511 {
512 if (treeD->GetEntries() > 0)
513 {
514
515 TObjArray* lob = treeD->GetListOfBranches();
516 TObjArray* loaders = new TObjArray();
517 TIter nextnewmodule(outAliRun->Modules());
518
519 while ((module = (AliModule*)nextnewmodule()))
520 {
521 TClass* modclass = module->IsA();
522 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
523 TClonesArray* ca = 0;
524 if (det)
525 {
526 AliLoader* loader = det->GetLoader();
527 if (loader == 0x0)
528 {
529 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
530 continue;
531 }
532
533 TString mask(det->GetName());
534
535 loader->LoadDigits("update");
536 loader->MakeTree("D");
537 loaders->Add(loader);
538 for(Int_t b=0; b<lob->GetEntries();b++)
539 {
540 TBranch* branch = (TBranch*)lob->At(b);
541 TString bname(branch->GetName());//
542 if ( bname.BeginsWith(det->GetName()) )
543 {
544
545 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
546 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
547 TString contname(branch->GetClassName());
548
549 Int_t splitlvl = branch->GetSplitLevel();
550 // if (splitlvl) splitlvl = 99;
551
552 if ( contname.CompareTo("TClonesArray") == 0)
553 {
554 TBranchElement* belem = (TBranchElement*)branch;
555 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
556
557 ca = new TClonesArray(belem->GetClonesName());
558 pbuf[nbranches] = ca;
559
560 branch->SetAddress(&(pbuf[nbranches]));
561 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
562
563 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
564 branches[nbranches] = loader->TreeD()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
565 nbranches++;
566 }
567 else
568 {
569 TClass* bcl = gROOT->GetClass(branch->GetClassName());
8eed56ee 570 if (bcl == 0x0)
571 {
572 ::Error("ConvertToNewIO.C","Can not get TClass object of class named %s",branch->GetClassName());
573 continue;
574 }
88cb7938 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);
582 nbranches++;
583 }
584 }
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);
590
591// ::Info("ConvertToNewIO.C","Getting event:");
592// nentr = 100;
593 Int_t nl = loaders->GetEntries();
594 for (Int_t e = 0; e < nentr; e++)
595 {
596 printf("%d\r",e);
597 treeD->GetEntry(e);
598
599 for (Int_t l = 0; l < nbranches; l++)
600 {
601// printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
602 branches[l]->SetAddress(&(pbuf[l]));
603 }
604
605 for (Int_t l = 0; l < nl; l++)
606 {
607 AliLoader* loader = (AliLoader*)loaders->At(l);
608// printf("Filling %s\n",loader->GetName());
609 loader->TreeD()->Fill();
610 }
611 #ifndef __MAKECINT__
612 #ifndef __CINT__
613 fflush(0);
614 #endif
615 #endif
616 }
617 printf("\n");
618
619 ::Info("ConvertToNewIO.C","Copying Digits ... Done");
620 for (Int_t l = 0; l < nl; l++)
621 {
622 AliLoader* loader = (AliLoader*)loaders->At(l);
623 loader->WriteDigits("OVERWRITE");
624 loader->UnloadDigits();
625 }
626 delete loaders;
627 }
628 else //tree has any entries
629 {
630 Info("ConvertToNewIO.C","S Digits Tree is Empty");
631 }
632 }
633 else //treeD
634 {
635 ::Warning("ConvertToNewIO.C","Could not get TreeD from in AliRun.");
636 }
637 delete treeD;
638 for (Int_t l = 0; l < nbranches; l++)
639 {
640 delete (TObject*)pbuf[l];
641 }
642 nbranches = 0;
643
644 /*****************************************/
645 /* R e c P o i n t s */
646 /*****************************************/
647 ::Info("ConvertToNewIO.C","Copying RecPoints.");
648 TString treeRname("TreeR");
649 treeRname+=i;
650 TTree* treeR = (TTree*)infile->Get(treeRname);
651 if (treeR)
652 {
653 if (treeR->GetEntries() > 0)
654 {
655 TObjArray* lob = treeR->GetListOfBranches();
656 TObjArray* loaders = new TObjArray();
657 TIter nextnewmodule(outAliRun->Modules());
658
659 while ((module = (AliModule*)nextnewmodule()))
660 {
661 TClass* modclass = module->IsA();
662 AliDetector *det = (AliDetector*)(modclass->DynamicCast(detclass,module));
663 TClonesArray* ca = 0;
664 if (det)
665 {
666 AliLoader* loader = det->GetLoader();
667 if (loader == 0x0)
668 {
669 ::Error("ConvertToNewIO.C","Can not find loader from %s.",det->GetName());
670 continue;
671 }
672
673 TString mask(det->GetName());
674
675 loader->LoadRecPoints("update");
676 loader->MakeTree("R");
677 loaders->Add(loader);
678 for(Int_t b=0; b<lob->GetEntries();b++)
679 {
680 TBranch* branch = (TBranch*)lob->At(b);
681 TString bname(branch->GetName());//
682 if ( bname.BeginsWith(det->GetName()) )
683 {
684
685 ::Info("ConvertToNewIO.C","Found branch %s.",branch->GetName());
686 ::Info("ConvertToNewIO.C","Buffer Class Name %s.",branch->GetClassName());
687 TString contname(branch->GetClassName());
688
689 Int_t splitlvl = branch->GetSplitLevel();
690 // if (splitlvl) splitlvl = 99;
691
692 if ( contname.CompareTo("TClonesArray") == 0)
693 {
694 TBranchElement* belem = (TBranchElement*)branch;
695 ::Info("ConvertToNewIO.C","Clones Class Name %s.",belem->GetClonesName());
696
697 ca = new TClonesArray(belem->GetClonesName());
698 pbuf[nbranches] = ca;
699
700 branch->SetAddress(&(pbuf[nbranches]));
701 ::Info("ConvertToNewIO.C","Buffer addrss %#x",pbuf[nbranches]);
702
703 ::Info("ConvertToNewIO.C","Creating branch for Clones SpliLvl = %d",splitlvl);
704 branches[nbranches] = loader->TreeR()->Branch(branch->GetName(),&(pbuf[nbranches]),4000,splitlvl);
705 nbranches++;
706 }
707 else
708 {
709 TClass* bcl = gROOT->GetClass(branch->GetClassName());
8eed56ee 710 if (bcl == 0x0)
711 {
712 ::Error("ConvertToNewIO.C","Can not get TClass object of class named %s",branch->GetClassName());
713 continue;
714 }
88cb7938 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);
722 nbranches++;
723 }
724 }
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);
730
731// ::Info("ConvertToNewIO.C","Getting event:");
732// nentr = 100;
733 Int_t nl = loaders->GetEntries();
734 for (Int_t e = 0; e < nentr; e++)
735 {
736 printf("%d\r",e);
737 treeR->GetEntry(e);
738
739 for (Int_t l = 0; l < nbranches; l++)
740 {
741// printf("%s %#x \n", branches[l]->GetName(),pbuf[l]);
742 branches[l]->SetAddress(&(pbuf[l]));
743 }
744
745 for (Int_t l = 0; l < nl; l++)
746 {
747 AliLoader* loader = (AliLoader*)loaders->At(l);
748// printf("Filling %s\n",loader->GetName());
749 loader->TreeR()->Fill();
750 }
751 #ifndef __MAKECINT__
752 #ifndef __CINT__
753 fflush(0);
754 #endif
755 #endif
756 }
757 printf("\n");
758
759 ::Info("ConvertToNewIO.C","Copying RecPoints ... Done");
760 for (Int_t l = 0; l < nl; l++)
761 {
762 AliLoader* loader = (AliLoader*)loaders->At(l);
763 loader->WriteRecPoints("OVERWRITE");
764 loader->UnloadRecPoints();
765 }
766 delete loaders;
767 for (Int_t l = 0; l < nbranches; l++)
768 {
769 delete (TObject*)pbuf[l];//delete branches buffers
770 }
771 nbranches = 0;
772 }
773 else //tree has any entries
774 {
775 Info("ConvertToNewIO.C","Rec Points Tree is Empty");
776 }
777 }
778 else //treeR
779 {
780 ::Warning("ConvertToNewIO.C","Could not get TreeR from in AliRun.");
781 }
782 delete treeR;
783
784 }//end of loop over events
785
786 /***************************************************/
787 /**** Run to Run *************/
788 /***************************************************/
789
790 rl->WriteHeader("OVERWRITE");
791
792 infile->cd();
793 TGeometry* geo = inAliRun->GetGeometry();
794 rl->CdGAFile();
795 geo->Write();
796
797 rl->WriteAliRun();
798 rl->WriteRunLoader();
799
800 ::Info("ConvertToNewIO.C","Done");
801
802}
803