Minor changes needed for debugging purphoses
[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#include "AliHLTPHOSRawAnalyzer.h"
cbab66dd 20#include "AliHLTPHOSRawAnalyzerComponent.h"
bde48b84 21#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
2b7cf4fb 22#include "AliHLTPHOSRcuChannelDataStruct.h"
e086ee30 23#include "AliHLTDDLDecoder.h"
24#include "AliHLTAltroData.h"
e086ee30 25#include "AliHLTPHOSMapper.h"
43dd7c5e 26#include "AliHLTAltroBunch.h"
dbd79fad 27#include "AliHLTPHOSSanityInspector.h"
28#include "AliHLTPHOSBaseline.h"
29#include "TFile.h"
30#include "TTree.h"
31#include "TClonesArray.h"
43dd7c5e 32//using namespace std;
2b7cf4fb 33
b60bd496 34AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTPHOSRcuProcessor(), fAnalyzerPtr(0),
43dd7c5e 35 fSendChannelData(kFALSE),fOutPtr(0), fMapperPtr(0), fDecoderPtr(0),
dbd79fad 36 fAltroDataPtr(0), fAltroBunchPtr(0), fUseBaselineSubtraction(false), fDebugCnt(0)
cbab66dd 37{
e086ee30 38 fMapperPtr = new AliHLTPHOSMapper();
43dd7c5e 39
d504c864 40}
2b7cf4fb 41
2ef3c547 42
cbab66dd 43AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
44{
b60bd496 45 delete fMapperPtr;
cbab66dd 46}
47
2ef3c547 48
cbab66dd 49int
d2a0b488 50AliHLTPHOSRawAnalyzerComponent::Deinit()
cbab66dd 51{
d2a0b488 52 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen Deinit");
d2a0b488 53 return 0;
cbab66dd 54}
55
2ef3c547 56
9dfd64cf 57const char*
58AliHLTPHOSRawAnalyzerComponent::GetComponentID()
59{
60 return "AliPhosTestRaw";
61}
ee7849e6 62
1c1b3412 63
cbab66dd 64void
ee7849e6 65AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
cbab66dd 66{
146c463a 67 const AliHLTComponentDataType* pType=fgkInputDataTypes;
ee7849e6 68 while (pType->fID!=0) {
69 list.push_back(*pType);
70 pType++;
71 }
cbab66dd 72}
73
2ef3c547 74
cbab66dd 75AliHLTComponentDataType
76AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
77{
d504c864 78 return AliHLTPHOSDefinitions::fgkCellEnergyDataType;
cbab66dd 79}
80
d504c864 81
cbab66dd 82void
9dfd64cf 83AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
84
cbab66dd 85{
ef408bb3 86 constBase = 30;
dbd79fad 87 inputMultiplier = 1.2;
cbab66dd 88}
89
2ef3c547 90
dbd79fad 91//int
92//AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventD // AliHLTPHOSRcuCellEnergyDebugDataStruct* fOutPtr;ata& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& trigData,
93// AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
d504c864 94int
dbd79fad 95AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& trigData,
96 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
cbab66dd 97{
bde48b84 98 UInt_t offset = 0;
99 UInt_t mysize = 0;
100 UInt_t tSize = 0;
dbd79fad 101 Float_t baseline = 0;
53740333 102 AliHLTUInt8_t* outBPtr;
43dd7c5e 103 AliHLTAltroBunch *bunchPtr;
53740333 104 outBPtr = outputPtr;
0a211711 105 const AliHLTComponentBlockData* iter = NULL;
106 unsigned long ndx;
dbd79fad 107
108 // printf("\n% \n", ndx);
109
110 // cout << "evtData block count = " << evtData.fBlockCnt << endl;
111
112
113 fDebugCnt++;
afc526a2 114
115
dbd79fad 116 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
117 {
118 // cout <<"TP0"<< endl;
119
120 Int_t tmpChannelCnt = 0;
0a211711 121 iter = blocks+ndx;
53740333 122 mysize = 0;
123 offset = tSize;
dbd79fad 124 // cout <<"TP1"<< endl;
125 Int_t *dt = (Int_t*)(reinterpret_cast<UChar_t*>( iter->fPtr ));
126 // cout <<"TP2"<< endl;
127 Int_t crazyness = 0;
128
d504c864 129 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
0a211711 130 {
32764ee6 131 // cout <<"WARNING: not AliHLTPHOSDefinitions::fgkDDLPackedRawDataType " << endl;
dbd79fad 132 // cout << "equippment "<< fkEquippmentID << " Event count =" << fDebugCnt <<" AliHLTPHOSRawAnalyzerComponent::DoEvent , ERROR"<< endl;
133 continue;
134
135 // if(fPhosEventCount < 10)
136 // {
137 // continue; //!!!!! Commented out to read TPC data, remember to put back
138 // }
0a211711 139 }
dbd79fad 140 else
141 {
142 // cout << "equippment " << fkEquippmentID << " Event count =" << fDebugCnt << " Dat type is: AliHLTPHOSDefinitions::fgkDDLPackedRawDataType" << endl;
143 }
144
145 if( fPhosEventCount%100 == 0)
146 {
147 cout << "event count = "<< fPhosEventCount <<endl;
148
149 }
150
151
152 /*
153 printf("\Common data header for equippment %d\n", fkEquippmentID);
154 printf("Event#: %d -- RCU X: %d - RCU Z: %d\n\n", fPhosEventCount, fRcuX, fRcuZ);
155
156 for(Int_t n = 0; n < 8; n++)
157 {
158 printf("CDH(%d): 0x%X\n", n, dt[n]);
159 }
160
161 printf("\n");
162 */
163
ef408bb3 164
dbd79fad 165 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
03b3d247 166 // fDecoderPtr->SetMemory2(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
e086ee30 167 fDecoderPtr->Decode();
dbd79fad 168
e086ee30 169 fOutPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
0d7c9b63 170 fOutPtr->fRcuX = fRcuX;
171 fOutPtr->fRcuZ = fRcuZ;
d2b84453 172 fOutPtr->fModuleID =fModuleID;
dbd79fad 173
e086ee30 174 while( fDecoderPtr->NextChannel(fAltroDataPtr) == true )
175 {
dbd79fad 176
177 // if(fAltroDataPtr->fDataSize != 72)
178 // if(fAltroDataPtr->fDataSize != 142)
179 if(fAltroDataPtr->fDataSize != (fNTotalSamples +2))
180 {
181 cout << "Error, fDataSize = " << fAltroDataPtr->fDataSize << endl;
182 continue;
183 }
184
185 crazyness = fSanityInspectorPtr->CheckInsanity(fAltroDataPtr->fData, fAltroDataPtr->fDataSize - 2);
186 fAnalyzerPtr->SetData(fAltroDataPtr->fData); // AliHLTPHOSRcuCellEnergyDebugDataStruct* fOutPtr;
6e709a0d 187 fAnalyzerPtr->Evaluate(0, fAltroDataPtr->fDataSize -2);
43dd7c5e 188
9c9d15d6 189 fOutPtr->fValidData[tmpChannelCnt].fZ = fMapperPtr->hw2geomapPtr[fAltroDataPtr->fHadd].zRow;
190 fOutPtr->fValidData[tmpChannelCnt].fX = fMapperPtr->hw2geomapPtr[fAltroDataPtr->fHadd].xCol;
43dd7c5e 191 fOutPtr->fValidData[tmpChannelCnt].fGain = fMapperPtr->hw2geomapPtr[fAltroDataPtr->fHadd].gain;
dbd79fad 192 if(fUseBaselineSubtraction)
193 {
194 baseline = fBaselines[fOutPtr->fValidData[tmpChannelCnt].fX][fOutPtr->fValidData[tmpChannelCnt].fZ][ fOutPtr->fValidData[tmpChannelCnt].fGain];
195 }
196 fOutPtr->fValidData[tmpChannelCnt].fEnergy = (float)fAnalyzerPtr->GetEnergy() - baseline;
e086ee30 197 fOutPtr->fValidData[tmpChannelCnt].fTime = (float)fAnalyzerPtr->GetTiming();
dbd79fad 198 fOutPtr->fValidData[tmpChannelCnt].fCrazyness = (int)crazyness;
199 for(Int_t sample = 0; sample < fNTotalSamples; sample++)
200 {
201 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
202 (fOutPtr->fValidData[tmpChannelCnt].fData)[sample] = fAltroDataPtr->fData[sample] - (int)baseline;
203 }
204
e086ee30 205 tmpChannelCnt ++;
dbd79fad 206
e086ee30 207 }
e086ee30 208 fOutPtr->fCnt = tmpChannelCnt;
03b3d247 209 mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
210
e086ee30 211 AliHLTComponentBlockData bd;
212 FillBlockData( bd );
213 bd.fOffset = offset;
214 bd.fSize = mysize;
215
216 bd.fDataType = AliHLTPHOSDefinitions::fgkCellEnergyDataType;
217 bd.fSpecification = 0xFFFFFFFF;
218 outputBlocks.push_back( bd );
219
220 tSize += mysize;
221 outBPtr += mysize;
222
223 if( tSize > size )
224 {
6e709a0d 225 cout <<"kHLTLogFatal, HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent Too much dataData written over allowed buffer. Amount written:"
e086ee30 226 << tSize << " allowed" << size << endl;
227 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
228 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
229 , tSize, size );
230 return EMSGSIZE;
231 }
dbd79fad 232
b60bd496 233 // fDecoderPtr->GetFailureRate();
dbd79fad 234
e086ee30 235 }
dbd79fad 236
e086ee30 237
d2a0b488 238 fPhosEventCount++;
2b7cf4fb 239
dbd79fad 240 // cout << "event cunt =" << fPhosEventCount << endl;
241
2b7cf4fb 242 if(fPrintInfo == kTRUE)
243 {
dbd79fad 244 if(fPhosEventCount%fPrintInfoFrequncy == 0)
2b7cf4fb 245 {
d2a0b488 246 cout <<"Analyzing event " << fPhosEventCount << "for Equippment " << fkEquippmentID << endl;
2b7cf4fb 247 }
248 }
e086ee30 249
2947a32c 250 return 0;
251}//end DoEvent
e086ee30 252
0a211711 253
0a211711 254int
255AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
256{
2ef3c547 257 cout <<"AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv ) "<< endl;
e086ee30 258 fAltroDataPtr = new AliHLTAltroData();
43dd7c5e 259 fAltroBunchPtr = new AliHLTAltroBunch();
e086ee30 260 fDecoderPtr = new AliHLTDDLDecoder();
dbd79fad 261 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
2b7cf4fb 262 fSendChannelData = kFALSE;
263 fPrintInfo = kFALSE;
2947a32c 264 Reset();
2b7cf4fb 265 int iResult=0;
266 TString argument="";
d2a0b488 267 iResult = ScanArguments(argc, argv);
2b7cf4fb 268
dbd79fad 269 for(int i = 0; i < argc; i++)
270 {
271 if(!strcmp("-baselinefile", argv[i]))
272 {
273 cout << "Getting baselines from " << argv[i+1] << endl;
274 SetBaselines(argv[i+1]);
275 }
276 }
277
278
d2a0b488 279 if(fIsSetEquippmentID == kFALSE)
2b7cf4fb 280 {
e56d0892 281 cout << "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>" << endl;
2b7cf4fb 282 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuHistogramProducerComponent::DoInt( int argc, const char** argv )", "Missing argument",
283 "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>");
e086ee30 284 iResult = -3;
2b7cf4fb 285 }
d2a0b488 286 else
287 {
2ef3c547 288 iResult = 0;
289 // fRawMemoryReader->SetEquipmentID(fkEquippmentID);
d2a0b488 290 }
dbd79fad 291
2ef3c547 292 // return iResult;
293 // return 0;
d2a0b488 294 return iResult;
0a211711 295}
9dfd64cf 296
9dfd64cf 297
2947a32c 298void
299AliHLTPHOSRawAnalyzerComponent::Reset()
300{
432edd34 301 for(int mod = 0; mod < N_MODULES; mod ++)
9dfd64cf 302 {
b60bd496 303 for(int row = 0; row < N_ZROWS_MOD; row ++)
2947a32c 304 {
b60bd496 305 for(int col = 0; col < N_XCOLUMNS_MOD; col ++)
2947a32c 306 {
432edd34 307 for(int gain = 0; gain < N_GAINS; gain ++ )
2947a32c 308 {
309 fMaxValues[mod][row][col][gain] = 0;
310 }
311 }
312 }
313 }
dbd79fad 314
2b7cf4fb 315 ResetDataPtr(0, ALTRO_MAX_SAMPLES);
432edd34 316
317} // end Reset
318
e086ee30 319
2947a32c 320void
432edd34 321AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
2947a32c 322{
432edd34 323 for(int i = startindex ; i< sampleCnt; i++)
2947a32c 324 {
325 fTmpChannelData[i] = 0;
326 }
cbab66dd 327}
ef408bb3 328
dbd79fad 329void
330AliHLTPHOSRawAnalyzerComponent::SetBaselines(const char* file)
331{
332 fUseBaselineSubtraction = true;
333 AliHLTPHOSBaseline *baseline = 0;
334 TFile *baselineFile = TFile::Open(file);
335 TTree *baselineTree = (TTree*)baselineFile->Get("baselineTree");
336 TClonesArray *baselineArray = new TClonesArray("AliHLTPHOSBaseline", 7168);
337 baselineTree->SetBranchAddress("Baselines", &baselineArray);
338 baselineTree->GetEntry(0);
339 for(Int_t i = 0; i < baselineArray->GetEntriesFast(); i++)
340 {
341 baseline = (AliHLTPHOSBaseline*)baselineArray->At(i);
342 if((baseline->GetX() < ((fRcuX + 1)*N_XCOLUMNS_RCU)) && (baseline->GetX() >= fRcuX*N_XCOLUMNS_RCU))
343 {
344 if((baseline->GetZ() < ((fRcuZ + 1)*N_ZROWS_RCU)) && (baseline->GetZ() >= fRcuZ*N_ZROWS_RCU))
345 {
346 fBaselines[baseline->GetX() - fRcuX*N_XCOLUMNS_RCU][baseline->GetZ() - fRcuZ*N_ZROWS_RCU][baseline->GetGain()] = baseline->GetBaseline();
347 // cout << fBaselines[baseline->GetX() - fRcuX*N_XCOLUMNS_RCU][baseline->GetZ() - fRcuZ*N_ZROWS_RCU][baseline->GetGain()] << endl;
348 }
349 }
350 }
351 baselineFile->Close();
352 delete baselineFile;
353 baselineFile = 0;
354}