]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/CALO/AliHLTCaloRawAnalyzerComponentv3.cxx
Usage of new constant classes
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloRawAnalyzerComponentv3.cxx
CommitLineData
178dd351 1
2/**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * All rights reserved. *
5 * *
6 * Primary Authors: Per Thomas Hille, Oystein Djuvsland *
7 * *
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 **************************************************************************/
16
72a884c8 17//#include "AliHLTCaloRawAnalyzer.h"
18#include "AliCaloRawAnalyzer.h"
19#include "AliCaloBunchInfo.h"
20#include "AliCaloFitResults.h"
21
178dd351 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"
4f4b7ba4 31#include "AliHLTCaloConstantsHandler.h"
76ffc0ce 32
33
34//#include "AliHLTCaloConstants.h"
35
c375e15d 36#include "AliHLTCaloRcuProcessor.h"
c6d582d5 37#include "AliHLTCaloCrazynessDefinitions.h"
38#include "AliHLTCaloChannelRawDataStruct.h"
f137c3c5 39#include "AliHLTCaloCoordinate.h"
ae3ca5ff 40#include "AliLog.h"
178dd351 41
72a884c8 42//#include "AliCALOBunchInfo.h"
43//AliCALORawAnalyzer
44
45#include <vector>
46using namespace std;
47
4f4b7ba4 48ClassImp(AliHLTCaloRawAnalyzerComponentv3);
49
77f350f7 50AliHLTCaloRawAnalyzerComponentv3::AliHLTCaloRawAnalyzerComponentv3(TString det):
4f4b7ba4 51 AliHLTCaloConstantsHandler(det),
c375e15d 52 AliHLTCaloRcuProcessor(),
5fc8dce6 53 // fCaloEventCount(0),
3800a654 54 fAnalyzerPtr(0),
55 fMapperPtr(0),
178dd351 56 fSanityInspectorPtr(0),
57 fRawReaderMemoryPtr(0),
58 fAltroRawStreamPtr(0),
3800a654 59 fAlgorithm(0),
178dd351 60 fOffset(0),
61 fBunchSizeCut(0),
62 fMinPeakPosition(0),
63 fMaxPeakPosition(100),
c6d582d5 64 fDoPushBadRawData(false),
f92dcf21 65 fDoPushRawData(false),
66 fRawDataWriter(0)
178dd351 67{
68 //comment
69
70 // fMapperPtr = new AliHLTCaloMapper();
4f4b7ba4 71
178dd351 72 fRawReaderMemoryPtr = new AliRawReaderMemory();
4f4b7ba4 73
178dd351 74 fAltroRawStreamPtr = new AliAltroRawStreamV3(fRawReaderMemoryPtr);
4f4b7ba4 75
178dd351 76 fSanityInspectorPtr = new AliHLTCaloSanityInspector();
c375e15d 77
c6d582d5 78 if( fDoPushRawData == true )
c375e15d 79 {
80 fRawDataWriter = new RawDataWriter(fCaloConstants);
81 }
82
83 fAltroRawStreamPtr = new AliCaloRawStreamV3(fRawReaderMemoryPtr, det);
4b09a7ed 84
178dd351 85}
86
87
88AliHLTCaloRawAnalyzerComponentv3::~AliHLTCaloRawAnalyzerComponentv3()
89{
90 //comment
09eaf24b 91 //this is not created here but in the derived classes
92 // if(fAnalyzerPtr)
93 // {
94 // delete fAnalyzerPtr;
95 // fAnalyzerPtr = 0;
96 // }
97
98 if(fMapperPtr)
99 {
100 delete fMapperPtr;
101 fMapperPtr = 0;
102 }
103
104 if(fRawReaderMemoryPtr)
105 {
106 delete fRawReaderMemoryPtr;
107 fRawReaderMemoryPtr = 0;
108 }
109
110 if(fAltroRawStreamPtr)
111 {
112 delete fAltroRawStreamPtr;
113 fAltroRawStreamPtr = 0;
114 }
115
116 if (fRawDataWriter)
117 {
118 delete fRawDataWriter;
119 fRawDataWriter = 0;
120 }
121
122 if (fSanityInspectorPtr)
123 {
124 delete fSanityInspectorPtr;
125 fSanityInspectorPtr = 0;
126 }
127
128 // NOT A GOOD IDEA TO CALL VIRTUAL FUNCTION
129 // ESPECIALLY IN VIRTUAL DESTRUCTOR - just stick to it
130 // DoDeinit();
c375e15d 131}
132
133
134
135int
136AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
137{
138
139 //See base class for documentation
140 // fPrintInfo = kFALSE;
141
142 int iResult=0;
143
144 // fMapperPtr = new AliHLTCaloMapper();
145
146 //InitMapping();
147
148 for(int i = 0; i < argc; i++)
149 {
150 if(!strcmp("-offset", argv[i]))
151 {
152 fOffset = atoi(argv[i+1]);
153 }
154 if(!strcmp("-bunchsizecut", argv[i]))
155 {
156 fBunchSizeCut = atoi(argv[i+1]);
157 }
158 if(!strcmp("-minpeakposition", argv[i]))
159 {
160 fMinPeakPosition = atoi(argv[i+1]);
161 }
162 if(!strcmp("-maxpeakposition", argv[i]))
163 {
164 fMaxPeakPosition = atoi(argv[i+1]);
165 }
c6d582d5 166 if(!strcmp("-pushrawdata", argv[i]))
167 {
168 fDoPushRawData = true;
169 }
170 if(!strcmp("-pushbaddata", argv[i]))
171 {
172 fDoPushBadRawData = true;
173 }
174 if(fDoPushBadRawData && fDoPushRawData)
175 {
176 HLTWarning("fDoPushBadRawData and fDoPushRawData in conflict, using fDoPushRawData");
177 fDoPushBadRawData = false;
178 }
ae3ca5ff 179 if(!strcmp("-suppressalilogwarnings", argv[i]))
180 {
181 AliLog::SetGlobalLogLevel(AliLog::kError); //PHOS sometimes produces bad data -> Fill up the HLT logs...
182 }
c375e15d 183 }
184
185 /*
186 if( fMapperPtr->GetIsInitializedMapping() == false)
187 {
188 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTCaloMapper::Could not initialise mapping from file %s, aborting", fMapperPtr->GetFilePath());
189 return -4;
190 }
191 */
c375e15d 192 return iResult;
178dd351 193}
194
178dd351 195int
c375e15d 196AliHLTCaloRawAnalyzerComponentv3::DoDeinit()
178dd351 197{
198 //comment
09eaf24b 199
200 //this is not created here but in the derived classes
201 // if(fAnalyzerPtr)
202 // {
203 // delete fAnalyzerPtr;
204 // fAnalyzerPtr = 0;
205 // }
c375e15d 206
09eaf24b 207 // what about the rest of the created objects?
208 // in the contructor?
c375e15d 209
178dd351 210 if(fMapperPtr)
211 {
212 delete fMapperPtr;
213 fMapperPtr = 0;
214 }
c375e15d 215
178dd351 216 if(fRawReaderMemoryPtr)
217 {
218 delete fRawReaderMemoryPtr;
219 fRawReaderMemoryPtr = 0;
220 }
c375e15d 221
178dd351 222 if(fAltroRawStreamPtr)
223 {
224 delete fAltroRawStreamPtr;
225 fAltroRawStreamPtr = 0;
226 }
c375e15d 227
178dd351 228 return 0;
229}
230
c375e15d 231
72a884c8 232/*
178dd351 233const char*
234AliHLTCaloRawAnalyzerComponentv3::GetComponentID()
235{
236 //comment
237 return "CaloRawAnalyzerv3";
238}
72a884c8 239*/
178dd351 240
72a884c8 241 /*
c6d582d5 242
178dd351 243void
244AliHLTCaloRawAnalyzerComponentv3::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
245{
246 //comment
247 list.clear();
248 list.push_back( AliHLTCaloDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
249}
72a884c8 250 */
251
178dd351 252
72a884c8 253 /*
c375e15d 254AliHLTComponentDataType
178dd351 255AliHLTCaloRawAnalyzerComponentv3::GetOutputDataType()
256{
257 //comment
258 return AliHLTCaloDefinitions::fgkChannelDataType;
259}
72a884c8 260 */
178dd351 261
c375e15d 262
72a884c8 263 /*
178dd351 264void
265AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
266{
267 //comment
268 constBase = sizeof(AliHLTCaloChannelDataHeaderStruct);
269 inputMultiplier = 0.5;
270}
72a884c8 271 */
4b09a7ed 272
178dd351 273
274
275Int_t
276AliHLTCaloRawAnalyzerComponentv3::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
277{
f137c3c5 278
178dd351 279 int tmpsize= 0;
280 Int_t crazyness = 0;
281 Int_t nSamples = 0;
282 Short_t channelCount = 0;
283
178dd351 284 AliHLTCaloChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(outputPtr);
285 AliHLTCaloChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(outputPtr+sizeof(AliHLTCaloChannelDataHeaderStruct));
4b09a7ed 286
178dd351 287 totSize += sizeof( AliHLTCaloChannelDataHeaderStruct );
288 fRawReaderMemoryPtr->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), static_cast<ULong_t>( iter->fSize ) );
9cd20a1c 289 fRawReaderMemoryPtr->SetEquipmentID( fMapperPtr->GetDDLFromSpec( iter->fSpecification) + fCaloConstants->GetDDLOFFSET() );
178dd351 290 fRawReaderMemoryPtr->Reset();
291 fRawReaderMemoryPtr->NextEvent();
4b09a7ed 292
c6d582d5 293 if( fDoPushRawData == true)
178dd351 294 {
295 fRawDataWriter->NewEvent( );
296 }
4b09a7ed 297
c89876f4 298 if(fAltroRawStreamPtr->NextDDL())
178dd351 299 {
300 int cnt = 0;
f137c3c5 301 // fOffset = ( fAltroRawStreamPtr->GetAltroCFG1() >> 10 ) & 0xf;
302 fOffset = 0;
178dd351 303 while( fAltroRawStreamPtr->NextChannel() )
304 {
3800a654 305 // cout << __FILE__ << ":" << __LINE__ << ":" <<__FUNCTION__ << "T3" << endl;
178dd351 306 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
307 {
308 continue;
309 }
310 else
311 {
8b848697 312 ++ cnt;
313 UShort_t* firstBunchPtr = 0;
b850c417 314 int chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
f137c3c5 315 // HLTError("Channel HW address: %d", fAltroRawStreamPtr->GetHWAddress());
c6d582d5 316 if( fDoPushRawData == true)
178dd351 317 {
318 fRawDataWriter->SetChannelId( chId );
319 }
4b09a7ed 320
321 // return 1;
72a884c8 322 vector <AliCaloBunchInfo> bvctr;
178dd351 323 while( fAltroRawStreamPtr->NextBunch() == true )
324 {
72a884c8 325 bvctr.push_back( AliCaloBunchInfo( fAltroRawStreamPtr->GetStartTimeBin(), fAltroRawStreamPtr->GetBunchLength(), fAltroRawStreamPtr->GetSignals() ) );
326
178dd351 327 nSamples = fAltroRawStreamPtr->GetBunchLength();
c6d582d5 328 if( fDoPushRawData == true)
178dd351 329 {
178dd351 330 fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
331 }
332 firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
333 }
4b09a7ed 334
335 //return 1;
336
f137c3c5 337 totSize += sizeof( AliHLTCaloChannelDataStruct );
178dd351 338 if(totSize > size)
339 {
c375e15d 340 //HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
178dd351 341 return -1;
342 }
343
72a884c8 344 // fAnalyzerPtr->SetData( firstBunchPtr, nSamples);
345 AliCaloFitResults res = fAnalyzerPtr->Evaluate( bvctr, fAltroRawStreamPtr->GetAltroCFG1(), fAltroRawStreamPtr->GetAltroCFG2() );
84af2960 346
347 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);
b850c417 348
178dd351 349 // if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition)
350 {
351 channelDataPtr->fChannelID = chId;
72a884c8 352 channelDataPtr->fEnergy = static_cast<Float_t>( res.GetAmp() ) - fOffset;
4b09a7ed 353
72a884c8 354 channelDataPtr->fTime = static_cast<Float_t>( res.GetTof() );
178dd351 355 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
356 channelCount++;
357 channelDataPtr++; // Updating position of the free output.
358 }
359 }
4b09a7ed 360
c6d582d5 361 // This should be the functionality for pushing the raw data for the bad channels
362
363 /*
364 if ( bad )
365 {
366 crazyness |= AliHLTCaloCrazynessDefinitions::fgkBadEstBit;
367 }
368
369 channelDataPtr->fChannelID = chId;
370 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
f137c3c5 371 AliHLTCaloCoordinate c;
372 fMapperPtr->ChannelId2Coordinate(chId, c);
ad44d760 373 HLTDebug("Got channel, x: %d, z: %d, gain: %d, energy: %f", c.fX, c.fZ, c.fGain, channelDataPtr->fEnergy);
c6d582d5 374 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
375 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
376 channelCount++;
377 channelDataPtr++; // Updating position of the free output.
378
379 // Push the raw data if we have crazyness and feature to push raw data for bad channels
380 if (crazyness && fDoPushBadRawData)
381
382 {
383 channelDataPtr->fCrazyness = crazyness | AliHLTCaloCrazynessDefinitions::fgkRawDataBit;
384 UShort_t extraSize = sizeof ( AliHLTCaloChannelRawDataStruct ) + ( nSamples-1 ) *sizeof ( UShort_t );
385 totSize += extraSize;
386
387 if ( totSize > size )
388 {
389 HLTError ( "Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size );
390 return -1;
391 }
392
393 AliHLTCaloChannelRawDataStruct *tmpChannel = reinterpret_cast<AliHLTCaloChannelRawDataStruct*> ( channelDataPtr );
394 memcpy ( & ( tmpChannel->fData ), firstBunchPtr, nSamples*sizeof ( UShort_t ) );
395 channelDataPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*> ( reinterpret_cast<UChar_t*> ( channelDataPtr ) + extraSize );
396 }
397
398 */
399 }
4b09a7ed 400
c6d582d5 401 if( fDoPushRawData == true)
4b09a7ed 402 {
403 fRawDataWriter->NewChannel();
404 }
405
178dd351 406 }
407
4b09a7ed 408
aa2ffd19 409// return 1;
410
411//Writing the header
178dd351 412 channelDataHeaderPtr->fNChannels = channelCount;
413 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
414 channelDataHeaderPtr->fInfo = 0;
415
4b09a7ed 416 // return 1;
417
418
c6d582d5 419 if( fDoPushRawData == true)
178dd351 420 {
421 tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
422 }
423
424 // channelDataHeaderPtr->fHasRawData = false;
c6d582d5 425 channelDataHeaderPtr->fHasRawData = fDoPushRawData;
ad44d760 426 HLTDebug("Number of channels: %d", channelCount);
178dd351 427 tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct);
178dd351 428 return tmpsize;
429
430}
431
4b09a7ed 432
433
434
178dd351 435
77f350f7 436AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter(AliHLTCaloConstants* cConst) : //fIsFirstChannel(true),
178dd351 437 fRawDataBuffer(0),
438 fCurrentChannelSize(0),
439 // fIsFirstChannel(true),
440 fBufferIndex(0),
441 // fBufferSize( NZROWSRCU*NXCOLUMNSRCU*ALTROMAXSAMPLES*NGAINS +1000 ),
77f350f7 442 fBufferSize( 64*56*cConst->GetNGAINS()*cConst->GetALTROMAXSAMPLES() +1000 ),
178dd351 443 fCurrentChannelIdPtr(0),
444 fCurrentChannelSizePtr(0),
445 fCurrentChannelDataPtr(0),
446 fTotalSize(0)
447{
178dd351 448 fRawDataBuffer = new UShort_t[fBufferSize];
449 Init();
450}
451
09eaf24b 452AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::~RawDataWriter()
453{
454 //destructor - added by MP
455 if (0 != fRawDataBuffer)
456 {
457 delete [] fRawDataBuffer;
458 fRawDataBuffer = 0;
459 }
460}
178dd351 461
462void
463AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
464{
178dd351 465 fCurrentChannelIdPtr = fRawDataBuffer;
466 fCurrentChannelSizePtr = fRawDataBuffer +1;
467 fCurrentChannelDataPtr = fRawDataBuffer +2;
468 ResetBuffer();
469}
470
471
472void
473AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
474{
178dd351 475 Init();
476 fTotalSize = 0;
477}
478
479
480void
481AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
482{
178dd351 483 *fCurrentChannelSizePtr = fCurrentChannelSize;
484 fCurrentChannelIdPtr += fCurrentChannelSize;
485 fCurrentChannelSizePtr += fCurrentChannelSize;
486 fCurrentChannelDataPtr += fCurrentChannelSize;
487 fBufferIndex = 0;
488 fCurrentChannelSize = 2;
489 fTotalSize += 2;
490}
491
492
493void
494AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
495{
178dd351 496 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
497 fCurrentChannelSize ++;
498 fBufferIndex++;
499 fCurrentChannelDataPtr[fBufferIndex] = length;
500 fCurrentChannelSize ++;
501 fBufferIndex++;
502
503 fTotalSize +=2;
504
505 for(int i=0; i < length; i++)
506 {
507 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
508 }
509
510 fCurrentChannelSize += length;
511 fTotalSize += length;
512 fBufferIndex += length;
513}
514
515
516void
517AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
518{
178dd351 519 *fCurrentChannelIdPtr = channeldid;
520}
521
522
523void
524AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
525{
178dd351 526 for(int i=0; i < fBufferSize ; i++ )
527 {
528 fRawDataBuffer[i] = 0;
529 }
530}
531
532
533int
534AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
535{
178dd351 536 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
537
538 if( sizerequested > sizetotal )
539 {
540 return 0;
541 }
542 else
543 {
544 for(int i=0; i < fTotalSize; i++)
545 {
546 memPtr[i] = fRawDataBuffer[i];
547 }
548 return fTotalSize;
549 }
550}
551