]> 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 046b6d405dff9a5af44cbbc130d579ce47275c64..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 "AliHLTErrorGuard.h"
-#include "AliRawDataHeader.h"
+#include "AliHLTCDHWrapper.h"
 #include "TString.h"
 #include "TMath.h"
 #include "TObjArray.h"
@@ -89,7 +85,7 @@ AliHLTComponent::AliHLTComponent()
   fpStopwatches(new TObjArray(kSWTypeCount)),
   fMemFiles(),
   fpRunDesc(NULL),
-  fCDBSetRunNoFunc(false),
+  fCDBSetRunNoFunc(NULL),
   fChainId(),
   fChainIdCrc(0),
   fpBenchmark(NULL),
@@ -102,7 +98,8 @@ AliHLTComponent::AliHLTComponent()
   , fLastObjectSize(0)
   , fpCTPData(NULL)
   , fPushbackPeriod(0)
-  , fLastPushBackTime(-1)
+  , fLastPushBackTime(-1),
+  fEventModulo(-1)
 {
   // see header file for class documentation
   // or
@@ -245,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;
@@ -459,7 +469,7 @@ int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
     // the argument is a single argument, just having whitespaces at the end.
     argument.Remove(0, argument.First(' '));
     if (argument.IsWhitespace()) {
-      ptrarray.push_back(argv[i]);
+      stringarray.push_back(argv[i]);
       continue;
     }
 
@@ -483,7 +493,6 @@ int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
            // every second entry is enclosed by quotes and thus
            // one single argument
            stringarray.push_back(argument.Data());
-           ptrarray.push_back(stringarray.back().c_str());
          } else {
     TObjArray* pTokens=argument.Tokenize(" ");
     if (pTokens) {
@@ -492,7 +501,6 @@ int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
          TString data=pTokens->At(n)->GetName();
          if (!data.IsNull() && !data.IsWhitespace()) {
            stringarray.push_back(data.Data());
-           ptrarray.push_back(stringarray.back().c_str());
          }
        }
       }
@@ -505,6 +513,13 @@ int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
     }
   }
 
+  // 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) {
@@ -560,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:"");
@@ -581,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);
@@ -1028,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) 
@@ -1733,6 +1749,10 @@ namespace
   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();
@@ -1755,6 +1775,10 @@ namespace
   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();
@@ -1875,10 +1899,10 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
        {
          // 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;
+         AliHLTCDHWrapper cdh;
          if (ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) == 0)
          {
-           fEventType = ExtractEventTypeFromCDH(cdh);
+           fEventType = ExtractEventTypeFromCDH(&cdh);
          }
        }
 
@@ -2054,6 +2078,15 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
     // 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)
@@ -2061,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) {
@@ -2345,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;
@@ -2443,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
@@ -2635,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
   )
@@ -2680,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;
@@ -2721,8 +2757,7 @@ int AliHLTComponent::ExtractTriggerData(
   }
   if (cdh != NULL)
   {
-    const AliRawDataHeader* cdhptr = reinterpret_cast<const AliRawDataHeader*>(&evtData->fCommonHeader[0]);
-    *cdh = cdhptr;
+    *cdh = &(evtData->fCommonHeader[0]);
   }
   if (readoutlist != NULL)
   {
@@ -2731,10 +2766,9 @@ int AliHLTComponent::ExtractTriggerData(
   return 0;
 }
 
-AliHLTUInt32_t AliHLTComponent::ExtractEventTypeFromCDH(const AliRawDataHeader* cdh)
+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.