+ ALIHLTCOMPONENT_BASE_STOPWATCH();
+ AliHLTComponentDataType dt;
+ SetDataType(dt, dtID, dtOrigin);
+ return CreateMemoryFile(capacity, dt, spec);
+}
+
+AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
+ const AliHLTComponentDataType& dt,
+ AliHLTUInt32_t spec)
+{
+ // see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
+ AliHLTMemoryFile* pFile=NULL;
+ if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
+ AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
+ pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
+ if (pFile) {
+ unsigned int nofBlocks=fOutputBlocks.size();
+ if (nofBlocks+1>fMemFiles.size()) {
+ fMemFiles.resize(nofBlocks+1, NULL);
+ }
+ if (nofBlocks<fMemFiles.size()) {
+ fMemFiles[nofBlocks]=pFile;
+ AliHLTComponentBlockData bd;
+ FillBlockData( bd );
+ bd.fOffset = fOutputBufferFilled;
+ bd.fSize = capacity;
+ bd.fDataType = dt;
+ bd.fSpecification = spec;
+ fOutputBufferFilled+=bd.fSize;
+ fOutputBlocks.push_back( bd );
+ } else {
+ HLTError("can not allocate/grow object array");
+ pFile->CloseMemoryFile(0);
+ delete pFile;
+ pFile=NULL;
+ }
+ }
+ } else {
+ HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
+ }
+ return pFile;
+}
+
+AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
+ const char* dtOrigin,
+ AliHLTUInt32_t spec,
+ float capacity)
+{
+ // see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
+ AliHLTComponentDataType dt;
+ SetDataType(dt, dtID, dtOrigin);
+ int size=fOutputBufferSize-fOutputBufferFilled;
+ if (capacity<0 || capacity>1.0) {
+ HLTError("invalid parameter: capacity %f", capacity);
+ return NULL;
+ }
+ size=(int)(size*capacity);
+ return CreateMemoryFile(size, dt, spec);
+}
+
+AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
+ AliHLTUInt32_t spec,
+ float capacity)
+{
+ // see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
+ int size=fOutputBufferSize-fOutputBufferFilled;
+ if (capacity<0 || capacity>1.0) {
+ HLTError("invalid parameter: capacity %f", capacity);
+ return NULL;
+ }
+ size=(int)(size*capacity);
+ return CreateMemoryFile(size, dt, spec);
+}
+
+int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
+ const char* key, int option)
+{
+ // see header file for function documentation
+ int iResult=0;
+ if (pFile && pObject) {
+ pFile->cd();
+ iResult=pObject->Write(key, option);
+ if (iResult>0) {
+ // success
+ } else {
+ iResult=-pFile->GetErrno();
+ if (iResult==-ENOSPC) {
+ HLTError("error writing memory file, buffer too small");
+ }
+ }
+ } else {
+ iResult=-EINVAL;
+ }
+ return iResult;
+}
+
+int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
+{
+ // see header file for function documentation
+ int iResult=0;
+ if (pFile) {
+ AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
+ int i=0;
+ while (element!=fMemFiles.end() && iResult>=0) {
+ if (*element && *element==pFile) {
+ iResult=pFile->CloseMemoryFile();
+
+ // sync memory files and descriptors
+ if (iResult>=0) {
+ fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
+ }
+ delete *element;
+ *element=NULL;
+ return iResult;
+ }
+ element++; i++;
+ }
+ HLTError("can not find memory file %p", pFile);
+ iResult=-ENOENT;
+ } else {
+ iResult=-EINVAL;
+ }
+ return iResult;
+}
+
+int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
+{
+ // see header file for function documentation
+ 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;
+}
+
+int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
+ const AliHLTComponentBlockData* blocks,
+ AliHLTComponentTriggerData& trigData,
+ AliHLTUInt8_t* outputPtr,
+ AliHLTUInt32_t& size,
+ AliHLTUInt32_t& outputBlockCnt,
+ AliHLTComponentBlockData*& outputBlocks,
+ AliHLTComponentEventDoneData*& edd )
+{
+ // see header file for function documentation
+ HLTLogKeyword(GetComponentID());
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
+ int iResult=0;
+ fCurrentEvent=evtData.fEventID;
+ fCurrentEventData=evtData;
+ fpInputBlocks=blocks;
+ fCurrentInputBlock=-1;
+ fSearchDataType=kAliHLTAnyDataType;
+ fpOutputBuffer=outputPtr;
+ fOutputBufferSize=size;
+ fOutputBufferFilled=0;
+ fOutputBlocks.clear();
+ outputBlockCnt=0;
+ outputBlocks=NULL;
+
+ AliHLTComponentBlockDataList forwardedBlocks;
+
+ // optional component statistics
+ 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();
+ }
+#endif
+
+ // data processing is skipped
+ // - if there are only steering events in the block list.
+ // For the sake of data source components data processing
+ // is not skipped if there is no block list at all or if it
+ // just contains the eventType block
+ // - always skipped if the event is of type
+ // - gkAliEventTypeConfiguration
+ // - gkAliEventTypeReadPreprocessor
+ const unsigned int skipModeDefault=0x1;
+ const unsigned int skipModeForce=0x2;
+ unsigned int bSkipDataProcessing=skipModeDefault;
+
+ // find special events
+ if (fpInputBlocks && evtData.fBlockCnt>0) {
+ // first look for all special events and execute in the appropriate
+ // sequence afterwords
+ int indexComConfEvent=-1;
+ int indexUpdtDCSEvent=-1;
+ int indexSOREvent=-1;
+ int indexEOREvent=-1;
+ for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
+ if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
+ indexSOREvent=i;
+ // the AliHLTCalibrationProcessor relies on the SOR and EOR events
+ bSkipDataProcessing&=~skipModeDefault;
+ } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
+ // run type string
+ // handling is not clear yet
+ if (fpInputBlocks[i].fPtr) {
+ HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
+ }
+ } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
+ indexEOREvent=i;
+ // the calibration processor relies on the SOR and EOR events
+ bSkipDataProcessing&=~skipModeDefault;
+ } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
+ // DDL list
+ // 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) {
+ fEventType=fpInputBlocks[i].fSpecification;
+
+ // skip always in case of gkAliEventTypeConfiguration
+ if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
+
+ // skip always in case of gkAliEventTypeReadPreprocessor
+ if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
+
+ // never skip if the event type block is the only block
+ if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
+
+ } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
+ if (compStats.size()>0) {
+ AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
+ for (AliHLTUInt32_t offset=0;
+ offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
+ offset+=sizeof(AliHLTComponentStatistics)) {
+ AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
+ if (pStat && compStats[0].fLevel<=pStat->fLevel) {
+ compStats[0].fLevel=pStat->fLevel+1;
+ }
+ compStats.push_back(*pStat);
+ }
+ }
+ } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
+ forwardedBlocks.push_back(fpInputBlocks[i]);
+ parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
+ } else {
+ // the processing function is called if there is at least one
+ // non-steering data block. Steering blocks are not filtered out
+ // for sake of performance
+ bSkipDataProcessing&=~skipModeDefault;
+ if (compStats.size()>0) {
+ compStats[0].fInputBlockCount++;
+ compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
+ }
+ }
+ }
+
+ if (indexSOREvent>=0) {
+ // start of run
+ bAddComponentTableEntry=true;
+ if (fpRunDesc==NULL) {
+ fpRunDesc=new AliHLTRunDesc;
+ if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
+ }
+ if (fpRunDesc) {
+ AliHLTRunDesc rundesc;
+ if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
+ if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
+ *fpRunDesc=rundesc;
+ HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
+ SetCDBRunNo(fpRunDesc->fRunNo);
+ } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
+ HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
+ }
+ }
+ } else {
+ iResult=-ENOMEM;
+ }
+ }
+ if (indexEOREvent>=0) {
+ bAddComponentTableEntry=true;
+ 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 mismatch: 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");
+ }
+ }
+ if (indexComConfEvent>=0 || fEventType==gkAliEventTypeConfiguration) {
+ 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);
+ }
+ 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);
+ }
+ }
+ if (indexUpdtDCSEvent>=0 || fEventType==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);
+ }
+ }
+ } else {
+ // processing function needs to be called if there are no input data
+ // blocks in order to make data source components working.
+ bSkipDataProcessing&=~skipModeDefault;
+ }
+
+ // data processing is not skipped if the component explicitly asks
+ // for the private blocks
+ if (fRequireSteeringBlocks) bSkipDataProcessing=0;
+
+ AliHLTComponentBlockDataList blockData;
+ if (iResult>=0 && !bSkipDataProcessing)
+ { // dont delete, sets the scope for the stopwatch guard
+ // 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);
+ iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
+ } // end of the scope of the stopwatch guard
+ if (iResult>=0 && !bSkipDataProcessing) {
+ if (fOutputBlocks.size()>0) {
+ // High Level interface
+
+ //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
+ // sync memory files and descriptors
+ AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
+ int i=0;
+ while (element!=fMemFiles.end() && iResult>=0) {
+ if (*element) {
+ if ((*element)->IsClosed()==0) {
+ HLTWarning("memory file has not been closed, force flush");
+ iResult=CloseMemoryFile(*element);
+ }
+ }
+ element++; i++;
+ }
+
+ if (iResult>=0) {
+ // create the descriptor list
+ if (blockData.size()>0) {
+ HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
+ iResult=-EFAULT;
+ } else {
+ if (compStats.size()>0 && IsDataEvent()) {
+ int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
+ if (offset>0) fOutputBufferFilled+=offset;
+ }
+ if (bAddComponentTableEntry) {
+ int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables);
+ if (offset>0) size+=offset;
+ }
+ if (forwardedBlocks.size()>0) {
+ fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
+ }
+ iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
+ size=fOutputBufferFilled;
+ }