2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * All rights reserved. *
6 * Primary Authors: Per Thomas Hille, Oystein Djuvsland *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
17 #include "AliHLTPHOSRawAnalyzer.h"
18 #include "AliHLTPHOSRawAnalyzerComponentv3.h"
19 #include "AliHLTPHOSChannelDataHeaderStruct.h"
20 #include "AliHLTPHOSChannelDataStruct.h"
21 #include "AliHLTPHOSMapper.h"
22 #include "AliHLTPHOSSanityInspector.h"
24 #include "AliAltroRawStreamV3.h"
25 #include "AliCaloRawStreamV3.h"
26 #include "AliRawReaderMemory.h"
29 #include "AliHLTPHOSUtilities.h"
31 AliHLTPHOSRawAnalyzerComponentv3::AliHLTPHOSRawAnalyzerComponentv3():
32 AliHLTPHOSRcuProcessor(),
35 fSanityInspectorPtr(0),
36 fRawReaderMemoryPtr(0),
37 fAltroRawStreamPtr(0),
42 fMaxPeakPosition(100),
43 fDoPushRawData(false),
44 fInspectSanity(false),
48 fMapperPtr = new AliHLTPHOSMapper();
50 fRawReaderMemoryPtr = new AliRawReaderMemory();
52 fAltroRawStreamPtr = new AliAltroRawStreamV3(fRawReaderMemoryPtr);
53 // fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, TString("PHOS"));
54 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
56 if( fDoPushRawData == true )
59 fRawDataWriter = new AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter();
66 AliHLTPHOSRawAnalyzerComponentv3::~AliHLTPHOSRawAnalyzerComponentv3()
73 AliHLTPHOSRawAnalyzerComponentv3::Deinit()
86 if(fRawReaderMemoryPtr)
88 delete fRawReaderMemoryPtr;
89 fRawReaderMemoryPtr = 0;
91 if(fAltroRawStreamPtr)
93 delete fAltroRawStreamPtr;
94 fAltroRawStreamPtr = 0;
100 AliHLTPHOSRawAnalyzerComponentv3::GetComponentID()
103 return "PhosRawAnalyzerv3";
108 AliHLTPHOSRawAnalyzerComponentv3::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
112 list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS );
115 AliHLTComponentDataType
116 AliHLTPHOSRawAnalyzerComponentv3::GetOutputDataType()
119 return AliHLTPHOSDefinitions::fgkChannelDataType;
123 AliHLTPHOSRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
126 constBase = sizeof(AliHLTPHOSChannelDataHeaderStruct);
127 inputMultiplier = 0.5;
131 AliHLTPHOSRawAnalyzerComponentv3::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
132 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
138 const AliHLTComponentBlockData* iter = NULL;
141 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
144 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
146 HLTDebug("Data block is not of type fgkDDLPackedRawDataType");
150 blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
152 if(blockSize == -1) // If the processing returns -1 we are out of buffer and return an error msg.
157 totSize += blockSize; //Keeping track of the used size
158 // HLTDebug("Output data size: %d - Input data size: %d", totSize, iter->fSize);
160 //Filling the block data
161 AliHLTComponentBlockData bdChannelData;
162 FillBlockData( bdChannelData );
163 bdChannelData.fOffset = 0; //FIXME
164 bdChannelData.fSize = blockSize;
165 bdChannelData.fDataType = AliHLTPHOSDefinitions::fgkChannelDataType;
166 bdChannelData.fSpecification = iter->fSpecification;
167 outputBlocks.push_back(bdChannelData);
169 outputPtr += blockSize; //Updating position of the output buffer
173 size = totSize; //telling the framework how much buffer space we have used.
179 AliHLTPHOSRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
185 Short_t channelCount = 0;
187 // Firs we want to write a header to the output
188 AliHLTPHOSChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(outputPtr);
190 // Then comes the channel data
191 AliHLTPHOSChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTPHOSChannelDataStruct*>(outputPtr+sizeof(AliHLTPHOSChannelDataHeaderStruct));
192 //Adding to the total size of data written
193 totSize += sizeof( AliHLTPHOSChannelDataHeaderStruct );
195 fRawReaderMemoryPtr->SetMemory(reinterpret_cast<UChar_t*>(iter->fPtr), static_cast<ULong_t>(iter->fSize));
196 fRawReaderMemoryPtr->SetEquipmentID(fMapperPtr->GetDDLFromSpec(iter->fSpecification) + 1792);
197 fRawReaderMemoryPtr->Reset();
198 fRawReaderMemoryPtr->NextEvent();
200 // if( fDoPushRawData == true)
202 // fRawDataWriter->NewEvent( );
204 if(fAltroRawStreamPtr != NULL)
206 delete fAltroRawStreamPtr;
207 fAltroRawStreamPtr=NULL;
210 // fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, TString("PHOS"));
211 fAltroRawStreamPtr = new AliAltroRawStreamV3(fRawReaderMemoryPtr);
213 if(fAltroRawStreamPtr->NextDDL())
216 while( fAltroRawStreamPtr->NextChannel() )
219 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
226 UShort_t* firstBunchPtr = 0;
227 UShort_t chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
229 // if( fDoPushRawData == true)
231 // fRawDataWriter->SetChannelId( chId );
233 while( fAltroRawStreamPtr->NextBunch() == true )
235 nSamples = fAltroRawStreamPtr->GetBunchLength();
237 // if( fDoPushRawData == true)
239 // fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
241 firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
245 totSize += sizeof( AliHLTPHOSChannelDataStruct );
248 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
251 // if(fInspectSanity)
253 // crazyness = fSanityInspectorPtr->CheckAndHealInsanity(firstBunchPtr, nSamples);
256 fAnalyzerPtr->SetData( firstBunchPtr, nSamples);
257 fAnalyzerPtr->Evaluate(0, nSamples);
259 channelDataPtr->fChannelID = chId;
260 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
262 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
263 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
265 channelDataPtr++; // Updating position of the free output.
268 // if(fDoPushRawData)
270 // fRawDataWriter->NewChannel();
276 channelDataHeaderPtr->fNChannels = channelCount;
277 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
278 channelDataHeaderPtr->fInfo = 0;
280 // if( fDoPushRawData == true)
282 // tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
285 // channelDataHeaderPtr->fHasRawData = false;
286 channelDataHeaderPtr->fHasRawData = fDoPushRawData;
288 HLTDebug("Number of channels: %d", channelCount);
289 //returning the size used
290 // delete fAltroRawStreamPtr;
291 tmpsize += sizeof(AliHLTPHOSChannelDataStruct)*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
293 // return sizeof(AliHLTPHOSChannelDataStruct)*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
300 AliHLTPHOSRawAnalyzerComponentv3::WriteRawData(AliHLTPHOSChannelDataStruct*) //dtaPtr)
306 AliHLTPHOSRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
309 //See base class for documentation
310 // fPrintInfo = kFALSE;
312 fMapperPtr = new AliHLTPHOSMapper();
314 for(int i = 0; i < argc; i++)
316 if(!strcmp("-bunchsizecut", argv[i]))
318 fBunchSizeCut = atoi(argv[i+1]);
320 if(!strcmp("-minpeakposition", argv[i]))
322 fMinPeakPosition = atoi(argv[i+1]);
324 if(!strcmp("-maxpeakposition", argv[i]))
326 fMaxPeakPosition = atoi(argv[i+1]);
328 if(!strcmp("-pushrawdata", argv[i]))
330 fDoPushRawData = true;
332 if(!strcmp("-inspectsanity", argv[i]))
334 fInspectSanity = true;
338 if(fMapperPtr->GetIsInitializedMapping() == false)
340 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initialise mapping from file %s, aborting", fMapperPtr->GetFilePath());
350 AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::RawDataWriter() : //fIsFirstChannel(true),
352 fCurrentChannelSize(0),
353 // fIsFirstChannel(true),
355 fBufferSize( NZROWSRCU*NXCOLUMNSRCU*ALTROMAXSAMPLES*NGAINS +1000 ),
356 fCurrentChannelIdPtr(0),
357 fCurrentChannelSizePtr(0),
358 fCurrentChannelDataPtr(0),
361 fRawDataBuffer = new UShort_t[fBufferSize];
368 AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::Init()
370 fCurrentChannelIdPtr = fRawDataBuffer;
371 fCurrentChannelSizePtr = fRawDataBuffer +1;
372 fCurrentChannelDataPtr = fRawDataBuffer +2;
378 AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::NewEvent()
386 AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
388 *fCurrentChannelSizePtr = fCurrentChannelSize;
389 fCurrentChannelIdPtr += fCurrentChannelSize;
390 fCurrentChannelSizePtr += fCurrentChannelSize;
391 fCurrentChannelDataPtr += fCurrentChannelSize;
393 fCurrentChannelSize = 2;
399 AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
401 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
402 fCurrentChannelSize ++;
404 fCurrentChannelDataPtr[fBufferIndex] = length;
405 fCurrentChannelSize ++;
410 for(int i=0; i < length; i++)
412 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
415 fCurrentChannelSize += length;
416 fTotalSize += length;
417 fBufferIndex += length;
422 AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
424 *fCurrentChannelIdPtr = channeldid;
429 AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
431 for(int i=0; i < fBufferSize ; i++ )
433 fRawDataBuffer[i] = 0;
439 AliHLTPHOSRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
441 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
443 if( sizerequested > sizetotal )
449 for(int i=0; i < fTotalSize; i++)
451 memPtr[i] = fRawDataBuffer[i];