]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTSystem.cxx
- made package indepentend of src
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
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  *          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
18 /** @file   AliHLTSystem.cxx
19     @author Matthias Richter
20     @date   
21     @brief  Implementation of HLT module management.
22 */
23
24 #if __GNUC__>= 3
25 using namespace std;
26 #endif
27
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"
35
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTSystem)
38
39 AliHLTSystem::AliHLTSystem()
40   :
41   fpComponentHandler(new AliHLTComponentHandler()),
42   fpConfigurationHandler(new AliHLTConfigurationHandler()),
43   fTaskList()
44 {
45   if (fpComponentHandler) {
46     AliHLTComponentEnvironment env;
47     memset(&env, 0, sizeof(AliHLTComponentEnvironment));
48     env.fLoggingFunc=AliHLTLogging::Message;
49     fpComponentHandler->SetEnvironment(&env);
50
51     // init logging function in AliHLTLogging
52     Init(AliHLTLogging::Message);
53   } else {
54     HLTFatal("can not create Component Handler");
55   }
56   if (fpConfigurationHandler) {
57     AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
58   } else {
59     HLTFatal("can not create Configuration Handler");
60   }
61 }
62
63 AliHLTSystem::AliHLTSystem(const AliHLTSystem&)
64   :
65   fpComponentHandler(NULL),
66   fpConfigurationHandler(NULL),
67   fTaskList()
68 {
69   HLTFatal("copy constructor untested");
70 }
71
72 AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&)
73
74   HLTFatal("assignment operator untested");
75   return *this;
76 }
77
78 AliHLTSystem::~AliHLTSystem()
79 {
80     AliHLTConfiguration::GlobalDeinit();
81     if (fpConfigurationHandler) {
82       delete fpConfigurationHandler;
83     }
84     fpConfigurationHandler=NULL;
85
86     if (fpComponentHandler) {
87       delete fpComponentHandler;
88     }
89     fpComponentHandler=NULL;
90 }
91
92 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
93 {
94   int iResult=0;
95   return iResult;
96 }
97
98 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
99 {
100   int iResult=0;
101   return iResult;
102 }
103
104 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
105 {
106   int iResult=0;
107   return iResult;
108 }
109
110 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
111 {
112   int iResult=0;
113   if (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);
118         iResult=-EEXIST;
119         pTask=NULL;
120       }
121     } else if (pConf->SourcesResolved(1)!=1) {
122         HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
123         iResult=-ENOLINK;
124     } else {
125       pTask=new AliHLTTask(pConf, NULL);
126       if (pTask==NULL) {
127         iResult=-ENOMEM;
128       }
129     }
130     if (pTask) {
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 ...");
136         iResult=-ELOOP;
137       }
138       if (iResult>=0) {
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);
151           }
152           pDep=pConf->GetNextSource();
153         }
154         // remove the temporarily added task
155         fTaskList.Remove(pTask);
156
157         // insert the task and set the cross-links
158         if (iResult>=0) {
159           iResult=InsertTask(pTask);
160         }
161       } else {
162         delete pTask;
163         pTask=NULL;
164       }
165     }
166   } else {
167     iResult=-EINVAL;
168   }
169   return iResult;
170 }
171
172 int AliHLTSystem::CleanTaskList()
173 {
174   int iResult=0;
175   TObjLink* lnk=NULL;
176   while ((lnk=fTaskList.FirstLink())!=NULL) {
177     fTaskList.Remove(lnk);
178     delete (lnk->GetObject());
179   }
180   return iResult;
181 }
182
183 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
184 {
185   int iResult=0;
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);
193     if (iResult>0) {
194       iResult=pTask->SetDependency(pCurr);
195       pCurr->SetTarget(pTask);
196       HLTDebug("set dependency  \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
197     }
198     if (pCurr->Depends(pTask)) {
199       // circular dependency
200       HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
201       iResult=-ELOOP;
202     } else if ((iResult=pTask->CheckDependencies())>0) {
203       lnk = lnk->Next();
204     }
205   }
206   if (iResult==0) {
207       if (lnk) {
208         fTaskList.AddAfter(lnk, pTask);
209       } else {
210         fTaskList.AddFirst(pTask);
211       }
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);
215     iResult=-ENOLINK;
216   }
217   return iResult;
218 }
219
220 AliHLTTask* AliHLTSystem::FindTask(const char* id)
221 {
222   AliHLTTask* pTask=NULL;
223   if (id) {
224     pTask=(AliHLTTask*)fTaskList.FindObject(id); 
225   }
226   return pTask;
227 }
228
229 void AliHLTSystem::PrintTaskList()
230 {
231   HLTLogKeyword("task list");
232   TObjLink *lnk = NULL;
233   HLTMessage("Task List");
234   lnk=fTaskList.FirstLink();
235   while (lnk) {
236     TObject* obj=lnk->GetObject();
237     if (obj) {
238       HLTMessage("  %s - status:", obj->GetName());
239       AliHLTTask* pTask=(AliHLTTask*)obj;
240       pTask->PrintStatus();
241     } else {
242     }
243     lnk = lnk->Next();
244   }
245 }
246
247 int AliHLTSystem::Run() 
248 {
249   int iResult=0;
250   HLTError("function not yet implemented");
251   iResult=-ENOSYS;
252   return iResult;
253 }