]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTComponent.cxx
various fixes in the HLTOUT treatment
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
index fb8c9204ac23d0dd1f4b0b4b3488210725e98b14..4e050bb687e87ab0dfdb940205bd3ee1763dffc5 100644 (file)
@@ -37,11 +37,13 @@ using namespace std;
 #include "AliHLTComponentHandler.h"
 #include "AliHLTMessage.h"
 #include "TString.h"
+#include "TMath.h"
 #include "TObjArray.h"
 #include "TObjectTable.h"
 #include "TClass.h"
 #include "TStopwatch.h"
 #include "AliHLTMemoryFile.h"
+#include "AliHLTMisc.h"
 #include <cassert>
 
 /** ROOT macro for the implementation of ROOT specific class methods */
@@ -75,8 +77,9 @@ AliHLTComponent::AliHLTComponent()
   fpStopwatches(new TObjArray(kSWTypeCount)),
   fMemFiles(),
   fpRunDesc(NULL),
-  fpDDLList(NULL)
-
+  fpDDLList(NULL),
+  fCDBSetRunNoFunc(false),
+  fChainId()
 {
   // see header file for class documentation
   // or
@@ -196,28 +199,73 @@ int AliHLTComponent::Deinit()
     fpRunDesc=NULL;
     delete pRunDesc;
   }
+  fEventCount=0;
   return iResult;
 }
 
-int AliHLTComponent::DoInit( int argc, const char** argv )
+int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
 {
   // see header file for function documentation
-  if (argc==0 && argv==NULL) {
-    // this is currently just to get rid of the warning "unused parameter"
+  int iResult=0;
+  if (cdbPath, pHandler) {
+  // I have to think about separating the library handling from the
+  // component handler. Requiring the component hanlder here is not
+  // the cleanest solution.
+  // We presume the library already to be loaded
+  // find the symbol
+  AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
+  if (pFunc) {
+    TString path=cdbPath;
+    // very temporary fix, have to check for other formats
+    if (!path.BeginsWith("local://")) {
+      path="local://";
+      path+=cdbPath;
+    }
+    if ((iResult=(*pFunc)(path.Data()))>=0) {
+      if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
+       Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
+               "can not find function to set CDB run no");
+      }
+    }
+  } else {
+    Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
+           "can not find initialization function");
+    iResult=-ENOSYS;
   }
-  fEventCount=0;
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+int AliHLTComponent::SetCDBRunNo(int runNo)
+{
+  // see header file for function documentation
+  if (!fCDBSetRunNoFunc) return 0;
+  return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
+}
+
+int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
+{
+  // default implementation, childs can overload
   return 0;
 }
 
 int AliHLTComponent::DoDeinit()
 {
-  // see header file for function documentation
-  fEventCount=0;
+  // default implementation, childs can overload
+  return 0;
+}
+
+int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
+{
+  // default implementation, childs can overload
   return 0;
 }
 
 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
 {
+  // default implementation, childs can overload
   HLTLogKeyword("dummy");
   return 0;
 }
@@ -320,7 +368,7 @@ int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList
        return -ENOMEM;
     for ( unsigned long i = 0; i < count; i++ ) {
        (*outputBlocks)[i] = blocks[i];
-       if (blocks[i].fDataType==kAliHLTAnyDataType) {
+       if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
          (*outputBlocks)[i].fDataType=GetOutputDataType();
          /* data type was set to the output data type by the PubSub AliRoot
             Wrapper component, if data type of the block was ********:****.
@@ -367,8 +415,7 @@ int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTCom
       AliHLTComponentDataTypeList::iterator otype=otypes.begin();
       while (otype!=otypes.end() && (*itype)!=(*otype)) otype++;
       //if (otype!=otypes.end()) PrintDataTypeContent(*otype, "publisher \'%s\'");
-      if (otype!=otypes.end() ||
-         (*itype)==kAliHLTAnyDataType) {
+      if (otype!=otypes.end()) {
        if (tgtList) tgtList->push_back(*itype);
        iResult++;
       }
@@ -380,25 +427,26 @@ int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTCom
   return iResult;
 }
 
-void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const
+void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
 {
   // see header file for function documentation
-  const char* fmt="publisher \'%s\'";
+  const char* fmt="\'%s\'";
   if (format) fmt=format;
-  HLTMessage(fmt, (DataType2Text(dt)).c_str());
-  HLTMessage("%x %x %x %x %x %x %x %x : %x %x %x %x", 
-            dt.fID[0],
-            dt.fID[1],
-            dt.fID[2],
-            dt.fID[3],
-            dt.fID[4],
-            dt.fID[5],
-            dt.fID[6],
-            dt.fID[7],
-            dt.fOrigin[0],
-            dt.fOrigin[1],
-            dt.fOrigin[2],
-            dt.fOrigin[3]);
+  AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
+  AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, 
+                        Form("%x %x %x %x %x %x %x %x : %x %x %x %x", 
+                             dt.fID[0],
+                             dt.fID[1],
+                             dt.fID[2],
+                             dt.fID[3],
+                             dt.fID[4],
+                             dt.fID[5],
+                             dt.fID[6],
+                             dt.fID[7],
+                             dt.fOrigin[0],
+                             dt.fOrigin[1],
+                             dt.fOrigin[2],
+                             dt.fOrigin[3]));
 }
 
 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
@@ -437,9 +485,25 @@ void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTC
 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) 
 {
   // see header file for function documentation
-  tgtdt=kAliHLTVoidDataType;
-  strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
-  strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
+  tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
+  if (id) {
+    memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
+    strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
+  }
+  if (origin) {
+    memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
+    strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
+  }
+}
+
+void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
+{
+  // see header file for function documentation
+  dt.fStructSize=sizeof(AliHLTComponentDataType);
+  assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
+  assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
+  memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
+  memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
 }
 
 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
@@ -549,7 +613,7 @@ int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int start
        AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
        if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
       }
-      if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) {
+      if (dt==fpInputBlocks[idx].fDataType) {
        iResult=idx;
       }
     }
@@ -674,6 +738,43 @@ AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
   return iSpec;
 }
 
+int AliHLTComponent::Forward(const TObject* pObject)
+{
+  // see header file for function documentation
+  int iResult=0;
+  int idx=fCurrentInputBlock;
+  if (pObject) {
+    if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
+    } else {
+      HLTError("unknown object %p", pObject);
+      iResult=-ENOENT;
+    }
+  }
+  if (idx>=0) {
+    fOutputBlocks.push_back(fpInputBlocks[idx]);
+  }
+  return iResult;
+}
+
+int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
+{
+  // see header file for function documentation
+  int iResult=0;
+  int idx=fCurrentInputBlock;
+  if (pBlock) {
+    if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
+    } else {
+      HLTError("unknown Block %p", pBlock);
+      iResult=-ENOENT;      
+    }
+  }
+  if (idx>=0) {
+    // check for fpInputBlocks pointer done in FindInputBlock
+    fOutputBlocks.push_back(fpInputBlocks[idx]);
+  }
+  return iResult;
+}
+
 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
 {
   // see header file for function documentation
@@ -1030,42 +1131,67 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
 
   // find special events
   if (fpInputBlocks) {
+    // first look for all special events and execute in the appropriate
+    // sequence afterwords
+    int indexComConfEvent=-1;
+    int indexSOREvent=-1;
+    int indexEOREvent=-1;
     for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
       if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
-       // start of run
-       if (fpRunDesc==NULL) {
-         fpRunDesc=new AliHLTRunDesc;
-         if (fpRunDesc) {
-           if ((iResult=CopyStruct(fpRunDesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) {
-             HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
-           }
-         } else {
-           iResult=-ENOMEM;
+       indexSOREvent=i;
+      } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
+       indexEOREvent=i;
+      } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
+       // DDL list
+       // this event is most likely deprecated
+      } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
+       indexComConfEvent=i;
+      }
+    }
+    if (indexSOREvent>=0) {
+      // start of run
+      if (fpRunDesc==NULL) {
+       fpRunDesc=new AliHLTRunDesc;
+       if (fpRunDesc) {
+         if ((iResult=CopyStruct(fpRunDesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
+           HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
+           SetCDBRunNo(fpRunDesc->fRunNo);
          }
        } else {
-         HLTWarning("already received SOR event run no %d, ignoring SOR", fpRunDesc->fRunNo);
+         iResult=-ENOMEM;
        }
-      } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
-       if (fpRunDesc!=NULL) {
-         if (fpRunDesc) {
-           AliHLTRunDesc rundesc;
-           if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) {
-             if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
-               HLTWarning("run no missmatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
-             } else {
-               HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
-             }
+      } else {
+       HLTWarning("already received SOR event run no %d, ignoring SOR", fpRunDesc->fRunNo);
+      }
+    }
+    if (indexEOREvent>=0) {
+      if (fpRunDesc!=NULL) {
+       if (fpRunDesc) {
+         AliHLTRunDesc rundesc;
+         if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
+           if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
+             HLTWarning("run no missmatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
+           } else {
+             HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
            }
-           AliHLTRunDesc* pRunDesc=fpRunDesc;
-           fpRunDesc=NULL;
-           delete pRunDesc;
          }
-       } else {
-         HLTWarning("did not receive SOR, ignoring EOR");
+         AliHLTRunDesc* pRunDesc=fpRunDesc;
+         fpRunDesc=NULL;
+         delete pRunDesc;
        }
-       // end of run
-      } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
-       // DDL list
+      } else {
+       HLTWarning("did not receive SOR, ignoring EOR");
+      }
+    }
+    if (indexComConfEvent>=0) {
+      TString cdbEntry;
+      if (fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
+       cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
+      }
+      HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
+      int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
+      if (tmpResult<0) {
+       HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
       }
     }
   }
@@ -1281,3 +1407,70 @@ 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;
+}