- setup scripts for running environment added
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
CommitLineData
f23a6e1a 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
f23a6e1a 7 * for The ALICE Off-line Project. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
b22e91eb 18/** @file AliHLTSystem.cxx
19 @author Matthias Richter
20 @date
21 @brief Implementation of HLT module management.
22*/
f23a6e1a 23
0c0c9d99 24#if __GNUC__>= 3
f23a6e1a 25using namespace std;
26#endif
27
85869391 28#include "AliHLTStdIncludes.h"
f23a6e1a 29#include "AliHLTSystem.h"
30#include "AliHLTComponentHandler.h"
31#include "AliHLTComponent.h"
5ec8e281 32#include "AliHLTConfiguration.h"
c38ba6f9 33#include "AliHLTConfigurationHandler.h"
34#include "AliHLTTask.h"
f23a6e1a 35
b22e91eb 36/** ROOT macro for the implementation of ROOT specific class methods */
f23a6e1a 37ClassImp(AliHLTSystem)
38
f23a6e1a 39AliHLTSystem::AliHLTSystem()
85869391 40 :
41 fpComponentHandler(new AliHLTComponentHandler()),
42 fpConfigurationHandler(new AliHLTConfigurationHandler()),
43 fTaskList()
f23a6e1a 44{
f23a6e1a 45 if (fpComponentHandler) {
46 AliHLTComponentEnvironment env;
47 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
5ec8e281 48 env.fLoggingFunc=AliHLTLogging::Message;
f23a6e1a 49 fpComponentHandler->SetEnvironment(&env);
5ec8e281 50
51 // init logging function in AliHLTLogging
52 Init(AliHLTLogging::Message);
85465857 53 } else {
54 HLTFatal("can not create Component Handler");
55 }
85465857 56 if (fpConfigurationHandler) {
57 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
58 } else {
59 HLTFatal("can not create Configuration Handler");
f23a6e1a 60 }
61}
62
85869391 63AliHLTSystem::AliHLTSystem(const AliHLTSystem&)
64 :
53feaef5 65 AliHLTLogging(),
85869391 66 fpComponentHandler(NULL),
67 fpConfigurationHandler(NULL),
68 fTaskList()
69{
70 HLTFatal("copy constructor untested");
71}
72
73AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&)
74{
75 HLTFatal("assignment operator untested");
76 return *this;
77}
f23a6e1a 78
79AliHLTSystem::~AliHLTSystem()
80{
85465857 81 AliHLTConfiguration::GlobalDeinit();
82 if (fpConfigurationHandler) {
83 delete fpConfigurationHandler;
84 }
85 fpConfigurationHandler=NULL;
86
87 if (fpComponentHandler) {
88 delete fpComponentHandler;
89 }
90 fpComponentHandler=NULL;
f23a6e1a 91}
92
5ec8e281 93int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
94{
95 int iResult=0;
53feaef5 96 if (pConf) {
97 } else {
98 iResult=-EINVAL;
99 }
5ec8e281 100 return iResult;
101}
102
014d39ce 103int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
104{
105 int iResult=0;
53feaef5 106 if (pConf) {
107 if (pPrec) {
108 // find the position
109 }
110 } else {
111 iResult=-EINVAL;
112 }
014d39ce 113 return iResult;
114}
5ec8e281 115
116int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
117{
118 int iResult=0;
53feaef5 119 if (pConf) {
120 } else {
121 iResult=-EINVAL;
122 }
5ec8e281 123 return iResult;
124}
125
126int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
127{
f23a6e1a 128 int iResult=0;
5ec8e281 129 if (pConf) {
130 AliHLTTask* pTask=NULL;
131 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
132 if (pTask->GetConf()!=pConf) {
85465857 133 HLTError("configuration missmatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
5ec8e281 134 iResult=-EEXIST;
135 pTask=NULL;
136 }
137 } else if (pConf->SourcesResolved(1)!=1) {
85465857 138 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
5ec8e281 139 iResult=-ENOLINK;
140 } else {
53feaef5 141 pTask=new AliHLTTask(pConf);
5ec8e281 142 if (pTask==NULL) {
143 iResult=-ENOMEM;
144 }
145 }
146 if (pTask) {
3b35e87c 147 // check for circular dependencies
5ec8e281 148 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
3b35e87c 149 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
5ec8e281 150 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
85465857 151 HLTError("aborted ...");
5ec8e281 152 iResult=-ELOOP;
153 }
154 if (iResult>=0) {
155 // check whether all dependencies are already in the task list
156 // create the missing ones
3b35e87c 157 // this step is an iterative process which calls this function again for the missing
158 // configurations, in order to avoid the currently processed task to be created
159 // again it is added to the list temporarily and removed afterwards
160 // This is of high importance to preserve the order of the tasks. Furthermore, the
161 // InsertTask method has to be used in order to set all the cross links right
5ec8e281 162 fTaskList.Add(pTask);
163 AliHLTConfiguration* pDep=pConf->GetFirstSource();
164 while (pDep!=NULL && iResult>=0) {
165 if (FindTask(pDep->GetName())==NULL) {
166 iResult=BuildTaskList(pDep);
167 }
168 pDep=pConf->GetNextSource();
169 }
3b35e87c 170 // remove the temporarily added task
5ec8e281 171 fTaskList.Remove(pTask);
172
173 // insert the task and set the cross-links
174 if (iResult>=0) {
175 iResult=InsertTask(pTask);
176 }
177 } else {
178 delete pTask;
179 pTask=NULL;
180 }
181 }
182 } else {
183 iResult=-EINVAL;
f23a6e1a 184 }
f23a6e1a 185 return iResult;
186}
187
5ec8e281 188int AliHLTSystem::CleanTaskList()
189{
190 int iResult=0;
191 TObjLink* lnk=NULL;
192 while ((lnk=fTaskList.FirstLink())!=NULL) {
193 fTaskList.Remove(lnk);
194 delete (lnk->GetObject());
195 }
196 return iResult;
197}
198
199int AliHLTSystem::InsertTask(AliHLTTask* pTask)
200{
201 int iResult=0;
202 TObjLink *lnk = NULL;
203 if ((iResult=pTask->CheckDependencies())>0)
204 lnk=fTaskList.FirstLink();
205 while (lnk && iResult>0) {
206 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
85465857 207 //HLTDebug("checking \"%s\"", pCurr->GetName());
5ec8e281 208 iResult=pTask->Depends(pCurr);
209 if (iResult>0) {
210 iResult=pTask->SetDependency(pCurr);
211 pCurr->SetTarget(pTask);
85465857 212 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
f23a6e1a 213 }
5ec8e281 214 if (pCurr->Depends(pTask)) {
3b35e87c 215 // circular dependency
216 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
5ec8e281 217 iResult=-ELOOP;
218 } else if ((iResult=pTask->CheckDependencies())>0) {
219 lnk = lnk->Next();
220 }
221 }
222 if (iResult==0) {
223 if (lnk) {
224 fTaskList.AddAfter(lnk, pTask);
225 } else {
226 fTaskList.AddFirst(pTask);
227 }
85465857 228 HLTDebug("task \"%s\" inserted", pTask->GetName());
5ec8e281 229 } else if (iResult>0) {
85465857 230 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
5ec8e281 231 iResult=-ENOLINK;
f23a6e1a 232 }
5ec8e281 233 return iResult;
f23a6e1a 234}
235
5ec8e281 236AliHLTTask* AliHLTSystem::FindTask(const char* id)
237{
238 AliHLTTask* pTask=NULL;
239 if (id) {
240 pTask=(AliHLTTask*)fTaskList.FindObject(id);
241 }
242 return pTask;
243}
f23a6e1a 244
5ec8e281 245void AliHLTSystem::PrintTaskList()
246{
85465857 247 HLTLogKeyword("task list");
5ec8e281 248 TObjLink *lnk = NULL;
85465857 249 HLTMessage("Task List");
5ec8e281 250 lnk=fTaskList.FirstLink();
251 while (lnk) {
252 TObject* obj=lnk->GetObject();
253 if (obj) {
85465857 254 HLTMessage(" %s - status:", obj->GetName());
5ec8e281 255 AliHLTTask* pTask=(AliHLTTask*)obj;
256 pTask->PrintStatus();
257 } else {
258 }
259 lnk = lnk->Next();
260 }
261}
014d39ce 262
53feaef5 263int AliHLTSystem::Run(Int_t iNofEvents)
014d39ce 264{
265 int iResult=0;
53feaef5 266 if ((iResult=StartTasks())>=0) {
267 for (int i=0; i<iNofEvents && iResult>=0; i++) {
268 iResult=ProcessTasks(i);
269 }
270 StopTasks();
271 } else {
272 HLTError("can not start task list");
273 }
274 return iResult;
275}
276
277int AliHLTSystem::StartTasks()
278{
279 int iResult=0;
280 TObjLink *lnk=fTaskList.FirstLink();
281 while (lnk && iResult>=0) {
282 TObject* obj=lnk->GetObject();
283 if (obj) {
284 AliHLTTask* pTask=(AliHLTTask*)obj;
285 iResult=pTask->StartRun();
286 } else {
287 }
288 lnk = lnk->Next();
289 }
290 if (iResult<0) {
291 }
292 return iResult;
293}
294
295int AliHLTSystem::ProcessTasks(Int_t eventNo)
296{
297 int iResult=0;
298 HLTDebug("processing event no %d", eventNo);
299 TObjLink *lnk=fTaskList.FirstLink();
300 while (lnk && iResult>=0) {
301 TObject* obj=lnk->GetObject();
302 if (obj) {
303 AliHLTTask* pTask=(AliHLTTask*)obj;
304 iResult=pTask->ProcessTask();
305 } else {
306 }
307 lnk = lnk->Next();
308 }
309 return iResult;
310}
311
312int AliHLTSystem::StopTasks()
313{
314 int iResult=0;
315 TObjLink *lnk=fTaskList.FirstLink();
316 while (lnk && iResult>=0) {
317 TObject* obj=lnk->GetObject();
318 if (obj) {
319 AliHLTTask* pTask=(AliHLTTask*)obj;
320 iResult=pTask->EndRun();
321 } else {
322 }
323 lnk = lnk->Next();
324 }
014d39ce 325 return iResult;
326}