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