2 // split from AliHLTConfiguration.cxx,v 1.25 2007/10/12 13:24:47
3 ///**************************************************************************
4 ///* This file is property of and copyright by the *
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.
28 #include "AliHLTConfigurationHandler.h"
29 #include "AliHLTConfiguration.h"
30 #include "AliHLTErrorGuard.h"
32 #include "TObjString.h"
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTConfigurationHandler)
37 AliHLTConfigurationHandler::AliHLTConfigurationHandler()
39 , fgListConfigurations()
40 , fgListScheduledRegistrations()
45 // Global Handling of HLT configurations.
47 // This class implements the global handling of @ref AliHLTConfiguration objects.
48 // It is a list of all configuration descriptors currently available in the system.
49 // Each @ref AliHLTConfiguration object is registered automatically with the
50 // handler and put into the list.
51 SetLocalLoggingLevel(kHLTLogInfo);
54 AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
58 while ((lnk=fgListConfigurations.FirstLink())!=NULL) {
59 AliHLTConfiguration* pConf=(AliHLTConfiguration*)lnk->GetObject();
60 HLTDebug("delete configuration \"%s\"", pConf->GetName());
61 fgListConfigurations.Remove(lnk);
64 fgListScheduledRegistrations.Delete();
67 AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL;
68 int AliHLTConfigurationHandler::fgNofInstances=0;
69 TMap* AliHLTConfigurationHandler::fgpSubstitutions=NULL;
71 AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler()
73 // create global handler instance
74 if (!fgpInstance) fgpInstance=new AliHLTConfigurationHandler;
79 int AliHLTConfigurationHandler::Destroy()
83 if (fgpInstance==this) {
84 nofInstances=--fgNofInstances;
86 if (fgNofInstances==0) {
88 if (fgpSubstitutions) delete fgpSubstitutions;
89 fgpSubstitutions=NULL;
91 if (nofInstances==0) delete this;
96 int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf)
98 // register a configuration
101 AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf);
103 AliHLTConfiguration* pExisting=NULL;
104 if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) {
105 fgListConfigurations.Add(pClone);
106 HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf);
108 // mark all configurations with unresolved dependencies for re-evaluation
109 TObjLink* lnk=fgListConfigurations.FirstLink();
111 AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
112 if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) {
113 pSrc->InvalidateSources();
118 if ((*pExisting)!=(*pConf)) {
120 HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName());
123 } else if (IsScheduling()) {
124 fgListScheduledRegistrations.Add(pClone);
132 int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
134 // create configuration
136 // if this handler is the global instance the configuration is added
137 // automatically in the creation of the AliHLTConfiguration object
138 // the global instance must be deactivated otherwise in order to just create
139 // the object and then add it to THIS handler
140 bool bIamGlobal=fgpInstance==this;
141 if (!bIamGlobal && fgpInstance) {
142 // deactivate the automatic registration in the global handler
143 fgpInstance->Deactivate(false);
145 AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
148 // the configuration will be registered automatically, if this failes the configuration
149 // is missing -> delete it
150 if (FindConfiguration(id)==NULL) {
156 RegisterConfiguration(pConf);
159 HLTError("system error: object allocation failed");
162 if (!bIamGlobal && fgpInstance) {
163 // deactivate the automatic registration in the global handler
164 fgpInstance->Activate();
169 void AliHLTConfigurationHandler::PrintConfigurations()
172 HLTLogKeyword("configuration listing");
173 HLTMessage("registered configurations:");
174 TObjLink *lnk = fgListConfigurations.FirstLink();
176 TObject *obj = lnk->GetObject();
177 HLTMessage(" %s", obj->GetName());
182 void AliHLTConfigurationHandler::Print(const char* option)
185 TString argument(option);
186 if (argument.BeginsWith("treeroot=")) {
187 argument.ReplaceAll("treeroot=", "");
188 if (argument.IsNull()) {
189 cout << "invalid argument to option 'treeroot=', please specify configuration" << endl;
192 // TODO: add functionality to print a dependency tree beginning from a root configuration
193 // add also option to limit the depth
194 cout << "need to implement option 'treeview', argument " << argument << endl;
198 // default: print all
199 PrintConfigurations();
202 int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
204 // remove configuration from registry
207 AliHLTConfiguration* pConf=NULL;
208 if ((pConf=FindConfiguration(id))!=NULL) {
209 iResult=RemoveConfiguration(pConf);
213 HLTWarning("can not find configuration \"%s\"", id);
222 int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
224 // remove configuration from registry
227 // remove the configuration from the list
228 HLTDebug("remove configuration \"%s\"", pConf->GetName());
229 fgListConfigurations.Remove(pConf);
230 // remove cross links in the remaining configurations
231 TObjLink* lnk=fgListConfigurations.FirstLink();
232 while (lnk && iResult>=0) {
233 AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject();
235 pRem->InvalidateSource(pConf);
245 AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
247 // find configuration by id
248 AliHLTConfiguration* pConf=NULL;
250 pConf=(AliHLTConfiguration*)fgListConfigurations.FindObject(id);
255 int AliHLTConfigurationHandler::Deactivate(bool schedule)
257 // deactivate handler
264 int AliHLTConfigurationHandler::Activate()
268 if (IsScheduling()) {
269 fFlags&=~kScheduling;
270 TObjLink *lnk = fgListScheduledRegistrations.FirstLink();
272 RegisterConfiguration((AliHLTConfiguration*)lnk->GetObject());
275 ClearScheduledRegistrations();
280 int AliHLTConfigurationHandler::MissedRegistration(const char* name)
282 /// indicate a failed attempt to register because of unavailable global instance
284 /// everything fine if global instance is inactive
286 if (fgpInstance->IsActive()) {
287 static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration",
288 "internal error, global instance available but registration of configuration failed");
293 TString message("Missing configuration handler, failed to register configuration");
294 if (name) {message+=" '"; message+=name;}
295 message+="'\n AliHLTSystem and configuration handler can be initialized by adding the line";
296 message+="\n AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();";
297 message+="\n to the macro before the first AliHLTConfiguration definition. Suppressing further messages.\n";
298 static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration", message.Data());
303 int AliHLTConfigurationHandler::AddSubstitution(const char* componentId, const AliHLTConfiguration& subst)
305 /// add component substitution for components of specified id
306 if (!componentId) return -EINVAL;
307 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
308 if (!fgpSubstitutions) return -ENOMEM;
309 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
311 fgpSubstitutions->Add(new TObjString(componentId), new AliHLTConfiguration(subst));
316 int AliHLTConfigurationHandler::AddSubstitution(const AliHLTConfiguration& conf , const AliHLTConfiguration& subst)
318 /// add component substitution for components of specified id
319 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
320 if (!fgpSubstitutions) return -ENOMEM;
321 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
323 fgpSubstitutions->Add(new AliHLTConfiguration(conf), new AliHLTConfiguration(subst));
328 const AliHLTConfiguration* AliHLTConfigurationHandler::FindSubstitution(const AliHLTConfiguration& conf)
330 /// find component substitution for a configuration
331 if (!fgpSubstitutions) return NULL;
334 // check for specific configuration
335 value=fgpSubstitutions->GetValue(conf.GetName());
336 if (value) return dynamic_cast<AliHLTConfiguration*>(value);
338 // check for component Id
339 value=fgpSubstitutions->GetValue(conf.GetComponentID());
340 if (value) return dynamic_cast<AliHLTConfiguration*>(value);