3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * for The ALICE Off-line Project. *
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 **************************************************************************/
18 /** @file AliHLTSystem.cxx
19 @author Matthias Richter
21 @brief Implementation of HLT module management.
28 #include "AliHLTStdIncludes.h"
29 #include "AliHLTSystem.h"
30 #include "AliHLTComponentHandler.h"
31 #include "AliHLTComponent.h"
32 #include "AliHLTConfiguration.h"
33 #include "AliHLTConfigurationHandler.h"
34 #include "AliHLTTask.h"
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTSystem)
39 AliHLTSystem::AliHLTSystem()
41 fpComponentHandler(new AliHLTComponentHandler()),
42 fpConfigurationHandler(new AliHLTConfigurationHandler()),
45 if (fpComponentHandler) {
46 AliHLTComponentEnvironment env;
47 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
48 env.fLoggingFunc=AliHLTLogging::Message;
49 fpComponentHandler->SetEnvironment(&env);
51 // init logging function in AliHLTLogging
52 Init(AliHLTLogging::Message);
54 HLTFatal("can not create Component Handler");
56 if (fpConfigurationHandler) {
57 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
59 HLTFatal("can not create Configuration Handler");
63 AliHLTSystem::AliHLTSystem(const AliHLTSystem&)
66 fpComponentHandler(NULL),
67 fpConfigurationHandler(NULL),
70 HLTFatal("copy constructor untested");
73 AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&)
75 HLTFatal("assignment operator untested");
79 AliHLTSystem::~AliHLTSystem()
81 AliHLTConfiguration::GlobalDeinit();
82 if (fpConfigurationHandler) {
83 delete fpConfigurationHandler;
85 fpConfigurationHandler=NULL;
87 if (fpComponentHandler) {
88 delete fpComponentHandler;
90 fpComponentHandler=NULL;
93 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
103 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
116 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
126 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
130 AliHLTTask* pTask=NULL;
131 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
132 if (pTask->GetConf()!=pConf) {
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);
137 } else if (pConf->SourcesResolved(1)!=1) {
138 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
141 pTask=new AliHLTTask(pConf);
147 // check for circular dependencies
148 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
149 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
150 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
151 HLTError("aborted ...");
155 // check whether all dependencies are already in the task list
156 // create the missing ones
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
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);
168 pDep=pConf->GetNextSource();
170 // remove the temporarily added task
171 fTaskList.Remove(pTask);
173 // insert the task and set the cross-links
175 iResult=InsertTask(pTask);
188 int AliHLTSystem::CleanTaskList()
192 while ((lnk=fTaskList.FirstLink())!=NULL) {
193 fTaskList.Remove(lnk);
194 delete (lnk->GetObject());
199 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
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();
207 //HLTDebug("checking \"%s\"", pCurr->GetName());
208 iResult=pTask->Depends(pCurr);
210 iResult=pTask->SetDependency(pCurr);
211 pCurr->SetTarget(pTask);
212 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
214 if (pCurr->Depends(pTask)) {
215 // circular dependency
216 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
218 } else if ((iResult=pTask->CheckDependencies())>0) {
224 fTaskList.AddAfter(lnk, pTask);
226 fTaskList.AddFirst(pTask);
228 HLTDebug("task \"%s\" inserted", pTask->GetName());
229 } else if (iResult>0) {
230 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
236 AliHLTTask* AliHLTSystem::FindTask(const char* id)
238 AliHLTTask* pTask=NULL;
240 pTask=(AliHLTTask*)fTaskList.FindObject(id);
245 void AliHLTSystem::PrintTaskList()
247 HLTLogKeyword("task list");
248 TObjLink *lnk = NULL;
249 HLTMessage("Task List");
250 lnk=fTaskList.FirstLink();
252 TObject* obj=lnk->GetObject();
254 HLTMessage(" %s - status:", obj->GetName());
255 AliHLTTask* pTask=(AliHLTTask*)obj;
256 pTask->PrintStatus();
263 int AliHLTSystem::Run(Int_t iNofEvents)
266 if ((iResult=StartTasks())>=0) {
267 for (int i=0; i<iNofEvents && iResult>=0; i++) {
268 iResult=ProcessTasks(i);
272 HLTError("can not start task list");
277 int AliHLTSystem::StartTasks()
280 TObjLink *lnk=fTaskList.FirstLink();
281 while (lnk && iResult>=0) {
282 TObject* obj=lnk->GetObject();
284 AliHLTTask* pTask=(AliHLTTask*)obj;
285 iResult=pTask->StartRun();
295 int AliHLTSystem::ProcessTasks(Int_t eventNo)
298 HLTDebug("processing event no %d", eventNo);
299 TObjLink *lnk=fTaskList.FirstLink();
300 while (lnk && iResult>=0) {
301 TObject* obj=lnk->GetObject();
303 AliHLTTask* pTask=(AliHLTTask*)obj;
304 iResult=pTask->ProcessTask();
312 int AliHLTSystem::StopTasks()
315 TObjLink *lnk=fTaskList.FirstLink();
316 while (lnk && iResult>=0) {
317 TObject* obj=lnk->GetObject();
319 AliHLTTask* pTask=(AliHLTTask*)obj;
320 iResult=pTask->EndRun();