// header files of library components
#include "AliHLTDummyComponent.h"
+#include "AliHLTSampleComponent1.h"
+#include "AliHLTSampleComponent2.h"
// header file of the module preprocessor
#include "AliHLTSamplePreprocessor.h"
assert(pHandler);
if (!pHandler) return -EINVAL;
pHandler->AddComponent(new AliHLTDummyComponent);
+ pHandler->AddComponent(new AliHLTSampleComponent1);
+ pHandler->AddComponent(new AliHLTSampleComponent2);
+
return 0;
}
#endif
#include "AliHLTSampleComponent1.h"
+#include "TString.h"
+#include "TObjString.h"
+#include "TObjArray.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
-/**
- * The global object used for automatic component registration,
- * @note DO NOT use this component for calculation!
- */
-AliHLTSampleComponent1 gAliHLTSampleComponent1;
-
+/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(AliHLTSampleComponent1)
AliHLTSampleComponent1::AliHLTSampleComponent1()
{
// see header file for class documentation
+ // or
+ // refer to README to build package
+ // or
+ // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
}
AliHLTSampleComponent1::~AliHLTSampleComponent1()
// see header file for class documentation
}
-int AliHLTSampleComponent1::DoInit( int argc, const char** argv ){
+int AliHLTSampleComponent1::DoInit( int argc, const char** argv )
+{
// see header file for class documentation
- Logging(kHLTLogInfo, "HLT", "Sample", "Sample component1, DoInit");
- if (argc==0 && argv==NULL) {
- // this is just to get rid of the warning "unused parameter"
+ int iResult=0;
+ HLTInfo("parsing %d arguments", argc);
+
+ TString argument="";
+ TString configuration="";
+ int bMissingParam=0;
+ bool bHaveMandatory1=false;
+ bool bHaveMandatory2=false;
+ for (int i=0; i<argc && iResult>=0; i++) {
+ argument=argv[i];
+ if (argument.IsNull()) continue;
+
+ // -mandatory1
+ if (argument.CompareTo("-mandatory1")==0) {
+ bHaveMandatory1|=1;
+ if ((bMissingParam=(++i>=argc))) break;
+ HLTInfo("got \'-mandatory1\' argument: %s", argv[i]);
+
+ // -mandatory2
+ } else if (argument.CompareTo("-mandatory2")==0) {
+ bHaveMandatory2|=1;
+ HLTInfo("got \'-mandatory2\' argument");
+
+ // -optional1
+ } else if (argument.CompareTo("-optional1")==0) {
+ if ((bMissingParam=(++i>=argc))) break;
+ HLTInfo("got \'-optional1\' argument: %s", argv[i]);
+
+ // -optional2
+ } else if (argument.CompareTo("-optional2")==0) {
+ HLTInfo("got \'-optional2\' argument");
+
+ } else {
+ // the remaining arguments are treated as configuration
+ if (!configuration.IsNull()) configuration+=" ";
+ configuration+=argument;
+ }
}
- return 0;
+ if (bMissingParam) {
+ HLTError("missing parameter for argument %s", argument.Data());
+ iResult=-EINVAL;
+ }
+
+ if (iResult>=0 && !bHaveMandatory1) {
+ HLTError("mandatory argument \'-mandatory1\' missing");
+ iResult=-EPROTO;
+ }
+ if (iResult>=0 && !bHaveMandatory2) {
+ HLTError("mandatory argument \'-mandatory2\' missing");
+ iResult=-EPROTO;
+ }
+ if (iResult>=0 && !configuration.IsNull()) {
+ iResult=Configure(configuration.Data());
+ } else {
+ iResult=Reconfigure(NULL, NULL);
+ }
+
+ return iResult;
}
-int AliHLTSampleComponent1::DoDeinit(){
+int AliHLTSampleComponent1::DoDeinit()
+{
// see header file for class documentation
- Logging(kHLTLogInfo, "HLT", "Sample", "Sample component1, DoDeinit");
+ HLTInfo("processing cleanup");
return 0;
}
AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
// see header file for class documentation
- Logging(kHLTLogInfo, "HLT", "Sample", "Sample component1, DoEvent");
+ HLTInfo("processing data");
if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
outputPtr==0 && size==0)
{
}
return 0;
}
+
+int AliHLTSampleComponent1::Configure(const char* arguments)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!arguments) return iResult;
+ HLTInfo("parsing configuration string \'%s\'", arguments);
+
+ TString allArgs=arguments;
+ TString argument;
+ int bMissingParam=0;
+
+ TObjArray* pTokens=allArgs.Tokenize(" ");
+ if (pTokens) {
+ for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
+ argument=((TObjString*)pTokens->At(i))->GetString();
+ if (argument.IsNull()) continue;
+
+ // -config1
+ if (argument.CompareTo("-config1")==0) {
+ if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+ HLTInfo("got \'-config1\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+
+ // -config2
+ } else if (argument.CompareTo("-config2")==0) {
+ HLTInfo("got \'-config2\'");
+ } else {
+ HLTError("unknown argument %s", argument.Data());
+ iResult=-EINVAL;
+ break;
+ }
+ }
+ delete pTokens;
+ }
+ if (bMissingParam) {
+ HLTError("missing parameter for argument %s", argument.Data());
+ iResult=-EINVAL;
+ }
+ return iResult;
+}
+
+int AliHLTSampleComponent1::Reconfigure(const char* cdbEntry, const char* chainId)
+{
+ // see header file for class documentation
+ int iResult=0;
+ const char* path="HLT/ConfigSample/SampleComponent1";
+ const char* defaultNotify="";
+ if (cdbEntry) {
+ path=cdbEntry;
+ defaultNotify=" (default)";
+ }
+ if (path) {
+ HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+ AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
+ if (pEntry) {
+ TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
+ if (pString) {
+ HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
+ iResult=Configure(pString->GetString().Data());
+ } else {
+ HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
+ }
+ } else {
+ HLTError("can not fetch object \"%s\" from CDB", path);
+ }
+ }
+ return iResult;
+}
+//-*- Mode: C++ -*-
// @(#) $Id$
-
#ifndef ALIHLTSAMPLECOMPONENT1_H
#define ALIHLTSAMPLECOMPONENT1_H
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice */
+
+//* 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 AliHLTSampleComponent1.h
@author Matthias Richter, Timm Steinbeck
@date
- @brief A sample processing component for the HLT. */
+ @brief A sample processing component for the HLT.
+*/
#include "AliHLTProcessor.h"
/**
* @class AliHLTSampleComponent1
- * @brief An HLT sample component.
+ * An HLT sample component.
* This component does not any data processing at all. It just
* illustrates the existence of several components in ine library and
* allows to set up a very simple chain with different components.
+ *
+ * Component ID: \b Sample-component1 <br>
+ * Library: \b libAliHLTSample.so
+ *
+ * Mandatory arguments: <br>
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
+ * \li -mandatory1 <i> teststring </i> <br>
+ * an argument with one parameter
+ * \li -mandatory2 <br>
+ * an argument without parameters
+ *
+ * Optional arguments: <br>
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
+ * \li -optional1 <i> teststring </i> <br>
+ * an argument with one parameter
+ * \li -optional2 <br>
+ * an argument without parameters
+ *
+ * Configuration: <br>
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
+ * \li -config1 <i> teststring </i> <br>
+ * a configuration argument with one parameter
+ * \li -config2 <br>
+ * a configuration argument without parameters
+ *
+ * Furthermore it illustrates the component argument scanning and the
+ * component configuration. There are actually two methods to init/
+ * configure a component:
+ * - via command line arguments. The arguments are specified in the HLT
+ * chain configuration and are passed to the component during
+ * initialization in @ref DoInit()
+ * - from a CDB entry. The CDB can contain configuration objects for a
+ * component and the component can implement the handling
+ *
+ * The component implements the @ref alihltcomponent-low-level-interface.
+ * for data processing.
+ *
+ * Using the latter case, a component can also be reconfigured. Special
+ * events are propageted through the chain in order to trigger the re-
+ * configuration. The component needs to implement the function
+ * @ref Reconfigure(). The simplest version of a configuration object is
+ * a string object (TObjString) containing configuration arguments.
+ *
* @ingroup alihlt_tutorial
*/
class AliHLTSampleComponent1 : public AliHLTProcessor {
AliHLTSampleComponent1();
virtual ~AliHLTSampleComponent1();
+ // AliHLTComponent interface functions
const char* GetComponentID() { return "Sample-component1";}
void GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
list.push_back(kAliHLTAnyDataType);
AliHLTComponent* Spawn() {return new AliHLTSampleComponent1;};
protected:
-
+ // AliHLTComponent interface functions
int DoInit( int argc, const char** argv );
int DoDeinit();
int DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks );
+ int Reconfigure(const char* cdbEntry, const char* chainId);
using AliHLTProcessor::DoEvent;
private:
+ /**
+ * Configure the component.
+ * Parse a string for the configuration arguments and set the component
+ * properties.
+ *
+ * This function illustrates the scanning of an argument string. The string
+ * was presumably fetched from the CDB.
+ */
+ int Configure(const char* arguments);
- ClassDef(AliHLTSampleComponent1, 0)
+ ClassDef(AliHLTSampleComponent1, 1)
};
#endif
#include "AliHLTSampleComponent2.h"
-/**
- * The global object used for automatic component registration,
- * @note DO NOT use this component for calculation!
- */
-AliHLTSampleComponent2 gAliHLTSampleComponent2;
-
ClassImp(AliHLTSampleComponent2)
AliHLTSampleComponent2::AliHLTSampleComponent2()
--- /dev/null
+// $Id: 1.1 2007/11/08 12:17:24 richterm Exp $
+/**
+ * Sample macro for the component initialization and configuration
+ *
+ * Usage:
+ * aliroot -b -q sample-component1.C | tee sample-component1.log
+ *
+ * This macro illustrates the creation of an HLT component and it's
+ * initialization and configuration.
+ *
+ * A component can be initialized by command line arguments. The scan
+ * and interpretation of those arguments must be implemented in the
+ * DoInit function of the component. The command line arguments are
+ * specified in the chain configuration. In this example, it is an
+ * AliRoot HLT chain. The same applies for PubSub online HLT chains.
+ *
+ * Configuration of components is done from configuration objects in
+ * the CDB. It's the responsibility of the component to retrieve the
+ * CDB entry from the CDB and interprete it. The CDB initialization
+ * is done by the framework.
+ *
+ * The component can also decide if it wants to configure already during
+ * initialization (DoInit) from configuration objects.
+ *
+ * @author Matthias.Richter@ift.uib.no
+ */
+{
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ // some parameters for this test macro
+
+ // the path of a temporary file needed to send the reconfigure event
+ const char* tmpFile="/tmp/samplecomponent1-dummy.dat";
+
+ // path of the cdb entry
+ const char* cdbEntryPath="HLT/ConfigSample/SampleComponent1";
+
+ // path of the CDB to be created
+ const char* cdbUri="local:///tmp/OCDB";
+
+ // initialization arguments for the component
+ const char* componentInit="-mandatory1 testarg -mandatory2";
+
+ // configuration arguments for the component
+ const char* componentConfig="-config1 config-param -config2";
+
+
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ // global initialization of the HLT
+
+ // this is just a tool to switch the logging systems
+ AliHLTLogging log;
+ //log.SwitchAliLog(0);
+
+ AliHLTSystem gHLT;
+ gHLT.SetGlobalLoggingLevel(0x3c);
+
+ // load the component library
+ gHLT.LoadComponentLibraries("libAliHLTUtil.so");
+ gHLT.LoadComponentLibraries("libAliHLTSample.so");
+
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ // CDB initialization
+
+ // this is a tool to send the reconfiguration event and the
+ // path of the cdb entry
+ FILE* fp = fopen(tmpFile, "w");
+ if (fp) {
+ fprintf(fp, cdbEntryPath);
+ fclose(fp);
+ }
+
+ // now we create the actual entry in the CDB
+ // the CDB is created in /tmp
+ AliCDBManager* man = AliCDBManager::Instance();
+ if (!man->IsDefaultStorageSet())
+ {
+ man->SetDefaultStorage(cdbUri);
+ man->SetRun(0);
+
+ // here is the actual content of the configuration object
+ TObjString obj=componentConfig;
+ AliCDBPath cdbPath(cdbEntryPath);
+ AliCDBId cdbId(cdbPath, 0, 0);
+ AliCDBMetaData cdbMetaData;
+ man->Put(&obj, cdbId, &cdbMetaData);
+ }
+
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ // now we build up a small chain
+
+ // publisher for the reconfigure event
+ TString arg;
+ arg.Form("-datatype COM_CONF PRIV -datafile %s", tmpFile);
+ AliHLTConfiguration reconfevent("reconfevent", "FilePublisher", NULL , arg.Data());
+
+ AliHLTConfiguration sc1("sc1", "Sample-component1", "reconfevent" , componentInit);
+
+ // run the chain
+ gHLT.BuildTaskList("sc1");
+ gHLT.Run();
+
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
+ // cleanup
+
+ // delete temporary file
+ TString cmd;
+ cmd.Form("rm -r %s", tmpFile, cdbUri);
+ gSystem->Exec(cmd.Data());
+}