]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTSystem.cxx
- adaption to gcc >=3
[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  *          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 <cerrno>
31 #include <string>
32 #include "AliL3StandardIncludes.h"
33 #include "AliHLTSystem.h"
34 #include "AliHLTComponentHandler.h"
35 #include "AliHLTComponent.h"
36 #include "AliHLTConfiguration.h"
37
38 ClassImp(AliHLTSystem)
39
40 AliHLTSystem::AliHLTSystem()
41 {
42   fpComponentHandler=new AliHLTComponentHandler();
43   if (fpComponentHandler) {
44     AliHLTComponentEnvironment env;
45     memset(&env, 0, sizeof(AliHLTComponentEnvironment));
46     env.fLoggingFunc=AliHLTLogging::Message;
47     fpComponentHandler->SetEnvironment(&env);
48
49     // init logging function in AliHLTLogging
50     Init(AliHLTLogging::Message);
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");
59   }
60 }
61
62
63 AliHLTSystem::~AliHLTSystem()
64 {
65     AliHLTConfiguration::GlobalDeinit();
66     if (fpConfigurationHandler) {
67       delete fpConfigurationHandler;
68     }
69     fpConfigurationHandler=NULL;
70
71     if (fpComponentHandler) {
72       delete fpComponentHandler;
73     }
74     fpComponentHandler=NULL;
75 }
76
77 int 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
89 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
90 {
91   int iResult=0;
92   return iResult;
93 }
94
95 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
96 {
97   int iResult=0;
98   if (pConf) {
99     AliHLTTask* pTask=NULL;
100     if ((pTask=FindTask(pConf->GetName()))!=NULL) {
101       if (pTask->GetConf()!=pConf) {
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);
103         iResult=-EEXIST;
104         pTask=NULL;
105       }
106     } else if (pConf->SourcesResolved(1)!=1) {
107         HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
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 circular dependencies
117       if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
118         HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
119         pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
120         HLTError("aborted ...");
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         // this step is an iterative process which calls this function again for the missing
127         // configurations, in order to avoid the currently processed task to be created
128         // again it is added to the list temporarily and removed afterwards
129         // This is of high importance to preserve the order of the tasks. Furthermore, the
130         // InsertTask method has to be used in order to set all the cross links right 
131         fTaskList.Add(pTask);
132         AliHLTConfiguration* pDep=pConf->GetFirstSource();
133         while (pDep!=NULL && iResult>=0) {
134           if (FindTask(pDep->GetName())==NULL) {
135             iResult=BuildTaskList(pDep);
136           }
137           pDep=pConf->GetNextSource();
138         }
139         // remove the temporarily added task
140         fTaskList.Remove(pTask);
141
142         // insert the task and set the cross-links
143         if (iResult>=0) {
144           iResult=InsertTask(pTask);
145         }
146       } else {
147         delete pTask;
148         pTask=NULL;
149       }
150     }
151   } else {
152     iResult=-EINVAL;
153   }
154   return iResult;
155 }
156
157 int AliHLTSystem::CleanTaskList()
158 {
159   int iResult=0;
160   TObjLink* lnk=NULL;
161   while ((lnk=fTaskList.FirstLink())!=NULL) {
162     fTaskList.Remove(lnk);
163     delete (lnk->GetObject());
164   }
165   return iResult;
166 }
167
168 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
169 {
170   int iResult=0;
171   TObjLink *lnk = NULL;
172   if ((iResult=pTask->CheckDependencies())>0)
173     lnk=fTaskList.FirstLink();
174   while (lnk && iResult>0) {
175     AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
176     //HLTDebug("checking  \"%s\"", pCurr->GetName());
177     iResult=pTask->Depends(pCurr);
178     if (iResult>0) {
179       iResult=pTask->SetDependency(pCurr);
180       pCurr->SetTarget(pTask);
181       HLTDebug("set dependency  \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
182     }
183     if (pCurr->Depends(pTask)) {
184       // circular dependency
185       HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
186       iResult=-ELOOP;
187     } else if ((iResult=pTask->CheckDependencies())>0) {
188       lnk = lnk->Next();
189     }
190   }
191   if (iResult==0) {
192       if (lnk) {
193         fTaskList.AddAfter(lnk, pTask);
194       } else {
195         fTaskList.AddFirst(pTask);
196       }
197       HLTDebug("task \"%s\" inserted", pTask->GetName());
198   } else if (iResult>0) {
199     HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
200     iResult=-ENOLINK;
201   }
202   return iResult;
203 }
204
205 AliHLTTask* AliHLTSystem::FindTask(const char* id)
206 {
207   AliHLTTask* pTask=NULL;
208   if (id) {
209     pTask=(AliHLTTask*)fTaskList.FindObject(id); 
210   }
211   return pTask;
212 }
213
214 void AliHLTSystem::PrintTaskList()
215 {
216   HLTLogKeyword("task list");
217   TObjLink *lnk = NULL;
218   HLTMessage("Task List");
219   lnk=fTaskList.FirstLink();
220   while (lnk) {
221     TObject* obj=lnk->GetObject();
222     if (obj) {
223       HLTMessage("  %s - status:", obj->GetName());
224       AliHLTTask* pTask=(AliHLTTask*)obj;
225       pTask->PrintStatus();
226     } else {
227     }
228     lnk = lnk->Next();
229   }
230 }
231
232 int AliHLTSystem::Run() 
233 {
234   int iResult=0;
235   HLTError("function not yet implemented");
236   iResult=-ENOSYS;
237   return iResult;
238 }