]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliLoader.cxx
Coding convention violation corrections
[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 void AliLoader::AddDataLoader(AliDataLoader* dl)
194 {
195
196   if (dl == 0x0)
197    {
198      Error("AddDataLoader","Pointer is NULL");
199      return;
200    }
201   if (fDataLoaders->FindObject(dl->GetName()))
202    {
203      Error("AddDataLoader","Such a loader exists");
204      return;
205    }
206   fDataLoaders->AddLast(dl);
207   dl->SetEventFolder(fEventFolder);
208   dl->SetFolder(GetDetectorDataFolder()); //Must exists - ensure register is called before
209 }
210 /*****************************************************************************/ 
211
212 Int_t AliLoader::SetEvent()
213 {
214  //basically the same that GetEvent but do not post data to folders
215  TIter next(fDataLoaders);
216  AliDataLoader* dl;
217  while ((dl = (AliDataLoader*)next()))
218   {
219     dl->SetEvent();
220   }
221  return 0;
222 }
223 /******************************************************************/
224
225 void AliLoader::UnloadAll()
226 {
227  //calls UnloadAll for all base laoders
228  //Unloads everything
229  TIter next(fDataLoaders);
230  AliDataLoader* dl;
231  while ((dl = (AliDataLoader*)next()))
232   {
233     dl->UnloadAll();
234   }
235 }
236 /******************************************************************/
237
238 Int_t AliLoader::GetEvent()
239 {
240  //changes to proper root  directory and tries to load data from files to folders
241  // event number is defined in RunLoader
242  // 
243  //returns:
244  //     0  - in case of no error
245  //     1  - event not found
246  //     
247  
248  Int_t retval;   
249  TIter next(fDataLoaders);
250  AliDataLoader* dl;
251  while ((dl = (AliDataLoader*)next()))
252   {
253     retval = dl->GetEvent();
254     if (retval)
255      {
256        Error("GetEvent","Error occured while GetEvent for %s",dl->GetName());
257        return retval;
258      }
259   }
260
261  return 0;
262 }
263
264 /******************************************************************/
265
266 TFolder* AliLoader::GetTopFolder()
267 {
268 //returns TOP aliroot folder, just a simple interface to AliConfig (gives shorter notation)
269  return AliConfig::Instance()->GetTopFolder();
270 }
271
272 /******************************************************************/
273
274 TFolder* AliLoader::GetEventFolder()
275 {
276 //get EVENT folder (data that are changing from event to event, even in single run)
277   return fEventFolder;
278 }
279 /******************************************************************/
280 TFolder* AliLoader::GetDataFolder()
281 {
282 //returns the folder speciofic to given detector e.g. /Folders/Event/Data/
283  if (!fDataFolder)
284   {
285    fDataFolder =  dynamic_cast<TFolder*>(GetEventFolder()->FindObject(AliConfig::Instance()->GetDataFolderName()));
286    
287    if (!fDataFolder)
288     {
289      Fatal("GetDataFolder","Can not find AliRoot data folder. Aborting");
290      return 0x0;
291     }
292   }
293   return fDataFolder;
294 }
295
296 /*****************************************************************************/ 
297
298 TFolder* AliLoader::GetTasksFolder()
299 {
300 //Returns pointer to Folder with Alice Tasks
301  if (!fTasksFolder)
302   {
303    fTasksFolder =  dynamic_cast<TFolder*>(GetTopFolder()->FindObject(AliConfig::GetTasksFolderName()));
304    
305    if (!fTasksFolder)
306     {
307      Fatal("GetTasksFolder","Can not find tasks folder. Aborting");
308      return 0x0;
309     }
310   }
311   return fTasksFolder;
312    
313 }
314 /*****************************************************************************/ 
315
316 TFolder* AliLoader::GetModulesFolder()
317 {
318   //returns pointer to the folder containing modules
319  if (!fModuleFolder)
320   {
321    fModuleFolder =  dynamic_cast<TFolder*>(GetEventFolder()->FindObjectAny(AliConfig::GetModulesFolderName()));
322    
323    if (!fModuleFolder)
324     {
325      Fatal("GetModulesFolder","Can not find modules folder. Aborting");
326      return 0x0;
327     }
328   }
329  return fModuleFolder;
330    
331 }
332 /*****************************************************************************/ 
333
334 TFolder* AliLoader::GetQAFolder()
335
336   //returns folder with Quality assurance 
337   if (fQAFolder == 0x0)
338    {
339      TObject *obj = GetEventFolder()->FindObjectAny(AliConfig::Instance()->GetQAFolderName());
340      fQAFolder = (obj)?dynamic_cast<TFolder*>(obj):0x0;
341
342      if (fQAFolder == 0x0)
343       {
344        Fatal("GetQAFolder","Can not find Quality Assurance folder. Aborting");
345        return 0x0;
346       }
347    }
348   return fQAFolder;
349   
350 }
351 /*****************************************************************************/ 
352 TTask* AliLoader::SDigitizer() const
353 {
354 //returns SDigitizer task for this detector
355   return GetSDigitsDataLoader()->GetBaseTaskLoader()->Task();
356
357 }
358 /*****************************************************************************/ 
359
360 AliDigitizer* AliLoader::Digitizer() const
361 {
362 //returns Digitizer task for this detector
363   return dynamic_cast<AliDigitizer*>(GetDigitsDataLoader()->GetBaseTaskLoader()->Task());
364 }
365 /*****************************************************************************/ 
366
367 TTask* AliLoader::Reconstructioner() const
368 {
369 //returns Recontructioner (Cluster Finder, Cluster Maker, 
370 //or whatever you want to call it) task for this detector
371   return GetRecPointsDataLoader()->GetBaseTaskLoader()->Task();
372 }
373 /*****************************************************************************/ 
374
375 TTask* AliLoader::Tracker() const
376 {
377 //returns tracker
378   return dynamic_cast<TTask*>(GetTracksDataLoader()->GetBaseTaskLoader()->Task());
379 }
380
381 /*****************************************************************************/ 
382 TTask* AliLoader::PIDTask() const
383 {
384 //returns tracker
385   return dynamic_cast<TTask*>(GetRecParticlesDataLoader()->GetBaseTaskLoader()->Task());
386 }
387
388 /*****************************************************************************/ 
389
390 TTask* AliLoader::QAtask(const char* name) const
391 {
392   // Returns pointer to the quality assurance task
393   TTask* qat = AliRunLoader::GetRunQATask();
394   if ( qat == 0x0 ) 
395    {
396     Error("QAtask","Can not get RunQATask. (Name:%s)",GetName());
397     return 0x0;
398    }
399   
400   TString dqatname(fDetectorName + AliConfig::Instance()->GetQATaskName());
401   TTask* dqat = dynamic_cast<TTask*>(qat->GetListOfTasks()->FindObject(dqatname));
402   
403   if ( dqat == 0x0 ) 
404    {
405     Error("QAtask","Can not find QATask in RunQATask for %s",GetDetectorName().Data());
406     return 0x0;
407    }
408   
409   if (strlen(name) == 0) return dqat;
410   
411   TList* list = dqat->GetListOfTasks();
412   
413   TIter it(list) ;
414   TTask * task = 0 ; 
415   while((task = static_cast<TTask *>(it.Next()) ))
416    {
417     TString taskname(task->GetName()) ;
418     if(taskname.BeginsWith(name))
419       return task ;
420    }
421   Error("QAtask","Can not find sub-task with name starting with %s in task %s",name,dqat->GetName());
422   return 0x0;   
423 }
424 /*****************************************************************************/ 
425
426 TDirectory* AliLoader::ChangeDir(TFile* file, Int_t eventno)
427 {
428 //changes the root directory in "file" to "dirname" which corresponds to event 'eventno'
429 //in case of success returns the pointer to directory
430 //else NULL
431  
432  if (file == 0x0)
433   {
434     ::Error("AliLoader::ChangeDir","File is null");
435     return 0x0;
436   }
437  if (file->IsOpen() == kFALSE)
438   {
439     ::Error("AliLoader::ChangeDir","File is not opened");
440     return 0x0;
441   }
442
443  TString dirname("Event");
444  dirname+=eventno;
445  if (AliLoader::fgDebug > 1) 
446    ::Info("AliLoader::ChangeDir","Changing Dir to %s in file %s.",dirname.Data(),file->GetName());
447
448  Bool_t result;
449  
450  TDirectory* dir = dynamic_cast<TDirectory*>(file->Get(dirname));
451
452  if (dir == 0x0)
453   {
454     if (AliLoader::fgDebug > 1)
455      ::Info("AliLoader::ChangeDir","Can not find directory %s in file %s, creating...",
456             dirname.Data(),file->GetName());
457     
458     if (file->IsWritable() == kFALSE)
459      {
460        ::Error("AliLoader::ChangeDir","Can not create directory. File %s in not writable.",
461                 file->GetName());
462        return 0x0;
463      }
464             
465     TDirectory* newdir = file->mkdir(dirname);
466     if (newdir == 0x0)
467      {
468        ::Error("AliLoader::ChangeDir","Failed to create new directory in file %s.",
469                file->GetName());
470        return 0x0;
471      }
472     result = file->cd(dirname);
473     if (result == kFALSE)
474      {
475        return 0x0;
476      }
477   }
478  else
479   {
480    file->cd();//make a file active 
481    file->cd(dirname);//cd event dir
482   }
483
484  return gDirectory;
485 }
486 /*****************************************************************************/ 
487
488 TString AliLoader::GetUnixDir() const
489  {
490  //This Method will manage jumping through unix directories in case of 
491  //run with more events per run than defined in gAlice
492  
493    TString dir;
494    
495    return dir;
496  }
497 /*****************************************************************************/ 
498 /************************************************************/
499
500 void AliLoader::MakeTree(Option_t *option)
501  {
502 //Makes a tree depending on option 
503 //   H: - Hits
504 //   D: - Digits
505 //   S: - Summable Digits
506 //   R: - Reconstructed Points (clusters)
507 //   T: - Tracks (tracklets)
508
509   const char *oH = strstr(option,"H");
510   const char *oD = strstr(option,"D");
511   const char *oS = strstr(option,"S");
512   const char *oR = strstr(option,"R");
513   const char *oT = strstr(option,"T");
514   const char *oP = strstr(option,"P");
515   
516   if (oH) MakeHitsContainer();
517   if (oD) MakeDigitsContainer();
518   if (oS) MakeSDigitsContainer();
519   if (oR) MakeRecPointsContainer();
520   if (oT) MakeTracksContainer();
521   if (oP) MakeRecParticlesContainer();
522  }
523
524 /*****************************************************************************/ 
525 Int_t  AliLoader::WriteHits(Option_t* opt) const
526  {
527    // Writes hits
528    AliDataLoader* dl = GetHitsDataLoader();
529    Int_t ret = dl->WriteData(opt);
530    return ret;
531  }
532 /*****************************************************************************/ 
533
534 Int_t AliLoader::WriteSDigits(Option_t* opt) const
535  {
536    // Writes summable digits
537    AliDataLoader* dl = GetSDigitsDataLoader();
538    Int_t ret = dl->WriteData(opt);
539    return ret;
540  }
541  
542 /*****************************************************************************/ 
543
544 Int_t AliLoader::PostSDigitizer(TTask* sdzer) const
545 {
546   // Posts sdigitizer
547   return GetSDigitsDataLoader()->GetBaseTaskLoader()->Post(sdzer);
548 }
549 /*****************************************************************************/ 
550
551 Int_t AliLoader::PostDigitizer(AliDigitizer* task) const
552  {
553    // Posts digitizer
554   return GetDigitsDataLoader()->GetBaseTaskLoader()->Post(task);
555  }
556 /*****************************************************************************/ 
557
558 Int_t AliLoader::PostReconstructioner(TTask* task) const
559  {
560    // Posts Reconstructioner
561   return GetRecPointsDataLoader()->GetBaseTaskLoader()->Post(task);
562  }
563 /*****************************************************************************/ 
564
565 Int_t AliLoader::PostTracker(TTask* task) const
566  {
567    // Posts a tracker
568   return GetTracksDataLoader()->GetBaseTaskLoader()->Post(task);
569  }
570 /*****************************************************************************/ 
571
572 Int_t AliLoader::PostPIDTask(TTask* task) const
573  {
574   // Posts particle identification task
575   return GetRecParticlesDataLoader()->GetBaseTaskLoader()->Post(task);
576  }
577 /*****************************************************************************/ 
578
579 TObject** AliLoader::GetDetectorDataRef(TObject *obj)
580 {
581   // Returns pointer to an entry in the list of folders pointing to "obj"
582  if (obj == 0x0)
583   {
584     return 0x0;
585   }
586  return GetDetectorDataFolder()->GetListOfFolders()->GetObjectRef(obj) ;
587 }
588 /*****************************************************************************/ 
589
590 TObject** AliLoader::SDigitizerRef()
591 {
592   // Returns pointer to a Runloader's task-list entry pointing to SDigitizer
593   TTask* rsd = AliRunLoader::GetRunSDigitizer();
594   if (rsd == 0x0)
595    {
596      return 0x0;
597    }
598   return rsd->GetListOfTasks()->GetObjectRef(SDigitizer());
599 }
600 /*****************************************************************************/ 
601
602 TObject** AliLoader::DigitizerRef()
603 {
604   // Returns pointer to a Runloader's task-list entry pointing to Digitizer
605  TTask* rd = AliRunLoader::GetRunDigitizer();
606  if (rd == 0x0)
607   {
608     return 0x0;
609   }
610  return rd->GetListOfTasks()->GetObjectRef(Digitizer()) ;
611 }
612 /*****************************************************************************/ 
613
614 TObject** AliLoader::ReconstructionerRef()
615 {
616   // Returns pointer to a Runloader's task-list entry pointing to Reconstructioner
617   TTask* rrec = AliRunLoader::GetRunReconstructioner();
618   if (rrec == 0x0)
619    {
620      return 0x0;
621    }
622   return rrec->GetListOfTasks()->GetObjectRef(Reconstructioner());
623 }
624 /*****************************************************************************/ 
625
626 TObject** AliLoader::TrackerRef()
627 {
628   // Returns pointer to a Runloader's task-list entry pointing to Tracker
629    TTask* rrec = AliRunLoader::GetRunTracker();
630    if (rrec == 0x0)
631     {
632       return 0x0;
633     }
634    return rrec->GetListOfTasks()->GetObjectRef(Tracker());
635 }
636 /*****************************************************************************/ 
637
638 TObject** AliLoader::PIDTaskRef()
639 {
640   // Returns pointer to a Runloader's task-list entry pointing to PIDTask
641   TTask* rrec = AliRunLoader::GetRunPIDTask();
642   if (rrec == 0x0)
643    {
644      return 0x0;
645    }
646   return rrec->GetListOfTasks()->GetObjectRef(PIDTask());
647 }
648
649 /*****************************************************************************/ 
650 void AliLoader::CleanFolders()
651  {
652  //Cleans all posted objects == removes from folders and deletes them
653    TIter next(fDataLoaders);
654    AliDataLoader* dl;
655    while ((dl = (AliDataLoader*)next()))
656     { 
657       if (GetDebug()) Info("CleanFolders","name = %s cleaning",dl->GetName());
658       dl->Clean();
659     }
660  }
661 /*****************************************************************************/ 
662
663 /*****************************************************************************/ 
664
665 void AliLoader::CleanSDigitizer()
666 {
667 //removes and deletes detector task from Run Task
668  if ( GetSDigitsDataLoader()->GetBaseTaskLoader() == 0x0 )
669   {
670     Warning("CleanSDigitizer","Task Loader for SDigits does not exist");
671     return;
672   }
673  GetSDigitsDataLoader()->GetBaseTaskLoader()->Clean();
674 }
675 /*****************************************************************************/ 
676
677 void AliLoader::CleanDigitizer()
678 {
679 //removes and deletes detector task from Run Task
680  if ( GetDigitsDataLoader()->GetBaseTaskLoader() == 0x0 )
681   {
682     Warning("CleanDigitizer","Task Loader for Digits does not exist");
683     return;
684   }
685  GetDigitsDataLoader()->GetBaseTaskLoader()->Clean();
686 }
687 /*****************************************************************************/ 
688
689 void AliLoader::CleanReconstructioner()
690 {
691 //removes and deletes detector Reconstructioner from Run Reconstructioner
692  if ( GetRecPointsDataLoader()->GetBaseTaskLoader() == 0x0 )
693   {
694     Warning("CleanSDigitizer","Task Loader for SDigits does not exist");
695     return;
696   }
697  GetRecPointsDataLoader()->GetBaseTaskLoader()->Clean();
698 }
699 /*****************************************************************************/ 
700
701 void AliLoader::CleanTracker()
702 {
703 //removes and deletes detector task from Run Task
704  if ( GetTracksDataLoader()->GetBaseTaskLoader() == 0x0 )
705   {
706     Warning("CleanTracker","Task Loader for Tracks does not exist");
707     return;
708   }
709  GetTracksDataLoader()->GetBaseTaskLoader()->Clean();
710 }
711 /*****************************************************************************/ 
712
713 void AliLoader::CleanPIDTask()
714 {
715 //removes and deletes detector Reconstructioner from Run Reconstructioner
716
717  if (  GetRecParticlesDataLoader()->GetBaseTaskLoader() == 0x0 )
718   {
719     Warning("CleanPIDTask","Task Loader for Reconstructed Particles does not exist");
720     return;
721   }
722   GetRecParticlesDataLoader()->GetBaseTaskLoader()->Clean();
723 }
724 /*****************************************************************************/ 
725
726 Int_t AliLoader::ReloadAll()
727 {
728   // Calling Reload function for all the data loaders
729  TIter next(fDataLoaders);
730  AliDataLoader* dl;
731  
732  while((dl = (AliDataLoader*)next()))
733   {
734    Int_t err = dl->Reload();
735    if (err)
736     {
737       Error("ReloadAll","Reload returned error for %s",dl->GetName());
738       return err;
739     }
740   }
741  return 0;
742 }
743 /*****************************************************************************/ 
744
745 void AliLoader::CloseFiles()
746 {
747 //close files for data loaders
748  TIter next(fDataLoaders);
749  AliDataLoader* dl;
750  while((dl = (AliDataLoader*)next()))
751   {
752    dl->CloseFile();
753   }
754 }
755 /*****************************************************************************/ 
756
757 Int_t  AliLoader::SetEventFolder(TFolder* eventfolder)
758 {
759   //sets the event folder
760  if (eventfolder == 0x0)
761   {
762     Error("SetEventFolder","Stupid joke. Argument is NULL");
763     return 1;
764   }
765
766  fEventFolder = eventfolder;
767  TIter next(fDataLoaders);
768  AliDataLoader* dl;
769  
770  while((dl = (AliDataLoader*)next()))
771   {
772     dl->SetEventFolder(fEventFolder);
773     dl->SetFolder(GetDetectorDataFolder()); //Must exists - ensure register is called before
774   }
775
776  return 0;
777 }//sets the event folder
778 /*****************************************************************************/ 
779
780 Int_t AliLoader::Register(TFolder* eventFolder)
781 {
782 //triggers creation of subfolders for a given detector
783 //this method is called when session is read from disk
784 //
785 //warning: AliDetector in constructor (not default) calls
786 //creation of folder structure as well (some detectors needs folders 
787 //alrady in constructors)
788
789  if (GetDebug()) Info("Register","Name is %s.",GetName());
790  if (eventFolder == 0x0)
791   {
792     Error("Register","Event folder is not set.");
793     return 1;
794   }
795  Int_t retval = AliConfig::Instance()->AddDetector(eventFolder,fDetectorName,fDetectorName);
796  if(retval)
797   {
798     Error("SetEventFolder","Can not create tasks and/or folders for %s. Event folder name is %s",
799           fDetectorName.Data(),eventFolder->GetName());
800     return retval;
801   }
802  SetEventFolder(eventFolder);
803  return 0;
804 }
805 /*****************************************************************************/ 
806 AliRunLoader* AliLoader::GetRunLoader()
807 {
808 //gets the run-loader from event folder
809   AliRunLoader* rg = 0x0;
810   TObject * obj = GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
811   if (obj) rg = dynamic_cast<AliRunLoader*>(obj);
812   return rg;
813 }
814 /*****************************************************************************/ 
815 Bool_t  AliLoader::TestFileOption(Option_t* opt)
816 {
817 //tests the TFile::Option
818 //if file is truncated at opening moment ("recreate", "new" or "create") returns kFALSE;
819 //else kTRUE (means opened with "read" or "update" mode)
820   TString option(opt);
821   if (option.CompareTo("recreate",TString::kIgnoreCase) == 0) return kFALSE;
822   if (option.CompareTo("new",TString::kIgnoreCase) == 0) return kFALSE;
823   if (option.CompareTo("create",TString::kIgnoreCase) == 0) return kFALSE;
824   return kTRUE;
825 }
826 /*****************************************************************************/ 
827 void  AliLoader::SetDirName(TString& dirname)
828 {
829 //adds "dirname/" to each file 
830   TIter next(fDataLoaders);
831   AliDataLoader* dl;
832   while((dl = (AliDataLoader*)next()))
833    {
834     dl->SetDirName(dirname);
835    }
836 }
837
838 /*****************************************************************************/ 
839
840 void AliLoader::SetDigitsFileNameSuffix(const TString& suffix) const
841 {
842   //adds the suffix before ".root", 
843   //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
844   //made on Jiri Chudoba demand
845   GetDigitsDataLoader()->SetFileNameSuffix(suffix);
846 }
847 /*****************************************************************************/ 
848
849 void AliLoader::SetCompressionLevel(Int_t cl)
850 {
851 //sets comression level for data defined by di
852   TIter next(fDataLoaders);
853   AliDataLoader* dl;
854   while((dl = (AliDataLoader*)next()))
855    {
856      dl->SetCompressionLevel(cl);
857    }
858 }
859 /*****************************************************************************/ 
860
861 void AliLoader::Clean()
862 {
863 //Cleans all data loaders
864   TIter next(fDataLoaders);
865   AliDataLoader* dl;
866   while((dl = (AliDataLoader*)next()))
867    {
868      dl->Clean();
869    }
870 }
871 /*****************************************************************************/
872
873 void AliLoader::Clean(const TString& name)
874 {
875   // Removes object with "name" from the detector's data folder
876   // and from the memory
877   TObject* obj = GetDetectorDataFolder()->FindObject(name);
878   if(obj)
879    {
880      if (GetDebug())
881        Info("Clean(const TString&)","name=%s, cleaning %s.",GetName(),name.Data());
882      GetDetectorDataFolder()->Remove(obj);
883      delete obj;
884    }
885 }
886
887 /*****************************************************************************/ 
888
889 Bool_t AliLoader::IsOptionWritable(const TString& opt)
890 {
891   // Returns "true" if the option means also "writable"
892   if (opt.CompareTo("recreate",TString::kIgnoreCase)) return kTRUE;
893   if (opt.CompareTo("new",TString::kIgnoreCase)) return kTRUE;
894   if (opt.CompareTo("create",TString::kIgnoreCase)) return kTRUE;
895   if (opt.CompareTo("update",TString::kIgnoreCase)) return kTRUE;
896   return kFALSE;
897 }
898 /*****************************************************************************/ 
899
900 void AliLoader::SetTAddrInDet()
901 {
902   //calls SetTreeAddress for corresponding detector
903   AliRunLoader* rl = GetRunLoader();   
904   if (rl == 0x0) return;
905   AliRun* ar = rl->GetAliRun();
906   if (ar == 0x0) return;
907   AliDetector* det = ar->GetDetector(fDetectorName);  
908   if (det == 0x0) return;
909   det->SetTreeAddress();
910 }
911 /*****************************************************************************/ 
912
913 void AliLoader::Synchronize()
914 {
915   //synchrinizes all writtable files 
916  TIter next(fDataLoaders);
917  AliDataLoader* dl;
918  while ((dl = (AliDataLoader*)next()))
919   {
920     dl->Synchronize();
921   }
922   
923 }
924 /*****************************************************************************/ 
925 /*****************************************************************************/ 
926 /*****************************************************************************/ 
927