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&)
65 fpComponentHandler(NULL),
66 fpConfigurationHandler(NULL),
69 HLTFatal("copy constructor untested");
72 AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&)
74 HLTFatal("assignment operator untested");
78 AliHLTSystem::~AliHLTSystem()
80 AliHLTConfiguration::GlobalDeinit();
81 if (fpConfigurationHandler) {
82 delete fpConfigurationHandler;
84 fpConfigurationHandler=NULL;
86 if (fpComponentHandler) {
87 delete fpComponentHandler;
89 fpComponentHandler=NULL;
92 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
98 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
104 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
110 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
114 AliHLTTask* pTask=NULL;
115 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
116 if (pTask->GetConf()!=pConf) {
117 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);
121 } else if (pConf->SourcesResolved(1)!=1) {
122 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
125 pTask=new AliHLTTask(pConf, NULL);
131 // check for circular dependencies
132 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
133 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
134 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
135 HLTError("aborted ...");
139 // check whether all dependencies are already in the task list
140 // create the missing ones
141 // this step is an iterative process which calls this function again for the missing
142 // configurations, in order to avoid the currently processed task to be created
143 // again it is added to the list temporarily and removed afterwards
144 // This is of high importance to preserve the order of the tasks. Furthermore, the
145 // InsertTask method has to be used in order to set all the cross links right
146 fTaskList.Add(pTask);
147 AliHLTConfiguration* pDep=pConf->GetFirstSource();
148 while (pDep!=NULL && iResult>=0) {
149 if (FindTask(pDep->GetName())==NULL) {
150 iResult=BuildTaskList(pDep);
152 pDep=pConf->GetNextSource();
154 // remove the temporarily added task
155 fTaskList.Remove(pTask);
157 // insert the task and set the cross-links
159 iResult=InsertTask(pTask);
172 int AliHLTSystem::CleanTaskList()
176 while ((lnk=fTaskList.FirstLink())!=NULL) {
177 fTaskList.Remove(lnk);
178 delete (lnk->GetObject());
183 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
186 TObjLink *lnk = NULL;
187 if ((iResult=pTask->CheckDependencies())>0)
188 lnk=fTaskList.FirstLink();
189 while (lnk && iResult>0) {
190 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
191 //HLTDebug("checking \"%s\"", pCurr->GetName());
192 iResult=pTask->Depends(pCurr);
194 iResult=pTask->SetDependency(pCurr);
195 pCurr->SetTarget(pTask);
196 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
198 if (pCurr->Depends(pTask)) {
199 // circular dependency
200 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
202 } else if ((iResult=pTask->CheckDependencies())>0) {
208 fTaskList.AddAfter(lnk, pTask);
210 fTaskList.AddFirst(pTask);
212 HLTDebug("task \"%s\" inserted", pTask->GetName());
213 } else if (iResult>0) {
214 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
220 AliHLTTask* AliHLTSystem::FindTask(const char* id)
222 AliHLTTask* pTask=NULL;
224 pTask=(AliHLTTask*)fTaskList.FindObject(id);
229 void AliHLTSystem::PrintTaskList()
231 HLTLogKeyword("task list");
232 TObjLink *lnk = NULL;
233 HLTMessage("Task List");
234 lnk=fTaskList.FirstLink();
236 TObject* obj=lnk->GetObject();
238 HLTMessage(" %s - status:", obj->GetName());
239 AliHLTTask* pTask=(AliHLTTask*)obj;
240 pTask->PrintStatus();
247 int AliHLTSystem::Run()
250 HLTError("function not yet implemented");