]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTConfigurationHandler.cxx
Bug Fix.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTConfigurationHandler.cxx
CommitLineData
7a436c89 1// $Id$
2// splitted from AliHLTConfiguration.cxx,v 1.25 2007/10/12 13:24:47
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTConfigurationHandler.cxx
20 @author Matthias Richter
21 @date
22 @brief Implementation of HLT tasks.
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#if __GNUC__>= 3
32using namespace std;
33#endif
34
35#include <cerrno>
36#include <iostream>
37#include <string>
38#include "AliHLTConfigurationHandler.h"
39#include "AliHLTConfiguration.h"
e7b1a4ad 40#include "TMap.h"
41#include "TObjString.h"
7a436c89 42
43/** ROOT macro for the implementation of ROOT specific class methods */
44ClassImp(AliHLTConfigurationHandler)
45
46AliHLTConfigurationHandler::AliHLTConfigurationHandler()
47 :
48 fgListConfigurations()
49{
50 // see header file for class documentation
51 // or
52 // refer to README to build package
53 // or
54 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 SetLocalLoggingLevel(kHLTLogInfo);
56}
57
58AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
59{
60 // see header file for function documentation
61 TObjLink* lnk=NULL;
62 while ((lnk=fgListConfigurations.FirstLink())!=NULL) {
63 AliHLTConfiguration* pConf=(AliHLTConfiguration*)lnk->GetObject();
64 HLTDebug("delete configuration \"%s\"", pConf->GetName());
65 fgListConfigurations.Remove(lnk);
66 delete pConf;
67 }
68}
69
b005ef92 70AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL;
71int AliHLTConfigurationHandler::fgNofInstances=0;
e7b1a4ad 72TMap* AliHLTConfigurationHandler::fgpSubstitutions=NULL;
b005ef92 73
74AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler()
75{
76 // see header file for class documentation
77 if (!fgpInstance) fgpInstance=new AliHLTConfigurationHandler;
78 fgNofInstances++;
79 return fgpInstance;
80}
81
82int AliHLTConfigurationHandler::Destroy()
83{
84 // see header file for class documentation
85 int nofInstances=0;
86 if (fgpInstance==this) {
153e7db5 87 nofInstances=--fgNofInstances;
b005ef92 88 }
66efe0e1 89 if (fgNofInstances==0) {
66efe0e1 90 fgpInstance = NULL;
e7b1a4ad 91 if (fgpSubstitutions) delete fgpSubstitutions;
92 fgpSubstitutions=NULL;
66efe0e1 93 }
153e7db5 94 if (nofInstances==0) delete this;
b005ef92 95 return nofInstances;
96}
97
98
7a436c89 99int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf)
100{
101 // see header file for function documentation
102 int iResult=0;
103 if (pConf) {
d4a18597 104 AliHLTConfiguration* pExisting=NULL;
105 if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) {
7a436c89 106 AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf);
107 fgListConfigurations.Add(pClone);
108 HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf);
109
110 // mark all configurations with unresolved dependencies for re-evaluation
111 TObjLink* lnk=fgListConfigurations.FirstLink();
112 while (lnk) {
113 AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
114 if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) {
115 pSrc->InvalidateSources();
116 }
117 lnk=lnk->Next();
118 }
119 } else {
d4a18597 120 if ((*pExisting)!=(*pConf)) {
7a436c89 121 iResult=-EEXIST;
d4a18597 122 HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName());
123 }
7a436c89 124 }
125 } else {
126 iResult=-EINVAL;
127 }
128 return iResult;
129}
130
131int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
132{
133 // see header file for function documentation
134 int iResult=0;
135 AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
136 if (pConf) {
137 // the configuration will be registered automatically, if this failes the configuration
138 // is missing -> delete it
139 if (FindConfiguration(id)==NULL) {
140 delete pConf;
141 pConf=NULL;
142 iResult=-EEXIST;
143 }
144 } else {
145 HLTError("system error: object allocation failed");
146 iResult=-ENOMEM;
147 }
148 return iResult;
149}
150
151void AliHLTConfigurationHandler::PrintConfigurations()
152{
153 // see header file for function documentation
154 HLTLogKeyword("configuration listing");
155 HLTMessage("registered configurations:");
156 TObjLink *lnk = fgListConfigurations.FirstLink();
157 while (lnk) {
158 TObject *obj = lnk->GetObject();
159 HLTMessage(" %s", obj->GetName());
160 lnk = lnk->Next();
161 }
162}
163
164int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
165{
166 // see header file for function documentation
167 int iResult=0;
168 if (id) {
169 AliHLTConfiguration* pConf=NULL;
170 if ((pConf=FindConfiguration(id))!=NULL) {
171 iResult=RemoveConfiguration(pConf);
172 delete pConf;
173 pConf=NULL;
174 } else {
175 HLTWarning("can not find configuration \"%s\"", id);
176 iResult=-ENOENT;
177 }
178 } else {
179 iResult=-EINVAL;
180 }
181 return iResult;
182}
183
184int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
185{
186 // see header file for function documentation
187 int iResult=0;
188 if (pConf) {
189 // remove the configuration from the list
190 HLTDebug("remove configuration \"%s\"", pConf->GetName());
191 fgListConfigurations.Remove(pConf);
192 // remove cross links in the remaining configurations
193 TObjLink* lnk=fgListConfigurations.FirstLink();
194 while (lnk && iResult>=0) {
195 AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject();
196 if (pRem) {
197 pRem->InvalidateSource(pConf);
198 } else {
199 iResult=-EFAULT;
200 }
201 lnk=lnk->Next();
202 }
203 }
204 return iResult;
205}
206
207AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
208{
209 // see header file for function documentation
210 AliHLTConfiguration* pConf=NULL;
211 if (id) {
212 pConf=(AliHLTConfiguration*)fgListConfigurations.FindObject(id);
213 }
214 return pConf;
215}
216
e7b1a4ad 217int AliHLTConfigurationHandler::AddSubstitution(const char* componentId, const AliHLTConfiguration& subst)
218{
219 /// add component substitution for components of specified id
220 if (!componentId) return -EINVAL;
221 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
222 if (!fgpSubstitutions) return -ENOMEM;
223 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
224
225 fgpSubstitutions->Add(new TObjString(componentId), new AliHLTConfiguration(subst));
226
227 return 0;
228}
229
230int AliHLTConfigurationHandler::AddSubstitution(const AliHLTConfiguration& conf , const AliHLTConfiguration& subst)
231{
232 /// add component substitution for components of specified id
233 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
234 if (!fgpSubstitutions) return -ENOMEM;
235 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
236
237 fgpSubstitutions->Add(new AliHLTConfiguration(conf), new AliHLTConfiguration(subst));
238
239 return 0;
240}
241
242const AliHLTConfiguration* AliHLTConfigurationHandler::FindSubstitution(const AliHLTConfiguration& conf)
243{
244 /// find component substitution for a configuration
245 if (!fgpSubstitutions) return NULL;
246 TObject* value=NULL;
247
248 // check for specific configuration
249 value=fgpSubstitutions->GetValue(conf.GetName());
250 if (value) return dynamic_cast<AliHLTConfiguration*>(value);
251
252 // check for component Id
253 value=fgpSubstitutions->GetValue(conf.GetComponentID());
254 if (value) return dynamic_cast<AliHLTConfiguration*>(value);
255
256 return NULL;
257}