]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
Bug fix. Incorrect usage of types was corrected.
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRawAnalyzerComponent.cxx
CommitLineData
cbab66dd 1/**************************************************************************
99388135 2 * This file is property of and copyright by the Experimental Nuclear *
3 * Physics Group, Dep. of Physics *
4 * University of Oslo, Norway, 2007 *
5 * *
6 * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
cbab66dd 7 * Contributors are mentioned in the code where appropriate. *
99388135 8 * Please report bugs to perthi@fys.uio.no *
cbab66dd 9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19#include "AliHLTPHOSRawAnalyzerComponent.h"
20#include <iostream>
9dfd64cf 21#include "stdio.h"
22#include "AliRawReaderMemory.h"
0a211711 23#include "AliCaloRawStream.h"
2947a32c 24#include <cstdlib>
bde48b84 25#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
cbab66dd 26
ee7849e6 27const AliHLTComponentDataType AliHLTPHOSRawAnalyzerComponent::inputDataTypes[]={kAliHLTVoidDataType,{0,"",""}}; //'zero' terminated array
2bcb5a06 28int AliHLTPHOSRawAnalyzerComponent::fEventCount = 0;
ee7849e6 29
4df5dd10 30
1c1b3412 31/**
32 * @class AliHLTPHOSRawAnalyzerComponent
33 * Base class of PHOS HLT online raw analysis component.
34 * The class provides a common interface for the implementation of PHOS
35 * HLT raw data
36 * processors components. The class is intended for processing of
37 * arrays of raw data samples to evaluate energy and timing.
38 * The Energy will be given in entities of ADC leves ranging from 0 to
39 * 1023. Timing will be given in entities of samples periods.
40 * Drived clases must implement the fucntions
41 * - @ref GetComponentID
42 * - @ref Spawn
43 */
44AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTProcessor(), analyzerPtr(0), fEquippmentID(0), fRcuX(0),
45fRcuZ(0),fRcuZOffset(0), fRcuXOffset(0), fModuleID(0), fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
cbab66dd 46{
cf434398 47
cbab66dd 48}
49
50AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
51{
0a211711 52 if(fRawMemoryReader != 0)
53 {
54 delete fRawMemoryReader;
55 }
56 if(fPHOSRawStream != 0)
57 {
58 delete fPHOSRawStream;
59 }
60
cbab66dd 61}
62
63
0a211711 64
1c1b3412 65AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent(const AliHLTPHOSRawAnalyzerComponent & ) : AliHLTProcessor(), analyzerPtr(0),
66fEquippmentID(0), fRcuX(0), fRcuZ(0),fRcuZOffset(0), fRcuXOffset(0), fModuleID(0), fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
cbab66dd 67{
cbab66dd 68}
69
9dfd64cf 70
1c1b3412 71/*
72 *Deinit function called by the HLT framwork at end of run
73 *@return 0 if the denitialzation was sucessfull.
74 */
cbab66dd 75int
76AliHLTPHOSRawAnalyzerComponent::Deinit()
77{
78 return 0;
79}
80
1c1b3412 81
82/*
83 *Deinit function called by the HLT framwork at end of run
84 *@return 0 if the denitialzation was sucessfull.
85 */
cbab66dd 86int
87AliHLTPHOSRawAnalyzerComponent::DoDeinit()
88{
9dfd64cf 89 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen DoDeinit");
90
0a211711 91 if(fRawMemoryReader !=0)
92 {
93 delete fRawMemoryReader;
94 }
95
96 if(fPHOSRawStream != 0)
97 {
98 delete fPHOSRawStream;
99 }
cbab66dd 100 return 0;
cbab66dd 101
cbab66dd 102}
103
1c1b3412 104/*
105 *Function called by the HLT framework during initialization
106 *@return the ID of the component
107 */
9dfd64cf 108const char*
109AliHLTPHOSRawAnalyzerComponent::GetComponentID()
110{
111 return "AliPhosTestRaw";
112}
ee7849e6 113
1c1b3412 114
cbab66dd 115void
ee7849e6 116AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
cbab66dd 117{
ee7849e6 118 const AliHLTComponentDataType* pType=inputDataTypes;
119 while (pType->fID!=0) {
120 list.push_back(*pType);
121 pType++;
122 }
cbab66dd 123}
124
125AliHLTComponentDataType
126AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
127{
53740333 128 return AliHLTPHOSDefinitions::gkCellEnergyDataType;
cbab66dd 129}
130
131void
9dfd64cf 132AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
133
cbab66dd 134{
ef408bb3 135 constBase = 30;
136 inputMultiplier = 0.1;
cbab66dd 137}
138
0a211711 139
140int AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
141 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
142 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
cbab66dd 143{
1c1b3412 144 // Int_t tmpMod = 0;
145 // Int_t tmpZ = 0;
146 // Int_t tmpX = 0;
147 // Int_t tmpGain = 0;
148
149 AliHLTUInt8_t tmpMod = 0;
150 AliHLTUInt8_t tmpZ = 0;
151 AliHLTUInt8_t tmpX = 0;
152 AliHLTUInt8_t tmpGain = 0;
153
bde48b84 154 Int_t sampleCnt = 0;
2947a32c 155 Int_t processedChannels = 0;
bde48b84 156 UInt_t offset = 0;
157 UInt_t mysize = 0;
158 UInt_t tSize = 0;
2bcb5a06 159 Int_t tmpChannelCnt = 0;
432edd34 160 Int_t tmpStartIndex = 0;
53740333 161 AliHLTUInt8_t* outBPtr;
53740333 162 outBPtr = outputPtr;
0a211711 163 const AliHLTComponentBlockData* iter = NULL;
164 unsigned long ndx;
cf434398 165
68d9caee 166 if((fEventCount % 100) == 0)
167 {
d4ef0417 168 // cout << "analyzing event: " << fEventCount << endl;
68d9caee 169 }
2947a32c 170
0a211711 171 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
172 {
0a211711 173 iter = blocks+ndx;
53740333 174 mysize = 0;
175 offset = tSize;
176
0a211711 177 if ( iter->fDataType != AliHLTPHOSDefinitions::gkDDLPackedRawDataType )
178 {
d4ef0417 179 // cout << "Warning: data type = is nOT gkDDLPackedRawDataType " << endl;
0a211711 180 continue;
181 }
ef408bb3 182
bde48b84 183 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
184 analyzerPtr->SetData(fTmpChannelData);
a00e1689 185 fOutPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
bde48b84 186 mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
a00e1689 187 fOutPtr->fRcuX = fRcuX;
188 fOutPtr->fRcuZ = fRcuZ;
189 fOutPtr->fModuleID = fModuleID;
2bcb5a06 190 tmpChannelCnt = 0;
2bcb5a06 191
a00e1689 192 if(fEventCount%100 ==0)
193 {
d4ef0417 194 // cout <<"Analyzing event: " << fEventCount << endl;
a00e1689 195 }
196
2947a32c 197 while(fPHOSRawStream->Next())
198 {
199 if (fPHOSRawStream->IsNewHWAddress())
200 {
201 if(processedChannels > 0)
202 {
203 analyzerPtr->SetData(fTmpChannelData);
68d9caee 204 analyzerPtr->Evaluate(0, sampleCnt);
68d9caee 205 sampleCnt = 0;
a00e1689 206 fOutPtr->fValidData[tmpChannelCnt].fGain = tmpGain;
1c1b3412 207 fOutPtr->fValidData[tmpChannelCnt].fZ = tmpZ;
208 fOutPtr->fValidData[tmpChannelCnt].fX = tmpX;
432edd34 209 fOutPtr->fValidData[tmpChannelCnt].fEnergy = analyzerPtr->GetEnergy();
210 fOutPtr->fValidData[tmpChannelCnt].fTime = analyzerPtr->GetTiming();
2bcb5a06 211 tmpChannelCnt ++;
432edd34 212 ResetDataPtr(tmpStartIndex, sampleCnt);
68d9caee 213 sampleCnt = 0;
2947a32c 214 }
215
1c1b3412 216 tmpMod = (AliHLTUInt8_t)fPHOSRawStream->GetModule() ;
217
218 tmpX =(AliHLTUInt8_t)fPHOSRawStream->GetRow() - fRcuXOffset;
219 tmpZ =(AliHLTUInt8_t)fPHOSRawStream->GetColumn() - fRcuZOffset;
220
221 // if(tmpZ < 0)
222
223 /*
224 {
225 cout << endl << endl;
226 cout << "RCUZ = " <<fRcuZ <<"\t";
227 cout << "Equippment ID ="<< fRawMemoryReader->GetEquipmentId() << "\t";
228 cout << "fPHOSRawStream->GetrOW() = " << fPHOSRawStream->GetRow() <<"\t";
229 cout << "fRcuZOffset = "<< fRcuZOffset <<"\t";
230 cout << " fPHOSRawStream->GetRow() - fRcuZOffset = " << fPHOSRawStream->GetRow() - fRcuZOffset << "\t";
231 cout << " AliHLTPHOSRawAnalyzerComponent::DoEven: tmpZ =" << tmpZ<< "\t";
232 }
233
234 // if(tmpX < 0)
235 {
236 cout << endl;
237 cout << "RCUX = " <<fRcuX <<"\t";
238 cout << "Equippment ID ="<< fRawMemoryReader->GetEquipmentId() << "\t";
239 cout << "fPHOSRawStream->GetColumn() = " << fPHOSRawStream->GetColumn() << "\t";
240 cout << "fRcuXOffset = "<< fRcuXOffset <<"\t";
241 cout << " fPHOSRawStream->GetColumn() - fRcuXOffset = " << fPHOSRawStream->GetColumn() - fRcuXOffset << "\t";
242 cout << " AliHLTPHOSRawAnalyzerComponent::DoEven: tmpX =" << tmpX<< "\t";
243 }
244
245 */
246
247
2947a32c 248 tmpGain = fPHOSRawStream->IsLowGain();
249 processedChannels ++;
250 }
432edd34 251
252 if(sampleCnt == 0)
253 {
254 tmpStartIndex = fPHOSRawStream->GetTime();
255 }
256
2947a32c 257 fTmpChannelData[fPHOSRawStream->GetTime()] = fPHOSRawStream->GetSignal();
bde48b84 258 sampleCnt ++;
68d9caee 259
2947a32c 260 }
a00e1689 261
262 fOutPtr->fCnt = tmpChannelCnt;
53740333 263 AliHLTComponentBlockData bd;
264 FillBlockData( bd );
53740333 265 bd.fOffset = offset;
266 bd.fSize = mysize;
53740333 267 bd.fDataType = AliHLTPHOSDefinitions::gkCellEnergyDataType;
9ce19a20 268 bd.fSpecification = 0xFFFFFFFF;
53740333 269 outputBlocks.push_back( bd );
53740333 270 tSize += mysize;
271 outBPtr += mysize;
272
cf434398 273 if( tSize > size )
53740333 274 {
275 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
276 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
277 , tSize, size );
278 return EMSGSIZE;
279 }
2947a32c 280 }
53740333 281
2947a32c 282 fEventCount++;
53740333 283 size = tSize;
2947a32c 284 return 0;
285}//end DoEvent
0a211711 286
287
288
289int
290AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
291{
53740333 292 int equippmentID = atoi(argv[6]);
2947a32c 293 Reset();
0a211711 294 fRawMemoryReader = new AliRawReaderMemory();
295 fPHOSRawStream = new AliCaloRawStream(fRawMemoryReader,"PHOS");
1c1b3412 296 fPHOSRawStream->SetOldRCUFormat(kFALSE);
53740333 297 fRawMemoryReader->SetEquipmentID(equippmentID);
53740333 298 SetEquippmentID(equippmentID);
299 SetCoordinates(equippmentID);
0a211711 300 if (argc==0 && argv==NULL) {
301 // this is currently just to get rid of the warning "unused parameter"
302 }
303 return 0;
304}
9dfd64cf 305
2947a32c 306void
432edd34 307AliHLTPHOSRawAnalyzerComponent::DumpData(int gain)
0a211711 308{
432edd34 309 for(int mod = 0; mod < N_MODULES; mod ++)
2947a32c 310 {
311 printf("\n *********** MODULE %d ************\n", mod);
432edd34 312 for(int row = 0; row < N_ROWS_MOD; row ++)
2947a32c 313 {
432edd34 314 for(int col = 0; col < N_COLUMNS_MOD; col ++)
2947a32c 315 {
316 if( fMaxValues[mod][row][col][0] != 0)
317 {
432edd34 318 cout << fMaxValues[mod][row][col][gain] << "\t";
2947a32c 319 }
320 }
321 }
322 }
323}
9dfd64cf 324
432edd34 325
326void
327AliHLTPHOSRawAnalyzerComponent::DumpData()
328{
329 DumpData(0);
330}
331
68d9caee 332void
333AliHLTPHOSRawAnalyzerComponent::DumpChannelData(Double_t *data)
334{
335 cout << endl;
336
432edd34 337 for(int i=0; i< ALTRO_MAX_SAMPLES; i++)
68d9caee 338 {
339 if (data[i] != 0)
340 {
341 cout <<i <<"\t";
342 }
343 }
344 cout << endl;
345
432edd34 346 for(int i=0; i< ALTRO_MAX_SAMPLES; i++)
68d9caee 347 {
348 if (data[i] != 0)
349 {
350 cout <<data[i] <<"\t";
351 }
352 }
353
354 cout << endl;
355}
356
357
0a211711 358
2947a32c 359void
360AliHLTPHOSRawAnalyzerComponent::Reset()
361{
432edd34 362 for(int mod = 0; mod < N_MODULES; mod ++)
9dfd64cf 363 {
432edd34 364 for(int row = 0; row < N_ROWS_MOD; row ++)
2947a32c 365 {
432edd34 366 for(int col = 0; col < N_COLUMNS_MOD; col ++)
2947a32c 367 {
432edd34 368 for(int gain = 0; gain < N_GAINS; gain ++ )
2947a32c 369 {
370 fMaxValues[mod][row][col][gain] = 0;
371 }
372 }
373 }
374 }
9dfd64cf 375
432edd34 376 ResetDataPtr();
377
378} // end Reset
379
380
381
382void
383AliHLTPHOSRawAnalyzerComponent::ResetDataPtr()
384{
385 for(int i = 0 ; i< ALTRO_MAX_SAMPLES; i++)
386 {
387 fTmpChannelData[i] = 0;
388 }
389}
390
391void
392AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int sampleCnt)
393{
394 for(int i = 0 ; i< sampleCnt; i++)
2947a32c 395 {
396 fTmpChannelData[i] = 0;
0a211711 397 }
432edd34 398}
9dfd64cf 399
2947a32c 400void
432edd34 401AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
2947a32c 402{
432edd34 403 for(int i = startindex ; i< sampleCnt; i++)
2947a32c 404 {
405 fTmpChannelData[i] = 0;
406 }
cbab66dd 407}
ef408bb3 408
409
410void
1c1b3412 411//AliHLTPHOSRawAnalyzerComponent::SetEquippmentID(AliHLTUInt32_t id)
412AliHLTPHOSRawAnalyzerComponent::SetEquippmentID(AliHLTUInt16_t id)
ef408bb3 413{
53740333 414 fEquippmentID = id;
ef408bb3 415}
416
1c1b3412 417AliHLTUInt16_t
53740333 418AliHLTPHOSRawAnalyzerComponent::GetEquippmentID()
419{
420 return fEquippmentID;
421}
422
53740333 423void
1c1b3412 424//AliHLTPHOSRawAnalyzerComponent::SetCoordinates(AliHLTUInt32_t equippmentID)
425AliHLTPHOSRawAnalyzerComponent::SetCoordinates(AliHLTUInt16_t equippmentID)
ef408bb3 426{
1c1b3412 427 // int rcuIndex = (fEquippmentID - 1792)%N_RCUS_PER_MODULE;
428 int rcuIndex = (fEquippmentID - 1792)%N_RCUS_PER_MODULE;
53740333 429
1c1b3412 430 fModuleID = (fEquippmentID -1792 -rcuIndex)/N_RCUS_PER_MODULE;
431
53740333 432 if(rcuIndex == 0)
433 {
434 fRcuX = 0;
cf434398 435 fRcuZ = 0;
53740333 436 }
437
438 if(rcuIndex == 1)
439 {
cf434398 440 fRcuX = 0;
441 fRcuZ = 1;
53740333 442 }
443
444 if(rcuIndex == 2)
445 {
cf434398 446 fRcuX = 1;
447 fRcuZ = 0;
53740333 448 }
449
450
cf434398 451 if(rcuIndex == 3)
53740333 452 {
453 fRcuX = 1;
cf434398 454 fRcuZ = 1;
53740333 455 }
1c1b3412 456
457
53740333 458
1c1b3412 459 fRcuZOffset = N_ZROWS_RCU*fRcuZ;
460 fRcuXOffset = N_XCOLUMNS_RCU*fRcuX;
cf434398 461
1c1b3412 462 cout <<"********InitInfo************"<< endl;
463 cout <<"AliHLTPHOSRawAnalyzerComponent::SetCoordinate"<< endl;
464 cout <<"Equpippment ID =\t"<< fEquippmentID <<endl;
465 cout <<"Module ID =\t"<< fModuleID<<endl;
466 cout <<"RCUX =\t\t" << fRcuX << endl;
467 cout <<"RCUZ =\t\t" << fRcuZ << endl;
468 cout <<"RcuZOffset = \t" << fRcuZOffset << endl;
469 cout <<"RcuXOffset = \t" << fRcuXOffset << endl << endl;
ef408bb3 470}