]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
Coding conventions and minor fixes
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRawAnalyzerComponent.cxx
... / ...
CommitLineData
1/**************************************************************************
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.*
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to perthi@fys.uio.no *
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 "AliHLTPHOSRawAnalyzer.h"
20#include "AliHLTPHOSRawAnalyzerComponent.h"
21#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
22#include "AliHLTPHOSRcuChannelDataStruct.h"
23#include "AliHLTPHOSMapper.h"
24#include "AliHLTPHOSSanityInspector.h"
25#include "AliHLTPHOSBaseline.h"
26#include "TFile.h"
27#include "TTree.h"
28#include "TClonesArray.h"
29
30#include "AliAltroDecoder.h" // decoder for altro payload
31#include "AliAltroData.h" // container for altro payload
32#include "AliAltroBunch.h" // container for altro bunches
33
34
35AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTPHOSRcuProcessor(),
36 fAnalyzerPtr(0),
37 fSendChannelData(kFALSE),
38 fOutPtr(0),
39 fMapperPtr(0),
40 fUseBaselineSubtraction(false),
41 fDecoderPtr(0),
42 fAltroDataPtr(0),
43 fAltroBunchPtr(0)
44 // fRawMemoryReader(0), fPHOSRawStream(0)
45{
46 //comment
47 fMapperPtr = new AliHLTPHOSMapper();
48 fAltroDataPtr = new AliAltroData();
49 fAltroBunchPtr = new AliAltroBunch();
50 fDecoderPtr = new AliAltroDecoder();
51 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
52}
53
54
55
56AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
57{
58 //comment
59 delete fMapperPtr;
60}
61
62
63int
64AliHLTPHOSRawAnalyzerComponent::Deinit()
65{
66 //comment
67 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen Deinit");
68 return 0;
69}
70
71
72const char*
73AliHLTPHOSRawAnalyzerComponent::GetComponentID()
74{
75 //comment
76 return "AliPhosTestRaw";
77}
78
79
80void
81AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
82{
83 //comment
84 const AliHLTComponentDataType* pType=fgkInputDataTypes;
85 while (pType->fID!=0) {
86 list.push_back(*pType);
87 pType++;
88 }
89}
90
91
92AliHLTComponentDataType
93AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
94{
95 //comment
96 return AliHLTPHOSDefinitions::fgkCellEnergyDataType;
97}
98
99
100void
101AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
102
103{
104 //comment
105 constBase = 30;
106 inputMultiplier = 1.2;
107}
108
109
110
111int
112AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
113 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
114{
115 //comment
116 UInt_t offset = 0;
117 UInt_t mysize = 0;
118 UInt_t tSize = 0;
119 Float_t baseline = 0;
120 AliHLTUInt8_t* outBPtr;
121 outBPtr = outputPtr;
122 const AliHLTComponentBlockData* iter = NULL;
123 unsigned long ndx;
124
125 // fDebugCnt++;
126
127 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
128 {
129 Int_t tmpChannelCnt = 0;
130 iter = blocks+ndx;
131 mysize = 0;
132 offset = tSize;
133 Int_t crazyness = 0;
134
135 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
136 {
137 continue;
138 }
139
140
141 if( fPhosEventCount%100 == 0)
142 {
143 cout << "event count = "<< fPhosEventCount <<endl;
144
145 }
146
147
148 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
149 fDecoderPtr->Decode();
150 fOutPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
151 fOutPtr->fRcuX = fRcuX;
152 fOutPtr->fRcuZ = fRcuZ;
153 fOutPtr->fModuleID =fModuleID;
154
155 while( fDecoderPtr->NextChannel(fAltroDataPtr) == true )
156 {
157 if(fAltroDataPtr->GetDataSize() != (fNTotalSamples +2))
158 {
159 cout << "Error, fDataSize = " << fAltroDataPtr->GetDataSize() << endl;
160 continue;
161 }
162
163 crazyness = fSanityInspectorPtr->CheckInsanity(fAltroDataPtr->GetData(), fAltroDataPtr->GetDataSize() - 2);
164
165 fAnalyzerPtr->SetData(fAltroDataPtr->GetData());
166 fAnalyzerPtr->Evaluate(0, fAltroDataPtr->GetDataSize() -2);
167 fOutPtr->fValidData[tmpChannelCnt].fZ = fMapperPtr->hw2geomapPtr[fAltroDataPtr->GetHadd()].zRow;
168 fOutPtr->fValidData[tmpChannelCnt].fX = fMapperPtr->hw2geomapPtr[fAltroDataPtr->GetHadd()].xCol;
169 fOutPtr->fValidData[tmpChannelCnt].fGain = fMapperPtr->hw2geomapPtr[fAltroDataPtr->GetHadd()].gain;
170
171
172 if(fUseBaselineSubtraction)
173 {
174 baseline = fBaselines[fOutPtr->fValidData[tmpChannelCnt].fX][fOutPtr->fValidData[tmpChannelCnt].fZ][ fOutPtr->fValidData[tmpChannelCnt].fGain];
175 }
176
177
178 fOutPtr->fValidData[tmpChannelCnt].fEnergy = (float)fAnalyzerPtr->GetEnergy() - baseline;
179
180
181 fOutPtr->fValidData[tmpChannelCnt].fTime = (float)fAnalyzerPtr->GetTiming();
182
183
184 fOutPtr->fValidData[tmpChannelCnt].fCrazyness = (int)crazyness;
185
186 const UInt_t *tmpData = fAltroDataPtr->GetData();
187
188 for(Int_t sample = 0; sample < fNTotalSamples; sample++)
189 {
190 (fOutPtr->fValidData[tmpChannelCnt].fData)[sample] = tmpData[sample] - (int)baseline;
191 }
192
193 tmpChannelCnt ++;
194 }
195
196 fOutPtr->fCnt = tmpChannelCnt;
197 mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
198
199 AliHLTComponentBlockData bd;
200 FillBlockData( bd );
201 bd.fOffset = offset;
202 bd.fSize = mysize;
203
204 bd.fDataType = AliHLTPHOSDefinitions::fgkCellEnergyDataType;
205 bd.fSpecification = 0xFFFFFFFF;
206 outputBlocks.push_back( bd );
207
208 tSize += mysize;
209 outBPtr += mysize;
210
211 if( tSize > size )
212 {
213 cout <<"kHLTLogFatal, HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent Too much dataData written over allowed buffer. Amount written:"
214 << tSize << " allowed" << size << endl;
215 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
216 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
217 , tSize, size );
218 return EMSGSIZE;
219 }
220
221 }
222
223
224 fPhosEventCount++;
225
226 if(fPrintInfo == kTRUE)
227 {
228 if(fPhosEventCount%fPrintInfoFrequncy == 0)
229 {
230 cout <<"Analyzing event " << fPhosEventCount << "for Equippment " << fkEquippmentID << endl;
231 }
232 }
233
234 return 0;
235}//end DoEvent
236
237
238int
239AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
240{
241 //See base class for documentation
242 cout <<"AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv ) "<< endl;
243
244 fSendChannelData = kFALSE;
245 fPrintInfo = kFALSE;
246 Reset();
247 int iResult=0;
248 TString argument="";
249 iResult = ScanArguments(argc, argv);
250
251 for(int i = 0; i < argc; i++)
252 {
253 if(!strcmp("-baselinefile", argv[i]))
254 {
255 cout << "Getting baselines from " << argv[i+1] << endl;
256 SetBaselines(argv[i+1]);
257 }
258 }
259
260
261 if(fIsSetEquippmentID == kFALSE)
262 {
263 cout << "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>" << endl;
264 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuHistogramProducerComponent::DoInt( int argc, const char** argv )", "Missing argument",
265 "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>");
266 iResult = -3;
267 }
268 else
269 {
270 iResult = 0;
271 // fRawMemoryReader->SetEquipmentID(fkEquippmentID);
272 }
273
274 return iResult;
275}
276
277
278void
279AliHLTPHOSRawAnalyzerComponent::Reset()
280{
281 //comment
282 for(unsigned int mod = 0; mod < N_MODULES; mod ++)
283 {
284 for(unsigned int row = 0; row < N_ZROWS_MOD; row ++)
285 {
286 for(unsigned int col = 0; col < N_XCOLUMNS_MOD; col ++)
287 {
288 for(unsigned int gain = 0; gain < N_GAINS; gain ++ )
289 {
290 fMaxValues[mod][row][col][gain] = 0;
291 }
292 }
293 }
294 }
295
296 ResetDataPtr(0, ALTRO_MAX_SAMPLES);
297
298} // end Reset
299
300
301void
302AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
303{
304 //comment
305 for(int i = startindex ; i< sampleCnt; i++)
306 {
307 fTmpChannelData[i] = 0;
308 }
309}
310
311void
312AliHLTPHOSRawAnalyzerComponent::SetBaselines(const char* file)
313{
314 //comment
315 fUseBaselineSubtraction = true;
316 AliHLTPHOSBaseline *baseline = 0;
317 TFile *baselineFile = TFile::Open(file);
318 TTree *baselineTree = (TTree*)baselineFile->Get("baselineTree");
319 TClonesArray *baselineArray = new TClonesArray("AliHLTPHOSBaseline", 7168);
320 baselineTree->SetBranchAddress("Baselines", &baselineArray);
321 baselineTree->GetEntry(0);
322 for(Int_t i = 0; i < baselineArray->GetEntriesFast(); i++)
323 {
324 baseline = (AliHLTPHOSBaseline*)baselineArray->At(i);
325 if((baseline->GetX() < (Int_t)((fRcuX + 1)*N_XCOLUMNS_RCU)) && (baseline->GetX() >= (Int_t)(fRcuX*N_XCOLUMNS_RCU)))
326 {
327 if((baseline->GetZ() < (Int_t)((fRcuZ + 1)*N_ZROWS_RCU)) && (baseline->GetZ() >= (Int_t)(fRcuZ*N_ZROWS_RCU)))
328 {
329 fBaselines[baseline->GetX() - fRcuX*N_XCOLUMNS_RCU][baseline->GetZ() - fRcuZ*N_ZROWS_RCU][baseline->GetGain()] = baseline->GetBaseline();
330 // cout << fBaselines[baseline->GetX() - fRcuX*N_XCOLUMNS_RCU][baseline->GetZ() - fRcuZ*N_ZROWS_RCU][baseline->GetGain()] << endl;
331 }
332 }
333 }
334 baselineFile->Close();
335 delete baselineFile;
336 baselineFile = 0;
337}