]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
usin global instance of configuration handler for automatic configuration, adding...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 26 Apr 2011 11:38:56 +0000 (11:38 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 26 Apr 2011 11:38:56 +0000 (11:38 +0000)
HLT/BASE/AliHLTConfiguration.cxx
HLT/BASE/AliHLTConfiguration.h
HLT/BASE/AliHLTConfigurationHandler.cxx
HLT/BASE/AliHLTConfigurationHandler.h
HLT/BASE/AliHLTSystem.cxx

index 4ec0f5d82c7c986b919b8aad54c3ebfcd07c7056..422433ec493bfd85f2f368b9ed9720ac07196c91 100644 (file)
@@ -1,32 +1,26 @@
 // $Id$
 
-/**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
- * ALICE Experiment at CERN, All rights reserved.                         *
- *                                                                        *
- * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
- *                  for The ALICE HLT Project.                            *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
-
-//  @file   AliHLTConfiguration.cxx
-//  @author Matthias Richter
-//  @date   2007
-//  @brief  HLT configuration description for a single component.
-//  @note   The class is used in Offline (AliRoot) context
-
-// see header file for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+///**************************************************************************
+///* This file is property of and copyright by the ALICE HLT Project        * 
+///* ALICE Experiment at CERN, All rights reserved.                         *
+///*                                                                        *
+///* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+///*                  for The ALICE HLT Project.                            *
+///*                                                                        *
+///* Permission to use, copy, modify and distribute this software and its   *
+///* documentation strictly for non-commercial purposes is hereby granted   *
+///* without fee, provided that the above copyright notice appears in all   *
+///* copies and that both the copyright notice and this permission notice   *
+///* appear in the supporting documentation. The authors make no claims     *
+///* about the suitability of this software for any purpose. It is          *
+///* provided "as is" without express or implied warranty.                  *
+///**************************************************************************
+
+/// @file   AliHLTConfiguration.cxx
+/// @author Matthias Richter
+/// @date   2007
+/// @brief  HLT configuration description for a single component.
+/// @note   The class is used in Offline (AliRoot) context
 
 #if __GNUC__>= 3
 using namespace std;
@@ -82,10 +76,10 @@ AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component,
   // see header file for function documentation
   if (bufsize) fBufferSize=ConvertSizeString(bufsize);
   if (id && component) {
-    if (fgConfigurationHandler) {
-      fgConfigurationHandler->RegisterConfiguration(this);
+    if (AliHLTConfigurationHandler::Instance()) {
+      AliHLTConfigurationHandler::Instance()->RegisterConfiguration(this);
     } else {
-      HLTWarning("no configuration handler set, skip registration");
+      AliHLTConfigurationHandler::MissedRegistration(id);
     }
   }
 }
@@ -127,11 +121,11 @@ AliHLTConfiguration& AliHLTConfiguration::operator=(const AliHLTConfiguration& s
 AliHLTConfiguration::~AliHLTConfiguration()
 {
   // see header file for function documentation
-  if (fgConfigurationHandler) {
-    if (fgConfigurationHandler->FindConfiguration(fID.Data())!=NULL) {
+  if (AliHLTConfigurationHandler::Instance()) {
+    if (AliHLTConfigurationHandler::Instance()->FindConfiguration(fID.Data())!=NULL) {
       // remove the configuration from the handler if it exists
       // but DO NOT remove the clone configuration
-      fgConfigurationHandler->RemoveConfiguration(this);
+      AliHLTConfigurationHandler::Instance()->RemoveConfiguration(this);
     }
   }
   if (fArgv != NULL) {
@@ -151,33 +145,6 @@ AliHLTConfiguration::~AliHLTConfiguration()
   }
 }
 
-/* the global configuration handler which is used to automatically register the configuration
- */
-AliHLTConfigurationHandler* AliHLTConfiguration::fgConfigurationHandler=NULL;
-
-int AliHLTConfiguration::GlobalInit(AliHLTConfigurationHandler* pHandler)
-{
-  // see header file for function documentation
-  int iResult=0;
-  if (fgConfigurationHandler!=NULL && fgConfigurationHandler!=pHandler) {
-    fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalInit", HLT_DEFAULT_LOG_KEYWORD, "configuration handler already initialized, overriding object %p with %p", fgConfigurationHandler, pHandler);
-  }
-  fgConfigurationHandler=pHandler;
-  return iResult;
-}
-
-int AliHLTConfiguration::GlobalDeinit(AliHLTConfigurationHandler* pHandler)
-{
-  // see header file for function documentation
-  int iResult=0;
-  if (fgConfigurationHandler!=NULL && fgConfigurationHandler!=pHandler) {
-    fgConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalDeinit", HLT_DEFAULT_LOG_KEYWORD, "handler %p is not set, skip ...", pHandler);
-    return -EBADF;
-  }
-  fgConfigurationHandler=NULL;
-  return iResult;
-}
-
 const char* AliHLTConfiguration::GetName() const 
 {
   // see header file for function documentation
@@ -329,7 +296,8 @@ int AliHLTConfiguration::ExtractSources()
   int iResult=0;
   fNofSources=0; // indicates that the function was called, there are either n or 0 sources
   fListSources.clear();
-  if (!fgConfigurationHandler) {
+  AliHLTConfigurationHandler* pHandler=AliHLTConfigurationHandler::Instance();
+  if (!pHandler) {
     HLTError("global configuration handler not initialized, can not resolve sources");
     return -EFAULT;
   }
@@ -339,7 +307,7 @@ int AliHLTConfiguration::ExtractSources()
       fNofSources=tgtList.size();
       vector<char*>::iterator element=tgtList.begin();
       while ((element=tgtList.begin())!=tgtList.end()) {
-         AliHLTConfiguration* pConf=fgConfigurationHandler->FindConfiguration(*element);
+         AliHLTConfiguration* pConf=pHandler->FindConfiguration(*element);
          if (pConf) {
            //HLTDebug("configuration %s (%p): source \"%s\" (%p) inserted", GetName(), this, pConf->GetName(), pConf);
            fListSources.push_back(pConf);
index 7139c9ca220cc7202981ed3aaba8539daf545055..47a42f835d53e8975426629af0defc0877bd4554 100644 (file)
@@ -89,20 +89,6 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
   /** destructor */
   virtual ~AliHLTConfiguration();
 
-  /*****************************************************************************
-   * global initialization
-   */
-
-  /**
-   * Global initialization of the configuration handler.
-   */
-  static int GlobalInit(AliHLTConfigurationHandler* pHandler);
-
-  /**
-   * Global de-init and cleanup of the global configuration handler
-   */
-  static int GlobalDeinit(AliHLTConfigurationHandler* pHandler);
-
   /*****************************************************************************
    * properties of the configuration
    */
@@ -279,10 +265,7 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
   /** size of the output buffer */
   int fBufferSize;                                                 // see above
 
-  /** the instance of the global configuration handler */
-  static AliHLTConfigurationHandler* fgConfigurationHandler;       //! transient
-
-  ClassDef(AliHLTConfiguration, 1);
+  ClassDef(AliHLTConfiguration, 0);
 };
 
 #endif
index def410c9a3eb4b686b2bd78468aca28e0174e8e3..9b0c228ab89b6f00bca2d44332fd98ad575b7625 100644 (file)
@@ -37,6 +37,7 @@ using namespace std;
 #include <string>
 #include "AliHLTConfigurationHandler.h"
 #include "AliHLTConfiguration.h"
+#include "AliHLTErrorGuard.h"
 #include "TMap.h"
 #include "TObjString.h"
 
@@ -44,8 +45,9 @@ using namespace std;
 ClassImp(AliHLTConfigurationHandler)
 
 AliHLTConfigurationHandler::AliHLTConfigurationHandler()
-  :
-  fgListConfigurations()
+  : AliHLTLogging()
+  , fgListConfigurations()
+  , fFlags(0)
 {
   // see header file for class documentation
   // or
@@ -161,6 +163,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
@@ -214,6 +236,29 @@ AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* i
   return pConf;
 }
 
+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
index 6c2e2071503bf22265d03e23b755dcefda9f824d..d95a9813c20a0ca20bd4e2291085623db026839c 100644 (file)
@@ -3,21 +3,15 @@
 
 #ifndef ALIHLTCONFIGURATIONHANDLER_H
 #define ALIHLTCONFIGURATIONHANDLER_H
-/* This file is property of and copyright by the ALICE HLT Project        * 
- * ALICE Experiment at CERN, All rights reserved.                         *
- * See cxx source for full Copyright notice                               */
-
-/** @file   AliHLTConfigurationHandler.h
-    @author Matthias Richter
-    @date   
-    @brief  Global handling of HLT configurations.
-*/
-
-// see below for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
+///* This file is property of and copyright by the ALICE HLT Project        * 
+///* ALICE Experiment at CERN, All rights reserved.                         *
+///* See cxx source for full Copyright notice                               *
+
+/// @file   AliHLTConfigurationHandler.h
+/// @author Matthias Richter
+/// @date   
+/// @brief  Global handling of HLT configurations.
+///
 
 #include <TList.h>
 
@@ -43,8 +37,6 @@ class AliHLTConfigurationHandler : public AliHLTLogging {
   /** standard constructor */
   AliHLTConfigurationHandler();
   
-  //AliHLTConfigurationHandler(AliHLTConfiguration* pConf);
-
   /** destructor */
   virtual ~AliHLTConfigurationHandler();
 
@@ -64,6 +56,33 @@ class AliHLTConfigurationHandler : public AliHLTLogging {
    */
   int Destroy();
 
+  /**
+   * Get the instance of the global singleton.
+   * Does not create the global instance. Returns NULL if status of the global
+   * instance is 'inactive'.
+   */
+  static AliHLTConfigurationHandler* Instance() {
+    if (!fgpInstance || !fgpInstance->IsActive()) return NULL;
+    return fgpInstance;
+  }
+
+  /*****************************************************************************
+   * activation, effects the availability of the global singleton via
+   * AliHLTConfigurationHandler::Instance()
+   */
+
+  /// deactivate the handler, AliHLTConfiguration objects will not register
+  int Deactivate() {fFlags|=kInactive; return 0;}
+
+  /// activate the handler, AliHLTConfiguration objects will register again
+  int Activate() {fFlags&=~kInactive; return 0;}
+
+  /// check if active
+  bool IsActive() const {return (fFlags&kInactive)==0;}
+
+  /// signal a missed registration
+  static int MissedRegistration(const char* name=NULL);
+
   /*****************************************************************************
    * registration
    */
@@ -106,6 +125,14 @@ class AliHLTConfigurationHandler : public AliHLTLogging {
    */
   void PrintConfigurations();
 
+  /**
+   * Print info
+   * Options:
+   * -  treeroot=configuration  print the dependency tree for a configuration
+   * default PrintConfigurations
+   */
+  void Print(const char* option="");
+
   /**
    * Add a component substitution by component id.
    * All components of the specified component id will be replaced by the
@@ -130,17 +157,24 @@ class AliHLTConfigurationHandler : public AliHLTLogging {
   static const AliHLTConfiguration* FindSubstitution(const AliHLTConfiguration& conf);
 
  private:
+  enum {
+    kInactive = 0x1
+  };
+
   /** the list of registered configurations */
-  TList fgListConfigurations;                              // see above
+  TList fgListConfigurations;                                      // see above
+
+  /** status of the handler */
+  unsigned fFlags;                                                 //! transient
 
   /** the global singleton */
-  static AliHLTConfigurationHandler* fgpInstance;                      //!transient
+  static AliHLTConfigurationHandler* fgpInstance;                  //!transient
   /** number of used instances of the global singleton */
   static int fgNofInstances;                                       //!transient 
 
   /// component substitution map
   /// key: either TObjString with component id or AliHLTConfiguration object
-  static TMap* fgpSubstitutions;                                    //!transient 
+  static TMap* fgpSubstitutions;                                   //!transient 
 
   ClassDef(AliHLTConfigurationHandler, 0);
 };
index 5402bc04a03d15dd091bec7972288e8d094c2e36..36e8bee29ea35e88e4d7d55d154e5f56c84dcb1b 100644 (file)
@@ -123,9 +123,7 @@ AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name
   } else {
     HLTFatal("can not create Component Handler");
   }
-  if (fpConfigurationHandler) {
-    AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
-  } else {
+  if (fpConfigurationHandler==NULL) {
     HLTFatal("can not create Configuration Handler");
   }
 }
@@ -136,7 +134,6 @@ AliHLTSystem::~AliHLTSystem()
   fgNofInstances--;
   CleanHLTOUT();
   CleanTaskList();
-  AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
   if (fpConfigurationHandler) {
     fpConfigurationHandler->Destroy();
   }