]>
Commit | Line | Data |
---|---|---|
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 | |
27 | using 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 | |
38 | ClassImp(AliHLTSystem) | |
39 | ||
f23a6e1a | 40 | AliHLTSystem::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); | |
f23a6e1a | 51 | } |
5ec8e281 | 52 | DebugMsg("create hlt object %s %p", "AliHLTSystem", this); |
53 | DebugMsg("done"); | |
f23a6e1a | 54 | } |
55 | ||
56 | ||
57 | AliHLTSystem::~AliHLTSystem() | |
58 | { | |
59 | } | |
60 | ||
5ec8e281 | 61 | int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf) |
62 | { | |
63 | int iResult=0; | |
64 | return iResult; | |
65 | } | |
66 | ||
67 | // int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec) | |
68 | // { | |
69 | // int iResult=0; | |
70 | // return iResult; | |
71 | // } | |
72 | ||
73 | int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf) | |
74 | { | |
75 | int iResult=0; | |
76 | return iResult; | |
77 | } | |
78 | ||
79 | int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf) | |
80 | { | |
f23a6e1a | 81 | int iResult=0; |
5ec8e281 | 82 | if (pConf) { |
83 | AliHLTTask* pTask=NULL; | |
84 | if ((pTask=FindTask(pConf->GetName()))!=NULL) { | |
85 | if (pTask->GetConf()!=pConf) { | |
86 | Logging(kHLTLogError, "BASE", "AliHLTSystem", "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); | |
87 | iResult=-EEXIST; | |
88 | pTask=NULL; | |
89 | } | |
90 | } else if (pConf->SourcesResolved(1)!=1) { | |
91 | Logging(kHLTLogError, "BASE", "AliHLTSystem", "configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName()); | |
92 | iResult=-ENOLINK; | |
93 | } else { | |
94 | pTask=new AliHLTTask(pConf, NULL); | |
95 | if (pTask==NULL) { | |
96 | iResult=-ENOMEM; | |
97 | } | |
98 | } | |
99 | if (pTask) { | |
100 | // check for ring dependencies | |
101 | if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) { | |
102 | Logging(kHLTLogError, "BASE", "AliHLTSystem", "detected ring dependency for configuration \"%s\"", pTask->GetName()); | |
103 | pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/); | |
104 | Logging(kHLTLogError, "BASE", "AliHLTSystem", "aborted ..."); | |
105 | iResult=-ELOOP; | |
106 | } | |
107 | if (iResult>=0) { | |
108 | // check whether all dependencies are already in the task list | |
109 | // create the missing ones | |
110 | fTaskList.Add(pTask); | |
111 | AliHLTConfiguration* pDep=pConf->GetFirstSource(); | |
112 | while (pDep!=NULL && iResult>=0) { | |
113 | if (FindTask(pDep->GetName())==NULL) { | |
114 | iResult=BuildTaskList(pDep); | |
115 | } | |
116 | pDep=pConf->GetNextSource(); | |
117 | } | |
118 | fTaskList.Remove(pTask); | |
119 | ||
120 | // insert the task and set the cross-links | |
121 | if (iResult>=0) { | |
122 | iResult=InsertTask(pTask); | |
123 | } | |
124 | } else { | |
125 | delete pTask; | |
126 | pTask=NULL; | |
127 | } | |
128 | } | |
129 | } else { | |
130 | iResult=-EINVAL; | |
f23a6e1a | 131 | } |
f23a6e1a | 132 | return iResult; |
133 | } | |
134 | ||
5ec8e281 | 135 | int AliHLTSystem::CleanTaskList() |
136 | { | |
137 | int iResult=0; | |
138 | TObjLink* lnk=NULL; | |
139 | while ((lnk=fTaskList.FirstLink())!=NULL) { | |
140 | fTaskList.Remove(lnk); | |
141 | delete (lnk->GetObject()); | |
142 | } | |
143 | return iResult; | |
144 | } | |
145 | ||
146 | int AliHLTSystem::InsertTask(AliHLTTask* pTask) | |
147 | { | |
148 | int iResult=0; | |
149 | TObjLink *lnk = NULL; | |
150 | if ((iResult=pTask->CheckDependencies())>0) | |
151 | lnk=fTaskList.FirstLink(); | |
152 | while (lnk && iResult>0) { | |
153 | AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject(); | |
154 | //Logging(kHLTLogDebug, "BASE", "AliHLTSystem", "checking \"%s\"", pCurr->GetName()); | |
155 | iResult=pTask->Depends(pCurr); | |
156 | if (iResult>0) { | |
157 | iResult=pTask->SetDependency(pCurr); | |
158 | pCurr->SetTarget(pTask); | |
159 | Logging(kHLTLogDebug, "BASE", "AliHLTSystem", "set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName()); | |
f23a6e1a | 160 | } |
5ec8e281 | 161 | if (pCurr->Depends(pTask)) { |
162 | // ring dependency | |
163 | Logging(kHLTLogError, "BASE", "AliHLTSystem", "ring dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName()); | |
164 | iResult=-ELOOP; | |
165 | } else if ((iResult=pTask->CheckDependencies())>0) { | |
166 | lnk = lnk->Next(); | |
167 | } | |
168 | } | |
169 | if (iResult==0) { | |
170 | if (lnk) { | |
171 | fTaskList.AddAfter(lnk, pTask); | |
172 | } else { | |
173 | fTaskList.AddFirst(pTask); | |
174 | } | |
175 | Logging(kHLTLogDebug, "BASE", "AliHLTSystem", "task \"%s\" inserted", pTask->GetName()); | |
176 | } else if (iResult>0) { | |
177 | Logging(kHLTLogError, "BASE", "AliHLTSystem", "can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult); | |
178 | iResult=-ENOLINK; | |
f23a6e1a | 179 | } |
5ec8e281 | 180 | return iResult; |
f23a6e1a | 181 | } |
182 | ||
5ec8e281 | 183 | AliHLTTask* AliHLTSystem::FindTask(const char* id) |
184 | { | |
185 | AliHLTTask* pTask=NULL; | |
186 | if (id) { | |
187 | pTask=(AliHLTTask*)fTaskList.FindObject(id); | |
188 | } | |
189 | return pTask; | |
190 | } | |
f23a6e1a | 191 | |
5ec8e281 | 192 | void AliHLTSystem::PrintTaskList() |
193 | { | |
194 | TObjLink *lnk = NULL; | |
195 | Logging(kHLTLogInfo, "BASE", "AliHLTSystem", "Task List"); | |
196 | lnk=fTaskList.FirstLink(); | |
197 | while (lnk) { | |
198 | TObject* obj=lnk->GetObject(); | |
199 | if (obj) { | |
200 | Logging(kHLTLogInfo, "BASE", "AliHLTSystem", " %s - status:", obj->GetName()); | |
201 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
202 | pTask->PrintStatus(); | |
203 | } else { | |
204 | } | |
205 | lnk = lnk->Next(); | |
206 | } | |
207 | } |