]>
Commit | Line | Data |
---|---|---|
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 | |
32 | using namespace std; | |
33 | #endif | |
34 | ||
35 | #include <cerrno> | |
36 | #include <iostream> | |
37 | #include <string> | |
38 | #include "AliHLTConfigurationHandler.h" | |
39 | #include "AliHLTConfiguration.h" | |
4403fb69 | 40 | #include "AliHLTErrorGuard.h" |
e7b1a4ad | 41 | #include "TMap.h" |
42 | #include "TObjString.h" | |
7a436c89 | 43 | |
44 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
45 | ClassImp(AliHLTConfigurationHandler) | |
46 | ||
47 | AliHLTConfigurationHandler::AliHLTConfigurationHandler() | |
4403fb69 | 48 | : AliHLTLogging() |
49 | , fgListConfigurations() | |
50 | , fFlags(0) | |
7a436c89 | 51 | { |
52 | // see header file for class documentation | |
53 | // or | |
54 | // refer to README to build package | |
55 | // or | |
56 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
57 | SetLocalLoggingLevel(kHLTLogInfo); | |
58 | } | |
59 | ||
60 | AliHLTConfigurationHandler::~AliHLTConfigurationHandler() | |
61 | { | |
62 | // see header file for function documentation | |
63 | TObjLink* lnk=NULL; | |
64 | while ((lnk=fgListConfigurations.FirstLink())!=NULL) { | |
65 | AliHLTConfiguration* pConf=(AliHLTConfiguration*)lnk->GetObject(); | |
66 | HLTDebug("delete configuration \"%s\"", pConf->GetName()); | |
67 | fgListConfigurations.Remove(lnk); | |
68 | delete pConf; | |
69 | } | |
70 | } | |
71 | ||
b005ef92 | 72 | AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL; |
73 | int AliHLTConfigurationHandler::fgNofInstances=0; | |
e7b1a4ad | 74 | TMap* AliHLTConfigurationHandler::fgpSubstitutions=NULL; |
b005ef92 | 75 | |
76 | AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler() | |
77 | { | |
78 | // see header file for class documentation | |
79 | if (!fgpInstance) fgpInstance=new AliHLTConfigurationHandler; | |
80 | fgNofInstances++; | |
81 | return fgpInstance; | |
82 | } | |
83 | ||
84 | int AliHLTConfigurationHandler::Destroy() | |
85 | { | |
86 | // see header file for class documentation | |
87 | int nofInstances=0; | |
88 | if (fgpInstance==this) { | |
153e7db5 | 89 | nofInstances=--fgNofInstances; |
b005ef92 | 90 | } |
66efe0e1 | 91 | if (fgNofInstances==0) { |
66efe0e1 | 92 | fgpInstance = NULL; |
e7b1a4ad | 93 | if (fgpSubstitutions) delete fgpSubstitutions; |
94 | fgpSubstitutions=NULL; | |
66efe0e1 | 95 | } |
153e7db5 | 96 | if (nofInstances==0) delete this; |
b005ef92 | 97 | return nofInstances; |
98 | } | |
99 | ||
100 | ||
7a436c89 | 101 | int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf) |
102 | { | |
103 | // see header file for function documentation | |
104 | int iResult=0; | |
105 | if (pConf) { | |
d4a18597 | 106 | AliHLTConfiguration* pExisting=NULL; |
107 | if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) { | |
7a436c89 | 108 | AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf); |
109 | fgListConfigurations.Add(pClone); | |
110 | HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf); | |
111 | ||
112 | // mark all configurations with unresolved dependencies for re-evaluation | |
113 | TObjLink* lnk=fgListConfigurations.FirstLink(); | |
114 | while (lnk) { | |
115 | AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject(); | |
116 | if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) { | |
117 | pSrc->InvalidateSources(); | |
118 | } | |
119 | lnk=lnk->Next(); | |
120 | } | |
121 | } else { | |
d4a18597 | 122 | if ((*pExisting)!=(*pConf)) { |
7a436c89 | 123 | iResult=-EEXIST; |
d4a18597 | 124 | HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName()); |
125 | } | |
7a436c89 | 126 | } |
127 | } else { | |
128 | iResult=-EINVAL; | |
129 | } | |
130 | return iResult; | |
131 | } | |
132 | ||
133 | int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments) | |
134 | { | |
135 | // see header file for function documentation | |
136 | int iResult=0; | |
137 | AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments); | |
138 | if (pConf) { | |
139 | // the configuration will be registered automatically, if this failes the configuration | |
140 | // is missing -> delete it | |
141 | if (FindConfiguration(id)==NULL) { | |
142 | delete pConf; | |
143 | pConf=NULL; | |
144 | iResult=-EEXIST; | |
145 | } | |
146 | } else { | |
147 | HLTError("system error: object allocation failed"); | |
148 | iResult=-ENOMEM; | |
149 | } | |
150 | return iResult; | |
151 | } | |
152 | ||
153 | void AliHLTConfigurationHandler::PrintConfigurations() | |
154 | { | |
155 | // see header file for function documentation | |
156 | HLTLogKeyword("configuration listing"); | |
157 | HLTMessage("registered configurations:"); | |
158 | TObjLink *lnk = fgListConfigurations.FirstLink(); | |
159 | while (lnk) { | |
160 | TObject *obj = lnk->GetObject(); | |
161 | HLTMessage(" %s", obj->GetName()); | |
162 | lnk = lnk->Next(); | |
163 | } | |
164 | } | |
165 | ||
4403fb69 | 166 | void AliHLTConfigurationHandler::Print(const char* option) |
167 | { | |
168 | // print info | |
169 | TString argument(option); | |
170 | if (argument.BeginsWith("treeroot=")) { | |
171 | argument.ReplaceAll("treeroot=", ""); | |
172 | if (argument.IsNull()) { | |
173 | cout << "invalid argument to option 'treeroot=', please specify configuration" << endl; | |
174 | return; | |
175 | } | |
176 | // TODO: add functionality to print a dependency tree beginning from a root configuration | |
177 | // add also option to limit the depth | |
178 | cout << "need to implement option 'treeview', argument " << argument << endl; | |
179 | return; | |
180 | } | |
181 | ||
182 | // default: print all | |
183 | PrintConfigurations(); | |
184 | } | |
185 | ||
7a436c89 | 186 | int AliHLTConfigurationHandler::RemoveConfiguration(const char* id) |
187 | { | |
188 | // see header file for function documentation | |
189 | int iResult=0; | |
190 | if (id) { | |
191 | AliHLTConfiguration* pConf=NULL; | |
192 | if ((pConf=FindConfiguration(id))!=NULL) { | |
193 | iResult=RemoveConfiguration(pConf); | |
194 | delete pConf; | |
195 | pConf=NULL; | |
196 | } else { | |
197 | HLTWarning("can not find configuration \"%s\"", id); | |
198 | iResult=-ENOENT; | |
199 | } | |
200 | } else { | |
201 | iResult=-EINVAL; | |
202 | } | |
203 | return iResult; | |
204 | } | |
205 | ||
206 | int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf) | |
207 | { | |
208 | // see header file for function documentation | |
209 | int iResult=0; | |
210 | if (pConf) { | |
211 | // remove the configuration from the list | |
212 | HLTDebug("remove configuration \"%s\"", pConf->GetName()); | |
213 | fgListConfigurations.Remove(pConf); | |
214 | // remove cross links in the remaining configurations | |
215 | TObjLink* lnk=fgListConfigurations.FirstLink(); | |
216 | while (lnk && iResult>=0) { | |
217 | AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject(); | |
218 | if (pRem) { | |
219 | pRem->InvalidateSource(pConf); | |
220 | } else { | |
221 | iResult=-EFAULT; | |
222 | } | |
223 | lnk=lnk->Next(); | |
224 | } | |
225 | } | |
226 | return iResult; | |
227 | } | |
228 | ||
229 | AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id) | |
230 | { | |
231 | // see header file for function documentation | |
232 | AliHLTConfiguration* pConf=NULL; | |
233 | if (id) { | |
234 | pConf=(AliHLTConfiguration*)fgListConfigurations.FindObject(id); | |
235 | } | |
236 | return pConf; | |
237 | } | |
238 | ||
4403fb69 | 239 | int AliHLTConfigurationHandler::MissedRegistration(const char* name) |
240 | { | |
241 | /// indicate a failed attempt to register because of unavailable global instance | |
242 | ||
243 | /// everything fine if global instance is inactive | |
244 | if (fgpInstance) { | |
245 | if (fgpInstance->IsActive()) { | |
246 | static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration", | |
247 | "internal error, global instance available but registration of configuration failed"); | |
248 | (++g).Throw(1); | |
249 | } | |
250 | return 0; | |
251 | } | |
252 | TString message("Missing configuration handler, failed to register configuration"); | |
253 | if (name) {message+=" '"; message+=name;} | |
254 | message+="'\n AliHLTSystem and configuration handler can be initialized by adding the line"; | |
255 | message+="\n AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();"; | |
256 | message+="\n to the macro before the first AliHLTConfiguration definition. Suppressing further messages.\n"; | |
257 | static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration", message.Data()); | |
258 | (++g).Throw(1); | |
259 | return 1; | |
260 | } | |
261 | ||
e7b1a4ad | 262 | int AliHLTConfigurationHandler::AddSubstitution(const char* componentId, const AliHLTConfiguration& subst) |
263 | { | |
264 | /// add component substitution for components of specified id | |
265 | if (!componentId) return -EINVAL; | |
266 | if (!fgpSubstitutions) fgpSubstitutions=new TMap; | |
267 | if (!fgpSubstitutions) return -ENOMEM; | |
268 | fgpSubstitutions->SetOwnerKeyValue(kTRUE); | |
269 | ||
270 | fgpSubstitutions->Add(new TObjString(componentId), new AliHLTConfiguration(subst)); | |
271 | ||
272 | return 0; | |
273 | } | |
274 | ||
275 | int AliHLTConfigurationHandler::AddSubstitution(const AliHLTConfiguration& conf , const AliHLTConfiguration& subst) | |
276 | { | |
277 | /// add component substitution for components of specified id | |
278 | if (!fgpSubstitutions) fgpSubstitutions=new TMap; | |
279 | if (!fgpSubstitutions) return -ENOMEM; | |
280 | fgpSubstitutions->SetOwnerKeyValue(kTRUE); | |
281 | ||
282 | fgpSubstitutions->Add(new AliHLTConfiguration(conf), new AliHLTConfiguration(subst)); | |
283 | ||
284 | return 0; | |
285 | } | |
286 | ||
287 | const AliHLTConfiguration* AliHLTConfigurationHandler::FindSubstitution(const AliHLTConfiguration& conf) | |
288 | { | |
289 | /// find component substitution for a configuration | |
290 | if (!fgpSubstitutions) return NULL; | |
291 | TObject* value=NULL; | |
292 | ||
293 | // check for specific configuration | |
294 | value=fgpSubstitutions->GetValue(conf.GetName()); | |
295 | if (value) return dynamic_cast<AliHLTConfiguration*>(value); | |
296 | ||
297 | // check for component Id | |
298 | value=fgpSubstitutions->GetValue(conf.GetComponentID()); | |
299 | if (value) return dynamic_cast<AliHLTConfiguration*>(value); | |
300 | ||
301 | return NULL; | |
302 | } |