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