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