logging class extended and macros for easy log messages introduced, code changed...
[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> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * Artur Szostak <artursz@iafrica.com> *
9 * for The ALICE Off-line Project. *
10 * *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
19
20///////////////////////////////////////////////////////////////////////////////
21// //
22// global HLT module management //
23// //
24///////////////////////////////////////////////////////////////////////////////
25
26#if __GNUC__== 3
27using namespace std;
28#endif
29
30#include <errno.h>
31#include <string.h>
32#include "AliL3StandardIncludes.h"
33#include "AliHLTSystem.h"
34#include "AliHLTComponentHandler.h"
35#include "AliHLTComponent.h"
5ec8e281 36#include "AliHLTConfiguration.h"
f23a6e1a 37
38ClassImp(AliHLTSystem)
39
f23a6e1a 40AliHLTSystem::AliHLTSystem()
41{
42 fpComponentHandler=new AliHLTComponentHandler();
43 if (fpComponentHandler) {
44 AliHLTComponentEnvironment env;
45 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
5ec8e281 46 env.fLoggingFunc=AliHLTLogging::Message;
f23a6e1a 47 fpComponentHandler->SetEnvironment(&env);
5ec8e281 48
49 // init logging function in AliHLTLogging
50 Init(AliHLTLogging::Message);
85465857 51 } else {
52 HLTFatal("can not create Component Handler");
53 }
54 fpConfigurationHandler=new AliHLTConfigurationHandler();
55 if (fpConfigurationHandler) {
56 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
57 } else {
58 HLTFatal("can not create Configuration Handler");
f23a6e1a 59 }
60}
61
62
63AliHLTSystem::~AliHLTSystem()
64{
85465857 65 AliHLTConfiguration::GlobalDeinit();
66 if (fpConfigurationHandler) {
67 delete fpConfigurationHandler;
68 }
69 fpConfigurationHandler=NULL;
70
71 if (fpComponentHandler) {
72 delete fpComponentHandler;
73 }
74 fpComponentHandler=NULL;
f23a6e1a 75}
76
5ec8e281 77int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
78{
79 int iResult=0;
80 return iResult;
81}
82
83// int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
84// {
85// int iResult=0;
86// return iResult;
87// }
88
89int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
90{
91 int iResult=0;
92 return iResult;
93}
94
95int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
96{
f23a6e1a 97 int iResult=0;
5ec8e281 98 if (pConf) {
99 AliHLTTask* pTask=NULL;
100 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
101 if (pTask->GetConf()!=pConf) {
85465857 102 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 103 iResult=-EEXIST;
104 pTask=NULL;
105 }
106 } else if (pConf->SourcesResolved(1)!=1) {
85465857 107 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
5ec8e281 108 iResult=-ENOLINK;
109 } else {
110 pTask=new AliHLTTask(pConf, NULL);
111 if (pTask==NULL) {
112 iResult=-ENOMEM;
113 }
114 }
115 if (pTask) {
116 // check for ring dependencies
117 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
85465857 118 HLTError("detected ring dependency for configuration \"%s\"", pTask->GetName());
5ec8e281 119 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
85465857 120 HLTError("aborted ...");
5ec8e281 121 iResult=-ELOOP;
122 }
123 if (iResult>=0) {
124 // check whether all dependencies are already in the task list
125 // create the missing ones
126 fTaskList.Add(pTask);
127 AliHLTConfiguration* pDep=pConf->GetFirstSource();
128 while (pDep!=NULL && iResult>=0) {
129 if (FindTask(pDep->GetName())==NULL) {
130 iResult=BuildTaskList(pDep);
131 }
132 pDep=pConf->GetNextSource();
133 }
134 fTaskList.Remove(pTask);
135
136 // insert the task and set the cross-links
137 if (iResult>=0) {
138 iResult=InsertTask(pTask);
139 }
140 } else {
141 delete pTask;
142 pTask=NULL;
143 }
144 }
145 } else {
146 iResult=-EINVAL;
f23a6e1a 147 }
f23a6e1a 148 return iResult;
149}
150
5ec8e281 151int AliHLTSystem::CleanTaskList()
152{
153 int iResult=0;
154 TObjLink* lnk=NULL;
155 while ((lnk=fTaskList.FirstLink())!=NULL) {
156 fTaskList.Remove(lnk);
157 delete (lnk->GetObject());
158 }
159 return iResult;
160}
161
162int AliHLTSystem::InsertTask(AliHLTTask* pTask)
163{
164 int iResult=0;
165 TObjLink *lnk = NULL;
166 if ((iResult=pTask->CheckDependencies())>0)
167 lnk=fTaskList.FirstLink();
168 while (lnk && iResult>0) {
169 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
85465857 170 //HLTDebug("checking \"%s\"", pCurr->GetName());
5ec8e281 171 iResult=pTask->Depends(pCurr);
172 if (iResult>0) {
173 iResult=pTask->SetDependency(pCurr);
174 pCurr->SetTarget(pTask);
85465857 175 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
f23a6e1a 176 }
5ec8e281 177 if (pCurr->Depends(pTask)) {
178 // ring dependency
85465857 179 HLTError("ring dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
5ec8e281 180 iResult=-ELOOP;
181 } else if ((iResult=pTask->CheckDependencies())>0) {
182 lnk = lnk->Next();
183 }
184 }
185 if (iResult==0) {
186 if (lnk) {
187 fTaskList.AddAfter(lnk, pTask);
188 } else {
189 fTaskList.AddFirst(pTask);
190 }
85465857 191 HLTDebug("task \"%s\" inserted", pTask->GetName());
5ec8e281 192 } else if (iResult>0) {
85465857 193 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
5ec8e281 194 iResult=-ENOLINK;
f23a6e1a 195 }
5ec8e281 196 return iResult;
f23a6e1a 197}
198
5ec8e281 199AliHLTTask* AliHLTSystem::FindTask(const char* id)
200{
201 AliHLTTask* pTask=NULL;
202 if (id) {
203 pTask=(AliHLTTask*)fTaskList.FindObject(id);
204 }
205 return pTask;
206}
f23a6e1a 207
5ec8e281 208void AliHLTSystem::PrintTaskList()
209{
85465857 210 HLTLogKeyword("task list");
5ec8e281 211 TObjLink *lnk = NULL;
85465857 212 HLTMessage("Task List");
5ec8e281 213 lnk=fTaskList.FirstLink();
214 while (lnk) {
215 TObject* obj=lnk->GetObject();
216 if (obj) {
85465857 217 HLTMessage(" %s - status:", obj->GetName());
5ec8e281 218 AliHLTTask* pTask=(AliHLTTask*)obj;
219 pTask->PrintStatus();
220 } else {
221 }
222 lnk = lnk->Next();
223 }
224}