]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
fixing coding violations
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRawAnalyzerComponent.cxx
CommitLineData
1b41ab20 1// $Id$
2
cbab66dd 3/**************************************************************************
99388135 4 * This file is property of and copyright by the Experimental Nuclear *
5 * Physics Group, Dep. of Physics *
6 * University of Oslo, Norway, 2007 *
7 * *
8 * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
cbab66dd 9 * Contributors are mentioned in the code where appropriate. *
99388135 10 * Please report bugs to perthi@fys.uio.no *
cbab66dd 11 * *
12 * Permission to use, copy, modify and distribute this software and its *
13 * documentation strictly for non-commercial purposes is hereby granted *
14 * without fee, provided that the above copyright notice appears in all *
15 * copies and that both the copyright notice and this permission notice *
16 * appear in the supporting documentation. The authors make no claims *
17 * about the suitability of this software for any purpose. It is *
18 * provided "as is" without express or implied warranty. *
19 **************************************************************************/
20
2b7cf4fb 21#include "AliHLTPHOSRawAnalyzer.h"
cbab66dd 22#include "AliHLTPHOSRawAnalyzerComponent.h"
bde48b84 23#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
e086ee30 24#include "AliHLTPHOSMapper.h"
dbd79fad 25#include "AliHLTPHOSSanityInspector.h"
dbd79fad 26#include "TFile.h"
27#include "TTree.h"
28#include "TClonesArray.h"
25b7f84c 29#include "TH2F.h"
94594220 30#include "AliAltroDecoder.h" // decoder for altro payload
31#include "AliAltroData.h" // container for altro payload
32#include "AliAltroBunch.h" // container for altro bunches
939c67e7 33
34
35AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTPHOSRcuProcessor(),
8efbf5fe 36 fAnalyzerPtr(0),
37 fSendChannelData(kFALSE),
38 fOutPtr(0),
39 fMapperPtr(0),
40 fSanityInspectorPtr(0),
41 fUseBaselineSubtraction(false),
42 fDecoderPtr(0),
43 fAltroDataPtr(0),
e304ea31 44 fAltroBunchPtr(0),
45 fDoPushRawData(false),
46 fDoMakeDigits(false),
8394d59f 47 fDigitMakerPtr(0),
e304ea31 48 fDigitContainerPtr(0),
8efbf5fe 49 fDoSelectiveReadOut(false),
50 fSelectedChannelsList(0),
04751caa 51 fDoCheckDataSize(false),
52 fNCorruptedBlocks(0),
53 fNOKBlocks(0)
8efbf5fe 54 //fRawMemoryReader(0), fPHOSRawStream(0)
cbab66dd 55{
ab38011b 56 //comment
7ce40e5c 57 fMapperPtr = new AliHLTPHOSMapper();
939c67e7 58 fAltroDataPtr = new AliAltroData();
59 fAltroBunchPtr = new AliAltroBunch();
60 fDecoderPtr = new AliAltroDecoder();
61 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
27029341 62 fSelectedChannelsList = new AliHLTUInt16_t[NXCOLUMNSRCU*NZROWSRCU*NGAINS];
939c67e7 63}
2589c3a3 64
65
cbab66dd 66AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
67{
2589c3a3 68 Deinit();
cbab66dd 69}
70
2ef3c547 71
8efbf5fe 72
cbab66dd 73int
d2a0b488 74AliHLTPHOSRawAnalyzerComponent::Deinit()
cbab66dd 75{
ab38011b 76 //comment
d949e02e 77 if(fMapperPtr)
78 {
79 delete fMapperPtr;
80 fMapperPtr = 0;
81 }
82 if(fAltroDataPtr)
83 {
84 delete fAltroDataPtr;
85 fAltroDataPtr = 0;
86 }
87 if(fAltroBunchPtr)
88 {
89 delete fAltroBunchPtr;
90 fAltroBunchPtr = 0;
91 }
92 if(fDecoderPtr)
93 {
94 delete fDecoderPtr;
95 fDecoderPtr = 0;
96 }
e304ea31 97
d2a0b488 98 return 0;
cbab66dd 99}
100
2ef3c547 101
9dfd64cf 102const char*
103AliHLTPHOSRawAnalyzerComponent::GetComponentID()
104{
ab38011b 105 //comment
9dfd64cf 106 return "AliPhosTestRaw";
107}
ee7849e6 108
2589c3a3 109
cbab66dd 110void
ee7849e6 111AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
cbab66dd 112{
ab38011b 113 //comment
94594220 114 list.clear();
115 list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
cbab66dd 116}
117
118AliHLTComponentDataType
119AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
120{
ab38011b 121 //comment
25b7f84c 122 return kAliHLTMultipleDataType;
123 // return AliHLTPHOSDefinitions::fgkDigitDataType;
cbab66dd 124}
125
25b7f84c 126int
127AliHLTPHOSRawAnalyzerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
128{
129 // Added by OD
130 // see header file for class documentation
131 tgtList.clear();
132 tgtList.push_back(AliHLTPHOSDefinitions::fgkCellEnergyDataType);
94594220 133 tgtList.push_back(kAliHLTDataTypeHwAddr16);
25b7f84c 134 return tgtList.size();
135}
d504c864 136
cbab66dd 137void
9dfd64cf 138AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
cbab66dd 139{
ab38011b 140 //comment
ef408bb3 141 constBase = 30;
94594220 142 inputMultiplier = 4;
143}
144
145
146
147
148void
e304ea31 149AliHLTPHOSRawAnalyzerComponent::FillDataArray(UInt_t *data, const AliAltroData */*altrodataptr*/, const int /*channel*/)
94594220 150{
27029341 151 ResetDataPtr(0, ALTROMAXSAMPLES);
94594220 152 bool islastbunch = true;
153
154 while( fAltroDataPtr->NextBunch(fAltroBunchPtr) == true)
155 {
156 const UInt_t *tmpdata = fAltroBunchPtr->GetData();
157
158 if(islastbunch == true)
159 {
160 data[0] = fAltroBunchPtr->GetEndTimeBin();
161 islastbunch = false;
162 }
163
164 int tmpstartbin = fAltroBunchPtr->GetStartTimeBin();
165 int tmpendbin = fAltroBunchPtr->GetEndTimeBin();
166 int tmplength = tmpendbin - tmpstartbin;
167
168 for(int i = 0; i < tmplength ; i++)
169 {
170 data[i+tmpstartbin] = tmpdata[i];
171 }
172 }
173
174
175 /*
176 cout <<__FILE__ <<" : " <<__LINE__ << "the resulting array is"<<endl;
177
178 for(int i=0; i< data[0]; i++)
179 {
180 if(i != 0 && i %16 == 0)
181 {
182 cout << endl;
183 }
184 cout <<data[i] << "\t" ;
185 }
186 cout << endl;
187 */
cbab66dd 188}
189
2ef3c547 190
94594220 191void
e304ea31 192AliHLTPHOSRawAnalyzerComponent::GetFirstBunch(AliAltroData */*altrodata*/, AliAltroBunch */*altrobunch*/)
94594220 193{
194 while( fAltroDataPtr->NextBunch(fAltroBunchPtr) == true)
195 {
196
197 }
198}
199
939c67e7 200
d504c864 201int
1804b020 202AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
dbd79fad 203 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
cbab66dd 204{
94594220 205 // cout << "Event" << fPhosEventCount << endl;
04751caa 206
14ff16ed 207 UInt_t offset = 0;
208 UInt_t mysize = 0;
209 UInt_t tSize = 0;
210 Float_t baseline = 0;
53740333 211 AliHLTUInt8_t* outBPtr;
53740333 212 outBPtr = outputPtr;
0a211711 213 const AliHLTComponentBlockData* iter = NULL;
214 unsigned long ndx;
14ff16ed 215 Int_t *rawDataBufferPos = (Int_t *)outputPtr;
b444d727 216 Int_t nSamples = 0;
d949e02e 217 UInt_t specification = 0;
94594220 218 bool droppedRaw = true;
219 if(fDoPushRawData) {droppedRaw = false;}
220
dbd79fad 221 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
222 {
94594220 223 iter = blocks+ndx;
224 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
225 {
226 continue;
227 }
421c2193 228
939c67e7 229 Int_t tmpChannelCnt = 0;
53740333 230 mysize = 0;
231 offset = tSize;
dbd79fad 232 Int_t crazyness = 0;
14ff16ed 233 mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
94594220 234 tSize += mysize;
235
236 if(tSize > size)
0a211711 237 {
94594220 238 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", tSize, size);
239 return -ENOBUFS;
240 }
421c2193 241
2589c3a3 242 specification = specification|iter->fSpecification;
2589c3a3 243 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
e086ee30 244 fDecoderPtr->Decode();
e086ee30 245 fOutPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
0d7c9b63 246 fOutPtr->fRcuX = fRcuX;
247 fOutPtr->fRcuZ = fRcuZ;
d2b84453 248 fOutPtr->fModuleID =fModuleID;
94594220 249
250 rawDataBufferPos += (tSize)/sizeof(Int_t);
251
e086ee30 252 while( fDecoderPtr->NextChannel(fAltroDataPtr) == true )
94594220 253 {
254 FillDataArray(fTmpChannelData, fAltroDataPtr, tmpChannelCnt);
255
256 if( fAltroDataPtr->GetDataSize() != 0 )
257 {
258 GetFirstBunch(fAltroDataPtr, fAltroBunchPtr);
259 nSamples = fAltroBunchPtr->GetBunchSize();
260 // cout <<__FILE__ <<" : " <<__LINE__ << ", the size of the first bunch is " << nSamples <<endl;
261 crazyness = fSanityInspectorPtr->CheckInsanity((const UInt_t*)fAltroBunchPtr->GetData(), (const Int_t)(fAltroBunchPtr->GetBunchSize()));
262 fAnalyzerPtr->SetData(fAltroBunchPtr->GetData(), fAltroBunchPtr->GetBunchSize());
263 fAnalyzerPtr->Evaluate(0, fAltroBunchPtr->GetBunchSize());
264 fOutPtr->fValidData[tmpChannelCnt].fZ = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fZRow;
265 fOutPtr->fValidData[tmpChannelCnt].fX = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fXCol;
266 fOutPtr->fValidData[tmpChannelCnt].fGain = fMapperPtr->fHw2geomapPtr[fAltroDataPtr->GetHadd()].fGain;
267
268 if(fUseBaselineSubtraction)
421c2193 269 {
94594220 270 baseline = fBaselines[fOutPtr->fValidData[tmpChannelCnt].fX][fOutPtr->fValidData[tmpChannelCnt].fZ][ fOutPtr->fValidData[tmpChannelCnt].fGain];
421c2193 271 }
94594220 272
273 fOutPtr->fValidData[tmpChannelCnt].fEnergy = (float)fAnalyzerPtr->GetEnergy() - baseline;
274 fOutPtr->fValidData[tmpChannelCnt].fTime = (float)fAnalyzerPtr->GetTiming();
275 fOutPtr->fValidData[tmpChannelCnt].fCrazyness = (int)crazyness;
421c2193 276
94594220 277 if(fDoPushRawData == true && droppedRaw == false)
25b7f84c 278 {
94594220 279 int tmpsize = fTmpChannelData[0];
280 // cout << __FILE__ << ":" << __LINE__ << "channel = " << tmpChannelCnt << " size ="<< tmpsize << endl;
281 mysize += (tmpsize + 1)*sizeof(Int_t);
282 tSize += (tmpsize + 1)*sizeof(Int_t);;
283
284 if(tSize > size)
285 {
286 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes. Dropping raw data.", tSize, size);
287 droppedRaw = true;
288 tSize -= mysize;
289 }
290 else
291 {
292 *rawDataBufferPos = tmpsize;
293
294 for(int sample = 0; sample < tmpsize; sample++)
295 {
296 rawDataBufferPos++;
297 *(rawDataBufferPos) = fTmpChannelData[sample];
298 }
299 rawDataBufferPos++;
300
301 }
25b7f84c 302 }
94594220 303 tmpChannelCnt ++;
dbd79fad 304 }
e086ee30 305 }
7ce40e5c 306
94594220 307 if(fDoPushRawData && droppedRaw == false)
25b7f84c 308 {
7ce40e5c 309 fOutPtr->fHasRawData = true;
25b7f84c 310 }
2589c3a3 311 else
312 {
7ce40e5c 313 fOutPtr->fHasRawData = false;
2589c3a3 314 }
94594220 315
7ce40e5c 316 fOutPtr->fCnt = tmpChannelCnt;
317 fOutPtr->fSize = mysize;
7ce40e5c 318 AliHLTComponentBlockData bdCellEnergy;
319 FillBlockData( bdCellEnergy );
320 bdCellEnergy.fOffset = offset;
321 bdCellEnergy.fSize = mysize;
322 bdCellEnergy.fDataType = AliHLTPHOSDefinitions::fgkCellEnergyDataType;
323 bdCellEnergy.fSpecification = specification;
324 outputBlocks.push_back( bdCellEnergy );
7ce40e5c 325 outBPtr += mysize;
94594220 326
327 if( tSize > size )
25b7f84c 328 {
94594220 329 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
330 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
331 , tSize, size );
332 return EMSGSIZE;
25b7f84c 333 }
04751caa 334
e086ee30 335 }
94594220 336
337 // *rawDataBufferPos = 0;
d2a0b488 338 fPhosEventCount++;
2947a32c 339 return 0;
340}//end DoEvent
e086ee30 341
0a211711 342
14ff16ed 343
0a211711 344int
345AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
8efbf5fe 346{
04751caa 347 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
348 // fAnalyzerPtr->SetCorrectBaselineUsingFirstFiveSamples();
349 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
350
351
939c67e7 352 //See base class for documentation
2b7cf4fb 353 fSendChannelData = kFALSE;
354 fPrintInfo = kFALSE;
2b7cf4fb 355 int iResult=0;
356 TString argument="";
7ce40e5c 357 const int nSigmas = 3;
8efbf5fe 358 fMapperPtr = new AliHLTPHOSMapper();
359
360 if(fMapperPtr->GetIsInitializedMapping() == false)
361 {
362 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initial mapping from file %s, aborting", fMapperPtr->GetFilePath());
363 return -4;
364 }
365
2589c3a3 366 char tmpbaselinfile[256];
367 if(fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-baselinefile", tmpbaselinfile) == true )
2b7cf4fb 368 {
18af2efc 369 HLTWarning("baseline file no longer supported");
370
371 // SetBaselines(tmpbaselinfile);
2b7cf4fb 372 }
2589c3a3 373
7ce40e5c 374 char tmpSelectiveThresholdfile[256];
375 if(fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-baselinefile", tmpSelectiveThresholdfile) == true )
2589c3a3 376 {
7ce40e5c 377 fDoSelectiveReadOut = true;
378 SetSelectiveReadOutThresholds(tmpSelectiveThresholdfile, nSigmas);
379 }
380
7ce40e5c 381 //fDoSelectiveReadOut = fUtilitiesPtr->ScanSingleNameArgument(argc, argv, "-selectivereadout");
2589c3a3 382
7ce40e5c 383 fDoPushRawData = fUtilitiesPtr->ScanSingleArgument(argc, argv, "-pushrawdata");
384
2589c3a3 385 fDoCheckDataSize = fUtilitiesPtr->ScanSingleArgument(argc, argv, "-checkdatasize");
386
387 iResult = ScanArguments(argc, argv);
d2a0b488 388 return iResult;
0a211711 389}
9dfd64cf 390
9dfd64cf 391
2947a32c 392void
e304ea31 393AliHLTPHOSRawAnalyzerComponent::Reset(AliHLTPHOSRcuCellEnergyDataStruct* /*cellDataPtr*/)
2947a32c 394{
27029341 395 ResetDataPtr(0, ALTROMAXSAMPLES);
432edd34 396} // end Reset
397
e086ee30 398
2947a32c 399void
432edd34 400AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
2947a32c 401{
ab38011b 402 //comment
432edd34 403 for(int i = startindex ; i< sampleCnt; i++)
2947a32c 404 {
405 fTmpChannelData[i] = 0;
406 }
cbab66dd 407}
ef408bb3 408
14ff16ed 409
dbd79fad 410void
18af2efc 411AliHLTPHOSRawAnalyzerComponent::SetBaselines(const char* /*file*/)
dbd79fad 412{
ab38011b 413 //comment
18af2efc 414// fUseBaselineSubtraction = true;
415// AliHLTPHOSBaseline *baseline = 0;
416// TFile *baselineFile = TFile::Open(file);
417// TTree *baselineTree = (TTree*)baselineFile->Get("baselineTree");
418// TClonesArray *baselineArray = new TClonesArray("AliHLTPHOSBaseline", 7168);
419// baselineTree->SetBranchAddress("Baselines", &baselineArray);
420// baselineTree->GetEntry(0);
421// for(Int_t i = 0; i < baselineArray->GetEntriesFast(); i++)
422// {
423// baseline = (AliHLTPHOSBaseline*)baselineArray->At(i);
424// if((baseline->GetX() < (Int_t)((fRcuX + 1)*N_XCOLUMNS_RCU)) && (baseline->GetX() >= (Int_t)(fRcuX*N_XCOLUMNS_RCU)))
425// {
426// if((baseline->GetZ() < (Int_t)((fRcuZ + 1)*N_ZROWS_RCU)) && (baseline->GetZ() >= (Int_t)(fRcuZ*N_ZROWS_RCU)))
427// {
428// fBaselines[baseline->GetX() - fRcuX*N_XCOLUMNS_RCU][baseline->GetZ() - fRcuZ*N_ZROWS_RCU][baseline->GetGain()] = baseline->GetBaseline();
429// }
430// }
431// }
432// baselineFile->Close();
433// delete baselineFile;
434// baselineFile = 0;
dbd79fad 435}
25b7f84c 436
437void
438AliHLTPHOSRawAnalyzerComponent::SetSelectiveReadOutThresholds(const char* filepath, Int_t nSigmas)
439{
440 //See header file for documentation
25b7f84c 441 TFile *histFile = new TFile(filepath);
25b7f84c 442 TH2F *lgHist = (TH2F*)histFile->Get("RMSLGMapHist");
443 TH2F *hgHist = (TH2F*)histFile->Get("RMSHGMapHist");
444
27029341 445 for(int x = 0; x < NXCOLUMNSMOD; x++)
25b7f84c 446 {
27029341 447 for(int z = 0; z < NZROWSMOD; z++)
25b7f84c 448 {
27029341 449 fSelectiveReadOutThresholds[x][z][LOWGAIN] = lgHist->GetBinContent(x, z) * nSigmas;
450 fSelectiveReadOutThresholds[x][z][HIGHGAIN] = hgHist->GetBinContent(x, z) * nSigmas;
25b7f84c 451 }
452 }
453}