]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTComponent.cxx
Minor cleanup of code.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
index db222bdbeece8d0228a0d405cff24bfd17d4786b..ea786d1246ba33bb169f6d0f35e6d1035ba1b69d 100644 (file)
@@ -78,7 +78,7 @@ AliHLTComponent::AliHLTComponent()
   fMemFiles(),
   fpRunDesc(NULL),
   fpDDLList(NULL),
-  fCDBInitialized(false),
+  fCDBSetRunNoFunc(false),
   fChainId()
 {
   // see header file for class documentation
@@ -135,6 +135,7 @@ int AliHLTComponent::UnsetGlobalComponentHandler()
 int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv )
 {
   // see header file for function documentation
+  HLTLogKeyword(GetComponentID());
   int iResult=0;
   if (environ) {
     memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
@@ -191,6 +192,7 @@ int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environPar
 int AliHLTComponent::Deinit()
 {
   // see header file for function documentation
+  HLTLogKeyword(GetComponentID());
   int iResult=0;
   iResult=DoDeinit();
   if (fpRunDesc) {
@@ -203,62 +205,79 @@ int AliHLTComponent::Deinit()
   return iResult;
 }
 
-int AliHLTComponent::InitCDB(const char* cdbPath)
+int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
 {
+  // see header file for function documentation
   int iResult=0;
-  // we presume the library already to be loaded
+  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
-  AliHLTComponentHandler cHandler;
-  AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)cHandler.FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB); 
+  AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
   if (pFunc) {
-    iResult=(*pFunc)(cdbPath);
-    fCDBInitialized=iResult>=0;
+    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;
   }
+  } else {
+    iResult=-EINVAL;
+  }
   return iResult;
 }
 
 int AliHLTComponent::SetCDBRunNo(int runNo)
 {
-  int iResult=0;
-  if (!fCDBInitialized) return iResult;
-  // we presume the library already to be loaded
-  // find the symbol
-  AliHLTComponentHandler cHandler;
-  AliHLTMiscSetCDBRunNo_t pFunc=(AliHLTMiscSetCDBRunNo_t)cHandler.FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO); 
-  if (pFunc) {
-    iResult=(*pFunc)(runNo);
-  } else {
-    Message(NULL, kHLTLogError, "AliHLTComponent::SetCDBRunNo", "init CDB",
-           "can not find initialization function");
-    iResult=-ENOSYS;
-  }
-  return iResult;
+  // 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
+  HLTLogKeyword("dummy");
   return 0;
 }
 
 int AliHLTComponent::DoDeinit()
 {
   // default implementation, childs can overload
+  HLTLogKeyword("dummy");
   return 0;
 }
 
 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
 {
   // default implementation, childs can overload
+  HLTLogKeyword("dummy");
+  return 0;
+}
+
+int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
+{
+  // default implementation, childs can overload
+  HLTLogKeyword("dummy");
   return 0;
 }
 
 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
 {
+  // default implementation, childs can overload
   HLTLogKeyword("dummy");
   return 0;
 }
@@ -361,7 +380,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 ********:****.
@@ -408,8 +427,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++;
       }
@@ -421,25 +439,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 )
@@ -489,6 +508,16 @@ void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id
   }
 }
 
+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)
 {
   // see header file for function documentation
@@ -596,11 +625,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 ||
-         (memcmp(dt.fID, kAliHLTAnyDataTypeID, kAliHLTComponentDataTypefIDsize)==0 &&
-          memcmp(dt.fOrigin, fpInputBlocks[idx].fDataType.fOrigin, kAliHLTComponentDataTypefOriginSize)==0) ||
-         (memcmp(dt.fID, fpInputBlocks[idx].fDataType.fID, kAliHLTComponentDataTypefIDsize)==0) &&
-          memcmp(dt.fOrigin, kAliHLTDataOriginAny, kAliHLTComponentDataTypefOriginSize)==0) {
+      if (dt==fpInputBlocks[idx].fDataType) {
        iResult=idx;
       }
     }
@@ -627,7 +652,7 @@ TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
          }
          //} else {
                } else if (bForce!=0) {
-         HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
+         HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
        }
       } else {
        HLTFatal("block descriptor empty");
@@ -792,7 +817,7 @@ const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index)
 {
   // see header file for function documentation
   ALIHLTCOMPONENT_BASE_STOPWATCH();
-  assert( 0 <= index and index < fCurrentEventData.fBlockCnt );
+  assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
   return &fpInputBlocks[index];
 }
 
@@ -1104,6 +1129,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
                                   AliHLTComponentEventDoneData*& edd )
 {
   // see header file for function documentation
+  HLTLogKeyword(GetComponentID());
   ALIHLTCOMPONENT_BASE_STOPWATCH();
   int iResult=0;
   fCurrentEvent=evtData.fEventID;
@@ -1116,11 +1142,14 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
   fOutputBufferFilled=0;
   fOutputBlocks.clear();
 
+  bool bSkipDataProcessing=false;
   // find special events
   if (fpInputBlocks) {
     // first look for all special events and execute in the appropriate
     // sequence afterwords
+    AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
     int indexComConfEvent=-1;
+    int indexUpdtDCSEvent=-1;
     int indexSOREvent=-1;
     int indexEOREvent=-1;
     for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
@@ -1133,6 +1162,12 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
        // this event is most likely deprecated
       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
        indexComConfEvent=i;
+      } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
+       indexUpdtDCSEvent=i;
+      } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
+       eventType=fpInputBlocks[i].fSpecification;
+       bSkipDataProcessing|=(fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration);
+       bSkipDataProcessing|=(fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor);
       }
     }
     if (indexSOREvent>=0) {
@@ -1157,7 +1192,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
          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);
+             HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
            } else {
              HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
            }
@@ -1170,9 +1205,9 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
        HLTWarning("did not receive SOR, ignoring EOR");
       }
     }
-    if (indexComConfEvent>=0) {
+    if (indexComConfEvent>=0 || eventType==gkAliEventTypeConfiguration) {
       TString cdbEntry;
-      if (fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
+      if (indexComConfEvent>=0 && 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());
@@ -1181,6 +1216,17 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
        HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
       }
     }
+    if (indexUpdtDCSEvent>=0 || eventType==gkAliEventTypeReadPreprocessor) {
+      TString modules;
+      if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
+       modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
+      }
+      HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
+      int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
+      if (tmpResult<0) {
+       HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
+      }
+    }
   }
   
   AliHLTComponentBlockDataList blockData;
@@ -1188,7 +1234,7 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
     ALIHLTCOMPONENT_DA_STOPWATCH();
     iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
   } // end of the scope of the stopwatch guard
-  if (iResult>=0) {
+  if (iResult>=0 && !bSkipDataProcessing) {
     if (fOutputBlocks.size()>0) {
       //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
       
@@ -1222,12 +1268,12 @@ int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
       HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
     }
   }
-  if (iResult<0) {
+  if (iResult<0 || bSkipDataProcessing) {
     outputBlockCnt=0;
     outputBlocks=NULL;
   }
   CleanupInputObjects();
-  if (iResult>=0) {
+  if (iResult>=0 && !bSkipDataProcessing) {
     IncrementEventCounter();
   }
   return iResult;
@@ -1368,11 +1414,11 @@ int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigne
       if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
        AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
        if (fpInputBlocks[iBlockNo].fSize!=copy) {
-         HLTWarning("%s event: missmatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
+         HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
          if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
        }
        if (copy!=iStructSize) {
-         HLTWarning("%s event: missmatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
+         HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
          if (copy>iStructSize) {
            copy=iStructSize;
          } else {