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 // if this handler is the global instance the configuration is added
144 // automatically in the creation of the AliHLTConfiguration object
145 // the global instance must be deactivated otherwise in order to just create
146 // the object and then add it to THIS handler
147 bool bIamGlobal=fgpInstance==this;
148 if (!bIamGlobal && fgpInstance) {
149 // deactivate the automatic registration in the global handler
150 fgpInstance->Deactivate(false);
152 AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
155 // the configuration will be registered automatically, if this failes the configuration
156 // is missing -> delete it
157 if (FindConfiguration(id)==NULL) {
163 RegisterConfiguration(pConf);
166 HLTError("system error: object allocation failed");
169 if (!bIamGlobal && fgpInstance) {
170 // deactivate the automatic registration in the global handler
171 fgpInstance->Activate();
176 void AliHLTConfigurationHandler::PrintConfigurations()
178 // see header file for function documentation
179 HLTLogKeyword("configuration listing");
180 HLTMessage("registered configurations:");
181 TObjLink *lnk = fgListConfigurations.FirstLink();
183 TObject *obj = lnk->GetObject();
184 HLTMessage(" %s", obj->GetName());
189 void AliHLTConfigurationHandler::Print(const char* option)
192 TString argument(option);
193 if (argument.BeginsWith("treeroot=")) {
194 argument.ReplaceAll("treeroot=", "");
195 if (argument.IsNull()) {
196 cout << "invalid argument to option 'treeroot=', please specify configuration" << endl;
199 // TODO: add functionality to print a dependency tree beginning from a root configuration
200 // add also option to limit the depth
201 cout << "need to implement option 'treeview', argument " << argument << endl;
205 // default: print all
206 PrintConfigurations();
209 int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
211 // see header file for function documentation
214 AliHLTConfiguration* pConf=NULL;
215 if ((pConf=FindConfiguration(id))!=NULL) {
216 iResult=RemoveConfiguration(pConf);
220 HLTWarning("can not find configuration \"%s\"", id);
229 int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
231 // see header file for function documentation
234 // remove the configuration from the list
235 HLTDebug("remove configuration \"%s\"", pConf->GetName());
236 fgListConfigurations.Remove(pConf);
237 // remove cross links in the remaining configurations
238 TObjLink* lnk=fgListConfigurations.FirstLink();
239 while (lnk && iResult>=0) {
240 AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject();
242 pRem->InvalidateSource(pConf);
252 AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
254 // see header file for function documentation
255 AliHLTConfiguration* pConf=NULL;
257 pConf=(AliHLTConfiguration*)fgListConfigurations.FindObject(id);
262 int AliHLTConfigurationHandler::Deactivate(bool schedule) {
263 // see header file for function documentation
270 int AliHLTConfigurationHandler::Activate() {
271 // see header file for function documentation
273 if (IsScheduling()) {
274 fFlags&=~kScheduling;
275 TObjLink *lnk = fgListScheduledRegistrations.FirstLink();
277 RegisterConfiguration((AliHLTConfiguration*)lnk->GetObject());
280 ClearScheduledRegistrations();
285 int AliHLTConfigurationHandler::MissedRegistration(const char* name)
287 /// indicate a failed attempt to register because of unavailable global instance
289 /// everything fine if global instance is inactive
291 if (fgpInstance->IsActive()) {
292 static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration",
293 "internal error, global instance available but registration of configuration failed");
298 TString message("Missing configuration handler, failed to register configuration");
299 if (name) {message+=" '"; message+=name;}
300 message+="'\n AliHLTSystem and configuration handler can be initialized by adding the line";
301 message+="\n AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();";
302 message+="\n to the macro before the first AliHLTConfiguration definition. Suppressing further messages.\n";
303 static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration", message.Data());
308 int AliHLTConfigurationHandler::AddSubstitution(const char* componentId, const AliHLTConfiguration& subst)
310 /// add component substitution for components of specified id
311 if (!componentId) return -EINVAL;
312 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
313 if (!fgpSubstitutions) return -ENOMEM;
314 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
316 fgpSubstitutions->Add(new TObjString(componentId), new AliHLTConfiguration(subst));
321 int AliHLTConfigurationHandler::AddSubstitution(const AliHLTConfiguration& conf , const AliHLTConfiguration& subst)
323 /// add component substitution for components of specified id
324 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
325 if (!fgpSubstitutions) return -ENOMEM;
326 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
328 fgpSubstitutions->Add(new AliHLTConfiguration(conf), new AliHLTConfiguration(subst));
333 const AliHLTConfiguration* AliHLTConfigurationHandler::FindSubstitution(const AliHLTConfiguration& conf)
335 /// find component substitution for a configuration
336 if (!fgpSubstitutions) return NULL;
339 // check for specific configuration
340 value=fgpSubstitutions->GetValue(conf.GetName());
341 if (value) return dynamic_cast<AliHLTConfiguration*>(value);
343 // check for component Id
344 value=fgpSubstitutions->GetValue(conf.GetComponentID());
345 if (value) return dynamic_cast<AliHLTConfiguration*>(value);