]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/CALO/AliHLTCaloRawAnalyzerComponentv3.cxx
removed deletion of pointers in destructor
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloRawAnalyzerComponentv3.cxx
CommitLineData
1882b7fd 1// $Id$
178dd351 2
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
6 * *
7 * Primary Authors: Per Thomas Hille, Oystein Djuvsland *
8 * *
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 **************************************************************************/
17
1a53578c 18
72a884c8 19#include "AliCaloRawAnalyzer.h"
20#include "AliCaloBunchInfo.h"
21#include "AliCaloFitResults.h"
178dd351 22#include "AliHLTCaloRawAnalyzerComponentv3.h"
23#include "AliHLTCaloChannelDataHeaderStruct.h"
24#include "AliHLTCaloChannelDataStruct.h"
25#include "AliHLTCaloMapper.h"
26#include "AliHLTCaloSanityInspector.h"
178dd351 27#include "AliRawReaderMemory.h"
178dd351 28#include "AliCaloRawStreamV3.h"
4f4b7ba4 29#include "AliHLTCaloConstantsHandler.h"
c6d582d5 30#include "AliHLTCaloChannelRawDataStruct.h"
ae3ca5ff 31#include "AliLog.h"
1a53578c 32#include "TStopwatch.h"
33
92d9f317 34#include "AliCaloRawAnalyzerFactory.h"
35
36//#include "AliCaloConstants.h"
37
38//#include "AliCaloRawAnalyzer.h"
39
40//using namespace Algo;
178dd351 41
72a884c8 42#include <vector>
43using namespace std;
44
69f0327f 45ClassImp(AliHLTCaloRawAnalyzerComponentv3);
1e46316a 46
47
4f4b7ba4 48
92d9f317 49AliHLTCaloRawAnalyzerComponentv3::AliHLTCaloRawAnalyzerComponentv3(TString det, fitAlgorithm algo ):AliHLTCaloProcessor(),
50 AliHLTCaloConstantsHandler(det),
51 fAnalyzerPtr(0),
52 fMapperPtr(0),
53 fCurrentSpec(-1),
54 fDebug(false),
55 fSanityInspectorPtr(0),
56 fRawReaderMemoryPtr(0),
57 fAltroRawStreamPtr(0),
1882b7fd 58 fDetector(det),
59 fAlgorithm(algo),
92d9f317 60 fOffset(0),
61 fBunchSizeCut(0),
62 fMinPeakPosition(0),
63 fMaxPeakPosition(100),
64 fDoPushBadRawData(false),
65 fDoPushRawData(false),
66 fRawDataWriter(0)
1e46316a 67
178dd351 68{
bdaaafe2 69 //Constructor
92d9f317 70
178dd351 71}
72
73
74AliHLTCaloRawAnalyzerComponentv3::~AliHLTCaloRawAnalyzerComponentv3()
75{
bdaaafe2 76 //destructor
c375e15d 77}
78
79
c375e15d 80int
81AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
82{
c375e15d 83 //See base class for documentation
c375e15d 84 int iResult=0;
3968076d 85
c375e15d 86 for(int i = 0; i < argc; i++)
87 {
88 if(!strcmp("-offset", argv[i]))
89 {
90 fOffset = atoi(argv[i+1]);
91 }
92 if(!strcmp("-bunchsizecut", argv[i]))
93 {
94 fBunchSizeCut = atoi(argv[i+1]);
95 }
96 if(!strcmp("-minpeakposition", argv[i]))
97 {
98 fMinPeakPosition = atoi(argv[i+1]);
99 }
100 if(!strcmp("-maxpeakposition", argv[i]))
101 {
102 fMaxPeakPosition = atoi(argv[i+1]);
103 }
c6d582d5 104 if(!strcmp("-pushrawdata", argv[i]))
105 {
106 fDoPushRawData = true;
107 }
108 if(!strcmp("-pushbaddata", argv[i]))
109 {
110 fDoPushBadRawData = true;
111 }
112 if(fDoPushBadRawData && fDoPushRawData)
113 {
114 HLTWarning("fDoPushBadRawData and fDoPushRawData in conflict, using fDoPushRawData");
115 fDoPushBadRawData = false;
116 }
ae3ca5ff 117 if(!strcmp("-suppressalilogwarnings", argv[i]))
118 {
119 AliLog::SetGlobalLogLevel(AliLog::kError); //PHOS sometimes produces bad data -> Fill up the HLT logs...
120 }
c375e15d 121 }
1882b7fd 122
123 fAnalyzerPtr = AliCaloRawAnalyzerFactory::CreateAnalyzer(fAlgorithm);
124 fAnalyzerPtr->SetIsZeroSuppressed(true);
125 fSanityInspectorPtr = new AliHLTCaloSanityInspector();
126
127 if( fDoPushRawData == true )
128 {
129 fRawDataWriter = new RawDataWriter(fCaloConstants);
130 }
131 fRawReaderMemoryPtr = new AliRawReaderMemory();
132 fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, fDetector);
c375e15d 133
c375e15d 134 return iResult;
178dd351 135}
136
1e46316a 137
178dd351 138int
c375e15d 139AliHLTCaloRawAnalyzerComponentv3::DoDeinit()
178dd351 140{
bdaaafe2 141 //comment
1e46316a 142 if(fAltroRawStreamPtr)
143 {
144 delete fAltroRawStreamPtr;
145 fAltroRawStreamPtr = 0;
146 }
1882b7fd 147
32539ca3 148 if (fRawReaderMemoryPtr) delete fRawReaderMemoryPtr;
149 fRawReaderMemoryPtr=NULL;
150 if (fAltroRawStreamPtr) delete fAltroRawStreamPtr;
151 fAltroRawStreamPtr=NULL;
152 if (fRawDataWriter) delete fRawDataWriter;
153 fRawDataWriter=NULL;
154 if (fSanityInspectorPtr) delete fSanityInspectorPtr;
155 fSanityInspectorPtr=NULL;
1882b7fd 156
32539ca3 157 return 0;
1e46316a 158}
c375e15d 159
c375e15d 160
1e46316a 161
162void
163AliHLTCaloRawAnalyzerComponentv3::PrintDebugInfo()
164{
bdaaafe2 165 //comment
166 static TStopwatch watch; //CRAP PTH
1e46316a 167 static double wlast = -1;
168 static double wcurrent = 0;
1e46316a 169
170 if( true == fDebug )
178dd351 171 {
1e46316a 172 if( fCaloEventCount %1000 == 0 )
173 {
174 cout << __FILE__ << __LINE__ << " : Processing event " << fCaloEventCount << endl;
175 wlast = wcurrent;
bdaaafe2 176 wcurrent = watch.RealTime();
1e46316a 177 cout << __FILE__ << __LINE__ << "The event rate is " <<
bdaaafe2 178 1000/( wcurrent - wlast ) << " Hz" << endl; watch.Start(kFALSE);
1e46316a 179 }
178dd351 180 }
1e46316a 181}
182
183
f9baa094 184void
185AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
186{
187 //comment
188 constBase = sizeof(AliHLTCaloChannelDataHeaderStruct);
189 inputMultiplier = 1.5;
190}
191
192
1e46316a 193bool
194AliHLTCaloRawAnalyzerComponentv3::CheckInputDataType(const AliHLTComponentDataType &datatype)
195{
bdaaafe2 196 //comment
1e46316a 197 vector <AliHLTComponentDataType> validTypes;
198 GetInputDataTypes(validTypes);
199
a03522e3 200 for(UInt_t i=0; i < validTypes.size(); i++ )
178dd351 201 {
1e46316a 202 if ( datatype == validTypes.at(i) )
203 {
204 return true;
205 }
178dd351 206 }
1e46316a 207
208 HLTDebug("Invalid Datatype");
209 return false;
210}
c375e15d 211
1e46316a 212
213int
214AliHLTCaloRawAnalyzerComponentv3::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
215 AliHLTComponentTriggerData& /*trigData*/,
216 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
217{
bdaaafe2 218 //comment
1e46316a 219 if(!IsDataEvent())
220 {
221 size = 0;
222 return 0;
223 }
69f0327f 224 if( true == fDebug )
225 { PrintDebugInfo();
226 };
1e46316a 227
69f0327f 228 Int_t blockSize = -1;
229 UInt_t totSize = 0;
230 const AliHLTComponentBlockData* iter = NULL;
231 unsigned long ndx;
1e46316a 232
69f0327f 233 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
178dd351 234 {
1e46316a 235 iter = blocks+ndx;
236 if( ! CheckInputDataType(iter->fDataType) )
1e46316a 237 {
238 continue;
239 }
240
1e46316a 241 if(iter->fSpecification != fCurrentSpec)
69f0327f 242 {
243 fCurrentSpec = iter->fSpecification;
244 InitMapping(iter->fSpecification);
245 }
1e46316a 246
69f0327f 247 blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
1e46316a 248 totSize += blockSize; //Keeping track of the used size
249 AliHLTComponentBlockData bdChannelData;
250 FillBlockData( bdChannelData );
251 bdChannelData.fOffset = 0; //FIXME
252 bdChannelData.fSize = blockSize;
253 bdChannelData.fDataType = GetOutputDataType();
254 bdChannelData.fSpecification = iter->fSpecification;
255 outputBlocks.push_back(bdChannelData);
256 outputPtr += blockSize; //Updating position of the output buffer
178dd351 257 }
c375e15d 258
69f0327f 259 fCaloEventCount++;
260 size = totSize; //telling the framework how much buffer space we have used.
1e46316a 261
69f0327f 262 return 0;
1e46316a 263
264}//end DoEvent
178dd351 265
c375e15d 266
178dd351 267
268Int_t
269AliHLTCaloRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
270{
bdaaafe2 271 //comment
178dd351 272 int tmpsize= 0;
273 Int_t crazyness = 0;
274 Int_t nSamples = 0;
275 Short_t channelCount = 0;
276
178dd351 277 AliHLTCaloChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(outputPtr);
278 AliHLTCaloChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(outputPtr+sizeof(AliHLTCaloChannelDataHeaderStruct));
178dd351 279 totSize += sizeof( AliHLTCaloChannelDataHeaderStruct );
280 fRawReaderMemoryPtr->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), static_cast<ULong_t>( iter->fSize ) );
9cd20a1c 281 fRawReaderMemoryPtr->SetEquipmentID( fMapperPtr->GetDDLFromSpec( iter->fSpecification) + fCaloConstants->GetDDLOFFSET() );
178dd351 282 fRawReaderMemoryPtr->Reset();
283 fRawReaderMemoryPtr->NextEvent();
9fb60fd9 284
c6d582d5 285 if( fDoPushRawData == true)
178dd351 286 {
69f0327f 287 fRawDataWriter->NewEvent( );
178dd351 288 }
9fb60fd9 289
c89876f4 290 if(fAltroRawStreamPtr->NextDDL())
69f0327f 291 {
292 int cnt = 0;
293 fOffset = 0;
294 while( fAltroRawStreamPtr->NextChannel() )
295 {
296 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
297 {
298 continue;
299 }
300 else
301 {
302 ++ cnt;
4b047255 303 //UShort_t* firstBunchPtr = 0;
69f0327f 304 int chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
9fb60fd9 305
69f0327f 306 if( fDoPushRawData == true)
307 {
308 fRawDataWriter->SetChannelId( chId );
309 }
9fb60fd9 310
69f0327f 311 vector <AliCaloBunchInfo> bvctr;
312 while( fAltroRawStreamPtr->NextBunch() == true )
313 {
314 bvctr.push_back( AliCaloBunchInfo( fAltroRawStreamPtr->GetStartTimeBin(),
315 fAltroRawStreamPtr->GetBunchLength(),
316 fAltroRawStreamPtr->GetSignals() ) );
317
318 nSamples = fAltroRawStreamPtr->GetBunchLength();
319 if( fDoPushRawData == true)
320 {
321 fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(),
322 nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
323 }
4b047255 324 //firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
69f0327f 325 }
b850c417 326
69f0327f 327 totSize += sizeof( AliHLTCaloChannelDataStruct );
328 if(totSize > size)
329 {
330 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
331 return -1;
332 }
333
334 AliCaloFitResults res = fAnalyzerPtr->Evaluate( bvctr, fAltroRawStreamPtr->GetAltroCFG1(),
335 fAltroRawStreamPtr->GetAltroCFG2() );
336
337 HLTDebug("Channel energy: %f, max sig: %d, gain = %d, x = %d, z = %d", res.GetAmp(), res.GetMaxSig(),
338 (chId >> 12)&0x1, chId&0x3f, (chId >> 6)&0x3f);
c6d582d5 339 {
69f0327f 340 channelDataPtr->fChannelID = chId;
341 channelDataPtr->fEnergy = static_cast<Float_t>( res.GetAmp() ) - fOffset;
342 channelDataPtr->fTime = static_cast<Float_t>( res.GetTof() );
343 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
344 channelCount++;
345 channelDataPtr++; // Updating position of the free output.
346 }
347 }
348 }
349 if( fDoPushRawData == true)
350 {
351 fRawDataWriter->NewChannel();
352 }
353 }
178dd351 354
69f0327f 355
178dd351 356 channelDataHeaderPtr->fNChannels = channelCount;
357 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
358 channelDataHeaderPtr->fInfo = 0;
1e46316a 359
c6d582d5 360 if( fDoPushRawData == true)
178dd351 361 {
362 tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
363 }
364
c6d582d5 365 channelDataHeaderPtr->fHasRawData = fDoPushRawData;
ad44d760 366 HLTDebug("Number of channels: %d", channelCount);
178dd351 367 tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct);
178dd351 368 return tmpsize;
369
370}
371
4b09a7ed 372
373
1e46316a 374AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter(AliHLTCaloConstants* cConst) :
69f0327f 375 fRawDataBuffer(0),
376 fCurrentChannelSize(0),
377 fBufferIndex(0),
378 fBufferSize( 64*56*cConst->GetNGAINS()*cConst->GetALTROMAXSAMPLES() +1000 ),
379 fCurrentChannelIdPtr(0),
380 fCurrentChannelSizePtr(0),
381 fCurrentChannelDataPtr(0),
382 fTotalSize(0)
178dd351 383{
bdaaafe2 384 //comment
178dd351 385 fRawDataBuffer = new UShort_t[fBufferSize];
386 Init();
387}
388
1e46316a 389
09eaf24b 390AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::~RawDataWriter()
391{
1e46316a 392 delete [] fRawDataBuffer;
09eaf24b 393}
1e46316a 394
178dd351 395
396void
397AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
398{
bdaaafe2 399 //comment
178dd351 400 fCurrentChannelIdPtr = fRawDataBuffer;
401 fCurrentChannelSizePtr = fRawDataBuffer +1;
402 fCurrentChannelDataPtr = fRawDataBuffer +2;
403 ResetBuffer();
404}
405
406
407void
408AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
409{
bdaaafe2 410 //comment
178dd351 411 Init();
412 fTotalSize = 0;
413}
414
415
416void
417AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
418{
bdaaafe2 419 //comment
178dd351 420 *fCurrentChannelSizePtr = fCurrentChannelSize;
421 fCurrentChannelIdPtr += fCurrentChannelSize;
422 fCurrentChannelSizePtr += fCurrentChannelSize;
423 fCurrentChannelDataPtr += fCurrentChannelSize;
424 fBufferIndex = 0;
425 fCurrentChannelSize = 2;
426 fTotalSize += 2;
427}
428
429
430void
431AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
432{
178dd351 433 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
434 fCurrentChannelSize ++;
435 fBufferIndex++;
436 fCurrentChannelDataPtr[fBufferIndex] = length;
437 fCurrentChannelSize ++;
438 fBufferIndex++;
439
440 fTotalSize +=2;
441
442 for(int i=0; i < length; i++)
443 {
444 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
445 }
446
447 fCurrentChannelSize += length;
448 fTotalSize += length;
449 fBufferIndex += length;
450}
451
452
453void
454AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
455{
178dd351 456 *fCurrentChannelIdPtr = channeldid;
457}
458
459
460void
461AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
462{
178dd351 463 for(int i=0; i < fBufferSize ; i++ )
464 {
465 fRawDataBuffer[i] = 0;
466 }
467}
468
469
470int
471AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
472{
178dd351 473 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
474
475 if( sizerequested > sizetotal )
476 {
477 return 0;
1e46316a 478 }
178dd351 479 else
480 {
481 for(int i=0; i < fTotalSize; i++)
482 {
483 memPtr[i] = fRawDataBuffer[i];
484 }
485 return fTotalSize;
1e46316a 486 }
178dd351 487}
488