// $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;
// 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);
}
}
}
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) {
}
}
-/* 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
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;
}
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);
/** 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
*/
/** 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
#include <string>
#include "AliHLTConfigurationHandler.h"
#include "AliHLTConfiguration.h"
+#include "AliHLTErrorGuard.h"
#include "TMap.h"
#include "TObjString.h"
ClassImp(AliHLTConfigurationHandler)
AliHLTConfigurationHandler::AliHLTConfigurationHandler()
- :
- fgListConfigurations()
+ : AliHLTLogging()
+ , fgListConfigurations()
+ , fFlags(0)
{
// see header file for class documentation
// or
}
}
+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::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
#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>
/** standard constructor */
AliHLTConfigurationHandler();
- //AliHLTConfigurationHandler(AliHLTConfiguration* pConf);
-
/** destructor */
virtual ~AliHLTConfigurationHandler();
*/
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
*/
*/
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
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);
};
} else {
HLTFatal("can not create Component Handler");
}
- if (fpConfigurationHandler) {
- AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
- } else {
+ if (fpConfigurationHandler==NULL) {
HLTFatal("can not create Configuration Handler");
}
}
fgNofInstances--;
CleanHLTOUT();
CleanTaskList();
- AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
if (fpConfigurationHandler) {
fpConfigurationHandler->Destroy();
}