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 "AliCaloRawAnalyzer.h"
19 #include "AliCaloBunchInfo.h"
20 #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 "AliAltroRawStreamV3.h"
28 #include "AliRawReaderMemory.h"
29 #include "AliAltroRawStreamV3.h"
30 #include "AliCaloRawStreamV3.h"
31 #include "AliHLTCaloConstantsHandler.h"
32 #include "AliHLTCaloConstants.h"
33 #include "AliHLTCaloRcuProcessor.h"
34 #include "AliHLTCaloCrazynessDefinitions.h"
35 #include "AliHLTCaloChannelRawDataStruct.h"
36 #include "AliHLTCaloCoordinate.h"
39 //#include "AliCALOBunchInfo.h"
45 ClassImp(AliHLTCaloRawAnalyzerComponentv3);
47 AliHLTCaloRawAnalyzerComponentv3::AliHLTCaloRawAnalyzerComponentv3(TString det):
48 AliHLTCaloConstantsHandler(det),
49 AliHLTCaloRcuProcessor(),
50 // fCaloEventCount(0),
53 fSanityInspectorPtr(0),
54 fRawReaderMemoryPtr(0),
55 fAltroRawStreamPtr(0),
60 fMaxPeakPosition(100),
61 fDoPushBadRawData(false),
62 fDoPushRawData(false),
67 // fMapperPtr = new AliHLTCaloMapper();
69 fRawReaderMemoryPtr = new AliRawReaderMemory();
71 fAltroRawStreamPtr = new AliAltroRawStreamV3(fRawReaderMemoryPtr);
73 fSanityInspectorPtr = new AliHLTCaloSanityInspector();
75 if( fDoPushRawData == true )
77 fRawDataWriter = new RawDataWriter(fCaloConstants);
80 fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, det);
85 AliHLTCaloRawAnalyzerComponentv3::~AliHLTCaloRawAnalyzerComponentv3()
94 AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
97 //See base class for documentation
98 // fPrintInfo = kFALSE;
102 // fMapperPtr = new AliHLTCaloMapper();
106 for(int i = 0; i < argc; i++)
108 if(!strcmp("-offset", argv[i]))
110 fOffset = atoi(argv[i+1]);
112 if(!strcmp("-bunchsizecut", argv[i]))
114 fBunchSizeCut = atoi(argv[i+1]);
116 if(!strcmp("-minpeakposition", argv[i]))
118 fMinPeakPosition = atoi(argv[i+1]);
120 if(!strcmp("-maxpeakposition", argv[i]))
122 fMaxPeakPosition = atoi(argv[i+1]);
124 if(!strcmp("-pushrawdata", argv[i]))
126 fDoPushRawData = true;
128 if(!strcmp("-pushbaddata", argv[i]))
130 fDoPushBadRawData = true;
132 if(fDoPushBadRawData && fDoPushRawData)
134 HLTWarning("fDoPushBadRawData and fDoPushRawData in conflict, using fDoPushRawData");
135 fDoPushBadRawData = false;
137 if(!strcmp("-suppressalilogwarnings", argv[i]))
139 AliLog::SetGlobalLogLevel(AliLog::kError); //PHOS sometimes produces bad data -> Fill up the HLT logs...
144 if( fMapperPtr->GetIsInitializedMapping() == false)
146 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTCaloMapper::Could not initialise mapping from file %s, aborting", fMapperPtr->GetFilePath());
154 AliHLTCaloRawAnalyzerComponentv3::DoDeinit()
170 if(fRawReaderMemoryPtr)
172 delete fRawReaderMemoryPtr;
173 fRawReaderMemoryPtr = 0;
176 if(fAltroRawStreamPtr)
178 delete fAltroRawStreamPtr;
179 fAltroRawStreamPtr = 0;
188 AliHLTCaloRawAnalyzerComponentv3::GetComponentID()
191 return "CaloRawAnalyzerv3";
198 AliHLTCaloRawAnalyzerComponentv3::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
202 list.push_back( AliHLTCaloDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
208 AliHLTComponentDataType
209 AliHLTCaloRawAnalyzerComponentv3::GetOutputDataType()
212 return AliHLTCaloDefinitions::fgkChannelDataType;
219 AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
222 constBase = sizeof(AliHLTCaloChannelDataHeaderStruct);
223 inputMultiplier = 0.5;
230 AliHLTCaloRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
236 Short_t channelCount = 0;
238 AliHLTCaloChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(outputPtr);
239 AliHLTCaloChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(outputPtr+sizeof(AliHLTCaloChannelDataHeaderStruct));
241 totSize += sizeof( AliHLTCaloChannelDataHeaderStruct );
242 fRawReaderMemoryPtr->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), static_cast<ULong_t>( iter->fSize ) );
243 fRawReaderMemoryPtr->SetEquipmentID( fMapperPtr->GetDDLFromSpec( iter->fSpecification) + fCaloConstants->GetDDLOFFSET() );
244 fRawReaderMemoryPtr->Reset();
245 fRawReaderMemoryPtr->NextEvent();
247 if( fDoPushRawData == true)
249 fRawDataWriter->NewEvent( );
252 if(fAltroRawStreamPtr->NextDDL())
255 // fOffset = ( fAltroRawStreamPtr->GetAltroCFG1() >> 10 ) & 0xf;
257 while( fAltroRawStreamPtr->NextChannel() )
259 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T3" << endl;
260 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
267 UShort_t* firstBunchPtr = 0;
268 int chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
269 // HLTError("Channel HW address: %d", fAltroRawStreamPtr->GetHWAddress());
270 if( fDoPushRawData == true)
272 fRawDataWriter->SetChannelId( chId );
276 vector <AliCaloBunchInfo> bvctr;
277 while( fAltroRawStreamPtr->NextBunch() == true )
279 bvctr.push_back( AliCaloBunchInfo( fAltroRawStreamPtr->GetStartTimeBin(), fAltroRawStreamPtr->GetBunchLength(), fAltroRawStreamPtr->GetSignals() ) );
281 nSamples = fAltroRawStreamPtr->GetBunchLength();
282 if( fDoPushRawData == true)
284 fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
286 firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
291 totSize += sizeof( AliHLTCaloChannelDataStruct );
294 //HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
298 // fAnalyzerPtr->SetData( firstBunchPtr, nSamples);
299 AliCaloFitResults res = fAnalyzerPtr->Evaluate( bvctr, fAltroRawStreamPtr->GetAltroCFG1(), fAltroRawStreamPtr->GetAltroCFG2() );
301 HLTDebug("Channel energy: %f, max sig: %d, gain = %d, x = %d, z = %d", res.GetAmp(), res.GetMaxSig(), (chId >> 12)&0x1, chId&0x3f, (chId >> 6)&0x3f);
303 // if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition)
305 channelDataPtr->fChannelID = chId;
306 channelDataPtr->fEnergy = static_cast<Float_t>( res.GetAmp() ) - fOffset;
308 channelDataPtr->fTime = static_cast<Float_t>( res.GetTof() );
309 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
311 channelDataPtr++; // Updating position of the free output.
315 // This should be the functionality for pushing the raw data for the bad channels
320 crazyness |= AliHLTCaloCrazynessDefinitions::fgkBadEstBit;
323 channelDataPtr->fChannelID = chId;
324 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
325 AliHLTCaloCoordinate c;
326 fMapperPtr->ChannelId2Coordinate(chId, c);
327 HLTDebug("Got channel, x: %d, z: %d, gain: %d, energy: %f", c.fX, c.fZ, c.fGain, channelDataPtr->fEnergy);
328 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
329 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
331 channelDataPtr++; // Updating position of the free output.
333 // Push the raw data if we have crazyness and feature to push raw data for bad channels
334 if (crazyness && fDoPushBadRawData)
337 channelDataPtr->fCrazyness = crazyness | AliHLTCaloCrazynessDefinitions::fgkRawDataBit;
338 UShort_t extraSize = sizeof ( AliHLTCaloChannelRawDataStruct ) + ( nSamples-1 ) *sizeof ( UShort_t );
339 totSize += extraSize;
341 if ( totSize > size )
343 HLTError ( "Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size );
347 AliHLTCaloChannelRawDataStruct *tmpChannel = reinterpret_cast<AliHLTCaloChannelRawDataStruct*> ( channelDataPtr );
348 memcpy ( & ( tmpChannel->fData ), firstBunchPtr, nSamples*sizeof ( UShort_t ) );
349 channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*> ( reinterpret_cast<UChar_t*> ( channelDataPtr ) + extraSize );
355 if( fDoPushRawData == true)
357 fRawDataWriter->NewChannel();
366 channelDataHeaderPtr->fNChannels = channelCount;
367 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
368 channelDataHeaderPtr->fInfo = 0;
373 if( fDoPushRawData == true)
375 tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
378 // channelDataHeaderPtr->fHasRawData = false;
379 channelDataHeaderPtr->fHasRawData = fDoPushRawData;
380 HLTDebug("Number of channels: %d", channelCount);
381 tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct);
390 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter(AliHLTCaloConstants* cConst) : //fIsFirstChannel(true),
392 fCurrentChannelSize(0),
393 // fIsFirstChannel(true),
395 // fBufferSize( NZROWSRCU*NXCOLUMNSRCU*ALTROMAXSAMPLES*NGAINS +1000 ),
396 fBufferSize( 64*56*cConst->GetNGAINS()*cConst->GetALTROMAXSAMPLES() +1000 ),
397 fCurrentChannelIdPtr(0),
398 fCurrentChannelSizePtr(0),
399 fCurrentChannelDataPtr(0),
402 fRawDataBuffer = new UShort_t[fBufferSize];
409 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
411 fCurrentChannelIdPtr = fRawDataBuffer;
412 fCurrentChannelSizePtr = fRawDataBuffer +1;
413 fCurrentChannelDataPtr = fRawDataBuffer +2;
419 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
427 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
429 *fCurrentChannelSizePtr = fCurrentChannelSize;
430 fCurrentChannelIdPtr += fCurrentChannelSize;
431 fCurrentChannelSizePtr += fCurrentChannelSize;
432 fCurrentChannelDataPtr += fCurrentChannelSize;
434 fCurrentChannelSize = 2;
440 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
442 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
443 fCurrentChannelSize ++;
445 fCurrentChannelDataPtr[fBufferIndex] = length;
446 fCurrentChannelSize ++;
451 for(int i=0; i < length; i++)
453 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
456 fCurrentChannelSize += length;
457 fTotalSize += length;
458 fBufferIndex += length;
463 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
465 *fCurrentChannelIdPtr = channeldid;
470 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
472 for(int i=0; i < fBufferSize ; i++ )
474 fRawDataBuffer[i] = 0;
480 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
482 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
484 if( sizerequested > sizetotal )
490 for(int i=0; i < fTotalSize; i++)
492 memPtr[i] = fRawDataBuffer[i];