]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
Coding conventions
[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
2b7cf4fb 19
20/// @class AliHLTPHOSRawAnalyzerComponent
21/// Base class of PHOS HLT online raw analysis component.
22/// The class provides a common interface for the implementation of PHOS
23/// HLT raw data
24/// processors components. The class is intended for processing of
25/// arrays of raw data samples to evaluate energy and timing.
26/// The Energy will be given in entities of ADC leves ranging from 0 to
27/// 1023. Timing will be given in entities of samples periods.
28/// Drived clases must implement the fucntions
29/// - @ref GetComponentID
30/// - @ref Spawn
31
32
33
34#include "AliHLTPHOSRawAnalyzer.h"
cbab66dd 35#include "AliHLTPHOSRawAnalyzerComponent.h"
9dfd64cf 36#include "AliRawReaderMemory.h"
0a211711 37#include "AliCaloRawStream.h"
2947a32c 38#include <cstdlib>
bde48b84 39#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
2b7cf4fb 40#include "AliHLTPHOSRcuChannelDataStruct.h"
cbab66dd 41
146c463a 42const AliHLTComponentDataType AliHLTPHOSRawAnalyzerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}}; //'zero' terminated array
43int AliHLTPHOSRawAnalyzerComponent::fgEventCount = 0;
ee7849e6 44
4df5dd10 45
2b7cf4fb 46
47AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTProcessor(), fAnalyzerPtr(0),
48fEquippmentID(0), fModuleID(0), fRcuX(0), fRcuZ(0),fRcuZOffset(0), fRcuXOffset(0),fPrintInfo(kFALSE),fSendChannelData(kFALSE),fPrintInfoFrequncy(1000),
49fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
cbab66dd 50{
cf434398 51
2b7cf4fb 52
53
54
cbab66dd 55}
56
2b7cf4fb 57
cbab66dd 58AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
59{
2b7cf4fb 60 ///Default destructor
61
0a211711 62 if(fRawMemoryReader != 0)
63 {
64 delete fRawMemoryReader;
65 }
66 if(fPHOSRawStream != 0)
67 {
68 delete fPHOSRawStream;
69 }
70
cbab66dd 71}
72
73
146c463a 74AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent(const AliHLTPHOSRawAnalyzerComponent & ) : AliHLTProcessor(), fAnalyzerPtr(0),
2b7cf4fb 75fEquippmentID(0), fModuleID(0), fRcuX(0), fRcuZ(0),fRcuZOffset(0), fRcuXOffset(0),fPrintInfo(kFALSE),fSendChannelData(kFALSE),fPrintInfoFrequncy(1000),
76fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
cbab66dd 77{
2b7cf4fb 78 //Copy Constructor
cbab66dd 79}
80
81int
82AliHLTPHOSRawAnalyzerComponent::Deinit()
83{
2b7cf4fb 84 //See base class for documentation
857f8ed5 85 cout << "Deinit" << endl;
cbab66dd 86 return 0;
87}
88
89int
90AliHLTPHOSRawAnalyzerComponent::DoDeinit()
91{
2b7cf4fb 92 //See base class for documentation
857f8ed5 93 cout << "DoDeinit" << endl;
9dfd64cf 94 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen DoDeinit");
95
0a211711 96 if(fRawMemoryReader !=0)
97 {
98 delete fRawMemoryReader;
99 }
100
101 if(fPHOSRawStream != 0)
102 {
103 delete fPHOSRawStream;
104 }
cbab66dd 105 return 0;
cbab66dd 106
cbab66dd 107}
108
9dfd64cf 109const char*
110AliHLTPHOSRawAnalyzerComponent::GetComponentID()
111{
2b7cf4fb 112 ///Returns the component ID
9dfd64cf 113 return "AliPhosTestRaw";
114}
ee7849e6 115
1c1b3412 116
cbab66dd 117void
ee7849e6 118AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
cbab66dd 119{
2b7cf4fb 120 //See Base class for documentation
146c463a 121 const AliHLTComponentDataType* pType=fgkInputDataTypes;
ee7849e6 122 while (pType->fID!=0) {
123 list.push_back(*pType);
124 pType++;
125 }
cbab66dd 126}
127
128AliHLTComponentDataType
129AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
130{
2b7cf4fb 131 //See Base class for documentation
53740333 132 return AliHLTPHOSDefinitions::gkCellEnergyDataType;
cbab66dd 133}
134
135void
9dfd64cf 136AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
137
cbab66dd 138{
2b7cf4fb 139 //See Base class for documentation
ef408bb3 140 constBase = 30;
2b7cf4fb 141 // inputMultiplier = 0.1;
142 inputMultiplier = 1;
cbab66dd 143}
144
0a211711 145int AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
146 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
147 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
cbab66dd 148{
2b7cf4fb 149 /// Function that proceesses the raw date to give Energy and TOF for the
150 /// Individual cells/crystals.
151
857f8ed5 152 AliHLTUInt8_t tmpMod = 0;
153 AliHLTUInt8_t tmpZ = 0;
154 AliHLTUInt8_t tmpX = 0;
155 AliHLTUInt8_t tmpGain = 0;
bde48b84 156 Int_t sampleCnt = 0;
2947a32c 157 Int_t processedChannels = 0;
bde48b84 158 UInt_t offset = 0;
159 UInt_t mysize = 0;
160 UInt_t tSize = 0;
2bcb5a06 161 Int_t tmpChannelCnt = 0;
432edd34 162 Int_t tmpStartIndex = 0;
53740333 163 AliHLTUInt8_t* outBPtr;
2b7cf4fb 164 unsigned long first;
165 unsigned long last;
53740333 166 outBPtr = outputPtr;
0a211711 167 const AliHLTComponentBlockData* iter = NULL;
168 unsigned long ndx;
cf434398 169
0a211711 170 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
171 {
0a211711 172 iter = blocks+ndx;
53740333 173 mysize = 0;
174 offset = tSize;
175
0a211711 176 if ( iter->fDataType != AliHLTPHOSDefinitions::gkDDLPackedRawDataType )
177 {
0a211711 178 continue;
179 }
ef408bb3 180
bde48b84 181 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
146c463a 182 fAnalyzerPtr->SetData(fTmpChannelData);
a00e1689 183 fOutPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
bde48b84 184 mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
a00e1689 185 fOutPtr->fRcuX = fRcuX;
186 fOutPtr->fRcuZ = fRcuZ;
187 fOutPtr->fModuleID = fModuleID;
2bcb5a06 188 tmpChannelCnt = 0;
2b7cf4fb 189
2947a32c 190 while(fPHOSRawStream->Next())
191 {
192 if (fPHOSRawStream->IsNewHWAddress())
193 {
194 if(processedChannels > 0)
195 {
146c463a 196 fAnalyzerPtr->SetData(fTmpChannelData);
197 fAnalyzerPtr->Evaluate(0, sampleCnt);
a00e1689 198 fOutPtr->fValidData[tmpChannelCnt].fGain = tmpGain;
1c1b3412 199 fOutPtr->fValidData[tmpChannelCnt].fZ = tmpZ;
200 fOutPtr->fValidData[tmpChannelCnt].fX = tmpX;
2b7cf4fb 201 fOutPtr->fValidData[tmpChannelCnt].fEnergy = (float)fAnalyzerPtr->GetEnergy();
202 fOutPtr->fValidData[tmpChannelCnt].fTime = (float)fAnalyzerPtr->GetTiming();
432edd34 203 ResetDataPtr(tmpStartIndex, sampleCnt);
2b7cf4fb 204 tmpChannelCnt ++;
68d9caee 205 sampleCnt = 0;
2947a32c 206 }
207
1c1b3412 208 tmpMod = (AliHLTUInt8_t)fPHOSRawStream->GetModule() ;
1c1b3412 209 tmpX =(AliHLTUInt8_t)fPHOSRawStream->GetRow() - fRcuXOffset;
210 tmpZ =(AliHLTUInt8_t)fPHOSRawStream->GetColumn() - fRcuZOffset;
2947a32c 211 tmpGain = fPHOSRawStream->IsLowGain();
212 processedChannels ++;
213 }
432edd34 214
215 if(sampleCnt == 0)
216 {
217 tmpStartIndex = fPHOSRawStream->GetTime();
218 }
219
2947a32c 220 fTmpChannelData[fPHOSRawStream->GetTime()] = fPHOSRawStream->GetSignal();
bde48b84 221 sampleCnt ++;
2947a32c 222 }
2b7cf4fb 223
006ee9b2 224 tmpChannelCnt ++;
146c463a 225 fAnalyzerPtr->SetData(fTmpChannelData);
226 fAnalyzerPtr->Evaluate(0, sampleCnt);
006ee9b2 227 fOutPtr->fValidData[tmpChannelCnt].fGain = tmpGain;
228 fOutPtr->fValidData[tmpChannelCnt].fZ = tmpZ;
229 fOutPtr->fValidData[tmpChannelCnt].fX = tmpX;
146c463a 230 fOutPtr->fValidData[tmpChannelCnt].fEnergy = fAnalyzerPtr->GetEnergy();
231 fOutPtr->fValidData[tmpChannelCnt].fTime = fAnalyzerPtr->GetTiming();
857f8ed5 232 ResetDataPtr(tmpStartIndex, sampleCnt);
006ee9b2 233
2b7cf4fb 234 sampleCnt = 0;
006ee9b2 235
a00e1689 236 fOutPtr->fCnt = tmpChannelCnt;
53740333 237 AliHLTComponentBlockData bd;
238 FillBlockData( bd );
53740333 239 bd.fOffset = offset;
240 bd.fSize = mysize;
53740333 241 bd.fDataType = AliHLTPHOSDefinitions::gkCellEnergyDataType;
9ce19a20 242 bd.fSpecification = 0xFFFFFFFF;
53740333 243 outputBlocks.push_back( bd );
53740333 244 tSize += mysize;
245 outBPtr += mysize;
2b7cf4fb 246
cf434398 247 if( tSize > size )
2b7cf4fb 248 {
249 cout <<"kHLTLogFatal, HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent Too much data Data written over allowed buffer. Amount written:" << tSize << " allowed" << size << endl;
250 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
251 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
252 , tSize, size );
253 return EMSGSIZE;
254 }
53740333 255
2b7cf4fb 256 }
257
146c463a 258 fgEventCount++;
2b7cf4fb 259
260 if(fPrintInfo == kTRUE)
261 {
262 if(fgEventCount%fPrintInfoFrequncy == 0)
263 {
264 cout <<"Analyzing event " << fgEventCount << "for Equippment " << fEquippmentID << endl;
265 }
266 }
53740333 267 size = tSize;
2947a32c 268 return 0;
269}//end DoEvent
0a211711 270
271
2b7cf4fb 272
0a211711 273int
274AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
275{
2b7cf4fb 276 /// See base class for documentation
277 fSendChannelData = kFALSE;
278 fPrintInfo = kFALSE;
2947a32c 279 Reset();
0a211711 280 fRawMemoryReader = new AliRawReaderMemory();
281 fPHOSRawStream = new AliCaloRawStream(fRawMemoryReader,"PHOS");
1c1b3412 282 fPHOSRawStream->SetOldRCUFormat(kFALSE);
2b7cf4fb 283 int iResult=0;
284 TString argument="";
285 Bool_t isSetEquippmentID = kFALSE;
286
287 for(int i=0; i<argc && iResult>=0; i++)
288 {
289 argument=argv[i];
290
291 if (argument.IsNull())
292 {
293 continue;
294 }
295
296 if (argument.CompareTo("-equipmentID") == 0)
297 {
298 cout << "AliHLTPHOSRawAnalyzerComponent:DoInit argument = -equipmentID " <<endl;
299 if(i+1 <= argc)
300 {
301 fEquippmentID = atoi(argv[i+1]);
302 cout << "AliHLTPHOSRawAnalyzerComponent:DoInit setting equippment ID to " << fEquippmentID <<endl;
303 fRawMemoryReader->SetEquipmentID(fEquippmentID);
304 SetEquippmentID(fEquippmentID);
305 SetCoordinates(fEquippmentID);
306 isSetEquippmentID = kTRUE;
307 }
308 else
309 {
310 iResult= -1;
311 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuHistogramProducerComponent::DoInt( int argc, const char** argv )", "Missing argument",
312 "The argument -equippmentID expects a number");
313 return iResult;
314 }
315 }
316
317
318 if (argument.CompareTo("-datatype") == 0)
319 {
320 if(i+1 <= argc)
321 {
322 argument=argv[i+1];
323 if(argument.CompareTo("channeldata") == 0)
324 {
325 cout << "AliHLTPHOSRawAnalyzerComponent::DoIni setting sendChannelData = kTRUE "<< endl;
326 fSendChannelData = kTRUE;
327 }
328 }
329 }
330
331 if (argument.CompareTo("-printinfo") == 0)
332 {
333 if(i+1 <= argc)
334 {
335 argument=argv[i+1];
336 fPrintInfoFrequncy = atoi(argv[i+1]);
337 fPrintInfo = kTRUE;
338 cout << "AliHLTPHOSRawAnalyzerComponent::DoIni setting printinfo = kTRUE, with update frequency every "<< fPrintInfoFrequncy << "th event" <<endl;
339 }
340 else
341 {
342 cout << "WARNING: asking for event info, but no update frequency is specified, otipn is ignored" << endl;
343 }
344 }
345
346 }
347
348
349 if(isSetEquippmentID == kFALSE)
350 {
351 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuHistogramProducerComponent::DoInt( int argc, const char** argv )", "Missing argument",
352 "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>");
353 iResult = -2;
354 }
355
0a211711 356 return 0;
357}
9dfd64cf 358
05be0766 359
2947a32c 360void
432edd34 361AliHLTPHOSRawAnalyzerComponent::DumpData(int gain)
0a211711 362{
2b7cf4fb 363 //Dumping data to std out
432edd34 364 for(int mod = 0; mod < N_MODULES; mod ++)
2947a32c 365 {
366 printf("\n *********** MODULE %d ************\n", mod);
432edd34 367 for(int row = 0; row < N_ROWS_MOD; row ++)
2947a32c 368 {
432edd34 369 for(int col = 0; col < N_COLUMNS_MOD; col ++)
2947a32c 370 {
371 if( fMaxValues[mod][row][col][0] != 0)
372 {
432edd34 373 cout << fMaxValues[mod][row][col][gain] << "\t";
2947a32c 374 }
375 }
376 }
377 }
378}
9dfd64cf 379
432edd34 380
68d9caee 381void
382AliHLTPHOSRawAnalyzerComponent::DumpChannelData(Double_t *data)
383{
384 cout << endl;
432edd34 385 for(int i=0; i< ALTRO_MAX_SAMPLES; i++)
68d9caee 386 {
387 if (data[i] != 0)
388 {
389 cout <<i <<"\t";
390 }
391 }
392 cout << endl;
393
432edd34 394 for(int i=0; i< ALTRO_MAX_SAMPLES; i++)
68d9caee 395 {
396 if (data[i] != 0)
397 {
398 cout <<data[i] <<"\t";
399 }
400 }
401
402 cout << endl;
403}
404
405
2947a32c 406void
407AliHLTPHOSRawAnalyzerComponent::Reset()
408{
432edd34 409 for(int mod = 0; mod < N_MODULES; mod ++)
9dfd64cf 410 {
432edd34 411 for(int row = 0; row < N_ROWS_MOD; row ++)
2947a32c 412 {
432edd34 413 for(int col = 0; col < N_COLUMNS_MOD; col ++)
2947a32c 414 {
432edd34 415 for(int gain = 0; gain < N_GAINS; gain ++ )
2947a32c 416 {
417 fMaxValues[mod][row][col][gain] = 0;
418 }
419 }
420 }
421 }
9dfd64cf 422
2b7cf4fb 423 ResetDataPtr(0, ALTRO_MAX_SAMPLES);
432edd34 424
425} // end Reset
426
2947a32c 427void
432edd34 428AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
2947a32c 429{
432edd34 430 for(int i = startindex ; i< sampleCnt; i++)
2947a32c 431 {
432 fTmpChannelData[i] = 0;
433 }
cbab66dd 434}
ef408bb3 435
ef408bb3 436void
1c1b3412 437AliHLTPHOSRawAnalyzerComponent::SetEquippmentID(AliHLTUInt16_t id)
ef408bb3 438{
53740333 439 fEquippmentID = id;
ef408bb3 440}
441
05be0766 442
2b7cf4fb 443const AliHLTUInt16_t
53740333 444AliHLTPHOSRawAnalyzerComponent::GetEquippmentID()
445{
446 return fEquippmentID;
447}
448
53740333 449void
1c1b3412 450AliHLTPHOSRawAnalyzerComponent::SetCoordinates(AliHLTUInt16_t equippmentID)
ef408bb3 451{
1c1b3412 452 int rcuIndex = (fEquippmentID - 1792)%N_RCUS_PER_MODULE;
1c1b3412 453 fModuleID = (fEquippmentID -1792 -rcuIndex)/N_RCUS_PER_MODULE;
454
53740333 455 if(rcuIndex == 0)
456 {
457 fRcuX = 0;
cf434398 458 fRcuZ = 0;
53740333 459 }
460
461 if(rcuIndex == 1)
462 {
cf434398 463 fRcuX = 0;
464 fRcuZ = 1;
53740333 465 }
466
467 if(rcuIndex == 2)
468 {
cf434398 469 fRcuX = 1;
470 fRcuZ = 0;
53740333 471 }
472
cf434398 473 if(rcuIndex == 3)
53740333 474 {
475 fRcuX = 1;
cf434398 476 fRcuZ = 1;
53740333 477 }
478
1c1b3412 479 fRcuZOffset = N_ZROWS_RCU*fRcuZ;
480 fRcuXOffset = N_XCOLUMNS_RCU*fRcuX;
cf434398 481
1c1b3412 482 cout <<"********InitInfo************"<< endl;
483 cout <<"AliHLTPHOSRawAnalyzerComponent::SetCoordinate"<< endl;
484 cout <<"Equpippment ID =\t"<< fEquippmentID <<endl;
006ee9b2 485 cout <<"Module ID =\t"<< (int)fModuleID<<endl;
486 cout <<"RCUX =\t\t" << (int)fRcuX << endl;
487 cout <<"RCUZ =\t\t" << (int)fRcuZ << endl;
488 cout <<"RcuZOffset = \t" << (int)fRcuZOffset << endl;
489 cout <<"RcuXOffset = \t" << (int)fRcuXOffset << endl << endl;
ef408bb3 490}