]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTConfigurationHandler.cxx
Analysis task used to extract the VZERO event-plane flatenning parameters.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTConfigurationHandler.cxx
index 023389caca8984d612e2ce8a4c464c43f2b5bd13..43fd10d6b6c025b94a6e92f3c8b5fd9d15fb14f5 100644 (file)
@@ -37,13 +37,18 @@ using namespace std;
 #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
@@ -63,10 +68,12 @@ AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
     fgListConfigurations.Remove(lnk);
     delete pConf;
   }
+  fgListScheduledRegistrations.Delete();
 }
 
 AliHLTConfigurationHandler* AliHLTConfigurationHandler::fgpInstance=NULL;
 int AliHLTConfigurationHandler::fgNofInstances=0;
+TMap* AliHLTConfigurationHandler::fgpSubstitutions=NULL;
 
 AliHLTConfigurationHandler* AliHLTConfigurationHandler::CreateHandler()
 {
@@ -81,7 +88,12 @@ int AliHLTConfigurationHandler::Destroy()
   // 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;
@@ -93,26 +105,30 @@ int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf
   // 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;
@@ -124,8 +140,18 @@ int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char*
 {
   // 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) {
@@ -133,10 +159,17 @@ int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char*
       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;
 }
 
@@ -153,6 +186,26 @@ void AliHLTConfigurationHandler::PrintConfigurations()
   }
 }
 
+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
@@ -206,3 +259,90 @@ AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* i
   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;
+}