3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
7 * Primary Authors: Per Thomas Hille, Oystein Djuvsland *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
19 #include "AliCaloRawAnalyzer.h"
20 #include "AliCaloBunchInfo.h"
21 #include "AliCaloFitResults.h"
22 #include "AliHLTCaloRawAnalyzerComponentv3.h"
23 #include "AliHLTCaloChannelDataHeaderStruct.h"
24 #include "AliHLTCaloChannelDataStruct.h"
25 #include "AliHLTCaloMapper.h"
26 #include "AliHLTCaloSanityInspector.h"
27 #include "AliRawReaderMemory.h"
28 #include "AliCaloRawStreamV3.h"
29 #include "AliHLTCaloConstantsHandler.h"
30 #include "AliHLTCaloChannelRawDataStruct.h"
32 #include "TStopwatch.h"
34 #include "AliCaloRawAnalyzerFactory.h"
36 //#include "AliCaloConstants.h"
38 //#include "AliCaloRawAnalyzer.h"
40 //using namespace Algo;
45 ClassImp(AliHLTCaloRawAnalyzerComponentv3);
49 AliHLTCaloRawAnalyzerComponentv3::AliHLTCaloRawAnalyzerComponentv3(TString det, fitAlgorithm algo ):AliHLTCaloProcessor(),
50 AliHLTCaloConstantsHandler(det),
55 fSanityInspectorPtr(0),
56 fRawReaderMemoryPtr(0),
57 fAltroRawStreamPtr(0),
63 fMaxPeakPosition(100),
64 fDoPushBadRawData(false),
65 fDoPushRawData(false),
74 AliHLTCaloRawAnalyzerComponentv3::~AliHLTCaloRawAnalyzerComponentv3()
81 AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
83 //See base class for documentation
86 for(int i = 0; i < argc; i++)
88 if(!strcmp("-offset", argv[i]))
90 fOffset = atoi(argv[i+1]);
92 if(!strcmp("-bunchsizecut", argv[i]))
94 fBunchSizeCut = atoi(argv[i+1]);
96 if(!strcmp("-minpeakposition", argv[i]))
98 fMinPeakPosition = atoi(argv[i+1]);
100 if(!strcmp("-maxpeakposition", argv[i]))
102 fMaxPeakPosition = atoi(argv[i+1]);
104 if(!strcmp("-pushrawdata", argv[i]))
106 fDoPushRawData = true;
108 if(!strcmp("-pushbaddata", argv[i]))
110 fDoPushBadRawData = true;
112 if(fDoPushBadRawData && fDoPushRawData)
114 HLTWarning("fDoPushBadRawData and fDoPushRawData in conflict, using fDoPushRawData");
115 fDoPushBadRawData = false;
117 if(!strcmp("-suppressalilogwarnings", argv[i]))
119 AliLog::SetGlobalLogLevel(AliLog::kError); //PHOS sometimes produces bad data -> Fill up the HLT logs...
123 fAnalyzerPtr = AliCaloRawAnalyzerFactory::CreateAnalyzer(fAlgorithm);
124 fAnalyzerPtr->SetIsZeroSuppressed(true);
125 fSanityInspectorPtr = new AliHLTCaloSanityInspector();
127 if( fDoPushRawData == true )
129 fRawDataWriter = new RawDataWriter(fCaloConstants);
131 fRawReaderMemoryPtr = new AliRawReaderMemory();
132 fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, fDetector);
139 AliHLTCaloRawAnalyzerComponentv3::DoDeinit()
142 if(fAltroRawStreamPtr)
144 delete fAltroRawStreamPtr;
145 fAltroRawStreamPtr = 0;
149 delete fRawReaderMemoryPtr;
150 delete fAltroRawStreamPtr;
151 delete fRawDataWriter;
152 delete fSanityInspectorPtr;
159 AliHLTCaloRawAnalyzerComponentv3::PrintDebugInfo()
162 static TStopwatch watch; //CRAP PTH
163 static double wlast = -1;
164 static double wcurrent = 0;
168 if( fCaloEventCount %1000 == 0 )
170 cout << __FILE__ << __LINE__ << " : Processing event " << fCaloEventCount << endl;
172 wcurrent = watch.RealTime();
173 cout << __FILE__ << __LINE__ << "The event rate is " <<
174 1000/( wcurrent - wlast ) << " Hz" << endl; watch.Start(kFALSE);
181 AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
184 constBase = sizeof(AliHLTCaloChannelDataHeaderStruct);
185 inputMultiplier = 1.5;
190 AliHLTCaloRawAnalyzerComponentv3::CheckInputDataType(const AliHLTComponentDataType &datatype)
193 vector <AliHLTComponentDataType> validTypes;
194 GetInputDataTypes(validTypes);
196 for(UInt_t i=0; i < validTypes.size(); i++ )
198 if ( datatype == validTypes.at(i) )
204 HLTDebug("Invalid Datatype");
210 AliHLTCaloRawAnalyzerComponentv3::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
211 AliHLTComponentTriggerData& /*trigData*/,
212 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
224 Int_t blockSize = -1;
226 const AliHLTComponentBlockData* iter = NULL;
229 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
232 if( ! CheckInputDataType(iter->fDataType) )
237 if(iter->fSpecification != fCurrentSpec)
239 fCurrentSpec = iter->fSpecification;
240 InitMapping(iter->fSpecification);
243 blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
244 totSize += blockSize; //Keeping track of the used size
245 AliHLTComponentBlockData bdChannelData;
246 FillBlockData( bdChannelData );
247 bdChannelData.fOffset = 0; //FIXME
248 bdChannelData.fSize = blockSize;
249 bdChannelData.fDataType = GetOutputDataType();
250 bdChannelData.fSpecification = iter->fSpecification;
251 outputBlocks.push_back(bdChannelData);
252 outputPtr += blockSize; //Updating position of the output buffer
256 size = totSize; //telling the framework how much buffer space we have used.
265 AliHLTCaloRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
271 Short_t channelCount = 0;
273 AliHLTCaloChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(outputPtr);
274 AliHLTCaloChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(outputPtr+sizeof(AliHLTCaloChannelDataHeaderStruct));
275 totSize += sizeof( AliHLTCaloChannelDataHeaderStruct );
276 fRawReaderMemoryPtr->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), static_cast<ULong_t>( iter->fSize ) );
277 fRawReaderMemoryPtr->SetEquipmentID( fMapperPtr->GetDDLFromSpec( iter->fSpecification) + fCaloConstants->GetDDLOFFSET() );
278 fRawReaderMemoryPtr->Reset();
279 fRawReaderMemoryPtr->NextEvent();
281 if( fDoPushRawData == true)
283 fRawDataWriter->NewEvent( );
286 if(fAltroRawStreamPtr->NextDDL())
290 while( fAltroRawStreamPtr->NextChannel() )
292 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
299 //UShort_t* firstBunchPtr = 0;
300 int chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
302 if( fDoPushRawData == true)
304 fRawDataWriter->SetChannelId( chId );
307 vector <AliCaloBunchInfo> bvctr;
308 while( fAltroRawStreamPtr->NextBunch() == true )
310 bvctr.push_back( AliCaloBunchInfo( fAltroRawStreamPtr->GetStartTimeBin(),
311 fAltroRawStreamPtr->GetBunchLength(),
312 fAltroRawStreamPtr->GetSignals() ) );
314 nSamples = fAltroRawStreamPtr->GetBunchLength();
315 if( fDoPushRawData == true)
317 fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(),
318 nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
320 //firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
323 totSize += sizeof( AliHLTCaloChannelDataStruct );
326 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
330 AliCaloFitResults res = fAnalyzerPtr->Evaluate( bvctr, fAltroRawStreamPtr->GetAltroCFG1(),
331 fAltroRawStreamPtr->GetAltroCFG2() );
333 HLTDebug("Channel energy: %f, max sig: %d, gain = %d, x = %d, z = %d", res.GetAmp(), res.GetMaxSig(),
334 (chId >> 12)&0x1, chId&0x3f, (chId >> 6)&0x3f);
336 channelDataPtr->fChannelID = chId;
337 channelDataPtr->fEnergy = static_cast<Float_t>( res.GetAmp() ) - fOffset;
338 channelDataPtr->fTime = static_cast<Float_t>( res.GetTof() );
339 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
341 channelDataPtr++; // Updating position of the free output.
345 if( fDoPushRawData == true)
347 fRawDataWriter->NewChannel();
352 channelDataHeaderPtr->fNChannels = channelCount;
353 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
354 channelDataHeaderPtr->fInfo = 0;
356 if( fDoPushRawData == true)
358 tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
361 channelDataHeaderPtr->fHasRawData = fDoPushRawData;
362 HLTDebug("Number of channels: %d", channelCount);
363 tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct);
370 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter(AliHLTCaloConstants* cConst) :
372 fCurrentChannelSize(0),
374 fBufferSize( 64*56*cConst->GetNGAINS()*cConst->GetALTROMAXSAMPLES() +1000 ),
375 fCurrentChannelIdPtr(0),
376 fCurrentChannelSizePtr(0),
377 fCurrentChannelDataPtr(0),
381 fRawDataBuffer = new UShort_t[fBufferSize];
386 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::~RawDataWriter()
388 delete [] fRawDataBuffer;
393 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
396 fCurrentChannelIdPtr = fRawDataBuffer;
397 fCurrentChannelSizePtr = fRawDataBuffer +1;
398 fCurrentChannelDataPtr = fRawDataBuffer +2;
404 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
413 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
416 *fCurrentChannelSizePtr = fCurrentChannelSize;
417 fCurrentChannelIdPtr += fCurrentChannelSize;
418 fCurrentChannelSizePtr += fCurrentChannelSize;
419 fCurrentChannelDataPtr += fCurrentChannelSize;
421 fCurrentChannelSize = 2;
427 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
429 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
430 fCurrentChannelSize ++;
432 fCurrentChannelDataPtr[fBufferIndex] = length;
433 fCurrentChannelSize ++;
438 for(int i=0; i < length; i++)
440 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
443 fCurrentChannelSize += length;
444 fTotalSize += length;
445 fBufferIndex += length;
450 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
452 *fCurrentChannelIdPtr = channeldid;
457 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
459 for(int i=0; i < fBufferSize ; i++ )
461 fRawDataBuffer[i] = 0;
467 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
469 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
471 if( sizerequested > sizetotal )
477 for(int i=0; i < fTotalSize; i++)
479 memPtr[i] = fRawDataBuffer[i];