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 **************************************************************************/
18 #include "AliCaloRawAnalyzer.h"
19 #include "AliCaloBunchInfo.h"
20 #include "AliCaloFitResults.h"
21 #include "AliHLTCaloRawAnalyzerComponentv3.h"
22 #include "AliHLTCaloChannelDataHeaderStruct.h"
23 #include "AliHLTCaloChannelDataStruct.h"
24 #include "AliHLTCaloMapper.h"
25 #include "AliHLTCaloSanityInspector.h"
26 #include "AliRawReaderMemory.h"
27 #include "AliCaloRawStreamV3.h"
28 #include "AliHLTCaloConstantsHandler.h"
29 #include "AliHLTCaloChannelRawDataStruct.h"
31 #include "TStopwatch.h"
37 ClassImp(AliHLTCaloRawAnalyzerComponentv3);
41 AliHLTCaloRawAnalyzerComponentv3::AliHLTCaloRawAnalyzerComponentv3(TString det):AliHLTCaloProcessor(),
42 AliHLTCaloConstantsHandler(det),
47 fSanityInspectorPtr(0),
48 fRawReaderMemoryPtr(0),
49 fAltroRawStreamPtr(0),
54 fMaxPeakPosition(100),
55 fDoPushBadRawData(false),
56 fDoPushRawData(false),
61 fSanityInspectorPtr = new AliHLTCaloSanityInspector();
63 if( fDoPushRawData == true )
65 fRawDataWriter = new RawDataWriter(fCaloConstants);
67 fRawReaderMemoryPtr = new AliRawReaderMemory();
68 fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, det);
72 AliHLTCaloRawAnalyzerComponentv3::~AliHLTCaloRawAnalyzerComponentv3()
75 delete fRawReaderMemoryPtr;
76 delete fAltroRawStreamPtr;
77 delete fRawDataWriter;
78 delete fSanityInspectorPtr;
83 AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
85 //See base class for documentation
88 for(int i = 0; i < argc; i++)
90 if(!strcmp("-offset", argv[i]))
92 fOffset = atoi(argv[i+1]);
94 if(!strcmp("-bunchsizecut", argv[i]))
96 fBunchSizeCut = atoi(argv[i+1]);
98 if(!strcmp("-minpeakposition", argv[i]))
100 fMinPeakPosition = atoi(argv[i+1]);
102 if(!strcmp("-maxpeakposition", argv[i]))
104 fMaxPeakPosition = atoi(argv[i+1]);
106 if(!strcmp("-pushrawdata", argv[i]))
108 fDoPushRawData = true;
110 if(!strcmp("-pushbaddata", argv[i]))
112 fDoPushBadRawData = true;
114 if(fDoPushBadRawData && fDoPushRawData)
116 HLTWarning("fDoPushBadRawData and fDoPushRawData in conflict, using fDoPushRawData");
117 fDoPushBadRawData = false;
119 if(!strcmp("-suppressalilogwarnings", argv[i]))
121 AliLog::SetGlobalLogLevel(AliLog::kError); //PHOS sometimes produces bad data -> Fill up the HLT logs...
130 AliHLTCaloRawAnalyzerComponentv3::DoDeinit()
133 if(fAltroRawStreamPtr)
135 delete fAltroRawStreamPtr;
136 fAltroRawStreamPtr = 0;
144 AliHLTCaloRawAnalyzerComponentv3::PrintDebugInfo()
147 static TStopwatch watch; //CRAP PTH
148 static double wlast = -1;
149 static double wcurrent = 0;
153 if( fCaloEventCount %1000 == 0 )
155 cout << __FILE__ << __LINE__ << " : Processing event " << fCaloEventCount << endl;
157 wcurrent = watch.RealTime();
158 cout << __FILE__ << __LINE__ << "The event rate is " <<
159 1000/( wcurrent - wlast ) << " Hz" << endl; watch.Start(kFALSE);
166 AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
169 constBase = sizeof(AliHLTCaloChannelDataHeaderStruct);
170 inputMultiplier = 1.5;
175 AliHLTCaloRawAnalyzerComponentv3::CheckInputDataType(const AliHLTComponentDataType &datatype)
178 vector <AliHLTComponentDataType> validTypes;
179 GetInputDataTypes(validTypes);
181 for(UInt_t i=0; i < validTypes.size(); i++ )
183 if ( datatype == validTypes.at(i) )
189 HLTDebug("Invalid Datatype");
195 AliHLTCaloRawAnalyzerComponentv3::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
196 AliHLTComponentTriggerData& /*trigData*/,
197 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
209 Int_t blockSize = -1;
211 const AliHLTComponentBlockData* iter = NULL;
214 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
217 if( ! CheckInputDataType(iter->fDataType) )
222 if(iter->fSpecification != fCurrentSpec)
224 fCurrentSpec = iter->fSpecification;
225 InitMapping(iter->fSpecification);
228 blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
229 totSize += blockSize; //Keeping track of the used size
230 AliHLTComponentBlockData bdChannelData;
231 FillBlockData( bdChannelData );
232 bdChannelData.fOffset = 0; //FIXME
233 bdChannelData.fSize = blockSize;
234 bdChannelData.fDataType = GetOutputDataType();
235 bdChannelData.fSpecification = iter->fSpecification;
236 outputBlocks.push_back(bdChannelData);
237 outputPtr += blockSize; //Updating position of the output buffer
241 size = totSize; //telling the framework how much buffer space we have used.
250 AliHLTCaloRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
256 Short_t channelCount = 0;
258 AliHLTCaloChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(outputPtr);
259 AliHLTCaloChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(outputPtr+sizeof(AliHLTCaloChannelDataHeaderStruct));
260 totSize += sizeof( AliHLTCaloChannelDataHeaderStruct );
261 fRawReaderMemoryPtr->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), static_cast<ULong_t>( iter->fSize ) );
262 fRawReaderMemoryPtr->SetEquipmentID( fMapperPtr->GetDDLFromSpec( iter->fSpecification) + fCaloConstants->GetDDLOFFSET() );
263 fRawReaderMemoryPtr->Reset();
264 fRawReaderMemoryPtr->NextEvent();
266 if( fDoPushRawData == true)
268 fRawDataWriter->NewEvent( );
271 if(fAltroRawStreamPtr->NextDDL())
275 while( fAltroRawStreamPtr->NextChannel() )
277 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
284 //UShort_t* firstBunchPtr = 0;
285 int chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
287 if( fDoPushRawData == true)
289 fRawDataWriter->SetChannelId( chId );
292 vector <AliCaloBunchInfo> bvctr;
293 while( fAltroRawStreamPtr->NextBunch() == true )
295 bvctr.push_back( AliCaloBunchInfo( fAltroRawStreamPtr->GetStartTimeBin(),
296 fAltroRawStreamPtr->GetBunchLength(),
297 fAltroRawStreamPtr->GetSignals() ) );
299 nSamples = fAltroRawStreamPtr->GetBunchLength();
300 if( fDoPushRawData == true)
302 fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(),
303 nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
305 //firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
308 totSize += sizeof( AliHLTCaloChannelDataStruct );
311 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
315 AliCaloFitResults res = fAnalyzerPtr->Evaluate( bvctr, fAltroRawStreamPtr->GetAltroCFG1(),
316 fAltroRawStreamPtr->GetAltroCFG2() );
318 HLTDebug("Channel energy: %f, max sig: %d, gain = %d, x = %d, z = %d", res.GetAmp(), res.GetMaxSig(),
319 (chId >> 12)&0x1, chId&0x3f, (chId >> 6)&0x3f);
321 channelDataPtr->fChannelID = chId;
322 channelDataPtr->fEnergy = static_cast<Float_t>( res.GetAmp() ) - fOffset;
323 channelDataPtr->fTime = static_cast<Float_t>( res.GetTof() );
324 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
326 channelDataPtr++; // Updating position of the free output.
330 if( fDoPushRawData == true)
332 fRawDataWriter->NewChannel();
337 channelDataHeaderPtr->fNChannels = channelCount;
338 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
339 channelDataHeaderPtr->fInfo = 0;
341 if( fDoPushRawData == true)
343 tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
346 channelDataHeaderPtr->fHasRawData = fDoPushRawData;
347 HLTDebug("Number of channels: %d", channelCount);
348 tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct);
355 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter(AliHLTCaloConstants* cConst) :
357 fCurrentChannelSize(0),
359 fBufferSize( 64*56*cConst->GetNGAINS()*cConst->GetALTROMAXSAMPLES() +1000 ),
360 fCurrentChannelIdPtr(0),
361 fCurrentChannelSizePtr(0),
362 fCurrentChannelDataPtr(0),
366 fRawDataBuffer = new UShort_t[fBufferSize];
371 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::~RawDataWriter()
373 delete [] fRawDataBuffer;
378 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
381 fCurrentChannelIdPtr = fRawDataBuffer;
382 fCurrentChannelSizePtr = fRawDataBuffer +1;
383 fCurrentChannelDataPtr = fRawDataBuffer +2;
389 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
398 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
401 *fCurrentChannelSizePtr = fCurrentChannelSize;
402 fCurrentChannelIdPtr += fCurrentChannelSize;
403 fCurrentChannelSizePtr += fCurrentChannelSize;
404 fCurrentChannelDataPtr += fCurrentChannelSize;
406 fCurrentChannelSize = 2;
412 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
414 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
415 fCurrentChannelSize ++;
417 fCurrentChannelDataPtr[fBufferIndex] = length;
418 fCurrentChannelSize ++;
423 for(int i=0; i < length; i++)
425 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
428 fCurrentChannelSize += length;
429 fTotalSize += length;
430 fBufferIndex += length;
435 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
437 *fCurrentChannelIdPtr = channeldid;
442 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
444 for(int i=0; i < fBufferSize ; i++ )
446 fRawDataBuffer[i] = 0;
452 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
454 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
456 if( sizerequested > sizetotal )
462 for(int i=0; i < fTotalSize; i++)
464 memPtr[i] = fRawDataBuffer[i];