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