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"
41 #include "TObjString.h"
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTConfigurationHandler)
46 AliHLTConfigurationHandler::AliHLTConfigurationHandler()
48 fgListConfigurations()
50 // see header file for class documentation
52 // refer to README to build package
54 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 SetLocalLoggingLevel(kHLTLogInfo);
58 AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
60 // see header file for function documentation
62 while ((lnk=fgListConfigurations.FirstLink())!=NULL) {
63 AliHLTConfiguration* pConf=(AliHLTConfiguration*)lnk->GetObject();
64 HLTDebug("delete configuration \"%s\"", pConf->GetName());
65 fgListConfigurations.Remove(lnk);
70 AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL;
71 int AliHLTConfigurationHandler::fgNofInstances=0;
72 TMap* AliHLTConfigurationHandler::fgpSubstitutions=NULL;
74 AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler()
76 // see header file for class documentation
77 if (!fgpInstance) fgpInstance=new AliHLTConfigurationHandler;
82 int AliHLTConfigurationHandler::Destroy()
84 // see header file for class documentation
86 if (fgpInstance==this) {
87 nofInstances=fgNofInstances--;
89 if (fgNofInstances==0) {
90 if (fgpInstance) delete fgpInstance;
92 if (fgpSubstitutions) delete fgpSubstitutions;
93 fgpSubstitutions=NULL;
99 int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf)
101 // see header file for function documentation
104 AliHLTConfiguration* pExisting=NULL;
105 if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) {
106 AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf);
107 fgListConfigurations.Add(pClone);
108 HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf);
110 // mark all configurations with unresolved dependencies for re-evaluation
111 TObjLink* lnk=fgListConfigurations.FirstLink();
113 AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
114 if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) {
115 pSrc->InvalidateSources();
120 if ((*pExisting)!=(*pConf)) {
122 HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName());
131 int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
133 // see header file for function documentation
135 AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
137 // the configuration will be registered automatically, if this failes the configuration
138 // is missing -> delete it
139 if (FindConfiguration(id)==NULL) {
145 HLTError("system error: object allocation failed");
151 void AliHLTConfigurationHandler::PrintConfigurations()
153 // see header file for function documentation
154 HLTLogKeyword("configuration listing");
155 HLTMessage("registered configurations:");
156 TObjLink *lnk = fgListConfigurations.FirstLink();
158 TObject *obj = lnk->GetObject();
159 HLTMessage(" %s", obj->GetName());
164 int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
166 // see header file for function documentation
169 AliHLTConfiguration* pConf=NULL;
170 if ((pConf=FindConfiguration(id))!=NULL) {
171 iResult=RemoveConfiguration(pConf);
175 HLTWarning("can not find configuration \"%s\"", id);
184 int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
186 // see header file for function documentation
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();
197 pRem->InvalidateSource(pConf);
207 AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
209 // see header file for function documentation
210 AliHLTConfiguration* pConf=NULL;
212 pConf=(AliHLTConfiguration*)fgListConfigurations.FindObject(id);
217 int AliHLTConfigurationHandler::AddSubstitution(const char* componentId, const AliHLTConfiguration& subst)
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);
225 fgpSubstitutions->Add(new TObjString(componentId), new AliHLTConfiguration(subst));
230 int AliHLTConfigurationHandler::AddSubstitution(const AliHLTConfiguration& conf , const AliHLTConfiguration& subst)
232 /// add component substitution for components of specified id
233 if (!fgpSubstitutions) fgpSubstitutions=new TMap;
234 if (!fgpSubstitutions) return -ENOMEM;
235 fgpSubstitutions->SetOwnerKeyValue(kTRUE);
237 fgpSubstitutions->Add(new AliHLTConfiguration(conf), new AliHLTConfiguration(subst));
242 const AliHLTConfiguration* AliHLTConfigurationHandler::FindSubstitution(const AliHLTConfiguration& conf)
244 /// find component substitution for a configuration
245 if (!fgpSubstitutions) return NULL;
248 // check for specific configuration
249 value=fgpSubstitutions->GetValue(conf.GetName());
250 if (value) return dynamic_cast<AliHLTConfiguration*>(value);
252 // check for component Id
253 value=fgpSubstitutions->GetValue(conf.GetComponentID());
254 if (value) return dynamic_cast<AliHLTConfiguration*>(value);