]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTComponent.cxx
Changes required to handle software triggers correctly in the global trigger component.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
index ce780374a656c9a5e09c22e68703a1518ceb72ae..46ab071bc24ccdcc8eace4f0f4d7e31964ef1c25 100644 (file)
 //* provided "as is" without express or implied warranty.                  *
 //**************************************************************************
 
-/** @file   AliHLTComponent.cxx
-    @author Matthias Richter, Timm Steinbeck
-    @date   
-    @brief  Base class implementation for HLT components. */
+//  @file   AliHLTComponent.cxx
+//  @author Matthias Richter, Timm Steinbeck
+//  @date   
+//  @brief  Base class implementation for HLT components. */
+//  @note   The class is both used in Online (PubSub) and Offline (AliRoot)
+//          context
+
 
 #if __GNUC__>= 3
 using namespace std;
@@ -30,15 +33,29 @@ using namespace std;
 #include "AliHLTComponent.h"
 #include "AliHLTComponentHandler.h"
 #include "AliHLTMessage.h"
+#include "AliHLTCTPData.h"
+#include "AliRawDataHeader.h"
 #include "TString.h"
 #include "TMath.h"
 #include "TObjArray.h"
 #include "TObjectTable.h"
 #include "TClass.h"
 #include "TStopwatch.h"
+#include "TFormula.h"
+#include "TUUID.h"
+#include "TMD5.h"
+#include "TRandom3.h"
 #include "AliHLTMemoryFile.h"
 #include "AliHLTMisc.h"
 #include <cassert>
+#include <ctime>
+#include <stdint.h>
+
+/**
+ * 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);
@@ -71,14 +88,20 @@ AliHLTComponent::AliHLTComponent()
   fpStopwatches(new TObjArray(kSWTypeCount)),
   fMemFiles(),
   fpRunDesc(NULL),
-  fpDDLList(NULL),
   fCDBSetRunNoFunc(false),
   fChainId(),
   fChainIdCrc(0),
   fpBenchmark(NULL),
-  fRequireSteeringBlocks(false),
+  fFlags(0),
   fEventType(gkAliEventTypeUnknown),
-  fComponentArgs()
+  fComponentArgs(),
+  fEventDoneData(NULL),
+  fEventDoneDataSize(0),
+  fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
+  , fLastObjectSize(0)
+  , fpCTPData(NULL)
+  , fPushbackPeriod(0)
+  , fLastPushBackTime(-1)
 {
   // see header file for class documentation
   // or
@@ -117,6 +140,14 @@ AliHLTComponent::~AliHLTComponent()
     delete fpRunDesc;
     fpRunDesc=NULL;
   }
+  if (fEventDoneData)
+    delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
+  fEventDoneData=NULL;
+
+  if (fpCTPData) {
+    delete fpCTPData;
+  }
+  fpCTPData=NULL;
 }
 
 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
@@ -138,10 +169,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));
@@ -149,6 +180,20 @@ 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);
+  }
+  fPushbackPeriod=0;
+  fLastPushBackTime=-1;
+
   fComponentArgs="";
   const char** pArguments=NULL;
   int iNofChildArgs=0;
@@ -164,12 +209,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()) {
@@ -180,6 +224,29 @@ int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environ
            HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
            iResult=-EINVAL;
          }
+         // -object-compression=
+       } else if (argument.BeginsWith("-object-compression=")) {
+         argument.ReplaceAll("-object-compression=", "");
+         if (argument.IsDigit()) {
+           fCompressionLevel=argument.Atoi();
+           if (fCompressionLevel<0 || fCompressionLevel>9) {
+             HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
+             fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
+           }
+         } else {
+           HLTError("wrong parameter for argument -object-compression, number expected");
+         }
+         // -pushback-period=
+       } else if (argument.BeginsWith("-pushback-period=")) {
+         argument.ReplaceAll("-pushback-period=", "");
+         if (argument.IsDigit()) {
+           fPushbackPeriod=argument.Atoi();
+         } else {
+           HLTError("wrong parameter for argument -pushback-period, number expected");
+         }
+         // -disable-component-stat
+       } else if (argument.CompareTo("-disable-component-stat")==0) {
+         fFlags|=kDisableComponentStat;
        } else {
          pArguments[iNofChildArgs++]=argv[i];
        }
@@ -192,6 +259,9 @@ int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environ
     HLTError("missing parameter for argument %s", argument.Data());
     iResult=-EINVAL;
   }
+  if (iResult>=0) {
+    iResult=CheckOCDBEntries();
+  }
   if (iResult>=0) {
     iResult=DoInit(iNofChildArgs, pArguments);
   }
@@ -202,25 +272,24 @@ int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environ
     // explicitly
     AliHLTComponentDataTypeList inputDt;
     GetInputDataTypes(inputDt);
+    bool bRequireSteeringBlocks=false;
     for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
-        dt!=inputDt.end() && !fRequireSteeringBlocks;
+        dt!=inputDt.end() && !bRequireSteeringBlocks;
         dt++) {
-      fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
-      fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
-      fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
-      fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
-      fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
+      bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
+      bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
+      bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
+      bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
+      bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
     }
+    if (bRequireSteeringBlocks) fFlags|=kRequireSteeringBlocks;
   }
   if (pArguments) delete [] pArguments;
 
-#if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
+#if defined(HLT_COMPONENT_STATISTICS)
   // benchmarking stopwatch for the component statistics
   fpBenchmark=new TStopwatch;
-  if (fpBenchmark) {
-    fpBenchmark->Start();
-  }
-#endif
+#endif // HLT_COMPONENT_STATISTICS
 
   return iResult;
 }
@@ -228,16 +297,28 @@ 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)
+    // 2009-09-08: now, the info is not cleared in the ProcessEvent, because it
+    // might be needed by components during the event processing.
+    //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
     AliHLTRunDesc* pRunDesc=fpRunDesc;
     fpRunDesc=NULL;
     delete pRunDesc;
   }
+  if (fpCTPData) {
+    delete fpCTPData;
+  }
+  fpCTPData=NULL;
+
   fEventCount=0;
+  fFlags=0;
   return iResult;
 }
 
@@ -245,11 +326,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) {
@@ -319,7 +403,7 @@ int AliHLTComponent::SetComponentDescription(const char* desc)
   TString descriptor=desc;
   TObjArray* pTokens=descriptor.Tokenize(" ");
   if (pTokens) {
-    for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
+    for (int i=0; i<pTokens->GetEntriesFast() && iResult>=0; i++) {
       TString argument=((TObjString*)pTokens->At(i++))->GetString();
       if (!argument || argument.IsNull()) continue;
 
@@ -337,11 +421,172 @@ int AliHLTComponent::SetComponentDescription(const char* desc)
        HLTWarning("unknown component description %s", argument.Data());
       }
     }
+    delete pTokens;
   }
   
   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.IsWhitespace()) continue;
+
+    // special handling for single component arguments ending with
+    // a sequence of blanks
+    argument.Remove(0, argument.First(' '));
+    if (argument.IsWhitespace()) {
+      array.push_back(argv[i]);
+      continue;
+    }
+
+    // extra blank to insert blank token before leading quotes
+    argument=" ";
+    argument+=argv[i];
+    // insert blank in consecutive quotes to correctly tokenize
+    argument.ReplaceAll("''", "' '");
+    // replace newlines by blanks
+    argument.ReplaceAll("\n", " ");
+    if (argument.IsNull()) continue;
+    TObjArray* pTokensQuote=argument.Tokenize("'");
+    if (pTokensQuote) {
+      if (pTokensQuote->GetEntriesFast()>0) {
+       for (int k=0; k<pTokensQuote->GetEntriesFast(); k++) {
+         argument=((TObjString*)pTokensQuote->At(k))->GetString();
+         if (argument.IsWhitespace()) continue;
+         if (k%2) {
+           // every second entry is enclosed by quotes and thus
+           // one single argument
+           array.push_back(argument.Data());
+         } else {
+    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;
+    }
+         }
+       }
+       pTokensQuote->SetOwner(kFALSE);
+      }
+      delete pTokensQuote;
+    }
+  }
+
+  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, const char* key)
+{
+  // load a list of OCDB objects and configure from the objects
+  // can either be a TObjString or a TMap with a TObjString:TObjString key-value pair
+  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\"%s%s, chain id %s", path, key?" key ":"",key?key:"", (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+      TObject* pOCDBObject = LoadAndExtractOCDBObject(path, key);
+      if (pOCDBObject) {
+       TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
+       if (!pString) {
+         TMap* pMap=dynamic_cast<TMap*>(pOCDBObject);
+         if (pMap) {
+           // this is the case where no key has been specified and the OCDB
+           // object is a TMap, search for the default key
+           TObject* pObject=pMap->GetValue("default");
+           if (pObject && (pString=dynamic_cast<TObjString*>(pObject))!=NULL) {
+             HLTInfo("using default key of TMap of configuration object \"%s\"", path);
+           } else {
+             HLTError("no default key available in TMap of configuration object \"%s\"", path);
+             iResult=-ENOENT;
+             break;
+           }
+         }
+       }
+
+       if (pString) {
+         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
+         arguments+=pString->GetString().Data();
+         arguments+=" ";
+       } else {
+         HLTError("configuration object \"%s\"%s%s has wrong type, required TObjString", path, key?" key ":"",key?key:"");
+         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, const char* key)
+{
+  // see header file for function documentation
+  AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
+  if (!pEntry) return NULL;
+  TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
+  TMap* pMap=dynamic_cast<TMap*>(pObject);
+  if (pMap && key) {
+    pObject=pMap->GetValue(key);
+    if (!pObject) {
+      pObject=pMap->GetValue("default");
+      if (pObject) {
+       HLTWarning("can not find object for key \"%s\" in TMap of configuration object \"%s\", using key \"default\"", key, path);
+      }
+    }
+    if (!pObject) {
+      HLTError("can not find object for key \"%s\" in TMap of configuration object \"%s\"", key, path);
+      return NULL;
+    }
+  }
+  return pObject;
+}
+
 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
 {
   // default implementation, childs can overload
@@ -370,6 +615,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
@@ -392,6 +645,36 @@ int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/
   return 0;
 }
 
+void AliHLTComponent::GetOCDBObjectDescription( TMap* const /*targetArray*/)
+{
+  // default implementation, childs can overload
+  HLTLogKeyword("dummy");
+}
+
+int AliHLTComponent::CheckOCDBEntries(const TMap* const externList)
+{
+  // check the availability of the OCDB entry descriptions in the TMap
+  //  key : complete OCDB path of the entry
+  //  value : auxiliary object - short description
+  // if the external map was not provided the function invokes
+  // interface function GetOCDBObjectDescription() to retrieve the list.
+  int iResult=0;
+  if (externList) {
+    iResult=AliHLTMisc::Instance().CheckOCDBEntries(externList);
+  } else {
+    TMap* pMap=new TMap;
+    if (pMap) {
+      pMap->SetOwnerKeyValue(kTRUE);
+      GetOCDBObjectDescription(pMap);
+      iResult=AliHLTMisc::Instance().CheckOCDBEntries(pMap);
+      delete pMap;
+      pMap=NULL;
+    }
+  }
+
+  return iResult;
+}
+
 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
 {
   // see header file for function documentation
@@ -406,6 +689,39 @@ string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int
   // see header file for function documentation
   string out("");
 
+  // 'typeid' 'origin'
+  // aligned to 8 and 4 chars respectively, blocks enclosed in quotes and
+  // separated by blank e.g.
+  // 'DDL_RAW ' 'TPC '
+  if (mode==3) {
+    int i=0;
+    char tmp[8];
+    out+="'";
+    for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
+      unsigned char* puc=(unsigned char*)type.fID;
+      if (puc[i]<32)
+       sprintf(tmp, "\\%x", type.fID[i]);
+      else
+       sprintf(tmp, "%c", type.fID[i]);
+      out+=tmp;
+    }
+    out+="' '";
+    for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
+      unsigned char* puc=(unsigned char*)type.fOrigin;
+      if ((puc[i])<32)
+       sprintf(tmp, "\\%x", type.fOrigin[i]);
+      else
+       sprintf(tmp, "%c", type.fOrigin[i]);
+      out+=tmp;
+    }
+    out+="'";
+    return out;
+  }
+
+  // origin typeid as numbers separated by colon e.g.
+  // aligned to 8 and 4 chars respectively, all characters separated by
+  // quotes, e.g.
+  // '84'80'67'32':'68'68'76'95'82'65'87'32'
   if (mode==2) {
     int i=0;
     char tmp[8];
@@ -421,6 +737,10 @@ string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int
     return out;
   }
 
+  // origin typeid separated by colon e.g.
+  // aligned to 8 and 4 chars respectively, all characters separated by
+  // quotes, e.g.
+  // 'T'P'C' ':'D'D'L'_'R'A'W' '
   if (mode==1) {
     int i=0;
     char tmp[8];
@@ -444,6 +764,9 @@ string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int
     return out;
   }
 
+  // origin typeid
+  // aligned to 8 and 4 chars respectively, separated by colon e.g.
+  // TPC :DDL_RAW 
   if (type==kAliHLTVoidDataType) {
     out="VOID:VOID";
   } else {
@@ -506,7 +829,7 @@ int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList
 
 }
 
-int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) 
+int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) const
 {
   // see header file for function documentation
   if (fEnvironment.fGetEventDoneDataFunc)
@@ -514,6 +837,55 @@ int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventD
   return -ENOSYS;
 }
 
+int AliHLTComponent::ReserveEventDoneData( unsigned long size )
+{
+  // see header file for function documentation
+  int iResult=0;
+
+  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);
+    newEDD->fDataSize = 0;
+    newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
+    if (fEventDoneData) {
+      memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
+      newEDD->fDataSize = fEventDoneData->fDataSize;
+      delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
+    }
+    fEventDoneData = newEDD;
+    fEventDoneDataSize = newSize;
+  }
+  return iResult;
+
+}
+
+int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
+{
+  // see header file for function documentation
+  if (!fEventDoneData)
+    return -ENOMEM;
+  if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
+    return -ENOSPC;
+  *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
+  fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
+  return 0;
+}
+
+void AliHLTComponent::ReleaseEventDoneData()
+{
+   // see header file for function documentation
+ if (fEventDoneData)
+    delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
+  fEventDoneData = NULL;
+  fEventDoneDataSize = 0;
+}
+
+
 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList) 
 {
   // see header file for function documentation
@@ -522,7 +894,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) {
@@ -530,7 +902,7 @@ int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTCom
        HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
       }
     }
-    ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes);
+    pConsumer->GetInputDataTypes(itypes);
     AliHLTComponentDataTypeList::iterator otype=otypes.begin();
     for (;otype!=otypes.end();otype++) {
       //PrintDataTypeContent((*otype), "publisher \'%s\'");
@@ -541,7 +913,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);
@@ -681,6 +1053,15 @@ int AliHLTComponent::GetNumberOfInputBlocks() const
   return 0;
 }
 
+AliHLTEventID_t AliHLTComponent::GetEventId() const
+{
+  // see header file for function documentation
+  if (fpInputBlocks!=NULL) {
+    return fCurrentEventData.fEventID;
+  }
+  return 0;
+}
+
 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
                                                    const char* classname,
                                                    int bForce)
@@ -810,13 +1191,23 @@ int AliHLTComponent::CleanupInputObjects()
   if (!fpInputObjects) return 0;
   TObjArray* array=fpInputObjects;
   fpInputObjects=NULL;
-  for (int i=0; i<array->GetEntries(); i++) {
+  for (int i=0; i<array->GetEntriesFast(); i++) {
     TObject* pObj=array->At(i);
     // grrr, garbage collection strikes back: When read via AliHLTMessage
     // (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;
@@ -890,7 +1281,7 @@ int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
   int iResult=0;
   int idx=fCurrentInputBlock;
   if (pBlock) {
-    if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
+    if ((idx=FindInputBlock(pBlock))>=0) {
     } else {
       HLTError("unknown Block %p", pBlock);
       iResult=-ENOENT;      
@@ -992,17 +1383,42 @@ int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& d
   // see header file for function documentation
   ALIHLTCOMPONENT_BASE_STOPWATCH();
   int iResult=0;
+  fLastObjectSize=0;
+  if (fPushbackPeriod>0) {
+    // suppress the output
+    TDatime time;
+    if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
+  }
   if (pObject) {
     AliHLTMessage msg(kMESS_OBJECT);
+    msg.SetCompressionLevel(fCompressionLevel);
     msg.WriteObject(pObject);
     Int_t iMsgLength=msg.Length();
     if (iMsgLength>0) {
+      // Matthias Sep 2008
+      // NOTE: AliHLTMessage does implement it's own SetLength method
+      // which is not architecture independent. The original SetLength
+      // stores the size always in network byte order.
+      // I'm trying to remember the rational for that, might be that
+      // it was just some lack of knowledge. Want to change this, but
+      // has to be done carefullt to be backward compatible.
       msg.SetLength(); // sets the length to the first (reserved) word
-      assert(msg.Buffer()!=NULL);
-      iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec, pHeader, headerSize);
+
+      // does nothing if the level is 0
+      msg.Compress();
+
+      char *mbuf = msg.Buffer();
+      if (msg.CompBuffer()) {
+       msg.SetLength(); // set once more to have to byte order
+       mbuf = msg.CompBuffer();
+       iMsgLength = msg.CompLength();
+      }
+      assert(mbuf!=NULL);
+      iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
       if (iResult>=0) {
-       HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength);
+       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;
@@ -1028,6 +1444,12 @@ int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTCompon
 {
   // see header file for function documentation
   ALIHLTCOMPONENT_BASE_STOPWATCH();
+  if (fPushbackPeriod>0) {
+    // suppress the output
+    TDatime time;
+    if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
+  }
+
   return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
 }
 
@@ -1071,7 +1493,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");
       }
@@ -1095,10 +1517,11 @@ int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, con
 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
 {
   // see header file for function documentation
-  if (!pObject) return -EINVAL;
-    AliHLTMessage msg(kMESS_OBJECT);
-    msg.WriteObject(pObject);
-    return msg.Length();  
+  if (!pObject) return 0;
+
+  AliHLTMessage msg(kMESS_OBJECT);
+  msg.WriteObject(pObject);
+  return msg.Length();  
 }
 
 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
@@ -1234,12 +1657,39 @@ int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
   return iResult;
 }
 
-int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData /*edd*/)
+int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
 {
   // see header file for function documentation
-  int iResult=-ENOSYS;
-  //#warning  function not yet implemented
-  HLTWarning("function not yet implemented");
+  int iResult=0;
+
+  AliHLTComponentEventDoneData* newEDD = NULL;
+  
+  unsigned long newSize=edd.fDataSize;
+  if (fEventDoneData)
+    newSize += fEventDoneData->fDataSize;
+
+  if (newSize>fEventDoneDataSize) {
+    newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
+    if (!newEDD)
+      return -ENOMEM;
+    newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
+    newEDD->fDataSize = newSize;
+    newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
+    unsigned long long offset = 0;
+    if (fEventDoneData) {
+      memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
+      offset += fEventDoneData->fDataSize;
+    }
+    memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
+    if (fEventDoneData)
+      delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
+    fEventDoneData = newEDD;
+    fEventDoneDataSize = newSize;
+  }
+  else {
+    memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
+    fEventDoneData->fDataSize += edd.fDataSize;
+  }
   return iResult;
 }
 
@@ -1253,7 +1703,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;
@@ -1274,16 +1724,21 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
   AliHLTComponentStatisticsList compStats;
   bool bAddComponentTableEntry=false;
   vector<AliHLTUInt32_t> parentComponentTables;
-#if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
-  AliHLTComponentStatistics outputStat;
-  memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
-  outputStat.fId=fChainIdCrc;
-  compStats.push_back(outputStat);
-  if (fpBenchmark) {
-    fpBenchmark->Reset();
-    fpBenchmark->Start();
+#if defined(HLT_COMPONENT_STATISTICS)
+  if ((fFlags&kDisableComponentStat)==0) {
+    AliHLTComponentStatistics outputStat;
+    memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
+    outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
+    outputStat.fId=fChainIdCrc;
+    if (fpBenchmark) {
+      fpBenchmark->Stop();
+      outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
+      fpBenchmark->Reset();
+      fpBenchmark->Start();
+    }
+    compStats.push_back(outputStat);
   }
-#endif
+#endif // HLT_COMPONENT_STATISTICS
 
   // data processing is skipped
   // -  if there are only steering events in the block list.
@@ -1305,6 +1760,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;
@@ -1329,6 +1785,18 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
        indexUpdtDCSEvent=i;
       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
        fEventType=fpInputBlocks[i].fSpecification;
+       if (fEventType != gkAliEventTypeConfiguration and
+           fEventType != gkAliEventTypeReadPreprocessor
+          )
+       {
+         // We can actually get the event type from the CDH if it is valid.
+         // Otherwise just use the specification of the input block.
+         const AliRawDataHeader* cdh;
+         if (ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) == 0)
+         {
+           fEventType = ExtractEventTypeFromCDH(cdh);
+         }
+       }
 
        // skip always in case of gkAliEventTypeConfiguration
        if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
@@ -1355,6 +1823,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
@@ -1388,8 +1858,29 @@ 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) {
+      fLastPushBackTime=0; // always send at EOR
       bAddComponentTableEntry=true;
       if (fpRunDesc!=NULL) {
        if (fpRunDesc) {
@@ -1401,9 +1892,10 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
              HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
            }
          }
-         AliHLTRunDesc* pRunDesc=fpRunDesc;
-         fpRunDesc=NULL;
-         delete pRunDesc;
+         // we do not unload the fpRunDesc struct here in order to have the run information
+         // available during the event processing
+         // https://savannah.cern.ch/bugs/?39711
+         // the info will be cleared in DeInit
        }
       } else {
        HLTWarning("did not receive SOR, ignoring EOR");
@@ -1439,7 +1931,14 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
 
   // data processing is not skipped if the component explicitly asks
   // for the private blocks
-  if (fRequireSteeringBlocks) bSkipDataProcessing=0;
+  if ((fFlags&kRequireSteeringBlocks)!=0) bSkipDataProcessing=0;
+
+  if (fpCTPData) {
+    // set the active triggers for this event
+    fpCTPData->SetTriggers(trigData);
+    // increment CTP trigger counters if available
+    if (IsDataEvent()) fpCTPData->Increment(trigData);
+  }
 
   AliHLTComponentBlockDataList blockData;
   if (iResult>=0 && !bSkipDataProcessing)
@@ -1519,6 +2018,22 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
     // no output blocks, set size to 0
     size=0;
   }
+
+  // reset the internal EventData struct
+  FillEventData(fCurrentEventData);
+
+  // reset the active triggers
+  if (fpCTPData) fpCTPData->SetTriggers(0);
+
+  // set the time for the pushback period
+  if (fPushbackPeriod>0) {
+    // suppress the output
+    TDatime time;
+    if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime>=fPushbackPeriod) {
+      fLastPushBackTime=time.Get();
+    }
+  }
+
   return iResult;
 }
 
@@ -1530,14 +2045,39 @@ int  AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& block
 {
   // see header file for function documentation
   int iResult=0;
-#if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
+  if ((fFlags&kDisableComponentStat)!=0) return 0;
+#if 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 );
@@ -1572,7 +2112,7 @@ int  AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& block
   if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
     // get rid of warning
   }
-#endif
+#endif // HLT_COMPONENT_STATISTICS
   return iResult;
 }
 
@@ -1584,7 +2124,8 @@ int  AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& block
 {
   // see header file for function documentation
   int iResult=0;
-#if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
+  if ((fFlags&kDisableComponentStat)!=0) return 0;
+#if defined(HLT_COMPONENT_STATISTICS)
   // the payload consists of the AliHLTComponentTableEntry struct,
   // followed by a an array of 32bit crc chain ids and the component
   // description string
@@ -1644,7 +2185,7 @@ int  AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& block
   if (blocks.size() && buffer && bufferSize && offset && parents.size()) {
     // get rid of warning
   }
- #endif
+#endif // HLT_COMPONENT_STATISTICS
   return iResult;
 }
 
@@ -1712,14 +2253,14 @@ AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
   fgpCurrent=fpPrec;
 }
 
-int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
+int AliHLTComponent::AliHLTStopwatchGuard::Hold(const TStopwatch* pSucc)
 {
   // see header file for function documentation
   if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
   return fpStopwatch!=pSucc?1:0;
 }
 
-int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
+int AliHLTComponent::AliHLTStopwatchGuard::Resume(const TStopwatch* pSucc)
 {
   // see header file for function documentation
   if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
@@ -1753,7 +2294,7 @@ int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
   if (pStopwatches==NULL) return -EINVAL;
 
   int iResult=0;
-  for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
+  for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntriesFast(); i++)
     SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
   return iResult;
 }
@@ -1761,7 +2302,18 @@ int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
 {
   // see header file for function documentation
-  if (fpRunDesc==NULL) return kAliHLTVoidRunNo;
+
+  // 2010-02-11 OCDB is now the reliable source for the run number, it is
+  // initialized either by aliroot or the external interface depending
+  // on the environment. It turned out that the rundescriptor is not set
+  // in the aliroot mode, resulting in an invalid run number. However this
+  // did not cause problems until now. OCDB initialization has been revised
+  // already in 10/2009. This was a remnant.
+  // Have to check whether we get rid of the rundescriptor at some point.
+  if (fpRunDesc==NULL) return AliHLTMisc::Instance().GetCDBRunNo();
+  if (fpRunDesc->fRunNo!=(unsigned)AliHLTMisc::Instance().GetCDBRunNo()) {
+    HLTWarning("run number mismatch: ocdb %d   run descriptor %d", AliHLTMisc::Instance().GetCDBRunNo(), fpRunDesc->fRunNo);
+  }
   return fpRunDesc->fRunNo;
 }
 
@@ -1772,13 +2324,40 @@ AliHLTUInt32_t AliHLTComponent::GetRunType() const
   return fpRunDesc->fRunType;
 }
 
-bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt)
+AliHLTUInt32_t    AliHLTComponent::GetTimeStamp() const
+{
+  // see header file for function documentation
+  if (fCurrentEventData.fEventCreation_s) {
+    return  fCurrentEventData.fEventCreation_s;
+  }
+  // using the actual UTC if the time stamp was not set by the framework
+  return static_cast<AliHLTUInt32_t>(time(NULL));
+}
+
+AliHLTUInt32_t    AliHLTComponent::GetPeriodNumber() const
+{
+  // see header file for function documentation
+  return (GetEventId()>>36)&0xfffffff;
+}
+
+AliHLTUInt32_t    AliHLTComponent::GetOrbitNumber() const
+{
+  // see header file for function documentation
+  return (GetEventId()>>12)&0xffffff;
+}
+
+AliHLTUInt16_t    AliHLTComponent::GetBunchCrossNumber() const
+{
+  // see header file for function documentation
+  return GetEventId()&0xfff;
+}
+
+bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt) const
 {
   // see header file for function documentation
   if (pTgt) *pTgt=fEventType;
   return (fEventType==gkAliEventTypeData ||
-         fEventType==gkAliEventTypeDataReplay ||
-         fEventType==gkAliEventTypeCalibration);
+         fEventType==gkAliEventTypeDataReplay);
 }
 
 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
@@ -1819,73 +2398,6 @@ int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigne
   return iResult;
 }
 
-void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const
-{
-  // see header file for function documentation
-  
-  // -- Detector offset
-  Int_t ddlIdBase =  TMath::FloorNint( (Double_t) ddlId / 256.0 );
-  
-  // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 ) 
-  Int_t wordBase = 0;
-
-  if ( ddlIdBase <= 3 )
-    wordBase = ddlIdBase;
-  else if ( ddlIdBase > 3 && ddlIdBase < 5 )
-    wordBase = ddlIdBase + 7;
-  else 
-    wordBase = ddlIdBase + 9;
-
-  // -- Bit index in Word
-  Int_t bitIdx = ddlId % 32;
-
-  // -- Index of word
-  Int_t wordIdx = wordBase;
-
-  // -- if TPC (3) or TOD (5) add word idx
-  if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) {
-    wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 );
-  }
-
-  // -- Set -- 'OR' word with bit mask;
-  if ( state )
-    list.fList[wordIdx] |= ( 0x00000001 << bitIdx );
-  // -- Unset -- 'AND' word with bit mask;
-  else
-    list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) );
-}
-
-Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const
-{
-  // see header file for function documentation
-
-  Int_t iResult = -1;
-
-  for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) {
-
-    if ( list.fList[wordNdx] != 0 && iResult == -1 ) {
-      // check for special cases TPC and TOF
-      if ( wordNdx > 3 && wordNdx <= 10 ) {
-       wordNdx = 10;
-       iResult = 3;
-      }
-      else if ( wordNdx > 12 && wordNdx <= 14 ) {
-       wordNdx = 14;
-       iResult = 12;
-      }
-      else
-       iResult = wordNdx;
-    }
-    else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) {
-      HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx );
-      iResult = -1;
-      break;
-    }
-  }
-
-  return iResult;
-}
-
 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
 {
   // see header file for function documentation
@@ -1967,20 +2479,20 @@ int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, Al
   TObjArray* pTokens=descriptor.Tokenize("{");
   if (pTokens) {
     int n=0;
-    if (pTokens->GetEntries()>n) {
+    if (pTokens->GetEntriesFast()>n) {
       retChainId=((TObjString*)pTokens->At(n++))->GetString();
     }
-    if (pTokens->GetEntries()>n) {
+    if (pTokens->GetEntriesFast()>n) {
       compId=((TObjString*)pTokens->At(n++))->GetString();
     }
     delete pTokens;
   }
   if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
     int n=0;
-    if (pTokens->GetEntries()>n) {
+    if (pTokens->GetEntriesFast()>n) {
       compId=((TObjString*)pTokens->At(n++))->GetString();
     }
-    if (pTokens->GetEntries()>n) {
+    if (pTokens->GetEntriesFast()>n) {
       compArgs=((TObjString*)pTokens->At(n++))->GetString();
     }
     delete pTokens;
@@ -1995,3 +2507,295 @@ int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, Al
 
   return 1;
 }
+
+int AliHLTComponent::ExtractTriggerData(
+    const AliHLTComponentTriggerData& trigData,
+    const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
+    AliHLTUInt64_t* status,
+    const AliRawDataHeader** cdh,
+    AliHLTReadoutList* readoutlist,
+    bool printErrors
+  )
+{
+  // see header file for function documentation
+  
+  // Check that the trigger data structure is the correct size.
+  if (trigData.fStructSize != sizeof(AliHLTComponentTriggerData))
+  {
+    if (printErrors)
+    {
+      AliHLTLogging log;
+      log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
+          "Invalid trigger structure size: %d but expected %d.", trigData.fStructSize, sizeof(AliHLTComponentTriggerData)
+        );
+    }
+    return -ENOENT;
+  }
+  
+  // Get the size of the AliHLTEventTriggerData structure without the readout list part.
+  // The way we do this here should also handle memory alignment correctly.
+  AliHLTEventTriggerData* dummy = NULL;
+  size_t sizeWithoutReadout = (char*)(&dummy->fReadoutList) - (char*)(dummy);
+  
+  // Check that the trigger data pointer points to data of a size we can handle.
+  // Either it is the size of AliHLTEventTriggerData or the size of the old
+  // version of AliHLTEventTriggerData using AliHLTEventDDLV0.
+  if (trigData.fDataSize != sizeof(AliHLTEventTriggerData) and
+      trigData.fDataSize != sizeWithoutReadout + sizeof(AliHLTEventDDLV0)
+     )
+  {
+    if (printErrors)
+    {
+      AliHLTLogging log;
+      log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
+          "Invalid trigger data size: %d but expected %d.", trigData.fDataSize, sizeof(AliHLTEventTriggerData)
+        );
+    }
+    return -EBADF;
+  }
+  
+  AliHLTEventTriggerData* evtData = reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
+  assert(evtData != NULL);
+  
+  // Check that the CDH has 8 words.
+  if (cdh != NULL and evtData->fCommonHeaderWordCnt != 8)
+  {
+    if (printErrors)
+    {
+      AliHLTLogging log;
+      log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
+          "Common Data Header (CDH) has wrong number of data words: %d but expected %d",
+          evtData->fCommonHeaderWordCnt, sizeof(AliRawDataHeader)/sizeof(AliHLTUInt32_t)
+        );
+    }
+    return -EBADMSG;
+  }
+  
+  // Check that the readout list has the correct count of words. i.e. something we can handle,
+  if (readoutlist != NULL and
+      evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV0 and
+      evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV1
+     )
+  {
+    if (printErrors)
+    {
+      AliHLTLogging log;
+      log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
+          "Readout list structure has wrong number of data words: %d but expected %d",
+          evtData->fReadoutList.fCount, gkAliHLTDDLListSize
+        );
+    }
+    return -EPROTO;
+  }
+  
+  if (attributes != NULL)
+  {
+    *attributes = &evtData->fAttributes;
+  }
+  if (status != NULL)
+  {
+    *status = evtData->fHLTStatus;
+  }
+  if (cdh != NULL)
+  {
+    const AliRawDataHeader* cdhptr = reinterpret_cast<const AliRawDataHeader*>(&evtData->fCommonHeader);
+    *cdh = cdhptr;
+  }
+  if (readoutlist != NULL)
+  {
+    *readoutlist = AliHLTReadoutList(evtData->fReadoutList);
+  }
+  return 0;
+}
+
+AliHLTUInt32_t AliHLTComponent::ExtractEventTypeFromCDH(const AliRawDataHeader* cdh)
+{
+  // see header file for function documentation
+  
+  UChar_t l1msg = cdh->GetL1TriggerMessage();
+  if ((l1msg & 0x1) == 0x0) return gkAliEventTypeData;
+  // The L2SwC bit must be one if we got here, i.e. l1msg & 0x1 == 0x1.
+  if (((l1msg >> 2) & 0xF) == 0xE) return gkAliEventTypeStartOfRun;
+  if (((l1msg >> 2) & 0xF) == 0xF) return gkAliEventTypeEndOfRun;
+  // Check the C1T bit to see if this is a calibration event,
+  // if not then it must be some other software trigger event.
+  if (((l1msg >> 6) & 0x1) == 0x1) return gkAliEventTypeCalibration;
+  return gkAliEventTypeSoftware;
+}
+
+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(this, ", %p", "%s (%s_pfmt_): ", 
+                             fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
+                             nonconst->GetComponentID());
+  iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
+  va_end(args);
+
+  return iResult;
+}
+
+TUUID AliHLTComponent::GenerateGUID()
+{
+  // Generates a globally unique identifier.
+
+  // Start by creating a new UUID. We cannot use the one automatically generated
+  // by ROOT because the algorithm used will not guarantee unique IDs when generating
+  // these UUIDs at a high rate in parallel.
+  TUUID uuid;
+  // We then use the generated UUID to form part of the random number seeds which
+  // will be used to generate a proper random UUID. For good measure we use a MD5
+  // hash also. Note that we want to use the TUUID class because it will combine the
+  // host address information into the UUID. Using gSystem->GetHostByName() apparently
+  // can cause problems on Windows machines with a firewall, because it always tries
+  // to contact a DNS. The TUUID class handles this case appropriately.
+  union
+  {
+    UChar_t buf[16];
+    UShort_t word[8];
+    UInt_t dword[4];
+  };
+  uuid.GetUUID(buf);
+  TMD5 md5;
+  md5.Update(buf, sizeof(buf));
+  TMD5 md52 = md5;
+  md5.Final(buf);
+  dword[0] += gSystem->GetUid();
+  dword[1] += gSystem->GetGid();
+  dword[2] += gSystem->GetPid();
+  for (int i = 0; i < 4; ++i)
+  {
+    gRandom->SetSeed(dword[i]);
+    dword[i] = gRandom->Integer(0xFFFFFFFF);
+  }
+  md52.Update(buf, sizeof(buf));
+  md52.Final(buf);
+  // To keep to the standard we need to set the version and reserved bits.
+  word[3] = (word[3] & 0x0FFF) | 0x4000;
+  buf[8] = (buf[8] & 0x3F) | 0x80;
+
+  // Create the name of the new class and file.
+  char uuidstr[64];
+  sprintf(uuidstr, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+    dword[0], word[2], word[3], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]
+  );
+
+  uuid.SetUUID(uuidstr);
+  return uuid;
+}
+
+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
+  //   RUN_TYPE=
+  //   RUN_NUMBER=
+  //   HLT_IN_DDL_LIST=
+  //   CTP_TRIGGER_CLASS=
+  //   DATA_FORMAT_VERSION=
+  //   BEAM_TYPE=
+  //   HLT_OUT_DDL_LIST=
+  //   HLT_TRIGGER_CODE=
+  //   DETECTOR_LIST=
+  //   HLT_MODE=
+  // The command apears not to be sent by the online framework
+  int iResult=0;
+  TString string=ecsParam;
+  TObjArray* parameter=string.Tokenize(";");
+  if (parameter) {
+    for (int i=0; i<parameter->GetEntriesFast(); i++) {
+      TString entry=((TObjString*)parameter->At(i))->GetString();
+      HLTDebug("scanning ECS entry: %s", entry.Data());
+      TObjArray* entryParams=entry.Tokenize("=");
+      if (entryParams) {
+       if (entryParams->GetEntriesFast()>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::SetupCTPData()
+{
+  // see header file for function documentation
+  if (fpCTPData) delete fpCTPData;
+  fpCTPData=new AliHLTCTPData;
+  if (!fpCTPData) return -ENOMEM;
+  return 0;
+}
+
+int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
+{
+  // see header file for function documentation
+  if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
+  return fpCTPData->InitCTPTriggerClasses(ctpString);
+}
+
+bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
+{
+  // see header file for function documentation
+  if (!fpCTPData) {
+    static bool bWarningThrown=false;
+    if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
+    bWarningThrown=true;
+    return false;
+  }
+
+  return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);
+}
+
+int AliHLTComponent::CheckCTPTrigger(const char* name) const
+{
+  // see header file for function documentation
+  if (!fpCTPData) {
+    static bool bWarningThrown=false;
+    if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
+    bWarningThrown=true;
+    return false;
+  }
+
+  return fpCTPData->CheckTrigger(name);
+}
+
+Double_t AliHLTComponent::GetBz()
+{
+  // Returns Bz.
+  return AliHLTMisc::Instance().GetBz();
+}
+
+Double_t AliHLTComponent::GetBz(const Double_t *r)
+{
+  // Returns Bz (kG) at the point "r" .
+  return AliHLTMisc::Instance().GetBz(r);
+}
+
+void AliHLTComponent::GetBxByBz(const Double_t r[3], Double_t b[3])
+{
+  // Returns Bx, By and Bz (kG) at the point "r" .
+  AliHLTMisc::Instance().GetBxByBz(r, b);
+}