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