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