* provided "as is" without express or implied warranty. *
**************************************************************************/
+#include "AliHLTPHOSRawAnalyzer.h"
#include "AliHLTPHOSRawAnalyzerComponentv3.h"
+#include "AliHLTPHOSChannelDataHeaderStruct.h"
+#include "AliHLTPHOSChannelDataStruct.h"
#include "AliHLTPHOSMapper.h"
-#include "AliHLTPHOSDefinitions.h"
+#include "AliHLTPHOSSanityInspector.h"
+
+#include "AliAltroRawStreamV3.h"
+#include "AliCaloRawStreamV3.h"
+#include "AliRawReaderMemory.h"
+
+
#include "AliHLTPHOSUtilities.h"
AliHLTPHOSRawAnalyzerComponentv3::AliHLTPHOSRawAnalyzerComponentv3():
- AliHLTCaloRawAnalyzerComponentv3()
+ AliHLTPHOSRcuProcessor(),
+ fAnalyzerPtr(0),
+ fMapperPtr(0),
+ fSanityInspectorPtr(0),
+ fRawReaderMemoryPtr(0),
+ fAltroRawStreamPtr(0),
+ fAlgorithm(0),
+ fOffset(0),
+ fBunchSizeCut(0),
+ fMinPeakPosition(0),
+ fMaxPeakPosition(100),
+ fkDoPushRawData(true),
+
+ fRawDataWriter(0)
{
//comment
+ fMapperPtr = new AliHLTPHOSMapper();
+
+ fRawReaderMemoryPtr = new AliRawReaderMemory();
+
+ fAltroRawStreamPtr = new AliAltroRawStreamV3(fRawReaderMemoryPtr);
+
+ fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
+
+ if( fkDoPushRawData == true )
+ {
+
+ fRawDataWriter = new AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter();
+
+ }
+
}
AliHLTPHOSRawAnalyzerComponentv3::~AliHLTPHOSRawAnalyzerComponentv3()
{
//comment
+ Deinit();
}
int
AliHLTPHOSRawAnalyzerComponentv3::Deinit()
{
//comment
+ if(fAnalyzerPtr)
+ {
+ delete fAnalyzerPtr;
+ fAnalyzerPtr = 0;
+ }
+ if(fMapperPtr)
+ {
+ delete fMapperPtr;
+ fMapperPtr = 0;
+ }
+ if(fRawReaderMemoryPtr)
+ {
+ delete fRawReaderMemoryPtr;
+ fRawReaderMemoryPtr = 0;
+ }
+ if(fAltroRawStreamPtr)
+ {
+ delete fAltroRawStreamPtr;
+ fAltroRawStreamPtr = 0;
+ }
return 0;
}
+const char*
+AliHLTPHOSRawAnalyzerComponentv3::GetComponentID()
+{
+ //comment
+ return "PhosRawAnalyzerv3";
+}
+
+
void
AliHLTPHOSRawAnalyzerComponentv3::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
{
list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS );
}
+AliHLTComponentDataType
+AliHLTPHOSRawAnalyzerComponentv3::GetOutputDataType()
+{
+ //comment
+ return AliHLTPHOSDefinitions::fgkChannelDataType;
+}
+
+void
+AliHLTPHOSRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
+{
+ //comment
+ constBase = sizeof(AliHLTPHOSChannelDataHeaderStruct);
+ inputMultiplier = 0.5;
+}
+
+int
+AliHLTPHOSRawAnalyzerComponentv3::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
+ AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
+{
+ //comment
+ Int_t blockSize = 0;
+ UInt_t totSize = 0;
+
+ const AliHLTComponentBlockData* iter = NULL;
+ unsigned long ndx;
+
+ for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
+ {
+ iter = blocks+ndx;
+ if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
+ {
+ HLTDebug("Data block is not of type fgkDDLPackedRawDataType");
+ continue;
+ }
+
+ blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
+
+ if(blockSize == -1) // If the processing returns -1 we are out of buffer and return an error msg.
+ {
+ return -ENOBUFS;
+ }
+
+ totSize += blockSize; //Keeping track of the used size
+ // HLTDebug("Output data size: %d - Input data size: %d", totSize, iter->fSize);
+
+ //Filling the block data
+ AliHLTComponentBlockData bdChannelData;
+ FillBlockData( bdChannelData );
+ bdChannelData.fOffset = 0; //FIXME
+ bdChannelData.fSize = blockSize;
+ bdChannelData.fDataType = AliHLTPHOSDefinitions::fgkChannelDataType;
+ bdChannelData.fSpecification = iter->fSpecification;
+ outputBlocks.push_back(bdChannelData);
+
+ outputPtr += blockSize; //Updating position of the output buffer
+ }
+
+ fPhosEventCount++;
+ size = totSize; //telling the framework how much buffer space we have used.
+
+ return 0;
+}//end DoEvent
+
+
+
+Int_t
+AliHLTPHOSRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
+{
+ //comment
+ int tmpsize= 0;
+ Int_t crazyness = 0;
+ Int_t nSamples = 0;
+ Short_t channelCount = 0;
+
+ // Firs we want to write a header to the output
+ AliHLTPHOSChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(outputPtr);
+
+ // Then comes the channel data
+ AliHLTPHOSChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTPHOSChannelDataStruct*>(outputPtr+sizeof(AliHLTPHOSChannelDataHeaderStruct));
+ //Adding to the total size of data written
+ totSize += sizeof( AliHLTPHOSChannelDataHeaderStruct );
+
+ fRawReaderMemoryPtr->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), static_cast<ULong_t>( iter->fSize ) );
+ fRawReaderMemoryPtr->SetEquipmentID( fMapperPtr->GetDDLFromSpec( iter->fSpecification) + 1792 );
+ fRawReaderMemoryPtr->Reset();
+ fRawReaderMemoryPtr->NextEvent();
+
+ if( fkDoPushRawData == true)
+ {
+ fRawDataWriter->NewEvent( );
+ }
+ if(fAltroRawStreamPtr != NULL)
+ {
+ delete fAltroRawStreamPtr;
+ fAltroRawStreamPtr=NULL;
+ }
+
+ fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, TString("PHOS"));
+ // fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, TString("EMCAL"));
+ // while( fAltroRawStreamPtr->NextDDL() )
+ fAltroRawStreamPtr->NextDDL();
+ {
+ int cnt = 0;
+ while( fAltroRawStreamPtr->NextChannel() )
+ {
+ if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
+ {
+ continue;
+ }
+ else
+ {
+ cnt ++;
+ UShort_t* firstBunchPtr;
+ UShort_t chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
+
+ if( fkDoPushRawData == true)
+ {
+ fRawDataWriter->SetChannelId( chId );
+ }
+ while( fAltroRawStreamPtr->NextBunch() == true )
+ {
+ nSamples = fAltroRawStreamPtr->GetBunchLength();
+
+ if( fkDoPushRawData == true)
+ {
+ // fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetStartTimeBin() );
+ fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
+ }
+ firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
+ }
+
+ totSize += sizeof( AliHLTPHOSChannelDataStruct );
+ if(totSize > size)
+ {
+ HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
+ return -1;
+ }
+
+ fAnalyzerPtr->SetData( firstBunchPtr, nSamples);
+ fAnalyzerPtr->Evaluate(0, nSamples);
+
+ // if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition)
+ {
+ channelDataPtr->fChannelID = chId;
+ channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
+
+ if( channelDataPtr->fEnergy > 70 )
+ {
+ cout << __FILE__ << __LINE__ << "The energy is of channel "<< chId << " is " << channelDataPtr->fEnergy << endl;
+ }
+
+ channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
+ channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
+ channelCount++;
+ channelDataPtr++; // Updating position of the free output.
+ }
+ }
+ fRawDataWriter->NewChannel();
+ }
+ }
+
+ //Writing the header
+ channelDataHeaderPtr->fNChannels = channelCount;
+ channelDataHeaderPtr->fAlgorithm = fAlgorithm;
+ channelDataHeaderPtr->fInfo = 0;
+
+ if( fkDoPushRawData == true)
+ {
+ tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
+ }
+
+ // channelDataHeaderPtr->fHasRawData = false;
+ channelDataHeaderPtr->fHasRawData = fkDoPushRawData;
+
+ HLTDebug("Number of channels: %d", channelCount);
+ //returning the size used
+ // delete fAltroRawStreamPtr;
+ tmpsize += sizeof(AliHLTPHOSChannelDataStruct)*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
+
+ // return sizeof(AliHLTPHOSChannelDataStruct)*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
+ return tmpsize;
+
+}
+
+
+int
+AliHLTPHOSRawAnalyzerComponentv3::WriteRawData(AliHLTPHOSChannelDataStruct *dtaPtr)
+{
+ cout << dtaPtr << endl;
+ return 0;
+}
+
+
int
-AliHLTPHOSRawAnalyzerComponentv3::InitMapping( const int spec)
+AliHLTPHOSRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
{
//See base class for documentation
// fPrintInfo = kFALSE;
+ int iResult=0;
+ fMapperPtr = new AliHLTPHOSMapper();
- if(fMapperPtr == 0)
+ for(int i = 0; i < argc; i++)
{
- fMapperPtr = new AliHLTPHOSMapper();
+ if(!strcmp("-offset", argv[i]))
+ {
+ fOffset = atoi(argv[i+1]);
+ }
+ if(!strcmp("-bunchsizecut", argv[i]))
+ {
+ fBunchSizeCut = atoi(argv[i+1]);
+ }
+ if(!strcmp("-minpeakposition", argv[i]))
+ {
+ fMinPeakPosition = atoi(argv[i+1]);
+ }
+ if(!strcmp("-maxpeakposition", argv[i]))
+ {
+ fMaxPeakPosition = atoi(argv[i+1]);
+ }
}
if(fMapperPtr->GetIsInitializedMapping() == false)
{
- HLTError("%d:%d, ERROR, mapping not initialized ", __FILE__, __LINE__ );
- exit(-2);
+ Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initialise mapping from file %s, aborting", fMapperPtr->GetFilePath());
+ return -4;
}
return iResult;
}
+
+
+AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::RawDataWriter() : //fIsFirstChannel(true),
+ fRawDataBuffer(0),
+ fCurrentChannelSize(0),
+ // fIsFirstChannel(true),
+ fBufferIndex(0),
+ fBufferSize( NZROWSRCU*NXCOLUMNSRCU*ALTROMAXSAMPLES*NGAINS +1000 ),
+ fCurrentChannelIdPtr(0),
+ fCurrentChannelSizePtr(0),
+ fCurrentChannelDataPtr(0),
+ fTotalSize(0)
+{
+ fRawDataBuffer = new UShort_t[fBufferSize];
+ Init();
+}
+
+
+
+void
+AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::Init()
+{
+ fCurrentChannelIdPtr = fRawDataBuffer;
+ fCurrentChannelSizePtr = fRawDataBuffer +1;
+ fCurrentChannelDataPtr = fRawDataBuffer +2;
+ ResetBuffer();
+}
+
+
+void
+AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::NewEvent()
+{
+ Init();
+ fTotalSize = 0;
+}
+
+
+void
+AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
+{
+ *fCurrentChannelSizePtr = fCurrentChannelSize;
+ fCurrentChannelIdPtr += fCurrentChannelSize;
+ fCurrentChannelSizePtr += fCurrentChannelSize;
+ fCurrentChannelDataPtr += fCurrentChannelSize;
+ fBufferIndex = 0;
+ fCurrentChannelSize = 2;
+ fTotalSize += 2;
+}
+
+
+void
+AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
+{
+ fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
+ fCurrentChannelSize ++;
+ fBufferIndex++;
+ fCurrentChannelDataPtr[fBufferIndex] = length;
+ fCurrentChannelSize ++;
+ fBufferIndex++;
+
+ fTotalSize +=2;
+
+ for(int i=0; i < length; i++)
+ {
+ fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
+ }
+
+ fCurrentChannelSize += length;
+ fTotalSize += length;
+ fBufferIndex += length;
+}
+
+
+void
+AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
+{
+ *fCurrentChannelIdPtr = channeldid;
+}
+
+
+void
+AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
+{
+ for(int i=0; i < fBufferSize ; i++ )
+ {
+ fRawDataBuffer[i] = 0;
+ }
+}
+
+
+int
+AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
+{
+ int sizerequested = (sizeof(int)*fTotalSize + sizeused);
+
+ if( sizerequested > sizetotal )
+ {
+ return 0;
+ }
+ else
+ {
+ for(int i=0; i < fTotalSize; i++)
+ {
+ memPtr[i] = fRawDataBuffer[i];
+ }
+ return fTotalSize;
+ }
+}
+
* @file AliHLTPHOSRawAnalyzerComponentv3.h
* @author Oystein Djuvsland
* @date
- * @brief A raw analyzer component for PHOS HLT
+ * @brief A clusterizer component for PHOS HLT
*/
// see below for class documentation
/**
* @class AliHLTPHOSRawAnalyzerComponentv3
+ * This the new and fast version of the component taking care of the decoding and energy and timing
+ * extraction of the raw data from PHOS.
+ *
+ * <h2>General properties:</h2>
+ *
+ * Component ID: \b PhosRawAnalyzerv3 <br>
+ * Library: \b libAliHLTPHOS.so <br>
+ * Input Data Types: @ref <br>
+ * Output Data Types: @ref AliHLTPHOSDefinitions::fgkChannelDataType<br>
+ *
+ * <h2>Mandatory arguments:</h2>
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
+ * \li No mandatory arguments for component <br>
+ *
+ * <h2>Optional arguments:</h2>
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
+ * \li -offset <i> value </i> <br>
+ * gives the offset added to the data during zero suppression (default value: 0)
+ * \li -bunchsizecut <i> value </i> <br>
+ * minimum number of samples a bunch must contain to be considered (default value: 0)
+ * \li -minpeakposition <i> value </i> <br>
+ * cut on minimum postion of the peak in the bunch (defaul value: 0)
+ * \li -maxpeakposition <i> value </i> <br>
+ * cut on maximum postion of the peak in the bunch (defaul value: 100)
+ *
+ * <h2>Configuration:</h2>
+ * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
+ * \li No configuration arguments
+ *
+ * <h2>Default CDB entries:</h2>
+ * \li No CDB entry yet, will come.
+ *
+ * <h2>Performance:</h2>
+ * Pretty good (~ 3 kHz), depends on amount of data...
+ *
+ * <h2>Memory consumption:</h2>
+ * Depends on the amount of data, but pretty godd
+ *
+ * <h2>Output size:</h2>
+ * Depends on the amount of data...
+ *
+ * More detailed description. (Soon)
+ *
* @ingroup alihlt_phos
*/
protected:
+ /** interface function, see @ref AliHLTComponent for description */
+ using AliHLTPHOSRcuProcessor::DoEvent;
+
+ /** interface function, see @ref AliHLTComponent for description */
+ virtual int DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
+ AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
+ AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks );
+
/**
- * Check for correct input data type (raw data from PHOS)
- * @datatype is the data type specifier
- * @return true if the data type is correct
+ * Do the real processing in the component
+ * @param iter is the pointer to the data blocks
+ * @param outputPtr is the pointer to the output buffer
+ * @param size is the available size for output
+ * @param totSize is the total size used for output
+ * @return the size output size used
*/
- virtual bool CheckInputDataType(const AliHLTComponentDataType &datatype);
+ virtual Int_t DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize);
+
+
+ /** Pointer to an analyzer object used for raw data anlysis */
+ AliHLTPHOSRawAnalyzer *fAnalyzerPtr; //COMMENT
private:
+ int WriteRawData( AliHLTPHOSChannelDataStruct *dtaPtr );
+
/** Keep the copy constructor private since it should not be used */
AliHLTPHOSRawAnalyzerComponentv3(const AliHLTPHOSRawAnalyzerComponentv3 & );
/** Keep the assignement operator private since it should not be used */
AliHLTPHOSRawAnalyzerComponentv3 & operator = (const AliHLTPHOSRawAnalyzerComponentv3 &);
+
+ /** Mapping from harware address to geometrical address */
+ AliHLTPHOSMapper *fMapperPtr; //!transient
+
+ /** Pointer to object which may check the integrity of the data */
+ AliHLTPHOSSanityInspector *fSanityInspectorPtr; //!transient
+
+ /** Pointer to the raw data reader which reads from memory */
+ AliRawReaderMemory* fRawReaderMemoryPtr; //!transient
- /**
- * Initialise the mapping according to the specification
- * @specification is the specification provided by the HLT framework
- */
- virtual void InitMapping(const int specification);
+ /** Pointer to the raw stream */
+ AliAltroRawStreamV3* fAltroRawStreamPtr; //!transient
+
+ /** Describing which algorithm we are using */
+ Short_t fAlgorithm; //COMMENT
+ /** The offset applied before ZS */
+ Int_t fOffset; //COMMENT
+
+ /** The minimum length a bunch can have to be considered */
+ Int_t fBunchSizeCut; //COMMENT
+
+ /** The lowest position a peak can have to be considered */
+ Int_t fMinPeakPosition; //COMMENT
+
+ /** The maximum position a peak can have to be considered */
+ Int_t fMaxPeakPosition; //COMMENT
+
+
+ const bool fkDoPushRawData;
+
+ // const UShort_t* fRawDataBuffer;
+ // RawDataWriter *fRawDataWriter;
+
+ // class RawDataWriter : public AliHLTLogging
+
+ class RawDataWriter
+ {
+ public:
+ RawDataWriter();
+ ~RawDataWriter();
+ // void WriteChannelId(const UShort_t channeldid );
+ void NewChannel( );
+ void WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin );
+ void ResetBuffer();
+ void SetChannelId( const UShort_t channeldid );
+
+ //void CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused );
+ int CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused );
+
+ void NewEvent();
+
+ private:
+ RawDataWriter (const RawDataWriter & );
+ RawDataWriter & operator = (const RawDataWriter &);
+
+ void Init();
+
+ // bool fIsFirstChannel;
+ UShort_t* fRawDataBuffer;
+ int fCurrentChannelSize;
+ int fBufferIndex;
+ int fBufferSize;
+ UShort_t *fCurrentChannelIdPtr;
+ UShort_t *fCurrentChannelSizePtr;
+ UShort_t *fCurrentChannelDataPtr;
+ int fTotalSize;
+ };
+
+ RawDataWriter *fRawDataWriter;
};