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. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliHLTConfigurationHandler.cxx
20 @author Matthias Richter
22 @brief Implementation of HLT tasks.
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
38 #include "AliHLTConfigurationHandler.h"
39 #include "AliHLTConfiguration.h"
40 #include "AliHLTErrorGuard.h"
42 #include "TObjString.h"
44 /** ROOT macro for the implementation of ROOT specific class methods */
45 ClassImp(AliHLTConfigurationHandler)
47 AliHLTConfigurationHandler::AliHLTConfigurationHandler()
49 , fgListConfigurations()
50 , fgListScheduledRegistrations()
53 // see header file for class documentation
55 // refer to README to build package
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58 SetLocalLoggingLevel(kHLTLogInfo);
61 AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
63 // see header file for function documentation
65 while ((lnk=fgListConfigurations.FirstLink())!=NULL) {
66 AliHLTConfiguration* pConf=(AliHLTConfiguration*)lnk->GetObject();
67 HLTDebug("delete configuration \"%s\"", pConf->GetName());
68 fgListConfigurations.Remove(lnk);
71 fgListScheduledRegistrations.Delete();
74 AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL;
75 int AliHLTConfigurationHandler::fgNofInstances=0;
76 TMap* AliHLTConfigurationHandler::fgpSubstitutions=NULL;
78 AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler()
80 // see header file for class documentation
81 if (!fgpInstance) fgpInstance=new AliHLTConfigurationHandler;
86 int AliHLTConfigurationHandler::Destroy()
88 // see header file for class documentation
90 if (fgpInstance==this) {
91 nofInstances=--fgNofInstances;
93 if (fgNofInstances==0) {
95 if (fgpSubstitutions) delete fgpSubstitutions;
96 fgpSubstitutions=NULL;
98 if (nofInstances==0) delete this;
103 int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf)
105 // see header file for function documentation
108 AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf);
110 AliHLTConfiguration* pExisting=NULL;
111 if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) {
112 fgListConfigurations.Add(pClone);
113 HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf);
115 // mark all configurations with unresolved dependencies for re-evaluation
116 TObjLink* lnk=fgListConfigurations.FirstLink();
118 AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
119 if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) {
120 pSrc->InvalidateSources();
125 if ((*pExisting)!=(*pConf)) {
127 HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName());
130 } else if (IsScheduling()) {
131 fgListScheduledRegistrations.Add(pClone);
139 int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
141 // see header file for function documentation
143 AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
145 // the configuration will be registered automatically, if this failes the configuration
146 // is missing -> delete it
147 if (FindConfiguration(id)==NULL) {
153 HLTError("system error: object allocation failed");
159 void AliHLTConfigurationHandler::PrintConfigurations()
161 // see header file for function documentation
162 HLTLogKeyword("configuration listing");
163 HLTMessage("registered configurations:");
164 TObjLink *lnk = fgListConfigurations.FirstLink();
166 TObject *obj = lnk->GetObject();
167 HLTMessage(" %s", obj->GetName());
172 void AliHLTConfigurationHandler::Print(const char* option)
175 TString argument(option);
176 if (argument.BeginsWith("treeroot=")) {
177 argument.ReplaceAll("treeroot=", "");
178 if (argument.IsNull()) {
179 cout << "invalid argument to option 'treeroot=', please specify configuration" << endl;
182 // TODO: add functionality to print a dependency tree beginning from a root configuration
183 // add also option to limit the depth
184 cout << "need to implement option 'treeview', argument " << argument << endl;
188 // default: print all
189 PrintConfigurations();
192 int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
194 // see header file for function documentation
197 AliHLTConfiguration* pConf=NULL;
198 if ((pConf=FindConfiguration(id))!=NULL) {
199 iResult=RemoveConfiguration(pConf);
203 HLTWarning("can not find configuration \"%s\"", id);
212 int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
214 // see header file for function documentation
217 // remove the configuration from the list
218 HLTDebug("remove configuration \"%s\"", pConf->GetName());
219 fgListConfigurations.Remove(pConf);
220 // remove cross links in the remaining configurations
221 TObjLink* lnk=fgListConfigurations.FirstLink();
222 while (lnk && iResult>=0) {
223 AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject();
225 pRem->InvalidateSource(pConf);
235 AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
237 // see header file for function documentation
238 AliHLTConfiguration* pConf=NULL;
240 pConf=(AliHLTConfiguration*)fgListConfigurations.FindObject(id);
245 int AliHLTConfigurationHandler::Deactivate(bool schedule) {
246 // see header file for function documentation
253 int AliHLTConfigurationHandler::Activate() {
254 // see header file for function documentation
256 if (IsScheduling()) {
257 fFlags&=~kScheduling;
258 TObjLink *lnk = fgListScheduledRegistrations.FirstLink();
260 RegisterConfiguration((AliHLTConfiguration*)lnk->GetObject());
263 ClearScheduledRegistrations();
268 int AliHLTConfigurationHandler::MissedRegistration(const char* name)
270 /// indicate a failed attempt to register because of unavailable global instance
272 /// everything fine if global instance is inactive
274 if (fgpInstance->IsActive()) {
275 static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration",
276 "internal error, global instance available but registration of configuration failed");
281 TString message("Missing configuration handler, failed to register configuration");
282 if (name) {message+=" '"; message+=name;}
283 message+="'\n AliHLTSystem and configuration handler can be initialized by adding the line";
284 message+="\n AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();";
285 message+="\n to the macro before the first AliHLTConfiguration definition. Suppressing further messages.\n";
286 static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration", message.Data());
291 int AliHLTConfigurationHandler::AddSubstitution(const char* componentId, const AliHLTConfiguration& subst)
293 /// add component substitution for components of specified id
294 if (!componentId) return -EINVAL;
295 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
296 if (!fgpSubstitutions) return -ENOMEM;
297 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
299 fgpSubstitutions->Add(new TObjString(componentId), new AliHLTConfiguration(subst));
304 int AliHLTConfigurationHandler::AddSubstitution(const AliHLTConfiguration& conf , const AliHLTConfiguration& subst)
306 /// add component substitution for components of specified id
307 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
308 if (!fgpSubstitutions) return -ENOMEM;
309 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
311 fgpSubstitutions->Add(new AliHLTConfiguration(conf), new AliHLTConfiguration(subst));
316 const AliHLTConfiguration* AliHLTConfigurationHandler::FindSubstitution(const AliHLTConfiguration& conf)
318 /// find component substitution for a configuration
319 if (!fgpSubstitutions) return NULL;
322 // check for specific configuration
323 value=fgpSubstitutions->GetValue(conf.GetName());
324 if (value) return dynamic_cast<AliHLTConfiguration*>(value);
326 // check for component Id
327 value=fgpSubstitutions->GetValue(conf.GetComponentID());
328 if (value) return dynamic_cast<AliHLTConfiguration*>(value);