]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliLoader.cxx
Adding again track references for the decay points
[u/mrichter/AliRoot.git] / STEER / AliLoader.cxx
1 //
2 //Class (base) responsible for management of data:
3 //    - opening and closing proper files
4 //    - posting data to folders
5 //    - writing data from folders to proper files
6 //
7 //Author: Alice Offline Group http://alisoft.cern.ch
8 //Responsible: Piotr.Skowronski@cern.ch
9 //
10 #include <AliLoader.h>
11
12 //Root includes
13 #include <TROOT.h>
14 #include <TFolder.h>
15 #include <TFile.h>
16 #include <TTree.h>
17 #include <TTask.h>
18 #include <TString.h>
19 #include <TError.h>
20
21 //AliRoot includes
22 #include <AliRun.h>
23 #include <AliRunLoader.h>
24 #include <AliRunDigitizer.h>
25 #include <AliDigitizer.h>
26 #include <AliDetector.h>
27 #include "AliConfig.h"
28
29 Int_t  AliLoader::fgDebug = 0;
30
31 const TString AliLoader::fgkDefaultHitsContainerName("TreeH");
32 const TString AliLoader::fgkDefaultDigitsContainerName = "TreeD";
33 const TString AliLoader::fgkDefaultSDigitsContainerName = "TreeS";
34 const TString AliLoader::fgkDefaultRecPointsContainerName = "TreeR";
35 const TString AliLoader::fgkDefaultTracksContainerName = "TreeT";
36 const TString AliLoader::fgkDefaultRecParticlesContainerName = "TreeP";
37 const TString AliLoader::fgkLoaderBaseName("Loader");
38
39 ClassImp(AliLoader)
40 //___________________________________________________________________
41 /////////////////////////////////////////////////////////////////////
42 //                                                                 //
43 //  class AliLoader                                                //
44 //                                                                 //
45 //  Base class for Loaders.                                        //
46 //  Loader provides base I/O fascilities for "standard" data.      //
47 //  Each detector has a laoder data member                         //
48 //  loader is accessible via folder structure as well              //
49 //                                                                 //
50 /////////////////////////////////////////////////////////////////////
51  
52 /*****************************************************************************/ 
53
54 AliLoader::AliLoader():
55  fDataLoaders(0x0),
56  fDetectorName(""),
57  fEventFolder(0x0),
58  fDataFolder(0x0),
59  fDetectorDataFolder(0x0),
60  fModuleFolder(0x0),
61  fTasksFolder(0x0),
62  fQAFolder(0x0)
63  {
64 //default constructor
65
66  }
67 /******************************************************************/
68
69 AliLoader::AliLoader(const Char_t* detname,const Char_t* eventfoldername):
70  fDataLoaders(new TObjArray(kNDataTypes)),
71  fDetectorName(""),
72  fEventFolder(0x0),
73  fDataFolder(0x0),
74  fDetectorDataFolder(0x0),
75  fModuleFolder(0x0),
76  fTasksFolder(0x0),
77  fQAFolder(0x0)
78 {
79   //ctor
80    if (GetDebug()) Info("AliLoader(const Char_t* detname,const Char_t* eventfoldername)",
81         "detname = %s eventfoldername = %s",detname,eventfoldername);
82
83    //try to find folder eventfoldername in top alice folder
84    //safe because GetTopFolder will abort in case of failure
85
86    fDetectorName = detname;
87    fName = fDetectorName+"Loader";
88    InitDefaults();
89
90    TObject* fobj = GetTopFolder()->FindObject(eventfoldername);
91    fEventFolder = (fobj)?dynamic_cast<TFolder*>(fobj):0x0;//in case FindObject returns NULL dynamic cast cause seg. fault
92    SetEventFolder(fEventFolder);
93    
94  }
95 /*****************************************************************************/ 
96
97 AliLoader::AliLoader(const Char_t * detname,TFolder* eventfolder):
98  fDataLoaders(new TObjArray(kNDataTypes)),
99  fDetectorName(detname),
100  fEventFolder(0x0),
101  fDataFolder(0x0),
102  fDetectorDataFolder(0x0),
103  fModuleFolder(0x0),
104  fTasksFolder(0x0),
105  fQAFolder(0x0)
106 {
107 //constructor
108    fDetectorName = detname;
109    fName = fDetectorName+"Loader";
110    InitDefaults();
111    SetEventFolder(eventfolder);
112    //fileoption's don't need to initialized because default TString ctor does it correctly
113 }
114 /*****************************************************************************/ 
115 AliLoader::AliLoader(const AliLoader& source):TNamed(source) {
116   // dummy copy constructor
117   if(&source==this)return;
118   
119   Fatal("AliLoader","Copy constructor not implemented. Aborting");
120   return;
121 }
122
123 /*****************************************************************************/ 
124 AliLoader& AliLoader::operator=(const AliLoader& source) {
125   // dummy assignment operator
126   if(&source==this) return *this;
127   
128   Fatal("AliLoader","Assignment operator not implemented. Aborting");
129   return *this;
130 }
131
132 /*****************************************************************************/ 
133 AliLoader::~AliLoader()
134 {
135 //detructor
136   if (fDataLoaders) fDataLoaders->SetOwner();
137   delete fDataLoaders;
138 }
139 /*****************************************************************************/ 
140
141 void AliLoader::InitDefaults()
142 {
143   // H I T S 
144   AliDataLoader* dl;
145   dl = new AliDataLoader(fDetectorName + ".Hits.root",fgkDefaultHitsContainerName, "Hits" );
146   fDataLoaders->AddAt(dl,kHits);
147   
148   
149   // S U M M A B L E   D I G I T S
150   dl = new AliDataLoader(fDetectorName + ".SDigits.root",fgkDefaultSDigitsContainerName, "Summable Digits");
151   AliTaskLoader* tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetSDigitizerTaskName(),
152                                         dl,AliRunLoader::GetRunSDigitizer(),kTRUE);
153   dl->SetBaseTaskLoader(tl);
154   fDataLoaders->AddAt(dl,kSDigits);
155
156   // D I G I T S  
157   dl = new AliDataLoader(fDetectorName + ".Digits.root",fgkDefaultDigitsContainerName, "Digits");
158   tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetDigitizerTaskName(),
159                                         dl,AliRunLoader::GetRunDigitizer(),kTRUE);
160   dl->SetBaseTaskLoader(tl);
161   fDataLoaders->AddAt(dl,kDigits);
162   
163   // R E C O N S T R U C T E D   P O I N T S aka C L U S T E R S 
164   dl = new AliDataLoader(fDetectorName + ".RecPoints.root",fgkDefaultRecPointsContainerName, "Reconstructed Points");
165   tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetReconstructionerTaskName(),
166                                         dl,AliRunLoader::GetRunReconstructioner(),kTRUE);
167   dl->SetBaseTaskLoader(tl);
168   fDataLoaders->AddAt(dl,kRecPoints);
169   
170   // T R A C K S
171   dl = new AliDataLoader(fDetectorName + ".Tracks.root",fgkDefaultTracksContainerName, "Tracks");
172   tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetTrackerTaskName(),
173                                         dl,AliRunLoader::GetRunTracker(),kTRUE);
174   dl->SetBaseTaskLoader(tl);
175   fDataLoaders->AddAt(dl,kTracks);
176   
177   // R E C O N S T R U C T E D   P O I N T S aka C L U S T E R S 
178   dl = new AliDataLoader(fDetectorName + ".RecParticles.root",fgkDefaultRecParticlesContainerName, "Reconstructed Particles");
179   tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetPIDTaskName(),
180                                         dl,AliRunLoader::GetRunPIDTask(),kTRUE);
181   dl->SetBaseTaskLoader(tl);
182   fDataLoaders->AddAt(dl,kRecParticles);
183
184  }
185 /*****************************************************************************/ 
186
187 AliDataLoader* AliLoader::GetDataLoader(const char* name)
188 {
189 //returns Data Loader with specified name
190   return dynamic_cast<AliDataLoader*>(fDataLoaders->FindObject(name));
191 }
192 /*****************************************************************************/ 
193
194 Int_t AliLoader::SetEvent()
195 {
196  //basically the same that GetEvent but do not post data to folders
197  TIter next(fDataLoaders);
198  AliDataLoader* dl;
199  while ((dl = (AliDataLoader*)next()))
200   {
201     dl->SetEvent();
202   }
203  return 0;
204 }
205 /******************************************************************/
206
207 void AliLoader::UnloadAll()
208 {
209  //calls UnloadAll for all base laoders
210  //Unloads everything
211  TIter next(fDataLoaders);
212  AliDataLoader* dl;
213  while ((dl = (AliDataLoader*)next()))
214   {
215     dl->UnloadAll();
216   }
217 }
218 /******************************************************************/
219
220 Int_t AliLoader::GetEvent()
221 {
222  //changes to proper root  directory and tries to load data from files to folders
223  // event number is defined in RunLoader
224  // 
225  //returns:
226  //     0  - in case of no error
227  //     1  - event not found
228  //     
229  
230  Int_t retval;   
231  TIter next(fDataLoaders);
232  AliDataLoader* dl;
233  while ((dl = (AliDataLoader*)next()))
234   {
235     retval = dl->GetEvent();
236     if (retval)
237      {
238        Error("GetEvent","Error occured while GetEvent for %s",dl->GetName());
239        return retval;
240      }
241   }
242
243  return 0;
244 }
245
246 /******************************************************************/
247
248 TFolder* AliLoader::GetTopFolder()
249 {
250 //returns TOP aliroot folder, just a simple interface to AliConfig (gives shorter notation)
251  return AliConfig::Instance()->GetTopFolder();
252 }
253
254 /******************************************************************/
255
256 TFolder* AliLoader::GetEventFolder()
257 {
258 //get EVENT folder (data that are changing from event to event, even in single run)
259   return fEventFolder;
260 }
261 /******************************************************************/
262 TFolder* AliLoader::GetDataFolder()
263 {
264 //returns the folder speciofic to given detector e.g. /Folders/Event/Data/
265  if (!fDataFolder)
266   {
267    fDataFolder =  dynamic_cast<TFolder*>(GetEventFolder()->FindObject(AliConfig::fgkDataFolderName));
268    
269    if (!fDataFolder)
270     {
271      Fatal("GetDataFolder","Can not find AliRoot data folder. Aborting");
272      return 0x0;
273     }
274   }
275   return fDataFolder;
276 }
277
278 /*****************************************************************************/ 
279
280 TFolder* AliLoader::GetTasksFolder()
281 {
282 //Returns pointer to Folder with Alice Tasks
283  if (!fTasksFolder)
284   {
285    fTasksFolder =  dynamic_cast<TFolder*>(GetTopFolder()->FindObject(AliConfig::fgkTasksFolderName));
286    
287    if (!fTasksFolder)
288     {
289      Fatal("GetTasksFolder","Can not find tasks folder. Aborting");
290      return 0x0;
291     }
292   }
293   return fTasksFolder;
294    
295 }
296 /*****************************************************************************/ 
297
298 TFolder* AliLoader::GetModulesFolder()
299 {
300   //returns pointer to the folder containing modules
301  if (!fModuleFolder)
302   {
303    fModuleFolder =  dynamic_cast<TFolder*>(GetEventFolder()->FindObjectAny(AliConfig::GetModulesFolderName()));
304    
305    if (!fModuleFolder)
306     {
307      Fatal("GetModulesFolder","Can not find modules folder. Aborting");
308      return 0x0;
309     }
310   }
311  return fModuleFolder;
312    
313 }
314 /*****************************************************************************/ 
315
316 TFolder* AliLoader::GetQAFolder()
317
318   //returns folder with Quality assurance 
319   if (fQAFolder == 0x0)
320    {
321      TObject *obj = GetEventFolder()->FindObjectAny(AliConfig::Instance()->GetQAFolderName());
322      fQAFolder = (obj)?dynamic_cast<TFolder*>(obj):0x0;
323
324      if (fQAFolder == 0x0)
325       {
326        Fatal("GetQAFolder","Can not find Quality Assurance folder. Aborting");
327        return 0x0;
328       }
329    }
330   return fQAFolder;
331   
332 }
333 /*****************************************************************************/ 
334 TTask* AliLoader::SDigitizer() const
335 {
336 //returns SDigitizer task for this detector
337   return GetSDigitsDataLoader()->GetBaseTaskLoader()->Task();
338
339 }
340 /*****************************************************************************/ 
341
342 AliDigitizer* AliLoader::Digitizer() const
343 {
344 //returns Digitizer task for this detector
345   return dynamic_cast<AliDigitizer*>(GetDigitsDataLoader()->GetBaseTaskLoader()->Task());
346 }
347 /*****************************************************************************/ 
348
349 TTask* AliLoader::Reconstructioner() const
350 {
351 //returns Recontructioner (Cluster Finder, Cluster Maker, 
352 //or whatever you want to call it) task for this detector
353   return GetRecPointsDataLoader()->GetBaseTaskLoader()->Task();
354 }
355 /*****************************************************************************/ 
356
357 TTask* AliLoader::Tracker() const
358 {
359 //returns tracker
360   return dynamic_cast<TTask*>(GetTracksDataLoader()->GetBaseTaskLoader()->Task());
361 }
362
363 /*****************************************************************************/ 
364 TTask* AliLoader::PIDTask() const
365 {
366 //returns tracker
367   return dynamic_cast<TTask*>(GetRecParticlesDataLoader()->GetBaseTaskLoader()->Task());
368 }
369
370 /*****************************************************************************/ 
371
372 TTask* AliLoader::QAtask(const char* name) const
373 {
374   // Returns pointer to the quality assurance task
375   TTask* qat = AliRunLoader::GetRunQATask();
376   if ( qat == 0x0 ) 
377    {
378     Error("QAtask","Can not get RunQATask. (Name:%s)",GetName());
379     return 0x0;
380    }
381   
382   TString dqatname(fDetectorName + AliConfig::Instance()->GetQATaskName());
383   TTask* dqat = dynamic_cast<TTask*>(qat->GetListOfTasks()->FindObject(dqatname));
384   
385   if ( dqat == 0x0 ) 
386    {
387     Error("QAtask","Can not find QATask in RunQATask for %s",GetDetectorName().Data());
388     return 0x0;
389    }
390   
391   if (strlen(name) == 0) return dqat;
392   
393   TList* list = dqat->GetListOfTasks();
394   
395   TIter it(list) ;
396   TTask * task = 0 ; 
397   while((task = static_cast<TTask *>(it.Next()) ))
398    {
399     TString taskname(task->GetName()) ;
400     if(taskname.BeginsWith(name))
401       return task ;
402    }
403   Error("QAtask","Can not find sub-task with name starting with %s in task %s",name,dqat->GetName());
404   return 0x0;   
405 }
406 /*****************************************************************************/ 
407
408 TDirectory* AliLoader::ChangeDir(TFile* file, Int_t eventno)
409 {
410 //changes the root directory in "file" to "dirname" which corresponds to event 'eventno'
411 //in case of success returns the pointer to directory
412 //else NULL
413  
414  if (file == 0x0)
415   {
416     ::Error("AliLoader::ChangeDir","File is null");
417     return 0x0;
418   }
419  if (file->IsOpen() == kFALSE)
420   {
421     ::Error("AliLoader::ChangeDir","File is not opened");
422     return 0x0;
423   }
424
425  TString dirname("Event");
426  dirname+=eventno;
427  if (AliLoader::fgDebug > 1) 
428    ::Info("AliLoader::ChangeDir","Changing Dir to %s in file %s.",dirname.Data(),file->GetName());
429
430  Bool_t result;
431  
432  TDirectory* dir = dynamic_cast<TDirectory*>(file->Get(dirname));
433
434  if (dir == 0x0)
435   {
436     if (AliLoader::fgDebug > 1)
437      ::Info("AliLoader::ChangeDir","Can not find directory %s in file %s, creating...",
438             dirname.Data(),file->GetName());
439     
440     if (file->IsWritable() == kFALSE)
441      {
442        ::Error("AliLoader::ChangeDir","Can not create directory. File %s in not writable.",
443                 file->GetName());
444        return 0x0;
445      }
446             
447     TDirectory* newdir = file->mkdir(dirname);
448     if (newdir == 0x0)
449      {
450        ::Error("AliLoader::ChangeDir","Failed to create new directory in file %s.",
451                file->GetName());
452        return 0x0;
453      }
454     result = file->cd(dirname);
455     if (result == kFALSE)
456      {
457        return 0x0;
458      }
459   }
460  else
461   {
462    file->cd();//make a file active 
463    file->cd(dirname);//cd event dir
464   }
465
466  return gDirectory;
467 }
468 /*****************************************************************************/ 
469
470 TString AliLoader::GetUnixDir() const
471  {
472  //This Method will manage jumping through unix directories in case of 
473  //run with more events per run than defined in gAlice
474  
475    TString dir;
476    
477    return dir;
478  }
479 /*****************************************************************************/ 
480 /************************************************************/
481
482 void AliLoader::MakeTree(Option_t *option)
483  {
484 //Makes a tree depending on option 
485 //   H: - Hits
486 //   D: - Digits
487 //   S: - Summable Digits
488 //   R: - Reconstructed Points (clusters)
489 //   T: - Tracks (tracklets)
490
491   const char *oH = strstr(option,"H");
492   const char *oD = strstr(option,"D");
493   const char *oS = strstr(option,"S");
494   const char *oR = strstr(option,"R");
495   const char *oT = strstr(option,"T");
496   const char *oP = strstr(option,"P");
497   
498   if (oH) MakeHitsContainer();
499   if (oD) MakeDigitsContainer();
500   if (oS) MakeSDigitsContainer();
501   if (oR) MakeRecPointsContainer();
502   if (oT) MakeTracksContainer();
503   if (oP) MakeRecParticlesContainer();
504  }
505
506 /*****************************************************************************/ 
507 Int_t  AliLoader::WriteHits(Option_t* opt) const
508  {
509    // Writes hits
510    AliDataLoader* dl = GetHitsDataLoader();
511    Int_t ret = dl->WriteData(opt);
512    return ret;
513  }
514 /*****************************************************************************/ 
515
516 Int_t AliLoader::WriteSDigits(Option_t* opt) const
517  {
518    // Writes summable digits
519    AliDataLoader* dl = GetSDigitsDataLoader();
520    Int_t ret = dl->WriteData(opt);
521    return ret;
522  }
523  
524 /*****************************************************************************/ 
525
526 Int_t AliLoader::PostSDigitizer(TTask* sdzer) const
527 {
528   // Posts sdigitizer
529   return GetSDigitsDataLoader()->GetBaseTaskLoader()->Post(sdzer);
530 }
531 /*****************************************************************************/ 
532
533 Int_t AliLoader::PostDigitizer(AliDigitizer* task) const
534  {
535    // Posts digitizer
536   return GetDigitsDataLoader()->GetBaseTaskLoader()->Post(task);
537  }
538 /*****************************************************************************/ 
539
540 Int_t AliLoader::PostReconstructioner(TTask* task) const
541  {
542    // Posts Reconstructioner
543   return GetRecPointsDataLoader()->GetBaseTaskLoader()->Post(task);
544  }
545 /*****************************************************************************/ 
546
547 Int_t AliLoader::PostTracker(TTask* task) const
548  {
549    // Posts a tracker
550   return GetTracksDataLoader()->GetBaseTaskLoader()->Post(task);
551  }
552 /*****************************************************************************/ 
553
554 Int_t AliLoader::PostPIDTask(TTask* task) const
555  {
556   // Posts particle identification task
557   return GetRecParticlesDataLoader()->GetBaseTaskLoader()->Post(task);
558  }
559 /*****************************************************************************/ 
560
561 TObject** AliLoader::GetDetectorDataRef(TObject *obj)
562 {
563   // Returns pointer to an entry in the list of folders pointing to "obj"
564  if (obj == 0x0)
565   {
566     return 0x0;
567   }
568  return GetDetectorDataFolder()->GetListOfFolders()->GetObjectRef(obj) ;
569 }
570 /*****************************************************************************/ 
571
572 TObject** AliLoader::SDigitizerRef()
573 {
574   // Returns pointer to a Runloader's task-list entry pointing to SDigitizer
575   TTask* rsd = AliRunLoader::GetRunSDigitizer();
576   if (rsd == 0x0)
577    {
578      return 0x0;
579    }
580   return rsd->GetListOfTasks()->GetObjectRef(SDigitizer());
581 }
582 /*****************************************************************************/ 
583
584 TObject** AliLoader::DigitizerRef()
585 {
586   // Returns pointer to a Runloader's task-list entry pointing to Digitizer
587  TTask* rd = AliRunLoader::GetRunDigitizer();
588  if (rd == 0x0)
589   {
590     return 0x0;
591   }
592  return rd->GetListOfTasks()->GetObjectRef(Digitizer()) ;
593 }
594 /*****************************************************************************/ 
595
596 TObject** AliLoader::ReconstructionerRef()
597 {
598   // Returns pointer to a Runloader's task-list entry pointing to Reconstructioner
599   TTask* rrec = AliRunLoader::GetRunReconstructioner();
600   if (rrec == 0x0)
601    {
602      return 0x0;
603    }
604   return rrec->GetListOfTasks()->GetObjectRef(Reconstructioner());
605 }
606 /*****************************************************************************/ 
607
608 TObject** AliLoader::TrackerRef()
609 {
610   // Returns pointer to a Runloader's task-list entry pointing to Tracker
611    TTask* rrec = AliRunLoader::GetRunTracker();
612    if (rrec == 0x0)
613     {
614       return 0x0;
615     }
616    return rrec->GetListOfTasks()->GetObjectRef(Tracker());
617 }
618 /*****************************************************************************/ 
619
620 TObject** AliLoader::PIDTaskRef()
621 {
622   // Returns pointer to a Runloader's task-list entry pointing to PIDTask
623   TTask* rrec = AliRunLoader::GetRunPIDTask();
624   if (rrec == 0x0)
625    {
626      return 0x0;
627    }
628   return rrec->GetListOfTasks()->GetObjectRef(PIDTask());
629 }
630
631 /*****************************************************************************/ 
632 void AliLoader::CleanFolders()
633  {
634  //Cleans all posted objects == removes from folders and deletes them
635    TIter next(fDataLoaders);
636    AliDataLoader* dl;
637    while ((dl = (AliDataLoader*)next()))
638     { 
639       if (GetDebug()) Info("CleanFolders","name = %s cleaning",dl->GetName());
640       dl->Clean();
641     }
642  }
643 /*****************************************************************************/ 
644
645 /*****************************************************************************/ 
646
647 void AliLoader::CleanSDigitizer()
648 {
649 //removes and deletes detector task from Run Task
650   TTask* task = AliRunLoader::GetRunSDigitizer();
651   if (task == 0x0)
652    {
653      Error("CleanSDigitizer","Can not get RunSDigitizer from folder. Can not clean");
654      return;
655    }
656
657   if (GetDebug()) Info("CleanSDigitizer","Attempting to delete S Digitizer");
658   delete task->GetListOfTasks()->Remove(SDigitizer()); //TTList::Remove does not delete object
659 }
660 /*****************************************************************************/ 
661
662 void AliLoader::CleanDigitizer()
663 {
664 //removes and deletes detector task from Run Task
665   TTask* task = AliRunLoader::GetRunDigitizer();
666   if (task == 0x0)
667    {
668      Error("CleanDigitizer","Can not get RunDigitizer from folder. Can not clean");
669      return;
670    }
671
672   if (GetDebug()) 
673    Info("CleanDigitizer","Attempting to delete Digitizer %X",
674          task->GetListOfTasks()->Remove(Digitizer()));
675   delete task->GetListOfTasks()->Remove(Digitizer()); //TTList::Remove does not delete object
676 }
677 /*****************************************************************************/ 
678
679 void AliLoader::CleanReconstructioner()
680 {
681 //removes and deletes detector Reconstructioner from Run Reconstructioner
682   TTask* task = AliRunLoader::GetRunReconstructioner();
683   if (task == 0x0)
684    {
685      Error("CleanReconstructioner","Can not get RunReconstructioner from folder. Can not clean");
686      return;
687    }
688
689   if (GetDebug()) 
690    Info("CleanReconstructioner","Attempting to delete Reconstructioner");
691   delete task->GetListOfTasks()->Remove(Reconstructioner()); //TTList::Remove does not delete object
692 }
693 /*****************************************************************************/ 
694
695 void AliLoader::CleanTracker()
696 {
697 //removes and deletes detector tracker from Run Tracker
698   TTask* task = AliRunLoader::GetRunTracker();
699   if (task == 0x0)
700    {
701      Error("CleanTracker","Can not get RunTracker from folder. Can not clean");
702      return;
703    }
704
705   if (GetDebug()) 
706    Info("CleanTracker","Attempting to delete Tracker %X",
707          task->GetListOfTasks()->Remove(Tracker()));
708   delete task->GetListOfTasks()->Remove(Tracker()); //TTList::Remove does not delete object
709 }
710 /*****************************************************************************/ 
711
712 void AliLoader::CleanPIDTask()
713 {
714 //removes and deletes detector Reconstructioner from Run Reconstructioner
715   TTask* task = AliRunLoader::GetRunPIDTask();
716   if (task == 0x0)
717    {
718      Error("CleanPIDTask","Can not get Run PID Task from folder. Can not clean");
719      return;
720    }
721
722   if (GetDebug()) 
723    Info("CleanPIDTask","Attempting to delete PID Task");
724   delete task->GetListOfTasks()->Remove(PIDTask()); //TTList::Remove does not delete object
725 }
726 /*****************************************************************************/ 
727
728 Int_t AliLoader::ReloadAll()
729 {
730   // Calling Reload function for all the data loaders
731  TIter next(fDataLoaders);
732  AliDataLoader* dl;
733  
734  while((dl = (AliDataLoader*)next()))
735   {
736    Int_t err = dl->Reload();
737    if (err)
738     {
739       Error("ReloadAll","Reload returned error for %s",dl->GetName());
740       return err;
741     }
742   }
743  return 0;
744 }
745 /*****************************************************************************/ 
746
747 void AliLoader::CloseFiles()
748 {
749 //close files for data loaders
750  TIter next(fDataLoaders);
751  AliDataLoader* dl;
752  while((dl = (AliDataLoader*)next()))
753   {
754    dl->CloseFile();
755   }
756 }
757 /*****************************************************************************/ 
758
759 Int_t  AliLoader::SetEventFolder(TFolder* eventfolder)
760 {
761   //sets the event folder
762  if (eventfolder == 0x0)
763   {
764     Error("SetEventFolder","Stupid joke. Argument is NULL");
765     return 1;
766   }
767
768  fEventFolder = eventfolder;
769  TIter next(fDataLoaders);
770  AliDataLoader* dl;
771  
772  while((dl = (AliDataLoader*)next()))
773   {
774     dl->SetEventFolder(fEventFolder);
775     dl->SetFolder(GetDetectorDataFolder()); //Must exists - ensure register is called before
776   }
777
778  return 0;
779 }//sets the event folder
780 /*****************************************************************************/ 
781
782 Int_t AliLoader::Register(TFolder* eventFolder)
783 {
784 //triggers creation of subfolders for a given detector
785 //this method is called when session is read from disk
786 //
787 //warning: AliDetector in constructor (not default) calls
788 //creation of folder structure as well (some detectors needs folders 
789 //alrady in constructors)
790
791  if (GetDebug()) Info("Register","Name is %s.",GetName());
792  if (eventFolder == 0x0)
793   {
794     Error("Register","Event folder is not set.");
795     return 1;
796   }
797  Int_t retval = AliConfig::Instance()->AddDetector(eventFolder,fDetectorName,fDetectorName);
798  if(retval)
799   {
800     Error("SetEventFolder","Can not create tasks and/or folders for %s. Event folder name is %s",
801           fDetectorName.Data(),eventFolder->GetName());
802     return retval;
803   }
804  SetEventFolder(eventFolder);
805  return 0;
806 }
807 /*****************************************************************************/ 
808 AliRunLoader* AliLoader::GetRunLoader()
809 {
810 //gets the run-loader from event folder
811   AliRunLoader* rg = 0x0;
812   TObject * obj = GetEventFolder()->FindObject(AliRunLoader::fgkRunLoaderName);
813   if (obj) rg = dynamic_cast<AliRunLoader*>(obj);
814   return rg;
815 }
816 /*****************************************************************************/ 
817 Bool_t  AliLoader::TestFileOption(Option_t* opt)
818 {
819 //tests the TFile::Option
820 //if file is truncated at opening moment ("recreate", "new" or "create") returns kFALSE;
821 //else kTRUE (means opened with "read" or "update" mode)
822   TString option(opt);
823   if (option.CompareTo("recreate",TString::kIgnoreCase) == 0) return kFALSE;
824   if (option.CompareTo("new",TString::kIgnoreCase) == 0) return kFALSE;
825   if (option.CompareTo("create",TString::kIgnoreCase) == 0) return kFALSE;
826   return kTRUE;
827 }
828 /*****************************************************************************/ 
829 void  AliLoader::SetDirName(TString& dirname)
830 {
831 //adds "dirname/" to each file 
832   TIter next(fDataLoaders);
833   AliDataLoader* dl;
834   while((dl = (AliDataLoader*)next()))
835    {
836     dl->SetDirName(dirname);
837    }
838 }
839
840 /*****************************************************************************/ 
841
842 void AliLoader::SetDigitsFileNameSuffix(const TString& suffix) const
843 {
844   //adds the suffix before ".root", 
845   //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
846   //made on Jiri Chudoba demand
847   GetDigitsDataLoader()->SetFileNameSuffix(suffix);
848 }
849 /*****************************************************************************/ 
850
851 void AliLoader::SetCompressionLevel(Int_t cl)
852 {
853 //sets comression level for data defined by di
854   TIter next(fDataLoaders);
855   AliDataLoader* dl;
856   while((dl = (AliDataLoader*)next()))
857    {
858      dl->SetCompressionLevel(cl);
859    }
860 }
861 /*****************************************************************************/ 
862
863 void AliLoader::Clean()
864 {
865 //Cleans all data loaders
866   TIter next(fDataLoaders);
867   AliDataLoader* dl;
868   while((dl = (AliDataLoader*)next()))
869    {
870      dl->Clean();
871    }
872 }
873 /*****************************************************************************/
874
875 void AliLoader::Clean(const TString& name)
876 {
877   // Removes object with "name" from the detector's data folder
878   // and from the memory
879   TObject* obj = GetDetectorDataFolder()->FindObject(name);
880   if(obj)
881    {
882      if (GetDebug())
883        Info("Clean(const TString&)","name=%s, cleaning %s.",GetName(),name.Data());
884      GetDetectorDataFolder()->Remove(obj);
885      delete obj;
886    }
887 }
888
889 /*****************************************************************************/ 
890
891 Bool_t AliLoader::IsOptionWritable(const TString& opt)
892 {
893   // Returns "true" if the option means also "writable"
894   if (opt.CompareTo("recreate",TString::kIgnoreCase)) return kTRUE;
895   if (opt.CompareTo("new",TString::kIgnoreCase)) return kTRUE;
896   if (opt.CompareTo("create",TString::kIgnoreCase)) return kTRUE;
897   if (opt.CompareTo("update",TString::kIgnoreCase)) return kTRUE;
898   return kFALSE;
899 }
900 /*****************************************************************************/ 
901
902 void AliLoader::SetTAddrInDet()
903 {
904   //calls SetTreeAddress for corresponding detector
905   AliRunLoader* rl = GetRunLoader();   
906   if (rl == 0x0) return;
907   AliRun* ar = rl->GetAliRun();
908   if (ar == 0x0) return;
909   AliDetector* det = ar->GetDetector(fDetectorName);  
910   if (det == 0x0) return;
911   det->SetTreeAddress();
912 }
913 /*****************************************************************************/ 
914
915 void AliLoader::Synchronize()
916 {
917   //synchrinizes all writtable files 
918  TIter next(fDataLoaders);
919  AliDataLoader* dl;
920  while ((dl = (AliDataLoader*)next()))
921   {
922     dl->Synchronize();
923   }
924   
925 }
926 /*****************************************************************************/ 
927 /*****************************************************************************/ 
928 /*****************************************************************************/ 
929