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