]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTComponent.cxx
ALIROOT-5600 - skip non-participating detector modules
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
index 6c5f40933f2ec54c5ac73580ae923783fc012459..3617a3e0d6fead46e00199fe4d08181cbb0d96c7 100644 (file)
 //          context
 
 
-#if __GNUC__>= 3
-using namespace std;
-#endif
-
 //#include "AliHLTStdIncludes.h"
 #include "AliHLTComponent.h"
 #include "AliHLTComponentHandler.h"
 #include "AliHLTMessage.h"
 #include "AliHLTCTPData.h"
-#include "AliRawDataHeader.h"
+#include "AliHLTErrorGuard.h"
+#include "AliHLTCDHWrapper.h"
 #include "TString.h"
 #include "TMath.h"
 #include "TObjArray.h"
@@ -88,7 +85,7 @@ AliHLTComponent::AliHLTComponent()
   fpStopwatches(new TObjArray(kSWTypeCount)),
   fMemFiles(),
   fpRunDesc(NULL),
-  fCDBSetRunNoFunc(false),
+  fCDBSetRunNoFunc(NULL),
   fChainId(),
   fChainIdCrc(0),
   fpBenchmark(NULL),
@@ -101,7 +98,8 @@ AliHLTComponent::AliHLTComponent()
   , fLastObjectSize(0)
   , fpCTPData(NULL)
   , fPushbackPeriod(0)
-  , fLastPushBackTime(-1)
+  , fLastPushBackTime(-1),
+  fEventModulo(-1)
 {
   // see header file for class documentation
   // or
@@ -244,6 +242,19 @@ int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environ
          } else {
            HLTError("wrong parameter for argument -pushback-period, number expected");
          }
+         // -event-modulo
+       } else if (argument.BeginsWith("-event-modulo=")) {
+         argument.ReplaceAll("-event-modulo=", "");
+         if (argument.IsDigit()) {
+           fEventModulo=argument.Atoi();
+           if (fEventModulo < 1)
+           {
+             fEventModulo = -1;
+             HLTError("number passed in -event-modulo must be a positive integer greater or equal to 1.");
+           }
+         } else {
+           HLTError("wrong parameter for argument -event-modulo, integer number expected");
+         }
          // -disable-component-stat
        } else if (argument.CompareTo("-disable-component-stat")==0) {
          fFlags|=kDisableComponentStat;
@@ -404,7 +415,7 @@ int AliHLTComponent::SetComponentDescription(const char* desc)
   TObjArray* pTokens=descriptor.Tokenize(" ");
   if (pTokens) {
     for (int i=0; i<pTokens->GetEntriesFast() && iResult>=0; i++) {
-      TString argument=((TObjString*)pTokens->At(i++))->GetString();
+      TString argument=pTokens->At(i++)->GetName();
       if (!argument || argument.IsNull()) continue;
 
       // chainid
@@ -429,10 +440,23 @@ int AliHLTComponent::SetComponentDescription(const char* desc)
 
 int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
 {
-  // see header file for function documentation
+  // Configure from an array of argument strings
+  // Function supports individual arguments in the argv array and arguments
+  // separated by blanks.
+  //
+  // Each argv entry can contain blanks, quotes and newlines. Newlines are interpreted
+  // as blanks. Enclosing quotes deactivate blank as delimiter.
+  // The separated arguments are stored in an array of strings, and the pointers to
+  // those strings in an array of pointers. The latter is used in the custom argument
+  // scan of the component.
+
   int iResult=0;
-  vector<const char*> array;
-  TObjArray choppedArguments;
+  vector<string> stringarray;   // array of argument copies
+  // array of pointers to the argument copies
+  // note: not necessarily in sync with the entries in stringarray
+  // can contain any pointer to valid arguments in arbitrary sequence
+  vector<const char*> ptrarray;
+
   TString argument="";
   int i=0;
   for (i=0; i<argc && iResult>=0; i++) {
@@ -440,14 +464,18 @@ int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
     if (argument.IsWhitespace()) continue;
 
     // special handling for single component arguments ending with
-    // a sequence of blanks
+    // a sequence of blanks. All characters until the first occurence
+    // of a blank are removed. If the remainder contains only whitespaces
+    // the argument is a single argument, just having whitespaces at the end.
     argument.Remove(0, argument.First(' '));
     if (argument.IsWhitespace()) {
-      array.push_back(argv[i]);
+      stringarray.push_back(argv[i]);
       continue;
     }
 
-    // extra blank to insert blank token before leading quotes
+    // outer loop checks for enclosing quotes
+    // extra blank to insert blank token before leading quotes, then
+    // quoted arguments are always the even ones
     argument=" ";
     argument+=argv[i];
     // insert blank in consecutive quotes to correctly tokenize
@@ -459,50 +487,54 @@ int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
     if (pTokensQuote) {
       if (pTokensQuote->GetEntriesFast()>0) {
        for (int k=0; k<pTokensQuote->GetEntriesFast(); k++) {
-         argument=((TObjString*)pTokensQuote->At(k))->GetString();
+         argument=pTokensQuote->At(k)->GetName();
          if (argument.IsWhitespace()) continue;
          if (k%2) {
            // every second entry is enclosed by quotes and thus
            // one single argument
-           array.push_back(argument.Data());
+           stringarray.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());
+         TString data=pTokens->At(n)->GetName();
+         if (!data.IsNull() && !data.IsWhitespace()) {
+           stringarray.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]);
+  // fill ptrarray; should be safe at this point
+  // since stringarray isn't modified any further
+  unsigned int idx;
+  for(idx=0; idx<stringarray.size(); ++idx) {
+    ptrarray.push_back(stringarray.at(idx).c_str());
+  }
+
+  for (i=0; (unsigned)i<ptrarray.size() && iResult>=0;) {
+    int result=ScanConfigurationArgument(ptrarray.size()-i, &ptrarray[i]);
     if (result==0) {
-      HLTWarning("unknown component argument %s", array[i]);
+      HLTWarning("unknown component argument %s", ptrarray[i]);
       i++;
     } else if (result>0) {
       i+=result;
     } else {
       iResult=result;
       if (iResult==-EINVAL) {
-       HLTError("unknown argument %s", array[i]);
+       HLTError("unknown argument %s", ptrarray[i]);
       } else if (iResult==-EPROTO) {
-       HLTError("missing/wrong parameter for argument %s (%s)", array[i], (array.size()>(unsigned)i+1)?array[i+1]:"missing");
+       HLTError("missing/wrong parameter for argument %s (%s)", ptrarray[i], (ptrarray.size()>(unsigned)i+1)?ptrarray[i+1]:"missing");
       } else {
-       HLTError("scan of argument %s failed (%d)", array[i], iResult);
+       HLTError("scan of argument %s failed (%d)", ptrarray[i], iResult);
       }
     }
   }
@@ -520,7 +552,7 @@ int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries, const char*
   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* path=pTokens->At(n)->GetName();
       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);
@@ -543,8 +575,8 @@ int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries, const char*
        }
 
        if (pString) {
-         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
-         arguments+=pString->GetString().Data();
+         HLTInfo("received configuration object string: \'%s\'", pString->GetName());
+         arguments+=pString->GetName();
          arguments+=" ";
        } else {
          HLTError("configuration object \"%s\"%s%s has wrong type, required TObjString", path, key?" key ":"",key?key:"");
@@ -564,10 +596,10 @@ int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries, const char*
   return iResult;
 }
 
-TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, int version, int subVersion, const char* key)
+TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, const char* key) const
 {
   // see header file for function documentation
-  AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
+  AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo());
   if (!pEntry) return NULL;
   TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
   TMap* pMap=dynamic_cast<TMap*>(pObject);
@@ -680,7 +712,7 @@ void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char o
   // see header file for function documentation
   memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
   strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
-  strcat( output, ":" );
+  strncat( output, ":", 1 );
   strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
 }
 
@@ -1011,6 +1043,7 @@ void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
   memset(&evtData, 0, sizeof(AliHLTComponentEventData));
   evtData.fStructSize=sizeof(AliHLTComponentEventData);
   evtData.fEventID=kAliHLTVoidEventID;
+  evtData.fEventCreation_s = kMaxUInt;
 }
 
 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) 
@@ -1377,7 +1410,7 @@ AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData*
   return iSpec;
 }
 
-int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, 
+int AliHLTComponent::PushBack(const TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, 
                              void* pHeader, int headerSize)
 {
   // see header file for function documentation
@@ -1429,7 +1462,7 @@ int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& d
   return iResult;
 }
 
-int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
+int AliHLTComponent::PushBack(const TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
                              void* pHeader, int headerSize)
 {
   // see header file for function documentation
@@ -1514,7 +1547,7 @@ int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, con
   return iResult;
 }
 
-int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
+int AliHLTComponent::EstimateObjectSize(const TObject* pObject) const
 {
   // see header file for function documentation
   if (!pObject) return 0;
@@ -1686,13 +1719,87 @@ int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
     fEventDoneData = newEDD;
     fEventDoneDataSize = newSize;
   }
-  else {
+  else if (fEventDoneData) {
     memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
     fEventDoneData->fDataSize += edd.fDataSize;
   }
+  else {
+    HLTError("internal mismatch, fEventDoneData=%d but buffer is NULL", fEventDoneDataSize);
+    iResult=-EFAULT;
+  }
   return iResult;
 }
 
+namespace
+{
+  // helper function for std:sort, implements an operator<
+  bool SortComponentStatisticsById(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
+  {
+    return a.fId<b.fId;
+  }
+
+  // helper function for std:sort
+  bool SortComponentStatisticsDescendingByLevel(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
+  {
+    return a.fId>b.fId;
+  }
+
+  // helper class to define operator== between AliHLTComponentStatistics and AliHLTComponentStatistics.fId
+  class AliHLTComponentStatisticsId {
+  public:
+    AliHLTComponentStatisticsId(AliHLTUInt32_t id) : fId(id) {}
+    AliHLTComponentStatisticsId(const AliHLTComponentStatisticsId& src) : fId(src.fId) {}
+    AliHLTComponentStatisticsId& operator=(const AliHLTComponentStatisticsId& src) {
+      if (this==&src) return *this;
+      fId=src.fId; return *this;
+    }
+    bool operator==(const AliHLTComponentStatistics& a) const {return a.fId==fId;}
+  private:
+    AliHLTComponentStatisticsId();
+    AliHLTUInt32_t fId;
+  };
+
+  // operator for std::find of AliHLTComponentStatistics by id
+  bool operator==(const AliHLTComponentStatistics& a, const AliHLTComponentStatisticsId& b)
+  {
+    return b==a;
+  }
+
+  bool AliHLTComponentStatisticsCompareIds(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
+  {
+    return a.fId==b.fId;
+  }
+
+  // helper class to define operator== between AliHLTComponentBlockData and AliHLTComponentBlockData.fSpecification
+  class AliHLTComponentBlockDataSpecification {
+  public:
+    AliHLTComponentBlockDataSpecification(AliHLTUInt32_t specification) : fSpecification(specification) {}
+    AliHLTComponentBlockDataSpecification(const AliHLTComponentBlockDataSpecification& src) : fSpecification(src.fSpecification) {}
+    AliHLTComponentBlockDataSpecification& operator=(const AliHLTComponentBlockDataSpecification& src) {
+      if (this==&src) return *this;
+      fSpecification=src.fSpecification; return *this;
+    }
+    bool operator==(const AliHLTComponentBlockData& bd) const {return bd.fSpecification==fSpecification;}
+  private:
+    AliHLTComponentBlockDataSpecification();
+    AliHLTUInt32_t fSpecification;
+  };
+
+  // operator for std::find of AliHLTComponentBlockData by specification
+  bool operator==(const AliHLTComponentBlockData& bd, const AliHLTComponentBlockDataSpecification& spec)
+  {
+    return spec==bd;
+  }
+
+  // operator for std::find
+  bool operator==(const AliHLTComponentBlockData& a, const AliHLTComponentBlockData& b)
+  {
+    if (!MatchExactly(a.fDataType,b.fDataType)) return false;
+    return a.fSpecification==b.fSpecification;
+  }
+
+} // end of namespace
+
 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
                                   const AliHLTComponentBlockData* blocks, 
                                   AliHLTComponentTriggerData& trigData,
@@ -1724,6 +1831,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
   AliHLTComponentStatisticsList compStats;
   bool bAddComponentTableEntry=false;
   vector<AliHLTUInt32_t> parentComponentTables;
+  int processingLevel=-1;
 #if defined(HLT_COMPONENT_STATISTICS)
   if ((fFlags&kDisableComponentStat)==0) {
     AliHLTComponentStatistics outputStat;
@@ -1785,6 +1893,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.
+         AliHLTCDHWrapper 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;
@@ -1805,12 +1925,30 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
            if (pStat && compStats[0].fLevel<=pStat->fLevel) {
              compStats[0].fLevel=pStat->fLevel+1;
            }
-           compStats.push_back(*pStat);
+           if (find(compStats.begin(), compStats.end(), AliHLTComponentStatisticsId(pStat->fId))==compStats.end()) {
+             compStats.push_back(*pStat);
+           }
          }
        }
       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
-       forwardedBlocks.push_back(fpInputBlocks[i]);
+       AliHLTComponentBlockDataList::iterator element=forwardedBlocks.begin();
+       while ((element=find(element, forwardedBlocks.end(), AliHLTComponentBlockDataSpecification(fpInputBlocks[i].fSpecification)))!=forwardedBlocks.end()) {
+         if (element->fDataType==fpInputBlocks[i].fDataType) break;
+         // TODO: think about some more checks inclusing also the actual data buffers
+         // this has to handle multiplicity>1 in the online system, where all components
+         // send the information on SOR, because this event is broadcasted
+       }
+       if (element==forwardedBlocks.end()) {
+         forwardedBlocks.push_back(fpInputBlocks[i]);
+       }
        parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
+       if (fpInputBlocks[i].fSize>=sizeof(AliHLTComponentTableEntry)) {
+         const AliHLTComponentTableEntry* entry=reinterpret_cast<AliHLTComponentTableEntry*>(fpInputBlocks[i].fPtr);
+         if (entry->fStructSize==sizeof(AliHLTComponentTableEntry)) {
+           if (processingLevel<0 || processingLevel<=(int)entry->fLevel) 
+             processingLevel=entry->fLevel+1;
+         }
+       }
       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
        indexECSParamBlock=i;
       } else {
@@ -1828,6 +1966,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
     if (indexSOREvent>=0) {
       // start of run
       bAddComponentTableEntry=true;
+      compStats.clear();   // no component statistics for SOR
       if (fpRunDesc==NULL) {
        fpRunDesc=new AliHLTRunDesc;
        if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
@@ -1870,6 +2009,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
     if (indexEOREvent>=0) {
       fLastPushBackTime=0; // always send at EOR
       bAddComponentTableEntry=true;
+      compStats.clear();   // no component statistics for EOR
       if (fpRunDesc!=NULL) {
        if (fpRunDesc) {
          AliHLTRunDesc rundesc;
@@ -1889,7 +2029,8 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
        HLTWarning("did not receive SOR, ignoring EOR");
       }
     }
-    if (indexComConfEvent>=0 || fEventType==gkAliEventTypeConfiguration) {
+    if (fEventType==gkAliEventTypeConfiguration) {
+      if (indexComConfEvent>=0) {
       TString cdbEntry;
       if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
        cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
@@ -1899,8 +2040,12 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
       if (tmpResult<0) {
        HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
       }
+      } else {
+       ALIHLTERRORGUARD(1, "incomplete Configure event, missing parameter data block");
+      }
     }
-    if (indexUpdtDCSEvent>=0 || fEventType==gkAliEventTypeReadPreprocessor) {
+    if (fEventType==gkAliEventTypeReadPreprocessor) {
+      if (indexUpdtDCSEvent>=0) {
       TString modules;
       if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
        modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
@@ -1910,6 +2055,9 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
       if (tmpResult<0) {
        HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
       }
+      } else {
+       ALIHLTERRORGUARD(1, "incomplete ReadPreprocessor event, missing parameter data block");
+      }
     }
   } else {
     // processing function needs to be called if there are no input data
@@ -1921,12 +2069,24 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
   // for the private blocks
   if ((fFlags&kRequireSteeringBlocks)!=0) bSkipDataProcessing=0;
 
+  // data processing is not skipped for data sources
+  if (GetComponentType()==AliHLTComponent::kSource) 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);
   }
+  
+  // Check if the event processing should be skipped because of the
+  // down scaling from the event modulo argument. Using a prime number
+  // as pre divisor to pseudo-randomise the event number to get a more
+  // uniform distribution.
+  if (fEventModulo > 1)
+  {
+    bSkipDataProcessing |= ( ((AliHLTUInt64_t(fCurrentEvent) / AliHLTUInt64_t(4789)) % AliHLTUInt64_t(fEventModulo)) != 0 );
+  }
 
   AliHLTComponentBlockDataList blockData;
   if (iResult>=0 && !bSkipDataProcessing)
@@ -1934,6 +2094,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
     // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
     // in order to avoid 'shadowed variable' warning
     AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
+    AliHLTMisc::AliOnlineGuard onlineGuard;
     iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
   } // end of the scope of the stopwatch guard
   if (iResult>=0 && !bSkipDataProcessing) {
@@ -1965,7 +2126,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
            if (offset>0) fOutputBufferFilled+=offset;
          }
          if (bAddComponentTableEntry) {
-           int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables);
+           int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables, processingLevel);
            if (offset>0) size+=offset;
          }
          if (forwardedBlocks.size()>0) {
@@ -1977,12 +2138,18 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
       }
     } else {
       // Low Level interface
+      if (blockData.empty() && size!=0) {
+       // set the size to zero because there is no announced data
+       //HLTWarning("no output blocks added by component but output buffer filled %d of %d", size, fOutputBufferSize);
+       size=0;
+      }
+
       if (compStats.size()>0) {
        int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
        if (offset>0) size+=offset;
       }
       if (bAddComponentTableEntry) {
-       int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables);
+       int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables, processingLevel);
        if (offset>0) size+=offset;
       }
       if (forwardedBlocks.size()>0) {
@@ -2017,7 +2184,13 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
   if (fPushbackPeriod>0) {
     // suppress the output
     TDatime time;
-    if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime>=fPushbackPeriod) {
+    if (fLastPushBackTime<0) {
+      // choose a random offset at beginning to equalize traffic for multiple instances
+      // of the component
+      gRandom->SetSeed(fChainIdCrc);
+      fLastPushBackTime=time.Get();
+      fLastPushBackTime-=gRandom->Integer(fPushbackPeriod);
+    } else if ((int)time.Get()-fLastPushBackTime>=fPushbackPeriod) {
       fLastPushBackTime=time.Get();
     }
   }
@@ -2046,7 +2219,12 @@ int  AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& block
     stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
     fpBenchmark->Continue();
   }
+
+  sort(stats.begin(), stats.end(), SortComponentStatisticsDescendingByLevel);
+
+  // shrink the number of entries if the buffer is too small
   if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
+    unsigned originalSize=stats.size();
     AliHLTUInt32_t removedLevel=0;
     do {
       // remove all entries of the level of the last entry
@@ -2062,6 +2240,10 @@ int  AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& block
       }
     } while (stats.size()>1 && 
             (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
+    HLTWarning("too little space in output buffer to add block of %d statistics entries (size %d), available %d, removed %d entries",
+              originalSize, sizeof(AliHLTComponentStatistics), bufferSize-offset, originalSize-stats.size());
+  } else {
+    HLTDebug("adding block of %d statistics entries", stats.size());
   }
   assert(stats.size()>0);
   if (stats.size()==0) return 0;
@@ -2072,26 +2254,7 @@ int  AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& block
     bd.fOffset        = offset;
     bd.fSize          = stats.size()*sizeof(AliHLTComponentStatistics);
     bd.fDataType      = kAliHLTDataTypeComponentStatistics;
-    bd.fSpecification = kAliHLTVoidDataSpec;
-    unsigned int master=0;
-    for (unsigned int i=1; i<blocks.size(); i++) {
-      if (blocks[i].fSize>blocks[master].fSize && 
-         !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate))
-       master=i;
-    }
-    if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) {
-      // take the data origin of the biggest block as specification
-      // this is similar to the treatment in the HOMER interface. For traditional
-      // reasons, the bytes are swapped there on a little endian architecture, so
-      // we do it as well.
-      memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification));
-#ifdef R__BYTESWAP // set on little endian architectures
-      bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) | 
-       ((bd.fSpecification & 0xFF00ULL) << 8) | 
-       ((bd.fSpecification & 0xFF0000ULL) >> 8) | 
-       ((bd.fSpecification & 0xFF000000ULL) >> 24);
-#endif
-    }
+    bd.fSpecification = fChainIdCrc;
     memcpy(buffer+offset, &(stats[0]), bd.fSize);
     blocks.push_back(bd);
     iResult=bd.fSize;
@@ -2108,7 +2271,8 @@ int  AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& block
                                             AliHLTUInt8_t* buffer,
                                             AliHLTUInt32_t bufferSize,
                                             AliHLTUInt32_t offset,
-                                            const vector<AliHLTUInt32_t>& parents) const
+                                            const vector<AliHLTUInt32_t>& parents,
+                                            int processingLevel) const
 {
   // see header file for function documentation
   int iResult=0;
@@ -2137,6 +2301,7 @@ int  AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& block
     // write entry
     AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
     pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
+    pEntry->fLevel=processingLevel>=0?processingLevel:0;
     pEntry->fNofParents=parents.size();
     pEntry->fSizeDescription=descriptionSize;
     pTgt=pEntry->fBuffer;
@@ -2170,7 +2335,7 @@ int  AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& block
     iResult=bd.fSize;
   }
 #else
-  if (blocks.size() && buffer && bufferSize && offset && parents.size()) {
+  if (blocks.size() && buffer && bufferSize && offset && parents.size() && processingLevel) {
     // get rid of warning
   }
 #endif // HLT_COMPONENT_STATISTICS
@@ -2214,11 +2379,12 @@ AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatc
   //
 }
 
-AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
+AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard& other)
 {
   //
   // assignment operator not for use
   //
+  if (this==&other) return *this;
   fpStopwatch=NULL;
   fpPrec=NULL;
   return *this;
@@ -2312,10 +2478,11 @@ AliHLTUInt32_t AliHLTComponent::GetRunType() const
   return fpRunDesc->fRunType;
 }
 
+
 AliHLTUInt32_t    AliHLTComponent::GetTimeStamp() const
 {
   // see header file for function documentation
-  if (fCurrentEventData.fEventCreation_s) {
+  if (fCurrentEventData.fEventCreation_s < kMaxUInt ) { 
     return  fCurrentEventData.fEventCreation_s;
   }
   // using the actual UTC if the time stamp was not set by the framework
@@ -2345,8 +2512,7 @@ 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,
@@ -2435,18 +2601,22 @@ AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, i
 
 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
                                                string& retChainId, string& retCompId, string& retCompArgs,
-                                               vector<AliHLTUInt32_t>& parents)
+                                               vector<AliHLTUInt32_t>& parents, int& level)
 {
   // see header file for function documentation
   retChainId.clear();
   retCompId.clear();
   retCompArgs.clear();
   parents.clear();
+  level=-1;
   if (!pBuffer || size==0) return 0;
 
   const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
   if (size<8/* the initial size of the structure*/ ||
       pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
+
+  if (pEntry->fStructSize!=sizeof(AliHLTComponentTableEntry)) return -EBADF;
+  level=pEntry->fLevel;
   const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
   const AliHLTUInt8_t* pEnd=pBuffer+size;
 
@@ -2469,20 +2639,20 @@ int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, Al
   if (pTokens) {
     int n=0;
     if (pTokens->GetEntriesFast()>n) {
-      retChainId=((TObjString*)pTokens->At(n++))->GetString();
+      retChainId=pTokens->At(n++)->GetName();
     }
     if (pTokens->GetEntriesFast()>n) {
-      compId=((TObjString*)pTokens->At(n++))->GetString();
+      compId=pTokens->At(n++)->GetName();
     }
     delete pTokens;
   }
   if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
     int n=0;
     if (pTokens->GetEntriesFast()>n) {
-      compId=((TObjString*)pTokens->At(n++))->GetString();
+      compId=pTokens->At(n++)->GetName();
     }
     if (pTokens->GetEntriesFast()>n) {
-      compArgs=((TObjString*)pTokens->At(n++))->GetString();
+      compArgs=pTokens->At(n++)->GetName();
     }
     delete pTokens;
   }
@@ -2501,7 +2671,7 @@ int AliHLTComponent::ExtractTriggerData(
     const AliHLTComponentTriggerData& trigData,
     const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
     AliHLTUInt64_t* status,
-    const AliRawDataHeader** cdh,
+    AliHLTCDHWrapper* const cdh,
     AliHLTReadoutList* readoutlist,
     bool printErrors
   )
@@ -2546,15 +2716,15 @@ int AliHLTComponent::ExtractTriggerData(
   AliHLTEventTriggerData* evtData = reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
   assert(evtData != NULL);
   
-  // Check that the CDH has 8 words.
-  if (cdh != NULL and evtData->fCommonHeaderWordCnt != 8)
+  // Check that the CDH has the right number of words.
+  if (cdh != NULL and evtData->fCommonHeaderWordCnt != gkAliHLTCommonHeaderCount)
   {
     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)
+          evtData->fCommonHeaderWordCnt, gkAliHLTCommonHeaderCount
         );
     }
     return -EBADMSG;
@@ -2587,8 +2757,7 @@ int AliHLTComponent::ExtractTriggerData(
   }
   if (cdh != NULL)
   {
-    const AliRawDataHeader* cdhptr = reinterpret_cast<const AliRawDataHeader*>(&evtData->fCommonHeader);
-    *cdh = cdhptr;
+    *cdh = &(evtData->fCommonHeader[0]);
   }
   if (readoutlist != NULL)
   {
@@ -2597,6 +2766,20 @@ int AliHLTComponent::ExtractTriggerData(
   return 0;
 }
 
+AliHLTUInt32_t AliHLTComponent::ExtractEventTypeFromCDH(const AliHLTCDHWrapper* const 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
@@ -2692,13 +2875,13 @@ int AliHLTComponent::ScanECSParam(const char* ecsParam)
   TObjArray* parameter=string.Tokenize(";");
   if (parameter) {
     for (int i=0; i<parameter->GetEntriesFast(); i++) {
-      TString entry=((TObjString*)parameter->At(i))->GetString();
+      TString entry=parameter->At(i)->GetName();
       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());
+           int result=InitCTPTriggerClasses(entryParams->At(1)->GetName());
            if (iResult>=0 && result<0) iResult=result;
          } else {
            // TODO: scan the other parameters