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()
88 //this is not created here but in the derived classes
91 // delete fAnalyzerPtr;
101 if(fRawReaderMemoryPtr)
103 delete fRawReaderMemoryPtr;
104 fRawReaderMemoryPtr = 0;
107 if(fAltroRawStreamPtr)
109 delete fAltroRawStreamPtr;
110 fAltroRawStreamPtr = 0;
115 delete fRawDataWriter;
119 if (fSanityInspectorPtr)
121 delete fSanityInspectorPtr;
122 fSanityInspectorPtr = 0;
125 // NOT A GOOD IDEA TO CALL VIRTUAL FUNCTION
126 // ESPECIALLY IN VIRTUAL DESTRUCTOR - just stick to it
133 AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
136 //See base class for documentation
137 // fPrintInfo = kFALSE;
141 // fMapperPtr = new AliHLTCaloMapper();
145 for(int i = 0; i < argc; i++)
147 if(!strcmp("-offset", argv[i]))
149 fOffset = atoi(argv[i+1]);
151 if(!strcmp("-bunchsizecut", argv[i]))
153 fBunchSizeCut = atoi(argv[i+1]);
155 if(!strcmp("-minpeakposition", argv[i]))
157 fMinPeakPosition = atoi(argv[i+1]);
159 if(!strcmp("-maxpeakposition", argv[i]))
161 fMaxPeakPosition = atoi(argv[i+1]);
163 if(!strcmp("-pushrawdata", argv[i]))
165 fDoPushRawData = true;
167 if(!strcmp("-pushbaddata", argv[i]))
169 fDoPushBadRawData = true;
171 if(fDoPushBadRawData && fDoPushRawData)
173 HLTWarning("fDoPushBadRawData and fDoPushRawData in conflict, using fDoPushRawData");
174 fDoPushBadRawData = false;
176 if(!strcmp("-suppressalilogwarnings", argv[i]))
178 AliLog::SetGlobalLogLevel(AliLog::kError); //PHOS sometimes produces bad data -> Fill up the HLT logs...
183 if( fMapperPtr->GetIsInitializedMapping() == false)
185 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTCaloMapper::Could not initialise mapping from file %s, aborting", fMapperPtr->GetFilePath());
193 AliHLTCaloRawAnalyzerComponentv3::DoDeinit()
197 //this is not created here but in the derived classes
200 // delete fAnalyzerPtr;
204 // what about the rest of the created objects?
205 // in the contructor?
213 if(fRawReaderMemoryPtr)
215 delete fRawReaderMemoryPtr;
216 fRawReaderMemoryPtr = 0;
219 if(fAltroRawStreamPtr)
221 delete fAltroRawStreamPtr;
222 fAltroRawStreamPtr = 0;
231 AliHLTCaloRawAnalyzerComponentv3::GetComponentID()
234 return "CaloRawAnalyzerv3";
241 AliHLTCaloRawAnalyzerComponentv3::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
245 list.push_back( AliHLTCaloDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
251 AliHLTComponentDataType
252 AliHLTCaloRawAnalyzerComponentv3::GetOutputDataType()
255 return AliHLTCaloDefinitions::fgkChannelDataType;
262 AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
265 constBase = sizeof(AliHLTCaloChannelDataHeaderStruct);
266 inputMultiplier = 0.5;
273 AliHLTCaloRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
279 Short_t channelCount = 0;
281 AliHLTCaloChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(outputPtr);
282 AliHLTCaloChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(outputPtr+sizeof(AliHLTCaloChannelDataHeaderStruct));
284 totSize += sizeof( AliHLTCaloChannelDataHeaderStruct );
285 fRawReaderMemoryPtr->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), static_cast<ULong_t>( iter->fSize ) );
286 fRawReaderMemoryPtr->SetEquipmentID( fMapperPtr->GetDDLFromSpec( iter->fSpecification) + fCaloConstants->GetDDLOFFSET() );
287 fRawReaderMemoryPtr->Reset();
288 fRawReaderMemoryPtr->NextEvent();
290 if( fDoPushRawData == true)
292 fRawDataWriter->NewEvent( );
295 if(fAltroRawStreamPtr->NextDDL())
298 // fOffset = ( fAltroRawStreamPtr->GetAltroCFG1() >> 10 ) & 0xf;
300 while( fAltroRawStreamPtr->NextChannel() )
302 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T3" << endl;
303 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
310 UShort_t* firstBunchPtr = 0;
311 int chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
312 // HLTError("Channel HW address: %d", fAltroRawStreamPtr->GetHWAddress());
313 if( fDoPushRawData == true)
315 fRawDataWriter->SetChannelId( chId );
319 vector <AliCaloBunchInfo> bvctr;
320 while( fAltroRawStreamPtr->NextBunch() == true )
322 bvctr.push_back( AliCaloBunchInfo( fAltroRawStreamPtr->GetStartTimeBin(), fAltroRawStreamPtr->GetBunchLength(), fAltroRawStreamPtr->GetSignals() ) );
324 nSamples = fAltroRawStreamPtr->GetBunchLength();
325 if( fDoPushRawData == true)
327 fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
329 firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
334 totSize += sizeof( AliHLTCaloChannelDataStruct );
337 //HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
341 // fAnalyzerPtr->SetData( firstBunchPtr, nSamples);
342 AliCaloFitResults res = fAnalyzerPtr->Evaluate( bvctr, fAltroRawStreamPtr->GetAltroCFG1(), fAltroRawStreamPtr->GetAltroCFG2() );
344 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);
346 // if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition)
348 channelDataPtr->fChannelID = chId;
349 channelDataPtr->fEnergy = static_cast<Float_t>( res.GetAmp() ) - fOffset;
351 channelDataPtr->fTime = static_cast<Float_t>( res.GetTof() );
352 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
354 channelDataPtr++; // Updating position of the free output.
358 // This should be the functionality for pushing the raw data for the bad channels
363 crazyness |= AliHLTCaloCrazynessDefinitions::fgkBadEstBit;
366 channelDataPtr->fChannelID = chId;
367 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
368 AliHLTCaloCoordinate c;
369 fMapperPtr->ChannelId2Coordinate(chId, c);
370 HLTDebug("Got channel, x: %d, z: %d, gain: %d, energy: %f", c.fX, c.fZ, c.fGain, channelDataPtr->fEnergy);
371 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
372 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
374 channelDataPtr++; // Updating position of the free output.
376 // Push the raw data if we have crazyness and feature to push raw data for bad channels
377 if (crazyness && fDoPushBadRawData)
380 channelDataPtr->fCrazyness = crazyness | AliHLTCaloCrazynessDefinitions::fgkRawDataBit;
381 UShort_t extraSize = sizeof ( AliHLTCaloChannelRawDataStruct ) + ( nSamples-1 ) *sizeof ( UShort_t );
382 totSize += extraSize;
384 if ( totSize > size )
386 HLTError ( "Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size );
390 AliHLTCaloChannelRawDataStruct *tmpChannel = reinterpret_cast<AliHLTCaloChannelRawDataStruct*> ( channelDataPtr );
391 memcpy ( & ( tmpChannel->fData ), firstBunchPtr, nSamples*sizeof ( UShort_t ) );
392 channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*> ( reinterpret_cast<UChar_t*> ( channelDataPtr ) + extraSize );
398 if( fDoPushRawData == true)
400 fRawDataWriter->NewChannel();
409 channelDataHeaderPtr->fNChannels = channelCount;
410 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
411 channelDataHeaderPtr->fInfo = 0;
416 if( fDoPushRawData == true)
418 tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
421 // channelDataHeaderPtr->fHasRawData = false;
422 channelDataHeaderPtr->fHasRawData = fDoPushRawData;
423 HLTDebug("Number of channels: %d", channelCount);
424 tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct);
433 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter(AliHLTCaloConstants* cConst) : //fIsFirstChannel(true),
435 fCurrentChannelSize(0),
436 // fIsFirstChannel(true),
438 // fBufferSize( NZROWSRCU*NXCOLUMNSRCU*ALTROMAXSAMPLES*NGAINS +1000 ),
439 fBufferSize( 64*56*cConst->GetNGAINS()*cConst->GetALTROMAXSAMPLES() +1000 ),
440 fCurrentChannelIdPtr(0),
441 fCurrentChannelSizePtr(0),
442 fCurrentChannelDataPtr(0),
445 fRawDataBuffer = new UShort_t[fBufferSize];
449 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::~RawDataWriter()
451 //destructor - added by MP
452 if (0 != fRawDataBuffer)
454 delete [] fRawDataBuffer;
460 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
462 fCurrentChannelIdPtr = fRawDataBuffer;
463 fCurrentChannelSizePtr = fRawDataBuffer +1;
464 fCurrentChannelDataPtr = fRawDataBuffer +2;
470 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
478 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
480 *fCurrentChannelSizePtr = fCurrentChannelSize;
481 fCurrentChannelIdPtr += fCurrentChannelSize;
482 fCurrentChannelSizePtr += fCurrentChannelSize;
483 fCurrentChannelDataPtr += fCurrentChannelSize;
485 fCurrentChannelSize = 2;
491 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
493 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
494 fCurrentChannelSize ++;
496 fCurrentChannelDataPtr[fBufferIndex] = length;
497 fCurrentChannelSize ++;
502 for(int i=0; i < length; i++)
504 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
507 fCurrentChannelSize += length;
508 fTotalSize += length;
509 fBufferIndex += length;
514 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
516 *fCurrentChannelIdPtr = channeldid;
521 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
523 for(int i=0; i < fBufferSize ; i++ )
525 fRawDataBuffer[i] = 0;
531 AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
533 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
535 if( sizerequested > sizetotal )
541 for(int i=0; i < fTotalSize; i++)
543 memPtr[i] = fRawDataBuffer[i];