1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Base class for the top level processor class in a task based procedure.
21 // It allows stepwise invokation of various sub-tasks by the derived
22 // (user defined) top level processor, based on looping over a certain
23 // main object structure (e.g. AliEvent for event-by-event processing).
24 // The main object structure (if needed) may be specified by the derived
25 // top level processor class and will be stored automatically in the
26 // working environment (see below).
27 // This base class provides a working environment for the derived
28 // (user defined) processor class and all of its subtasks.
30 // The working environment consists of (a.o.) :
31 // * A folder which may serve as a whiteboard for transferring pointers to
32 // objects which are posted there by the top level processor or any
34 // Objects can be posted in the job folder via the AddObject() facility
35 // of this AliJob class.
36 // Access to the job folder is obtained via the GetFolder() memberfunction
37 // and from this the various objects can be accessed via the usual TFolder
38 // FindObject and/or iterator facilities.
39 // * An array containing pointers to the objects which are stored
40 // via the AddObject() facility of this AliJob class.
41 // From this storage the objects can be (more directly) accessed via the
42 // GetObject() and GetObjects() memberfunctions.
43 // * A pointer to the main object structure during job processing.
44 // This pointer can be initiated/updated only by the derived top level
45 // processor via the SetMainObject() facility but all sub-tasks can access
46 // it via the above folder/array facilities or the GetMainObject() memberfunction.
47 // The latter provides faster access to the main object structure than
48 // the GetObject() or TFolder search based procedures.
52 // 1) This AliJob class is derived from TTask, which implies that every
53 // (user defined) top level processor class is itself also a TTask.
54 // This allows sub-tasks to be introduced to the top level processor
55 // using the standard TTask facilities.
57 // 2) Only references to the various introduced objects are stored.
58 // It is the user's responsibility to delete all introduced objects,
59 // either in the destructor of the derived top level processor class
60 // or via Clear() facility as provided by the TTask machinery.
62 // 3) The top level processor instance is entered into the standard ROOT
63 // ListOfTasks under the name which was provided by the user in the
64 // constructor of the top level processor.
65 // The name of the top level processor is passed automatically as the
66 // opt argument to the Exec(Option_t* opt) memberfunctions of the
67 // various sub-tasks by the ExecuteJob() memberfunction (see below).
68 // This allows all sub-tasks to obtain the pointer to the top level
69 // processor instance from its name via the statement :
71 // AliJob* parent=(AliJob*)gROOT->GetListOfTasks()->FindObject(opt)
73 // 4) The job-specific folder will be created in the generic folder called
74 // "AliJob-folders" as a sub-folder under the same name as the one
75 // introduced in the constructor of the derived top level processor class.
76 // The folder will only be created when the first object is posted via
77 // the AddObject() or SetMainObject() facilities.
79 // Execution of the (user defined) top level processor has to be invoked via
80 // the memberfunction ExecuteJob() of this AliJob base class.
81 // This will invoke the (user written) Exec() memberfunction of the top level
82 // processor class with as argument the name of the top level processor instance
83 // as specified by the user in the top level processor constructor.
84 // This will allow stepwise (e.g. event-by-event) execution of the various sub-tasks.
86 // It is the user's responsibility to invoke the sub-tasks via the
87 // ExecuteTasks() statement at the appropriate location in the top level
90 //--- Author: Nick van Eijndhoven 07-may-2005 Utrecht University
91 //- Modified: NvE $Date$ Utrecht University
92 ///////////////////////////////////////////////////////////////////////////
95 #include "Riostream.h"
97 ClassImp(AliJob) // Class implementation to enable ROOT I/O
99 AliJob::AliJob(const char* name,const char* title) : TTask(name,title)
101 // Default constructor.
102 // Initialise the working environment for general data access
103 // by the derived task and its subtasks.
110 // Introduce this AliJob based instance into the ROOT task list
111 TSeqCollection* tasks=gROOT->GetListOfTasks();
112 if (tasks) tasks->Add(this);
114 ///////////////////////////////////////////////////////////////////////////
117 // Default destructor.
118 // Note : The objects belonging to the various pointers in the folder
119 // and the main processing object are NOT deleted by this base class.
137 ///////////////////////////////////////////////////////////////////////////
138 void AliJob::ListEnvironment()
140 // Provide listing of the job environment.
142 cout << " ***" << endl;
143 cout << " *** Environment of job " << GetName() << " ***" << endl;
144 cout << " ***" << endl;
145 cout << " === Available (sub)tasks : " << endl;
147 cout << " === Current job-folder contents : " << endl;
151 ///////////////////////////////////////////////////////////////////////////
152 void AliJob::ExecuteJob()
154 // Invokation of the top level processor via its Exec() memberfunction.
157 ///////////////////////////////////////////////////////////////////////////
158 TFolder* AliJob::GetFolder() const
160 // Provide pointer to the whiteboard folder.
163 ///////////////////////////////////////////////////////////////////////////
164 TObject* AliJob::GetMainObject() const
166 // Provide pointer to the main object structure.
169 ///////////////////////////////////////////////////////////////////////////
170 void AliJob::SetMainObject(TObject* obj)
172 // Store pointer to the main object structure.
179 ///////////////////////////////////////////////////////////////////////////
180 void AliJob::AddObject(TObject* obj)
182 // Store pointer of specified object in the working environment.
186 if (!fObjects) fObjects=new TObjArray();
190 // Create the top level environment folder for all AliJobs if needed
191 TList* list=gROOT->GetListOfBrowsables();
194 TFolder* top=(TFolder*)list->FindObject("AliJob-folders");
197 top=new TFolder("AliJob-folders","Environment for all AliJob derived tasks");
198 list->Add(top,"AliJob-folders");
200 // Create the task-specific folder as a sub-folder in the top folder
201 fFolder=top->AddFolder(GetName(),GetTitle());
205 // Add object pointer to array and folder if it doesn't already exist
207 for (Int_t i=0; i<fObjects->GetEntries(); i++)
209 if (obj==fObjects->At(i))
221 ///////////////////////////////////////////////////////////////////////////
222 void AliJob::AddObjects(TObjArray* arr)
224 // Store pointers of all the array objects individually in the working environment.
229 for (Int_t i=0; i<arr->GetSize(); i++)
232 if (obj) AddObject(obj);
235 ///////////////////////////////////////////////////////////////////////////
236 void AliJob::RemoveObject(TObject* obj)
238 // Remove pointer of specified object from the working environment.
244 TObject* test=fObjects->Remove(obj);
245 if (test) fObjects->Compress();
248 if (fFolder) fFolder->Remove(obj);
250 ///////////////////////////////////////////////////////////////////////////
251 void AliJob::RemoveObjects(const char* classname)
253 // Remove all stored objects inheriting from classname.
255 if (!fObjects) return;
258 for (Int_t i=0; i<fObjects->GetEntries(); i++)
260 TObject* obj=fObjects->At(i);
261 if (obj->InheritsFrom(classname))
263 TObject* test=fObjects->Remove(obj);
265 if (fFolder) fFolder->Remove(obj);
268 if (remove) fObjects->Compress();
270 ///////////////////////////////////////////////////////////////////////////
271 TObject* AliJob::GetObject(Int_t j) const
273 // Provide pointer to j-th stored object.
274 // Note : j=1 indicates the first object.
276 if (!fObjects || j<1) return 0;
280 if (j<=fObjects->GetEntries()) obj=fObjects->At(j-1);
283 ///////////////////////////////////////////////////////////////////////////
284 TObject* AliJob::GetObject(const char* classname) const
286 // Provide pointer to the first stored object which inherits from classname.
288 if (!fObjects) return 0;
291 for (Int_t i=0; i<fObjects->GetEntries(); i++)
293 TObject* obx=fObjects->At(i);
294 if (obx->InheritsFrom(classname))
302 ///////////////////////////////////////////////////////////////////////////
303 TObjArray* AliJob::GetObjects() const
305 // Provide pointers of all the stored objects.
308 ///////////////////////////////////////////////////////////////////////////
309 TObjArray* AliJob::GetObjects(const char* classname)
311 // Provide pointers to all stored objects inheriting from classname.
313 if (!fObjects) return 0;
321 fSelect=new TObjArray();
324 for (Int_t i=0; i<fObjects->GetEntries(); i++)
326 TObject* obj=fObjects->At(i);
327 if (obj->InheritsFrom(classname)) fSelect->Add(obj);
331 ///////////////////////////////////////////////////////////////////////////