]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTComponent.cxx
correcting allocation of EventDoneData in order to support multiple calls
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
index 641f4d88228f1aee4423d7689c2a5dfcf89171c2..2d8f59780152c9353d226d27f00554af026b0847 100644 (file)
@@ -36,6 +36,7 @@ using namespace std;
 #include "TObjectTable.h"
 #include "TClass.h"
 #include "TStopwatch.h"
+#include "TFormula.h"
 #include "AliHLTMemoryFile.h"
 #include "AliHLTMisc.h"
 #include <cassert>
@@ -45,6 +46,7 @@ using namespace std;
  * default compression level for ROOT objects
  */
 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
+#define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTComponent);
@@ -88,6 +90,8 @@ AliHLTComponent::AliHLTComponent()
   fEventDoneData(NULL),
   fEventDoneDataSize(0),
   fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
+  , fLastObjectSize(0)
+  , fpTriggerClasses(NULL)
 {
   // see header file for class documentation
   // or
@@ -128,6 +132,13 @@ AliHLTComponent::~AliHLTComponent()
   }
   if (fEventDoneData)
     delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
+  fEventDoneData=NULL;
+
+  if (fpTriggerClasses) {
+    fpTriggerClasses->Delete();
+    delete fpTriggerClasses;
+  }
+  fpTriggerClasses=NULL;
 }
 
 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
@@ -149,10 +160,10 @@ int AliHLTComponent::UnsetGlobalComponentHandler()
   return SetGlobalComponentHandler(NULL,1);
 }
 
-int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
+int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
 {
   // see header file for function documentation
-  HLTLogKeyword(GetComponentID());
+  HLTLogKeyword(fChainId.c_str());
   int iResult=0;
   if (comenv) {
     memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
@@ -160,6 +171,17 @@ int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environ
     fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
     fEnvironment.fParam=environParam;
   }
+  return iResult;
+}
+
+int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
+{
+  // see header file for function documentation
+  HLTLogKeyword(fChainId.c_str());
+  int iResult=0;
+  if (comenv) {
+    SetComponentEnvironment(comenv, environParam);
+  }
   fComponentArgs="";
   const char** pArguments=NULL;
   int iNofChildArgs=0;
@@ -175,12 +197,11 @@ int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environ
        if (argument.IsNull()) continue;
 
        // benchmark
-       if (argument.CompareTo("benchmark")==0) {
+       if (argument.CompareTo("-benchmark")==0) {
 
-         // loglevel
-       } else if (argument.CompareTo("loglevel")==0) {
-         if ((bMissingParam=(++i>=argc))) break;
-         TString parameter(argv[i]);
+         // -loglevel=
+       } else if (argument.BeginsWith("-loglevel=")) {
+         TString parameter=argument.ReplaceAll("-loglevel=", "");
          parameter.Remove(TString::kLeading, ' '); // remove all blanks
          if (parameter.BeginsWith("0x") &&
              parameter.Replace(0,2,"",0).IsHex()) {
@@ -240,9 +261,6 @@ int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environ
 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
   // benchmarking stopwatch for the component statistics
   fpBenchmark=new TStopwatch;
-  if (fpBenchmark) {
-    fpBenchmark->Start();
-  }
 #endif
 
   return iResult;
@@ -251,15 +269,25 @@ int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environ
 int AliHLTComponent::Deinit()
 {
   // see header file for function documentation
-  HLTLogKeyword(GetComponentID());
+  HLTLogKeyword(fChainId.c_str());
   int iResult=0;
   iResult=DoDeinit();
   if (fpRunDesc) {
-    HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
+    // TODO: the warning should be kept, but the condition is wrong since the
+    // AliHLTRunDesc is set before the SOR event in the SetRunDescription
+    // method. A couple of state flags should be defined but that is a bit more
+    // work to do. For the moment disable the warning (2009-07-01)
+    //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
     AliHLTRunDesc* pRunDesc=fpRunDesc;
     fpRunDesc=NULL;
     delete pRunDesc;
   }
+  if (fpTriggerClasses) {
+    fpTriggerClasses->Delete();
+    delete fpTriggerClasses;
+  }
+  fpTriggerClasses=NULL;
+
   fEventCount=0;
   return iResult;
 }
@@ -268,11 +296,14 @@ int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandl
 {
   // see header file for function documentation
   int iResult=0;
+  HLTInfo("Using CDB: %s", cdbPath);
   if (pHandler) {
   // I have to think about separating the library handling from the
-  // component handler. Requiring the component hanlder here is not
+  // component handler. Requiring the component handler here is not
   // the cleanest solution.
-  // We presume the library already to be loaded
+  // We presume the library already to be loaded, which is the case
+  // because it is loaded in the initialization of the logging functionality
+  //
   // find the symbol
   AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
   if (pFunc) {
@@ -365,6 +396,100 @@ int AliHLTComponent::SetComponentDescription(const char* desc)
   return iResult;
 }
 
+int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
+{
+  // see header file for function documentation
+  int iResult=0;
+  vector<const char*> array;
+  TObjArray choppedArguments;
+  TString argument="";
+  int i=0;
+  for (i=0; i<argc && iResult>=0; i++) {
+    argument=argv[i];
+    if (argument.IsNull()) continue;
+    TObjArray* pTokens=argument.Tokenize(" ");
+    if (pTokens) {
+      if (pTokens->GetEntriesFast()>0) {
+       for (int n=0; n<pTokens->GetEntriesFast(); n++) {
+         choppedArguments.AddLast(pTokens->At(n));
+         TString data=((TObjString*)pTokens->At(n))->GetString();
+         if (!data.IsNull()) {
+           array.push_back(data.Data());
+         }
+       }
+       pTokens->SetOwner(kFALSE);
+      }
+      delete pTokens;
+    }
+  }
+
+  for (i=0; (unsigned)i<array.size() && iResult>=0;) {
+    int result=ScanConfigurationArgument(array.size()-i, &array[i]);
+    if (result==0) {
+      HLTWarning("unknown component argument %s", array[i]);
+      i++;
+    } else if (result>0) {
+      i+=result;
+    } else {
+      iResult=result;
+      if (iResult==-EINVAL) {
+       HLTError("unknown argument %s", array[i]);
+      } else if (iResult==-EPROTO) {
+       HLTError("missing/wrong parameter for argument %s (%s)", array[i], (array.size()>(unsigned)i+1)?array[i+1]:"missing");
+      } else {
+       HLTError("scan of argument %s failed (%d)", array[i], iResult);
+      }
+    }
+  }
+
+  return iResult;
+}
+
+int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries)
+{
+  // see header file for function documentation
+  int iResult=0;
+  TString arguments;
+  TString confEntries=entries;
+  TObjArray* pTokens=confEntries.Tokenize(" ");
+  if (pTokens) {
+    for (int n=0; n<pTokens->GetEntriesFast(); n++) {
+      const char* path=((TObjString*)pTokens->At(n))->GetString().Data();
+      const char* chainId=GetChainId();
+      HLTInfo("configure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+      TObject* pOCDBObject = LoadAndExtractOCDBObject(path);
+      if (pOCDBObject) {
+       TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
+       if (pString) {
+         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
+         arguments+=pString->GetString().Data();
+         arguments+=" ";
+       } else {
+         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
+         iResult=-EINVAL;
+       }
+      } else {
+       HLTError("can not fetch object \"%s\" from OCDB", path);
+       iResult=-ENOENT;
+      }
+    }
+    delete pTokens;
+  }
+  if (iResult>=0 && !arguments.IsNull())  {
+    const char* array=arguments.Data();
+    iResult=ConfigureFromArgumentString(1, &array);
+  }
+  return iResult;
+}
+
+TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, int version, int subVersion)
+{
+  // see header file for function documentation
+  AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
+  if (!pEntry) return NULL;
+  return AliHLTMisc::Instance().ExtractObject(pEntry);
+}
+
 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
 {
   // default implementation, childs can overload
@@ -393,6 +518,14 @@ int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
   return 0;
 }
 
+int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
+{
+  // default implementation, childs can overload
+  HLTLogKeyword("dummy");
+  HLTWarning("The function needs to be implemented by the component");
+  return 0;
+}
+
 int AliHLTComponent::StartOfRun()
 {
   // default implementation, childs can overload
@@ -542,9 +675,11 @@ int AliHLTComponent::ReserveEventDoneData( unsigned long size )
   // see header file for function documentation
   int iResult=0;
 
-  
-  if (size>fEventDoneDataSize) {
-    AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+size ] );
+  unsigned long capacity=fEventDoneDataSize;
+  if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
+  if (size>capacity) {
+    unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
+    AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
     if (!newEDD)
       return -ENOMEM;
     newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
@@ -556,7 +691,7 @@ int AliHLTComponent::ReserveEventDoneData( unsigned long size )
       delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
     }
     fEventDoneData = newEDD;
-    fEventDoneDataSize = size;
+    fEventDoneDataSize = newSize;
   }
   return iResult;
 
@@ -590,7 +725,7 @@ int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTCom
     AliHLTComponentDataTypeList itypes;
     AliHLTComponentDataTypeList otypes;
     otypes.push_back(GetOutputDataType());
-    if (otypes[0]==kAliHLTMultipleDataType) {
+    if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
       otypes.clear();
       int count=0;
       if ((count=GetOutputDataTypes(otypes))>0) {
@@ -609,7 +744,7 @@ int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTCom
       }
       
       AliHLTComponentDataTypeList::iterator itype=itypes.begin();
-      for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++);
+      for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
       //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
       if (itype!=itypes.end()) {
        if (tgtList) tgtList->push_back(*otype);
@@ -893,7 +1028,17 @@ int AliHLTComponent::CleanupInputObjects()
     // (CreateInputObject), and written to a TFile afterwards, the
     // TFile::Close calls ROOOT's garbage collection. No clue why the
     // object ended up in the key list and needs to be deleted
-    if (pObj && gObjectTable->PtrIsValid(pObj)) delete pObj;
+    //
+    // Matthias 09.11.2008 follow up
+    // This approach doesn't actually work in all cases: the object table
+    // can be switched off globally, the flag needs to be checked here as
+    // well in order to avoid memory leaks.
+    // This means we have to find another solution for the problem if it
+    // pops up again.
+    if (pObj &&
+       (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
+      delete pObj;
+    }
   }
   delete array;
   return 0;
@@ -1069,6 +1214,7 @@ int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& d
   // see header file for function documentation
   ALIHLTCOMPONENT_BASE_STOPWATCH();
   int iResult=0;
+  fLastObjectSize=0;
   if (pObject) {
     AliHLTMessage msg(kMESS_OBJECT);
     msg.SetCompressionLevel(fCompressionLevel);
@@ -1098,6 +1244,7 @@ int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& d
       if (iResult>=0) {
        HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
       }
+      fLastObjectSize=iMsgLength;
     } else {
       HLTError("object serialization failed for object %p", pObject);
       iResult=-ENOMSG;
@@ -1166,7 +1313,7 @@ int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, con
       //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
     } else {
       if (fpOutputBuffer) {
-       HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iBlkSize);
+       HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
       } else {
        HLTError("output buffer not available");
       }
@@ -1375,7 +1522,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
                                   AliHLTComponentEventDoneData*& edd )
 {
   // see header file for function documentation
-  HLTLogKeyword(GetComponentID());
+  HLTLogKeyword(fChainId.c_str());
   ALIHLTCOMPONENT_BASE_STOPWATCH();
   int iResult=0;
   fCurrentEvent=evtData.fEventID;
@@ -1399,12 +1546,15 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
   AliHLTComponentStatistics outputStat;
   memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
+  outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
   outputStat.fId=fChainIdCrc;
-  compStats.push_back(outputStat);
   if (fpBenchmark) {
+    fpBenchmark->Stop();
+    outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
     fpBenchmark->Reset();
     fpBenchmark->Start();
   }
+  compStats.push_back(outputStat);
 #endif
 
   // data processing is skipped
@@ -1427,6 +1577,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
     int indexUpdtDCSEvent=-1;
     int indexSOREvent=-1;
     int indexEOREvent=-1;
+    int indexECSParamBlock=-1;
     for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
       if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
        indexSOREvent=i;
@@ -1477,6 +1628,8 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
        forwardedBlocks.push_back(fpInputBlocks[i]);
        parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
+      } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
+       indexECSParamBlock=i;
       } else {
        // the processing function is called if there is at least one
        // non-steering data block. Steering blocks are not filtered out
@@ -1510,6 +1663,26 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
       } else {
        iResult=-ENOMEM;
       }
+
+      if (indexECSParamBlock>=0) {
+       if (fpInputBlocks[indexECSParamBlock].fSize>0) {
+         const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
+         TString paramString;
+         if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
+           HLTWarning("ECS parameter string not terminated");
+           paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
+           paramString+="";
+         } else {
+           paramString=param;
+         }
+         ScanECSParam(paramString.Data());
+       } else {
+         HLTWarning("empty ECS parameter received");
+       }
+      } else {
+       // TODO: later on we might throw a warning here since the CTP trigger classes
+       // should be mandatory
+      }
     }
     if (indexEOREvent>=0) {
       bAddComponentTableEntry=true;
@@ -1641,6 +1814,8 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
     // no output blocks, set size to 0
     size=0;
   }
+
+  // reset the internal EventData struct
   FillEventData(fCurrentEventData);
   return iResult;
 }
@@ -1655,12 +1830,36 @@ int  AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& block
   int iResult=0;
 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
   if (stats.size()==0) return -ENOENT;
+  // check if there is space for at least one entry
+  if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
   stats[0].fTotalOutputSize=offset;
   stats[0].fOutputBlockCount=blocks.size();
   if (fpBenchmark) {
-    stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*1000000);
-    stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*1000000);
+    fpBenchmark->Stop();
+    stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
+    stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
+    fpBenchmark->Continue();
+  }
+  if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
+    AliHLTUInt32_t removedLevel=0;
+    do {
+      // remove all entries of the level of the last entry
+      removedLevel=stats.back().fLevel;
+      AliHLTComponentStatisticsList::iterator element=stats.begin();
+      element++;
+      while (element!=stats.end()) {
+       if (element->fLevel<=removedLevel) {
+         element=stats.erase(element);
+       } else {
+         element++;
+       }
+      }
+    } while (stats.size()>1 && 
+            (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
   }
+  assert(stats.size()>0);
+  if (stats.size()==0) return 0;
+
   if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
     AliHLTComponentBlockData bd;
     FillBlockData( bd );
@@ -2118,3 +2317,154 @@ int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, Al
 
   return 1;
 }
+
+int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity, 
+                                   const char* originClass, const char* originFunc,
+                                   const char* file, int line, ... ) const
+{
+  // see header file for function documentation
+  int iResult=0;
+
+  va_list args;
+  va_start(args, line);
+
+  // logging function needs to be const in order to be called from const member functions
+  // without problems. But at this point we face the problem with virtual members which
+  // are not necessarily const.
+  AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
+  AliHLTLogging::SetLogString("%s (%s, %p): ", 
+                             fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
+                             nonconst->GetComponentID(), this);
+  iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
+  va_end(args);
+
+  return iResult;
+}
+
+int AliHLTComponent::ScanECSParam(const char* ecsParam)
+{
+  // see header file for function documentation
+
+  // format of the parameter string from ECS
+  // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
+  // search for a subset of the parameterkeys
+  int iResult=0;
+  TString string=ecsParam;
+  TObjArray* parameter=string.Tokenize(";");
+  if (parameter) {
+    for (int i=0; i<parameter->GetEntries(); i++) {
+      TString entry=((TObjString*)parameter->At(i))->GetString();
+      HLTDebug("scanning ECS entry: %s", entry.Data());
+      TObjArray* entryParams=entry.Tokenize("=");
+      if (entryParams) {
+       if (entryParams->GetEntries()>1) {
+         if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
+           int result=InitCTPTriggerClasses((((TObjString*)entryParams->At(1))->GetString()).Data());
+           if (iResult>=0 && result<0) iResult=result;
+         } else {
+           // TODO: scan the other parameters
+           // e.g. consistency check of run number
+         }
+       }
+       delete entryParams;
+      }
+    }
+    delete parameter;
+  }
+
+  return iResult;
+}
+
+int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
+{
+  // see header file for function documentation
+  if (!ctpString) return -EINVAL;
+
+  if (fpTriggerClasses) {
+    fpTriggerClasses->Delete();
+  } else {
+    fpTriggerClasses=new TObjArray(gkNCTPTriggerClasses);
+  }
+  if (!fpTriggerClasses) return -ENOMEM;
+
+  // general format of the CTP_TRIGGER_CLASS parameter
+  // <bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,<bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,...
+  // the detector ids are ignored for the moment
+  HLTDebug(": %s", ctpString);
+  TString string=ctpString;
+  TObjArray* classEntries=string.Tokenize(",");
+  if (classEntries) {
+    for (int i=0; i<classEntries->GetEntries(); i++) {
+      TString entry=((TObjString*)classEntries->At(i))->GetString();
+      TObjArray* entryParams=entry.Tokenize(":");
+      if (entryParams) {
+       if (entryParams->GetEntries()==3 &&
+           (((TObjString*)entryParams->At(0))->GetString()).IsDigit()) {
+         int index=(((TObjString*)entryParams->At(0))->GetString()).Atoi();
+         if (index<gkNCTPTriggerClasses) {
+           fpTriggerClasses->AddAt(new TNamed("TriggerClass", (((TObjString*)entryParams->At(1))->GetString()).Data()), index);
+         } else {
+           // the trigger bitfield is fixed to 50 bits (gkNCTPTriggerClasses)
+           HLTError("invalid trigger class entry %s, index width of trigger bitfield", entry.Data());
+         }
+       } else {
+         HLTError("invalid trigger class entry %s", entry.Data());
+       }
+       delete entryParams;
+      }
+    }
+    delete classEntries;
+  }
+  return 0;
+}
+
+bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
+{
+  // see header file for function documentation
+  if (!fpTriggerClasses) {
+    HLTError("trigger classes not initialized");
+    return false;
+  }
+
+  if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
+    HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
+    return false;
+  }
+
+  // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
+  AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
+  AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6];
+  triggerMask<<=32;
+  triggerMask|=evtData->fCommonHeader[5];
+
+  // use a TFormula to interprete the expression
+  // all classname are replaced by '[n]' which means the n'th parameter in the formula
+  // the parameters are set to 0 or 1 depending on the bit in the trigger mask
+  //
+  // TODO: this will most likely fail for class names like 'base', 'baseA', 'baseB'
+  // the class names must be fully unique, none must be contained as substring in
+  // another class name. Probably not needed for the moment but needs to be extended.
+  vector<Double_t> par;
+  TString condition=expression;
+  for (int i=0; i<gkNCTPTriggerClasses; i++) {
+    if (fpTriggerClasses->At(i)) {
+      TString className=fpTriggerClasses->At(i)->GetTitle();
+      //HLTDebug("checking trigger class %s", className.Data());
+      if (condition.Contains(className)) {
+       TString replace; replace.Form("[%d]", par.size());
+       //HLTDebug("replacing %s with %s in \"%s\"", className.Data(), replace.Data(), condition.Data());
+       condition.ReplaceAll(className, replace);
+       if (triggerMask&((AliHLTUInt64_t)0x1<<i)) par.push_back(1.0);
+       else par.push_back(0.0);
+      }
+    }
+  }
+
+  TFormula form("trigger expression", condition);
+  if (form.Compile()!=0) {
+    HLTError("invalid expression %s", expression);
+    return false;
+  }
+  if (form.EvalPar(&par[0], &par[0])>0.5) return true;
+  return false;
+}