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