]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliLoader.cxx
use AliLog message scheme
[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 <AliLog.h>
23 #include <AliRun.h>
24 #include <AliRunLoader.h>
25 #include <AliRunDigitizer.h>
26 #include <AliDigitizer.h>
27 #include <AliDetector.h>
28 #include "AliConfig.h"
29
30 const TString AliLoader::fgkDefaultHitsContainerName("TreeH");
31 const TString AliLoader::fgkDefaultDigitsContainerName = "TreeD";
32 const TString AliLoader::fgkDefaultSDigitsContainerName = "TreeS";
33 const TString AliLoader::fgkDefaultRecPointsContainerName = "TreeR";
34 const TString AliLoader::fgkDefaultTracksContainerName = "TreeT";
35 const TString AliLoader::fgkDefaultRecParticlesContainerName = "TreeP";
36 const TString AliLoader::fgkLoaderBaseName("Loader");
37
38 ClassImp(AliLoader)
39 //___________________________________________________________________
40 /////////////////////////////////////////////////////////////////////
41 //                                                                 //
42 //  class AliLoader                                                //
43 //                                                                 //
44 //  Base class for Loaders.                                        //
45 //  Loader provides base I/O fascilities for "standard" data.      //
46 //  Each detector has a laoder data member                         //
47 //  loader is accessible via folder structure as well              //
48 //                                                                 //
49 /////////////////////////////////////////////////////////////////////
50  
51 /*****************************************************************************/ 
52
53 AliLoader::AliLoader():
54  fDataLoaders(0x0),
55  fDetectorName(""),
56  fEventFolder(0x0),
57  fDataFolder(0x0),
58  fDetectorDataFolder(0x0),
59  fModuleFolder(0x0),
60  fTasksFolder(0x0),
61  fQAFolder(0x0)
62  {
63 //default constructor
64
65  }
66 /******************************************************************/
67
68 AliLoader::AliLoader(const Char_t* detname,const Char_t* eventfoldername):
69  fDataLoaders(new TObjArray(kNDataTypes)),
70  fDetectorName(""),
71  fEventFolder(0x0),
72  fDataFolder(0x0),
73  fDetectorDataFolder(0x0),
74  fModuleFolder(0x0),
75  fTasksFolder(0x0),
76  fQAFolder(0x0)
77 {
78   //ctor
79    AliDebug(1, Form("detname = %s eventfoldername = %s",detname,eventfoldername));
80
81    //try to find folder eventfoldername in top alice folder
82    //safe because GetTopFolder will abort in case of failure
83
84    fDetectorName = detname;
85    fName = fDetectorName+"Loader";
86    InitDefaults();
87
88    TObject* fobj = GetTopFolder()->FindObject(eventfoldername);
89    fEventFolder = (fobj)?dynamic_cast<TFolder*>(fobj):0x0;//in case FindObject returns NULL dynamic cast cause seg. fault
90    SetEventFolder(fEventFolder);
91    
92  }
93 /*****************************************************************************/ 
94
95 AliLoader::AliLoader(const Char_t * detname,TFolder* eventfolder):
96  fDataLoaders(new TObjArray(kNDataTypes)),
97  fDetectorName(detname),
98  fEventFolder(0x0),
99  fDataFolder(0x0),
100  fDetectorDataFolder(0x0),
101  fModuleFolder(0x0),
102  fTasksFolder(0x0),
103  fQAFolder(0x0)
104 {
105 //constructor
106    fDetectorName = detname;
107    fName = fDetectorName+"Loader";
108    InitDefaults();
109    SetEventFolder(eventfolder);
110    //fileoption's don't need to initialized because default TString ctor does it correctly
111 }
112 /*****************************************************************************/ 
113 AliLoader::AliLoader(const AliLoader& source):TNamed(source) {
114   // dummy copy constructor
115   if(&source==this)return;
116   
117   AliFatal("Copy constructor not implemented. Aborting");
118   return;
119 }
120
121 /*****************************************************************************/ 
122 AliLoader& AliLoader::operator=(const AliLoader& source) {
123   // dummy assignment operator
124   if(&source==this) return *this;
125   
126   AliFatal("Assignment operator not implemented. Aborting");
127   return *this;
128 }
129
130 /*****************************************************************************/ 
131 AliLoader::~AliLoader()
132 {
133 //detructor
134   if (fDataLoaders) fDataLoaders->SetOwner();
135   delete fDataLoaders;
136 }
137 /*****************************************************************************/ 
138
139 void AliLoader::InitDefaults()
140 {
141   // H I T S 
142   AliDataLoader* dl;
143   dl = new AliDataLoader(fDetectorName + ".Hits.root",fgkDefaultHitsContainerName, "Hits" );
144   fDataLoaders->AddAt(dl,kHits);
145   
146   
147   // S U M M A B L E   D I G I T S
148   dl = new AliDataLoader(fDetectorName + ".SDigits.root",fgkDefaultSDigitsContainerName, "Summable Digits");
149   AliTaskLoader* tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetSDigitizerTaskName(),
150                                         dl,AliRunLoader::GetRunSDigitizer(),kTRUE);
151   dl->SetBaseTaskLoader(tl);
152   fDataLoaders->AddAt(dl,kSDigits);
153
154   // D I G I T S  
155   dl = new AliDataLoader(fDetectorName + ".Digits.root",fgkDefaultDigitsContainerName, "Digits");
156   tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetDigitizerTaskName(),
157                                         dl,AliRunLoader::GetRunDigitizer(),kTRUE);
158   dl->SetBaseTaskLoader(tl);
159   fDataLoaders->AddAt(dl,kDigits);
160   
161   // 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 
162   dl = new AliDataLoader(fDetectorName + ".RecPoints.root",fgkDefaultRecPointsContainerName, "Reconstructed Points");
163   tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetReconstructionerTaskName(),
164                                         dl,AliRunLoader::GetRunReconstructioner(),kTRUE);
165   dl->SetBaseTaskLoader(tl);
166   fDataLoaders->AddAt(dl,kRecPoints);
167   
168   // T R A C K S
169   dl = new AliDataLoader(fDetectorName + ".Tracks.root",fgkDefaultTracksContainerName, "Tracks");
170   tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetTrackerTaskName(),
171                                         dl,AliRunLoader::GetRunTracker(),kTRUE);
172   dl->SetBaseTaskLoader(tl);
173   fDataLoaders->AddAt(dl,kTracks);
174   
175   // 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 
176   dl = new AliDataLoader(fDetectorName + ".RecParticles.root",fgkDefaultRecParticlesContainerName, "Reconstructed Particles");
177   tl = new AliTaskLoader(fDetectorName + AliConfig::Instance()->GetPIDTaskName(),
178                                         dl,AliRunLoader::GetRunPIDTask(),kTRUE);
179   dl->SetBaseTaskLoader(tl);
180   fDataLoaders->AddAt(dl,kRecParticles);
181
182  }
183 /*****************************************************************************/ 
184
185 AliDataLoader* AliLoader::GetDataLoader(const char* name)
186 {
187 //returns Data Loader with specified name
188   return dynamic_cast<AliDataLoader*>(fDataLoaders->FindObject(name));
189 }
190 /*****************************************************************************/ 
191 void AliLoader::AddDataLoader(AliDataLoader* dl)
192 {
193   //
194   // Adds a data loader
195   //
196   if (dl == 0x0)
197    {
198      AliError("Pointer is NULL");
199      return;
200    }
201   if (fDataLoaders->FindObject(dl->GetName()))
202    {
203      AliError("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        AliError(Form("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      AliFatal("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      AliFatal("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      AliFatal("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        AliFatal("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     AliError(Form("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     AliError(Form("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   AliError(Form("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     AliErrorClass("File is null");
435     return 0x0;
436   }
437  if (file->IsOpen() == kFALSE)
438   {
439     AliErrorClass("File is not opened");
440     return 0x0;
441   }
442
443  TString dirname("Event");
444  dirname+=eventno;
445  AliDebugClass(1, Form("Changing Dir to %s in file %s.",dirname.Data(),file->GetName()));
446
447  Bool_t result;
448  
449  TDirectory* dir = dynamic_cast<TDirectory*>(file->Get(dirname));
450
451  if (dir == 0x0)
452   {
453     AliDebugClass(1, Form("Can not find directory %s in file %s, creating...",
454                      dirname.Data(),file->GetName()));
455     
456     if (file->IsWritable() == kFALSE)
457      {
458        AliErrorClass(Form("Can not create directory. File %s in not writable.",
459                      file->GetName()));
460        return 0x0;
461      }
462             
463     TDirectory* newdir = file->mkdir(dirname);
464     if (newdir == 0x0)
465      {
466        AliErrorClass(Form("Failed to create new directory in file %s.",
467                      file->GetName()));
468        return 0x0;
469      }
470     result = file->cd(dirname);
471     if (result == kFALSE)
472      {
473        return 0x0;
474      }
475   }
476  else
477   {
478    file->cd();//make a file active 
479    file->cd(dirname);//cd event dir
480   }
481
482  return gDirectory;
483 }
484 /*****************************************************************************/ 
485
486 TString AliLoader::GetUnixDir() const
487  {
488  //This Method will manage jumping through unix directories in case of 
489  //run with more events per run than defined in gAlice
490  
491    TString dir;
492    
493    return dir;
494  }
495 /*****************************************************************************/ 
496 /************************************************************/
497
498 void AliLoader::MakeTree(Option_t *option)
499  {
500 //Makes a tree depending on option 
501 //   H: - Hits
502 //   D: - Digits
503 //   S: - Summable Digits
504 //   R: - Reconstructed Points (clusters)
505 //   T: - Tracks (tracklets)
506
507   const char *oH = strstr(option,"H");
508   const char *oD = strstr(option,"D");
509   const char *oS = strstr(option,"S");
510   const char *oR = strstr(option,"R");
511   const char *oT = strstr(option,"T");
512   const char *oP = strstr(option,"P");
513   
514   if (oH) MakeHitsContainer();
515   if (oD) MakeDigitsContainer();
516   if (oS) MakeSDigitsContainer();
517   if (oR) MakeRecPointsContainer();
518   if (oT) MakeTracksContainer();
519   if (oP) MakeRecParticlesContainer();
520  }
521
522 /*****************************************************************************/ 
523 Int_t  AliLoader::WriteHits(Option_t* opt) const
524  {
525    // Writes hits
526    AliDataLoader* dl = GetHitsDataLoader();
527    Int_t ret = dl->WriteData(opt);
528    return ret;
529  }
530 /*****************************************************************************/ 
531
532 Int_t AliLoader::WriteSDigits(Option_t* opt) const
533  {
534    // Writes summable digits
535    AliDataLoader* dl = GetSDigitsDataLoader();
536    Int_t ret = dl->WriteData(opt);
537    return ret;
538  }
539  
540 /*****************************************************************************/ 
541
542 Int_t AliLoader::PostSDigitizer(TTask* sdzer) const
543 {
544   // Posts sdigitizer
545   return GetSDigitsDataLoader()->GetBaseTaskLoader()->Post(sdzer);
546 }
547 /*****************************************************************************/ 
548
549 Int_t AliLoader::PostDigitizer(AliDigitizer* task) const
550  {
551    // Posts digitizer
552   return GetDigitsDataLoader()->GetBaseTaskLoader()->Post(task);
553  }
554 /*****************************************************************************/ 
555
556 Int_t AliLoader::PostReconstructioner(TTask* task) const
557  {
558    // Posts Reconstructioner
559   return GetRecPointsDataLoader()->GetBaseTaskLoader()->Post(task);
560  }
561 /*****************************************************************************/ 
562
563 Int_t AliLoader::PostTracker(TTask* task) const
564  {
565    // Posts a tracker
566   return GetTracksDataLoader()->GetBaseTaskLoader()->Post(task);
567  }
568 /*****************************************************************************/ 
569
570 Int_t AliLoader::PostPIDTask(TTask* task) const
571  {
572   // Posts particle identification task
573   return GetRecParticlesDataLoader()->GetBaseTaskLoader()->Post(task);
574  }
575 /*****************************************************************************/ 
576
577 TObject** AliLoader::GetDetectorDataRef(TObject *obj)
578 {
579   // Returns pointer to an entry in the list of folders pointing to "obj"
580  if (obj == 0x0)
581   {
582     return 0x0;
583   }
584  return GetDetectorDataFolder()->GetListOfFolders()->GetObjectRef(obj) ;
585 }
586 /*****************************************************************************/ 
587
588 TObject** AliLoader::SDigitizerRef()
589 {
590   // Returns pointer to a Runloader's task-list entry pointing to SDigitizer
591   TTask* rsd = AliRunLoader::GetRunSDigitizer();
592   if (rsd == 0x0)
593    {
594      return 0x0;
595    }
596   return rsd->GetListOfTasks()->GetObjectRef(SDigitizer());
597 }
598 /*****************************************************************************/ 
599
600 TObject** AliLoader::DigitizerRef()
601 {
602   // Returns pointer to a Runloader's task-list entry pointing to Digitizer
603  TTask* rd = AliRunLoader::GetRunDigitizer();
604  if (rd == 0x0)
605   {
606     return 0x0;
607   }
608  return rd->GetListOfTasks()->GetObjectRef(Digitizer()) ;
609 }
610 /*****************************************************************************/ 
611
612 TObject** AliLoader::ReconstructionerRef()
613 {
614   // Returns pointer to a Runloader's task-list entry pointing to Reconstructioner
615   TTask* rrec = AliRunLoader::GetRunReconstructioner();
616   if (rrec == 0x0)
617    {
618      return 0x0;
619    }
620   return rrec->GetListOfTasks()->GetObjectRef(Reconstructioner());
621 }
622 /*****************************************************************************/ 
623
624 TObject** AliLoader::TrackerRef()
625 {
626   // Returns pointer to a Runloader's task-list entry pointing to Tracker
627    TTask* rrec = AliRunLoader::GetRunTracker();
628    if (rrec == 0x0)
629     {
630       return 0x0;
631     }
632    return rrec->GetListOfTasks()->GetObjectRef(Tracker());
633 }
634 /*****************************************************************************/ 
635
636 TObject** AliLoader::PIDTaskRef()
637 {
638   // Returns pointer to a Runloader's task-list entry pointing to PIDTask
639   TTask* rrec = AliRunLoader::GetRunPIDTask();
640   if (rrec == 0x0)
641    {
642      return 0x0;
643    }
644   return rrec->GetListOfTasks()->GetObjectRef(PIDTask());
645 }
646
647 /*****************************************************************************/ 
648 void AliLoader::CleanFolders()
649  {
650  //Cleans all posted objects == removes from folders and deletes them
651    TIter next(fDataLoaders);
652    AliDataLoader* dl;
653    while ((dl = (AliDataLoader*)next()))
654     { 
655       AliDebug(1, Form("name = %s cleaning",dl->GetName()));
656       dl->Clean();
657     }
658  }
659 /*****************************************************************************/ 
660
661 /*****************************************************************************/ 
662
663 void AliLoader::CleanSDigitizer()
664 {
665 //removes and deletes detector task from Run Task
666  if ( GetSDigitsDataLoader()->GetBaseTaskLoader() == 0x0 )
667   {
668     AliWarning("Task Loader for SDigits does not exist");
669     return;
670   }
671  GetSDigitsDataLoader()->GetBaseTaskLoader()->Clean();
672 }
673 /*****************************************************************************/ 
674
675 void AliLoader::CleanDigitizer()
676 {
677 //removes and deletes detector task from Run Task
678  if ( GetDigitsDataLoader()->GetBaseTaskLoader() == 0x0 )
679   {
680     AliWarning("Task Loader for Digits does not exist");
681     return;
682   }
683  GetDigitsDataLoader()->GetBaseTaskLoader()->Clean();
684 }
685 /*****************************************************************************/ 
686
687 void AliLoader::CleanReconstructioner()
688 {
689 //removes and deletes detector Reconstructioner from Run Reconstructioner
690  if ( GetRecPointsDataLoader()->GetBaseTaskLoader() == 0x0 )
691   {
692     AliWarning("Task Loader for SDigits does not exist");
693     return;
694   }
695  GetRecPointsDataLoader()->GetBaseTaskLoader()->Clean();
696 }
697 /*****************************************************************************/ 
698
699 void AliLoader::CleanTracker()
700 {
701 //removes and deletes detector task from Run Task
702  if ( GetTracksDataLoader()->GetBaseTaskLoader() == 0x0 )
703   {
704     AliWarning("Task Loader for Tracks does not exist");
705     return;
706   }
707  GetTracksDataLoader()->GetBaseTaskLoader()->Clean();
708 }
709 /*****************************************************************************/ 
710
711 void AliLoader::CleanPIDTask()
712 {
713 //removes and deletes detector Reconstructioner from Run Reconstructioner
714
715  if (  GetRecParticlesDataLoader()->GetBaseTaskLoader() == 0x0 )
716   {
717     AliWarning("Task Loader for Reconstructed Particles does not exist");
718     return;
719   }
720   GetRecParticlesDataLoader()->GetBaseTaskLoader()->Clean();
721 }
722 /*****************************************************************************/ 
723
724 Int_t AliLoader::ReloadAll()
725 {
726   // Calling Reload function for all the data loaders
727  TIter next(fDataLoaders);
728  AliDataLoader* dl;
729  
730  while((dl = (AliDataLoader*)next()))
731   {
732    Int_t err = dl->Reload();
733    if (err)
734     {
735       AliError(Form("Reload returned error for %s",dl->GetName()));
736       return err;
737     }
738   }
739  return 0;
740 }
741 /*****************************************************************************/ 
742
743 void AliLoader::CloseFiles()
744 {
745 //close files for data loaders
746  TIter next(fDataLoaders);
747  AliDataLoader* dl;
748  while((dl = (AliDataLoader*)next()))
749   {
750    dl->CloseFile();
751   }
752 }
753 /*****************************************************************************/ 
754
755 Int_t  AliLoader::SetEventFolder(TFolder* eventfolder)
756 {
757   //sets the event folder
758  if (eventfolder == 0x0)
759   {
760     AliError("Stupid joke. Argument is NULL");
761     return 1;
762   }
763
764  fEventFolder = eventfolder;
765  TIter next(fDataLoaders);
766  AliDataLoader* dl;
767  
768  while((dl = (AliDataLoader*)next()))
769   {
770     dl->SetEventFolder(fEventFolder);
771     dl->SetFolder(GetDetectorDataFolder()); //Must exists - ensure register is called before
772   }
773
774  return 0;
775 }//sets the event folder
776 /*****************************************************************************/ 
777
778 Int_t AliLoader::Register(TFolder* eventFolder)
779 {
780 //triggers creation of subfolders for a given detector
781 //this method is called when session is read from disk
782 //
783 //warning: AliDetector in constructor (not default) calls
784 //creation of folder structure as well (some detectors needs folders 
785 //alrady in constructors)
786
787  AliDebug(1, Form("Name is %s.",GetName()));
788  if (eventFolder == 0x0)
789   {
790     AliError("Event folder is not set.");
791     return 1;
792   }
793  Int_t retval = AliConfig::Instance()->AddDetector(eventFolder,fDetectorName,fDetectorName);
794  if(retval)
795   {
796     AliError(Form("Can not create tasks and/or folders for %s. Event folder name is %s",
797                   fDetectorName.Data(),eventFolder->GetName()));
798     return retval;
799   }
800  SetEventFolder(eventFolder);
801  return 0;
802 }
803 /*****************************************************************************/ 
804 AliRunLoader* AliLoader::GetRunLoader()
805 {
806 //gets the run-loader from event folder
807   AliRunLoader* rg = 0x0;
808   TObject * obj = GetEventFolder()->FindObject(AliRunLoader::GetRunLoaderName());
809   if (obj) rg = dynamic_cast<AliRunLoader*>(obj);
810   return rg;
811 }
812 /*****************************************************************************/ 
813 Bool_t  AliLoader::TestFileOption(Option_t* opt)
814 {
815 //tests the TFile::Option
816 //if file is truncated at opening moment ("recreate", "new" or "create") returns kFALSE;
817 //else kTRUE (means opened with "read" or "update" mode)
818   TString option(opt);
819   if (option.CompareTo("recreate",TString::kIgnoreCase) == 0) return kFALSE;
820   if (option.CompareTo("new",TString::kIgnoreCase) == 0) return kFALSE;
821   if (option.CompareTo("create",TString::kIgnoreCase) == 0) return kFALSE;
822   return kTRUE;
823 }
824 /*****************************************************************************/ 
825 void  AliLoader::SetDirName(TString& dirname)
826 {
827 //adds "dirname/" to each file 
828   TIter next(fDataLoaders);
829   AliDataLoader* dl;
830   while((dl = (AliDataLoader*)next()))
831    {
832     dl->SetDirName(dirname);
833    }
834 }
835
836 /*****************************************************************************/ 
837
838 void AliLoader::SetDigitsFileNameSuffix(const TString& suffix) const
839 {
840   //adds the suffix before ".root", 
841   //e.g. TPC.Digits.root -> TPC.DigitsMerged.root
842   //made on Jiri Chudoba demand
843   GetDigitsDataLoader()->SetFileNameSuffix(suffix);
844 }
845 /*****************************************************************************/ 
846
847 void AliLoader::SetCompressionLevel(Int_t cl)
848 {
849 //sets comression level for data defined by di
850   TIter next(fDataLoaders);
851   AliDataLoader* dl;
852   while((dl = (AliDataLoader*)next()))
853    {
854      dl->SetCompressionLevel(cl);
855    }
856 }
857 /*****************************************************************************/ 
858
859 void AliLoader::Clean()
860 {
861 //Cleans all data loaders
862   TIter next(fDataLoaders);
863   AliDataLoader* dl;
864   while((dl = (AliDataLoader*)next()))
865    {
866      dl->Clean();
867    }
868 }
869 /*****************************************************************************/
870
871 void AliLoader::Clean(const TString& name)
872 {
873   // Removes object with "name" from the detector's data folder
874   // and from the memory
875   TObject* obj = GetDetectorDataFolder()->FindObject(name);
876   if(obj)
877    {
878      AliDebug(1, Form("name=%s, cleaning %s.",GetName(),name.Data()));
879      GetDetectorDataFolder()->Remove(obj);
880      delete obj;
881    }
882 }
883
884 /*****************************************************************************/ 
885
886 Bool_t AliLoader::IsOptionWritable(const TString& opt)
887 {
888   // Returns "true" if the option means also "writable"
889   if (opt.CompareTo("recreate",TString::kIgnoreCase)) return kTRUE;
890   if (opt.CompareTo("new",TString::kIgnoreCase)) return kTRUE;
891   if (opt.CompareTo("create",TString::kIgnoreCase)) return kTRUE;
892   if (opt.CompareTo("update",TString::kIgnoreCase)) return kTRUE;
893   return kFALSE;
894 }
895 /*****************************************************************************/ 
896
897 Int_t AliLoader::GetDebug()
898 {
899   AliWarningClass("Don't use this method any more, use AliDebug instead");
900   return AliDebugLevelClass();
901 }
902 /*****************************************************************************/ 
903
904 void AliLoader::SetDebug(Int_t deb)
905 {
906   // Sets debug level
907   AliLog::SetClassDebugLevel("AliRunLoader", deb);
908   AliLog::SetClassDebugLevel("AliLoader", deb);
909   AliLog::SetClassDebugLevel("AliDataLoader", deb);
910   AliLog::SetClassDebugLevel("AliBaseLoader", deb);
911   AliLog::SetClassDebugLevel("AliObjectLoader", deb);
912   AliLog::SetClassDebugLevel("AliTreeLoader", deb);
913   AliLog::SetClassDebugLevel("AliTaskLoader", deb);
914   AliLog::SetClassDebugLevel("AliConfig", deb);
915 }
916 /*****************************************************************************/ 
917
918 void AliLoader::SetTAddrInDet()
919 {
920   //calls SetTreeAddress for corresponding detector
921   AliRunLoader* rl = GetRunLoader();   
922   if (rl == 0x0) return;
923   AliRun* ar = rl->GetAliRun();
924   if (ar == 0x0) return;
925   AliDetector* det = ar->GetDetector(fDetectorName);  
926   if (det == 0x0) return;
927   det->SetTreeAddress();
928 }
929 /*****************************************************************************/ 
930
931 void AliLoader::Synchronize()
932 {
933   //synchrinizes all writtable files 
934  TIter next(fDataLoaders);
935  AliDataLoader* dl;
936  while ((dl = (AliDataLoader*)next()))
937   {
938     dl->Synchronize();
939   }
940   
941 }
942 /*****************************************************************************/ 
943 /*****************************************************************************/ 
944 /*****************************************************************************/ 
945