From 4403fb6907326043dd4a3b9232344bc44bbcac88 Mon Sep 17 00:00:00 2001 From: richterm Date: Tue, 26 Apr 2011 11:38:56 +0000 Subject: [PATCH 1/1] usin global instance of configuration handler for automatic configuration, adding functionality to disable registration --- HLT/BASE/AliHLTConfiguration.cxx | 92 ++++++++----------------- HLT/BASE/AliHLTConfiguration.h | 19 +---- HLT/BASE/AliHLTConfigurationHandler.cxx | 49 ++++++++++++- HLT/BASE/AliHLTConfigurationHandler.h | 74 ++++++++++++++------ HLT/BASE/AliHLTSystem.cxx | 5 +- 5 files changed, 133 insertions(+), 106 deletions(-) diff --git a/HLT/BASE/AliHLTConfiguration.cxx b/HLT/BASE/AliHLTConfiguration.cxx index 4ec0f5d82c7..422433ec493 100644 --- a/HLT/BASE/AliHLTConfiguration.cxx +++ b/HLT/BASE/AliHLTConfiguration.cxx @@ -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 * - * 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 * +///* 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::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); diff --git a/HLT/BASE/AliHLTConfiguration.h b/HLT/BASE/AliHLTConfiguration.h index 7139c9ca220..47a42f835d5 100644 --- a/HLT/BASE/AliHLTConfiguration.h +++ b/HLT/BASE/AliHLTConfiguration.h @@ -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 diff --git a/HLT/BASE/AliHLTConfigurationHandler.cxx b/HLT/BASE/AliHLTConfigurationHandler.cxx index def410c9a3e..9b0c228ab89 100644 --- a/HLT/BASE/AliHLTConfigurationHandler.cxx +++ b/HLT/BASE/AliHLTConfigurationHandler.cxx @@ -37,6 +37,7 @@ using namespace std; #include #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 diff --git a/HLT/BASE/AliHLTConfigurationHandler.h b/HLT/BASE/AliHLTConfigurationHandler.h index 6c2e2071503..d95a9813c20 100644 --- a/HLT/BASE/AliHLTConfigurationHandler.h +++ b/HLT/BASE/AliHLTConfigurationHandler.h @@ -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 @@ -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); }; diff --git a/HLT/BASE/AliHLTSystem.cxx b/HLT/BASE/AliHLTSystem.cxx index 5402bc04a03..36e8bee29ea 100644 --- a/HLT/BASE/AliHLTSystem.cxx +++ b/HLT/BASE/AliHLTSystem.cxx @@ -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(); } -- 2.43.5