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