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