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 "AliHLTCaloRawAnalyzer.h"
18 #include "AliHLTCaloRawAnalyzerComponentv3.h"
19 #include "AliHLTCaloChannelDataHeaderStruct.h"
20 #include "AliHLTCaloChannelDataStruct.h"
21 #include "AliHLTCaloMapper.h"
22 #include "AliHLTCaloSanityInspector.h"
23 #include "AliAltroRawStreamV3.h"
24 #include "AliRawReaderMemory.h"
25 #include "AliAltroRawStreamV3.h"
26 #include "AliCaloRawStreamV3.h"
28 AliHLTCaloRawAnalyzerComponentv3::AliHLTCaloRawAnalyzerComponentv3():
32 fkDoPushRawData(true),
34 fSanityInspectorPtr(0),
35 fRawReaderMemoryPtr(0),
36 fAltroRawStreamPtr(0),
41 fMaxPeakPosition(100),
46 // fMapperPtr = new AliHLTCaloMapper();
48 fRawReaderMemoryPtr = new AliRawReaderMemory();
50 fAltroRawStreamPtr = new AliAltroRawStreamV3(fRawReaderMemoryPtr);
52 fSanityInspectorPtr = new AliHLTCaloSanityInspector();
54 if( fkDoPushRawData == true )
56 fRawDataWriter = new RawDataWriter();
61 AliHLTCaloRawAnalyzerComponentv3::~AliHLTCaloRawAnalyzerComponentv3()
70 AliHLTCaloRawAnalyzerComponentv3::Deinit()
83 if(fRawReaderMemoryPtr)
85 delete fRawReaderMemoryPtr;
86 fRawReaderMemoryPtr = 0;
88 if(fAltroRawStreamPtr)
90 delete fAltroRawStreamPtr;
91 fAltroRawStreamPtr = 0;
98 AliHLTCaloRawAnalyzerComponentv3::GetComponentID()
101 return "CaloRawAnalyzerv3";
108 AliHLTCaloRawAnalyzerComponentv3::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
112 list.push_back( AliHLTCaloDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
116 AliHLTComponentDataType
117 AliHLTCaloRawAnalyzerComponentv3::GetOutputDataType()
120 return AliHLTCaloDefinitions::fgkChannelDataType;
124 AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
127 constBase = sizeof(AliHLTCaloChannelDataHeaderStruct);
128 inputMultiplier = 0.5;
132 AliHLTCaloRawAnalyzerComponentv3::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
133 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
137 const AliHLTComponentBlockData* iter = NULL;
139 // cout << __FILE__ << ":" << __LINE__ << "TP0" << endl;
140 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
142 // cout << __FILE__ << ":" << __LINE__ << "TP1" << endl;
144 if( CheckInputDataType( iter->fDataType ) == false )
146 // cout << __FILE__ << ":" << __LINE__ << ": wrong !! datatype" << endl;
147 // cout << "The datatype recieved was" << endl;
148 // cout << "the datatype is " << iter->fDataType.fID << ":" << iter->fDataType.fOrigin << endl;
153 // cout << __FILE__ << ":" << __LINE__ << ":" << "data is of type fgkDDLPackedRawDataType, continue processing " << endl;
154 // cout << "the datatype is " << iter->fDataType.fID << ":" << iter->fDataType.fOrigin << endl;
155 // cout << __FILE__ << ":" << __LINE__ << "T10" << endl;
156 InitMapping( iter->fSpecification);
157 // cout << __FILE__ << ":" << __LINE__ << "TP2" << endl;
158 blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
159 if(blockSize == -1) // If the processing returns -1 we are out of buffer and return an error msg.
164 totSize += blockSize; //Keeping track of the used size
165 // HLTDebug("Output data size: %d - Input data size: %d", totSize, iter->fSize);
166 //Filling the block data
167 AliHLTComponentBlockData bdChannelData;
168 FillBlockData( bdChannelData );
169 bdChannelData.fOffset = 0; //FIXME
170 bdChannelData.fSize = blockSize;
172 // bdChannelData.fDataType = AliHLTPHOSDefinitions::fgkChannelDataType;
173 bdChannelData.fDataType = AliHLTCaloDefinitions::fgkChannelDataType;
175 bdChannelData.fSpecification = iter->fSpecification;
176 outputBlocks.push_back(bdChannelData);
177 outputPtr += blockSize; //Updating position of the output buffer
181 size = totSize; //telling the framework how much buffer space we have used.
190 AliHLTCaloRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
192 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T0" << endl;
198 Short_t channelCount = 0;
200 // Firs we want to write a header to the output
201 AliHLTCaloChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(outputPtr);
202 AliHLTCaloChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(outputPtr+sizeof(AliHLTCaloChannelDataHeaderStruct));
203 //Adding to the total size of data written
204 totSize += sizeof( AliHLTCaloChannelDataHeaderStruct );
205 fRawReaderMemoryPtr->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), static_cast<ULong_t>( iter->fSize ) );
206 fRawReaderMemoryPtr->SetEquipmentID( fMapperPtr->GetDDLFromSpec( iter->fSpecification) + 4608 );
207 fRawReaderMemoryPtr->Reset();
208 fRawReaderMemoryPtr->NextEvent();
209 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T1" << endl;
210 if( fkDoPushRawData == true)
212 fRawDataWriter->NewEvent( );
214 if(fAltroRawStreamPtr != NULL)
216 delete fAltroRawStreamPtr;
217 fAltroRawStreamPtr=NULL;
221 // fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, TString("PHOS"));
223 fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, TString("EMCAL"));
224 // while( fAltroRawStreamPtr->NextDDL() )
225 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T2" << endl;
226 fAltroRawStreamPtr->NextDDL();
229 while( fAltroRawStreamPtr->NextChannel() )
231 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T3" << endl;
232 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
239 UShort_t* firstBunchPtr;
241 // UShort_t chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
242 UInt_t chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
244 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T4" << endl;
246 if( fkDoPushRawData == true)
248 fRawDataWriter->SetChannelId( chId );
250 while( fAltroRawStreamPtr->NextBunch() == true )
252 nSamples = fAltroRawStreamPtr->GetBunchLength();
254 if( fkDoPushRawData == true)
256 // fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetStartTimeBin() );
257 fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
259 firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
261 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T5" << endl;
262 totSize += sizeof( AliHLTCaloChannelDataStruct );
265 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
271 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T6" << endl;
272 fAnalyzerPtr->SetData( firstBunchPtr, nSamples);
273 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T6.1" << endl;
274 fAnalyzerPtr->Evaluate(0, nSamples);
275 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T6.2" << endl;
277 // if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition)
279 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T7" << endl;
280 channelDataPtr->fChannelID = chId;
281 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
282 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T8" << endl;
284 if( channelDataPtr->fEnergy > 70 )
286 // cout << __FILE__ << __LINE__ << "The energy is of channel "<< chId << " is " << channelDataPtr->fEnergy << endl;
289 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
290 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
292 channelDataPtr++; // Updating position of the free output.
295 fRawDataWriter->NewChannel();
300 channelDataHeaderPtr->fNChannels = channelCount;
301 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
302 channelDataHeaderPtr->fInfo = 0;
304 if( fkDoPushRawData == true)
306 tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
309 // channelDataHeaderPtr->fHasRawData = false;
310 channelDataHeaderPtr->fHasRawData = fkDoPushRawData;
312 HLTDebug("Number of channels: %d", channelCount);
313 //returning the size used
314 // delete fAltroRawStreamPtr;
315 tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct);
317 // return sizeof(AliHLTPHOSChannelDataStruct)*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
323 AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
326 //See base class for documentation
327 // fPrintInfo = kFALSE;
331 // fMapperPtr = new AliHLTCaloMapper();
335 for(int i = 0; i < argc; i++)
337 if(!strcmp("-offset", argv[i]))
339 fOffset = atoi(argv[i+1]);
341 if(!strcmp("-bunchsizecut", argv[i]))
343 fBunchSizeCut = atoi(argv[i+1]);
345 if(!strcmp("-minpeakposition", argv[i]))
347 fMinPeakPosition = atoi(argv[i+1]);
349 if(!strcmp("-maxpeakposition", argv[i]))
351 fMaxPeakPosition = atoi(argv[i+1]);
356 if( fMapperPtr->GetIsInitializedMapping() == false)
358 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTCaloMapper::Could not initialise mapping from file %s, aborting", fMapperPtr->GetFilePath());
369 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter() : //fIsFirstChannel(true),
371 fCurrentChannelSize(0),
372 // fIsFirstChannel(true),
374 // fBufferSize( NZROWSRCU*NXCOLUMNSRCU*ALTROMAXSAMPLES*NGAINS +1000 ),
375 fBufferSize( 64*56*ALTROMAXSAMPLES*NGAINS +1000 ),
376 fCurrentChannelIdPtr(0),
377 fCurrentChannelSizePtr(0),
378 fCurrentChannelDataPtr(0),
381 fRawDataBuffer = new UShort_t[fBufferSize];
388 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
390 fCurrentChannelIdPtr = fRawDataBuffer;
391 fCurrentChannelSizePtr = fRawDataBuffer +1;
392 fCurrentChannelDataPtr = fRawDataBuffer +2;
398 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
406 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
408 *fCurrentChannelSizePtr = fCurrentChannelSize;
409 fCurrentChannelIdPtr += fCurrentChannelSize;
410 fCurrentChannelSizePtr += fCurrentChannelSize;
411 fCurrentChannelDataPtr += fCurrentChannelSize;
413 fCurrentChannelSize = 2;
419 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
421 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
422 fCurrentChannelSize ++;
424 fCurrentChannelDataPtr[fBufferIndex] = length;
425 fCurrentChannelSize ++;
430 for(int i=0; i < length; i++)
432 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
435 fCurrentChannelSize += length;
436 fTotalSize += length;
437 fBufferIndex += length;
442 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
444 *fCurrentChannelIdPtr = channeldid;
449 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
451 for(int i=0; i < fBufferSize ; i++ )
453 fRawDataBuffer[i] = 0;
459 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
461 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
463 if( sizerequested > sizetotal )
469 for(int i=0; i < fTotalSize; i++)
471 memPtr[i] = fRawDataBuffer[i];