#include <string>
#include "AliHLTConfigurationHandler.h"
#include "AliHLTConfiguration.h"
+#include "AliHLTErrorGuard.h"
+#include "TMap.h"
+#include "TObjString.h"
/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(AliHLTConfigurationHandler)
AliHLTConfigurationHandler::AliHLTConfigurationHandler()
- :
- fgListConfigurations()
+ : AliHLTLogging()
+ , fgListConfigurations()
+ , fgListScheduledRegistrations()
+ , fFlags(0)
{
// see header file for class documentation
// or
fgListConfigurations.Remove(lnk);
delete pConf;
}
+ fgListScheduledRegistrations.Delete();
}
AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL;
int AliHLTConfigurationHandler::fgNofInstances=0;
+TMap* AliHLTConfigurationHandler::fgpSubstitutions=NULL;
AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler()
{
// see header file for class documentation
int nofInstances=0;
if (fgpInstance==this) {
- nofInstances=fgNofInstances--;
+ nofInstances=--fgNofInstances;
+ }
+ if (fgNofInstances==0) {
+ fgpInstance = NULL;
+ if (fgpSubstitutions) delete fgpSubstitutions;
+ fgpSubstitutions=NULL;
}
if (nofInstances==0) delete this;
return nofInstances;
// see header file for function documentation
int iResult=0;
if (pConf) {
- AliHLTConfiguration* pExisting=NULL;
- if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) {
- AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf);
- fgListConfigurations.Add(pClone);
- HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf);
-
- // mark all configurations with unresolved dependencies for re-evaluation
- TObjLink* lnk=fgListConfigurations.FirstLink();
- while (lnk) {
- AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
- if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) {
- pSrc->InvalidateSources();
- }
- lnk=lnk->Next();
- }
- } else {
- if ((*pExisting)!=(*pConf)) {
- iResult=-EEXIST;
- HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName());
+ AliHLTConfiguration* pClone=new AliHLTConfiguration(*pConf);
+ if (IsActive()) {
+ AliHLTConfiguration* pExisting=NULL;
+ if ((pExisting=FindConfiguration(pConf->GetName())) == NULL) {
+ fgListConfigurations.Add(pClone);
+ HLTDebug("configuration \"%s\" (%p) registered from %p", pClone->GetName(), pClone, pConf);
+
+ // mark all configurations with unresolved dependencies for re-evaluation
+ TObjLink* lnk=fgListConfigurations.FirstLink();
+ while (lnk) {
+ AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
+ if (pSrc && pSrc!=pClone && pSrc->SourcesResolved()!=1) {
+ pSrc->InvalidateSources();
+ }
+ lnk=lnk->Next();
+ }
+ } else {
+ if ((*pExisting)!=(*pConf)) {
+ iResult=-EEXIST;
+ HLTWarning("configuration \"%s\" already registered with different properties", pConf->GetName());
+ }
}
+ } else if (IsScheduling()) {
+ fgListScheduledRegistrations.Add(pClone);
}
} else {
iResult=-EINVAL;
{
// see header file for function documentation
int iResult=0;
+ // if this handler is the global instance the configuration is added
+ // automatically in the creation of the AliHLTConfiguration object
+ // the global instance must be deactivated otherwise in order to just create
+ // the object and then add it to THIS handler
+ bool bIamGlobal=fgpInstance==this;
+ if (!bIamGlobal && fgpInstance) {
+ // deactivate the automatic registration in the global handler
+ fgpInstance->Deactivate(false);
+ }
AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
if (pConf) {
+ if (bIamGlobal) {
// the configuration will be registered automatically, if this failes the configuration
// is missing -> delete it
if (FindConfiguration(id)==NULL) {
pConf=NULL;
iResult=-EEXIST;
}
+ } else {
+ RegisterConfiguration(pConf);
+ }
} else {
HLTError("system error: object allocation failed");
iResult=-ENOMEM;
}
+ if (!bIamGlobal && fgpInstance) {
+ // deactivate the automatic registration in the global handler
+ fgpInstance->Activate();
+ }
return iResult;
}
}
}
+void AliHLTConfigurationHandler::Print(const char* option)
+{
+ // print info
+ TString argument(option);
+ if (argument.BeginsWith("treeroot=")) {
+ argument.ReplaceAll("treeroot=", "");
+ if (argument.IsNull()) {
+ cout << "invalid argument to option 'treeroot=', please specify configuration" << endl;
+ return;
+ }
+ // TODO: add functionality to print a dependency tree beginning from a root configuration
+ // add also option to limit the depth
+ cout << "need to implement option 'treeview', argument " << argument << endl;
+ return;
+ }
+
+ // default: print all
+ PrintConfigurations();
+}
+
int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
{
// see header file for function documentation
return pConf;
}
+int AliHLTConfigurationHandler::Deactivate(bool schedule) {
+ // see header file for function documentation
+ fFlags|=kInactive;
+ if (schedule)
+ fFlags|=kScheduling;
+ return 0;
+}
+
+int AliHLTConfigurationHandler::Activate() {
+ // see header file for function documentation
+ fFlags&=~kInactive;
+ if (IsScheduling()) {
+ fFlags&=~kScheduling;
+ TObjLink *lnk = fgListScheduledRegistrations.FirstLink();
+ while (lnk) {
+ RegisterConfiguration((AliHLTConfiguration*)lnk->GetObject());
+ lnk = lnk->Next();
+ }
+ ClearScheduledRegistrations();
+ }
+ return 0;
+}
+
+int AliHLTConfigurationHandler::MissedRegistration(const char* name)
+{
+ /// indicate a failed attempt to register because of unavailable global instance
+
+ /// everything fine if global instance is inactive
+ if (fgpInstance) {
+ if (fgpInstance->IsActive()) {
+ static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration",
+ "internal error, global instance available but registration of configuration failed");
+ (++g).Throw(1);
+ }
+ return 0;
+ }
+ TString message("Missing configuration handler, failed to register configuration");
+ if (name) {message+=" '"; message+=name;}
+ message+="'\n AliHLTSystem and configuration handler can be initialized by adding the line";
+ message+="\n AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();";
+ message+="\n to the macro before the first AliHLTConfiguration definition. Suppressing further messages.\n";
+ static AliHLTErrorGuard g("AliHLTConfigurationHandler", "MissedRegistration", message.Data());
+ (++g).Throw(1);
+ return 1;
+}
+
+int AliHLTConfigurationHandler::AddSubstitution(const char* componentId, const AliHLTConfiguration& subst)
+{
+ /// add component substitution for components of specified id
+ if (!componentId) return -EINVAL;
+ if (!fgpSubstitutions) fgpSubstitutions=new TMap;
+ if (!fgpSubstitutions) return -ENOMEM;
+ fgpSubstitutions->SetOwnerKeyValue(kTRUE);
+
+ fgpSubstitutions->Add(new TObjString(componentId), new AliHLTConfiguration(subst));
+
+ return 0;
+}
+
+int AliHLTConfigurationHandler::AddSubstitution(const AliHLTConfiguration& conf , const AliHLTConfiguration& subst)
+{
+ /// add component substitution for components of specified id
+ if (!fgpSubstitutions) fgpSubstitutions=new TMap;
+ if (!fgpSubstitutions) return -ENOMEM;
+ fgpSubstitutions->SetOwnerKeyValue(kTRUE);
+
+ fgpSubstitutions->Add(new AliHLTConfiguration(conf), new AliHLTConfiguration(subst));
+
+ return 0;
+}
+
+const AliHLTConfiguration* AliHLTConfigurationHandler::FindSubstitution(const AliHLTConfiguration& conf)
+{
+ /// find component substitution for a configuration
+ if (!fgpSubstitutions) return NULL;
+ TObject* value=NULL;
+
+ // check for specific configuration
+ value=fgpSubstitutions->GetValue(conf.GetName());
+ if (value) return dynamic_cast<AliHLTConfiguration*>(value);
+
+ // check for component Id
+ value=fgpSubstitutions->GetValue(conf.GetComponentID());
+ if (value) return dynamic_cast<AliHLTConfiguration*>(value);
+
+ return NULL;
+}