]>
Commit | Line | Data |
---|---|---|
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> |
43 | using namespace std; | |
44 | ||
69f0327f | 45 | ClassImp(AliHLTCaloRawAnalyzerComponentv3); |
1e46316a | 46 | |
47 | ||
4f4b7ba4 | 48 | |
92d9f317 | 49 | AliHLTCaloRawAnalyzerComponentv3::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 | ||
74 | AliHLTCaloRawAnalyzerComponentv3::~AliHLTCaloRawAnalyzerComponentv3() | |
75 | { | |
bdaaafe2 | 76 | //destructor |
c375e15d | 77 | } |
78 | ||
79 | ||
c375e15d | 80 | int |
81 | AliHLTCaloRawAnalyzerComponentv3::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 | 138 | int |
c375e15d | 139 | AliHLTCaloRawAnalyzerComponentv3::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 | |
162 | void | |
163 | AliHLTCaloRawAnalyzerComponentv3::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 | 184 | void |
185 | AliHLTCaloRawAnalyzerComponentv3::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier ) | |
186 | { | |
187 | //comment | |
188 | constBase = sizeof(AliHLTCaloChannelDataHeaderStruct); | |
189 | inputMultiplier = 1.5; | |
190 | } | |
191 | ||
192 | ||
1e46316a | 193 | bool |
194 | AliHLTCaloRawAnalyzerComponentv3::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 | |
213 | int | |
214 | AliHLTCaloRawAnalyzerComponentv3::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 | |
268 | Int_t | |
269 | AliHLTCaloRawAnalyzerComponentv3::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()); |
0a899b5c | 305 | //patch to skip LG in EMC |
306 | if(fDetector.CompareTo("EMCAL") == 0 && (int)((chId >> 12)&0x1) == 0) continue; | |
69f0327f | 307 | if( fDoPushRawData == true) |
308 | { | |
309 | fRawDataWriter->SetChannelId( chId ); | |
310 | } | |
9fb60fd9 | 311 | |
69f0327f | 312 | vector <AliCaloBunchInfo> bvctr; |
313 | while( fAltroRawStreamPtr->NextBunch() == true ) | |
314 | { | |
315 | bvctr.push_back( AliCaloBunchInfo( fAltroRawStreamPtr->GetStartTimeBin(), | |
316 | fAltroRawStreamPtr->GetBunchLength(), | |
317 | fAltroRawStreamPtr->GetSignals() ) ); | |
318 | ||
319 | nSamples = fAltroRawStreamPtr->GetBunchLength(); | |
320 | if( fDoPushRawData == true) | |
321 | { | |
322 | fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), | |
323 | nSamples, fAltroRawStreamPtr->GetEndTimeBin() ); | |
324 | } | |
4b047255 | 325 | //firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() ); |
69f0327f | 326 | } |
b850c417 | 327 | |
69f0327f | 328 | totSize += sizeof( AliHLTCaloChannelDataStruct ); |
329 | if(totSize > size) | |
330 | { | |
331 | HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size); | |
332 | return -1; | |
333 | } | |
334 | ||
335 | AliCaloFitResults res = fAnalyzerPtr->Evaluate( bvctr, fAltroRawStreamPtr->GetAltroCFG1(), | |
336 | fAltroRawStreamPtr->GetAltroCFG2() ); | |
337 | ||
338 | HLTDebug("Channel energy: %f, max sig: %d, gain = %d, x = %d, z = %d", res.GetAmp(), res.GetMaxSig(), | |
339 | (chId >> 12)&0x1, chId&0x3f, (chId >> 6)&0x3f); | |
c6d582d5 | 340 | { |
69f0327f | 341 | channelDataPtr->fChannelID = chId; |
342 | channelDataPtr->fEnergy = static_cast<Float_t>( res.GetAmp() ) - fOffset; | |
343 | channelDataPtr->fTime = static_cast<Float_t>( res.GetTof() ); | |
0a899b5c | 344 | if(fDetector.CompareTo("EMCAL") == 0) channelDataPtr->fTime = static_cast<Float_t>( res.GetTof() )*100E-9 - fAltroRawStreamPtr->GetL1Phase(); |
69f0327f | 345 | channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness); |
346 | channelCount++; | |
347 | channelDataPtr++; // Updating position of the free output. | |
348 | } | |
349 | } | |
350 | } | |
351 | if( fDoPushRawData == true) | |
352 | { | |
353 | fRawDataWriter->NewChannel(); | |
354 | } | |
355 | } | |
178dd351 | 356 | |
69f0327f | 357 | |
178dd351 | 358 | channelDataHeaderPtr->fNChannels = channelCount; |
359 | channelDataHeaderPtr->fAlgorithm = fAlgorithm; | |
360 | channelDataHeaderPtr->fInfo = 0; | |
1e46316a | 361 | |
c6d582d5 | 362 | if( fDoPushRawData == true) |
178dd351 | 363 | { |
364 | tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize); | |
365 | } | |
366 | ||
c6d582d5 | 367 | channelDataHeaderPtr->fHasRawData = fDoPushRawData; |
ad44d760 | 368 | HLTDebug("Number of channels: %d", channelCount); |
178dd351 | 369 | tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct); |
178dd351 | 370 | return tmpsize; |
371 | ||
372 | } | |
373 | ||
4b09a7ed | 374 | |
375 | ||
1e46316a | 376 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter(AliHLTCaloConstants* cConst) : |
69f0327f | 377 | fRawDataBuffer(0), |
378 | fCurrentChannelSize(0), | |
379 | fBufferIndex(0), | |
380 | fBufferSize( 64*56*cConst->GetNGAINS()*cConst->GetALTROMAXSAMPLES() +1000 ), | |
381 | fCurrentChannelIdPtr(0), | |
382 | fCurrentChannelSizePtr(0), | |
383 | fCurrentChannelDataPtr(0), | |
384 | fTotalSize(0) | |
178dd351 | 385 | { |
bdaaafe2 | 386 | //comment |
178dd351 | 387 | fRawDataBuffer = new UShort_t[fBufferSize]; |
388 | Init(); | |
389 | } | |
390 | ||
1e46316a | 391 | |
09eaf24b | 392 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::~RawDataWriter() |
393 | { | |
1e46316a | 394 | delete [] fRawDataBuffer; |
09eaf24b | 395 | } |
1e46316a | 396 | |
178dd351 | 397 | |
398 | void | |
399 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init() | |
400 | { | |
bdaaafe2 | 401 | //comment |
178dd351 | 402 | fCurrentChannelIdPtr = fRawDataBuffer; |
403 | fCurrentChannelSizePtr = fRawDataBuffer +1; | |
404 | fCurrentChannelDataPtr = fRawDataBuffer +2; | |
405 | ResetBuffer(); | |
406 | } | |
407 | ||
408 | ||
409 | void | |
410 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent() | |
411 | { | |
bdaaafe2 | 412 | //comment |
178dd351 | 413 | Init(); |
414 | fTotalSize = 0; | |
415 | } | |
416 | ||
417 | ||
418 | void | |
419 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( ) | |
420 | { | |
bdaaafe2 | 421 | //comment |
178dd351 | 422 | *fCurrentChannelSizePtr = fCurrentChannelSize; |
423 | fCurrentChannelIdPtr += fCurrentChannelSize; | |
424 | fCurrentChannelSizePtr += fCurrentChannelSize; | |
425 | fCurrentChannelDataPtr += fCurrentChannelSize; | |
426 | fBufferIndex = 0; | |
427 | fCurrentChannelSize = 2; | |
428 | fTotalSize += 2; | |
429 | } | |
430 | ||
431 | ||
432 | void | |
433 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin ) | |
434 | { | |
178dd351 | 435 | fCurrentChannelDataPtr[fBufferIndex] = starttimebin; |
436 | fCurrentChannelSize ++; | |
437 | fBufferIndex++; | |
438 | fCurrentChannelDataPtr[fBufferIndex] = length; | |
439 | fCurrentChannelSize ++; | |
440 | fBufferIndex++; | |
441 | ||
442 | fTotalSize +=2; | |
443 | ||
444 | for(int i=0; i < length; i++) | |
445 | { | |
446 | fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i]; | |
447 | } | |
448 | ||
449 | fCurrentChannelSize += length; | |
450 | fTotalSize += length; | |
451 | fBufferIndex += length; | |
452 | } | |
453 | ||
454 | ||
455 | void | |
456 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid ) | |
457 | { | |
178dd351 | 458 | *fCurrentChannelIdPtr = channeldid; |
459 | } | |
460 | ||
461 | ||
462 | void | |
463 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer() | |
464 | { | |
178dd351 | 465 | for(int i=0; i < fBufferSize ; i++ ) |
466 | { | |
467 | fRawDataBuffer[i] = 0; | |
468 | } | |
469 | } | |
470 | ||
471 | ||
472 | int | |
473 | AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused ) | |
474 | { | |
178dd351 | 475 | int sizerequested = (sizeof(int)*fTotalSize + sizeused); |
476 | ||
477 | if( sizerequested > sizetotal ) | |
478 | { | |
479 | return 0; | |
1e46316a | 480 | } |
178dd351 | 481 | else |
482 | { | |
483 | for(int i=0; i < fTotalSize; i++) | |
484 | { | |
485 | memPtr[i] = fRawDataBuffer[i]; | |
486 | } | |
487 | return fTotalSize; | |
1e46316a | 488 | } |
178dd351 | 489 | } |
490 |