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