]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/CALO/AliHLTCaloRawAnalyzerComponentv3.cxx
Eliminating gsi specific lines
[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 {
178dd351 224 if( fAltroRawStreamPtr->GetHWAddress() < 128 || ( fAltroRawStreamPtr->GetHWAddress() ^ 0x800) < 128 )
225 {
226 continue;
227 }
228 else
229 {
230 cnt ++;
231 UShort_t* firstBunchPtr;
232 UShort_t chId = fMapperPtr->GetChannelID(iter->fSpecification, fAltroRawStreamPtr->GetHWAddress());
233
234 if( fkDoPushRawData == true)
235 {
236 fRawDataWriter->SetChannelId( chId );
237 }
238 while( fAltroRawStreamPtr->NextBunch() == true )
239 {
240 nSamples = fAltroRawStreamPtr->GetBunchLength();
241
242 if( fkDoPushRawData == true)
243 {
244 // fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetStartTimeBin() );
245 fRawDataWriter->WriteBunchData( fAltroRawStreamPtr->GetSignals(), nSamples, fAltroRawStreamPtr->GetEndTimeBin() );
246 }
247 firstBunchPtr = const_cast< UShort_t* >( fAltroRawStreamPtr->GetSignals() );
248 }
249
250 totSize += sizeof( AliHLTCaloChannelDataStruct );
251 if(totSize > size)
252 {
253 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
254 return -1;
255 }
256
257 fAnalyzerPtr->SetData( firstBunchPtr, nSamples);
258 fAnalyzerPtr->Evaluate(0, nSamples);
259
260 // if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition)
261 {
262 channelDataPtr->fChannelID = chId;
263 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
264
265 if( channelDataPtr->fEnergy > 70 )
266 {
267 // cout << __FILE__ << __LINE__ << "The energy is of channel "<< chId << " is " << channelDataPtr->fEnergy << endl;
268 }
269
270 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
271 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
272 channelCount++;
273 channelDataPtr++; // Updating position of the free output.
274 }
275 }
276 fRawDataWriter->NewChannel();
277 }
278 }
279
280 //Writing the header
281 channelDataHeaderPtr->fNChannels = channelCount;
282 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
283 channelDataHeaderPtr->fInfo = 0;
284
285 if( fkDoPushRawData == true)
286 {
287 tmpsize += fRawDataWriter->CopyBufferToSharedMemory( (UShort_t *)channelDataPtr, size, totSize);
288 }
289
290 // channelDataHeaderPtr->fHasRawData = false;
291 channelDataHeaderPtr->fHasRawData = fkDoPushRawData;
292
293 HLTDebug("Number of channels: %d", channelCount);
294 //returning the size used
295 // delete fAltroRawStreamPtr;
296 tmpsize += sizeof(AliHLTCaloChannelDataStruct)*channelCount + sizeof(AliHLTCaloChannelDataHeaderStruct);
297
298 // return sizeof(AliHLTPHOSChannelDataStruct)*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
299 return tmpsize;
300
301}
302
303int
304AliHLTCaloRawAnalyzerComponentv3::DoInit( int argc, const char** argv )
305{
306
307 //See base class for documentation
308 // fPrintInfo = kFALSE;
309
310 int iResult=0;
311
312 // fMapperPtr = new AliHLTCaloMapper();
313 InitMapping();
314
315 for(int i = 0; i < argc; i++)
316 {
317 if(!strcmp("-offset", argv[i]))
318 {
319 fOffset = atoi(argv[i+1]);
320 }
321 if(!strcmp("-bunchsizecut", argv[i]))
322 {
323 fBunchSizeCut = atoi(argv[i+1]);
324 }
325 if(!strcmp("-minpeakposition", argv[i]))
326 {
327 fMinPeakPosition = atoi(argv[i+1]);
328 }
329 if(!strcmp("-maxpeakposition", argv[i]))
330 {
331 fMaxPeakPosition = atoi(argv[i+1]);
332 }
333 }
334
335 if( fMapperPtr->GetIsInitializedMapping() == false)
336 {
337 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTCaloMapper::Could not initialise mapping from file %s, aborting", fMapperPtr->GetFilePath());
338 return -4;
339 }
340
341 return iResult;
342}
343
344
345
346
347AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::RawDataWriter() : //fIsFirstChannel(true),
348 fRawDataBuffer(0),
349 fCurrentChannelSize(0),
350 // fIsFirstChannel(true),
351 fBufferIndex(0),
352 // fBufferSize( NZROWSRCU*NXCOLUMNSRCU*ALTROMAXSAMPLES*NGAINS +1000 ),
353 fBufferSize( 64*56*ALTROMAXSAMPLES*NGAINS +1000 ),
354 fCurrentChannelIdPtr(0),
355 fCurrentChannelSizePtr(0),
356 fCurrentChannelDataPtr(0),
357 fTotalSize(0)
358{
178dd351 359 fRawDataBuffer = new UShort_t[fBufferSize];
360 Init();
361}
362
363
364
365void
366AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::Init()
367{
178dd351 368 fCurrentChannelIdPtr = fRawDataBuffer;
369 fCurrentChannelSizePtr = fRawDataBuffer +1;
370 fCurrentChannelDataPtr = fRawDataBuffer +2;
371 ResetBuffer();
372}
373
374
375void
376AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewEvent()
377{
178dd351 378 Init();
379 fTotalSize = 0;
380}
381
382
383void
384AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::NewChannel( )
385{
178dd351 386 *fCurrentChannelSizePtr = fCurrentChannelSize;
387 fCurrentChannelIdPtr += fCurrentChannelSize;
388 fCurrentChannelSizePtr += fCurrentChannelSize;
389 fCurrentChannelDataPtr += fCurrentChannelSize;
390 fBufferIndex = 0;
391 fCurrentChannelSize = 2;
392 fTotalSize += 2;
393}
394
395
396void
397AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::WriteBunchData(const UShort_t *bunchdata, const int length, const UInt_t starttimebin )
398{
178dd351 399 fCurrentChannelDataPtr[fBufferIndex] = starttimebin;
400 fCurrentChannelSize ++;
401 fBufferIndex++;
402 fCurrentChannelDataPtr[fBufferIndex] = length;
403 fCurrentChannelSize ++;
404 fBufferIndex++;
405
406 fTotalSize +=2;
407
408 for(int i=0; i < length; i++)
409 {
410 fCurrentChannelDataPtr[ fBufferIndex + i ] = bunchdata[i];
411 }
412
413 fCurrentChannelSize += length;
414 fTotalSize += length;
415 fBufferIndex += length;
416}
417
418
419void
420AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::SetChannelId( const UShort_t channeldid )
421{
178dd351 422 *fCurrentChannelIdPtr = channeldid;
423}
424
425
426void
427AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::ResetBuffer()
428{
178dd351 429 for(int i=0; i < fBufferSize ; i++ )
430 {
431 fRawDataBuffer[i] = 0;
432 }
433}
434
435
436int
437AliHLTCaloRawAnalyzerComponentv3::RawDataWriter::CopyBufferToSharedMemory(UShort_t *memPtr, const int sizetotal, const int sizeused )
438{
178dd351 439 int sizerequested = (sizeof(int)*fTotalSize + sizeused);
440
441 if( sizerequested > sizetotal )
442 {
443 return 0;
444 }
445 else
446 {
447 for(int i=0; i < fTotalSize; i++)
448 {
449 memPtr[i] = fRawDataBuffer[i];
450 }
451 return fTotalSize;
452 }
453}
454