]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCCalibRawBase.cxx
Coverity fixes: two minor resource leaks
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibRawBase.cxx
CommitLineData
880c3382 1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id: AliTPCCalibRawBase.cxx */
17
18/////////////////////////////////////////////////////////////////////////////////////////
19// //
20// Base class for the calibration algorithms using raw data as input //
21// //
22// Origin: Jens Wiechula J.Wiechula@gsi.de //
23// //
24/////////////////////////////////////////////////////////////////////////////////////////
25
26//Root includes
27#include <TDirectory.h>
28#include <TFile.h>
29
30//Aliroot includes
31#include "AliRawReaderDate.h"
32#include "AliRawReader.h"
33#include "AliRawEventHeaderBase.h"
34#include "AliAltroMapping.h"
35#include "AliAltroRawStream.h"
36#include "AliTPCROC.h"
c3066940 37#include "AliTPCRawStreamV3.h"
880c3382 38#include "AliTPCRawStream.h"
c3066940 39#include "AliLog.h"
880c3382 40#include "TTreeStream.h"
41#include "event.h"
42
43#include "AliTPCCalibRawBase.h"
44
45ClassImp(AliTPCCalibRawBase)
46
47AliTPCCalibRawBase::AliTPCCalibRawBase() :
48 TNamed(),
49 fFirstTimeBin(0),
50 fLastTimeBin(1000),
51 fNevents(0),
52 fDebugLevel(0),
53 fStreamLevel(0),
880c3382 54 fRunNumber(0),
78f17711 55 fFirstTimeStamp(0),
56 fLastTimeStamp(0),
c3066940 57 fTimeStamp(0),
880c3382 58 fEventType(0),
59 fAltroL1Phase(0),
60 fAltroL1PhaseTB(0),
c3066940 61 fCurrRCUId(-1),
62 fPrevRCUId(-1),
63 fCurrDDLNum(-1),
64 fPrevDDLNum(-1),
880c3382 65 fUseL1Phase(kTRUE),
66 fDebugStreamer(0x0),
67 fAltroRawStream(0x0),
68 fMapping(0x0),
69 fROC(AliTPCROC::Instance())
70{
71 //
72 // default ctor
73 //
74
75}
76//_____________________________________________________________________
77AliTPCCalibRawBase::AliTPCCalibRawBase(const AliTPCCalibRawBase &calib) :
78 TNamed(calib),
79 fFirstTimeBin(calib.fFirstTimeBin),
80 fLastTimeBin(calib.fLastTimeBin),
81 fNevents(calib.fNevents),
82 fDebugLevel(calib.fDebugLevel),
83 fStreamLevel(calib.fStreamLevel),
78f17711 84 fRunNumber(calib.fRunNumber),
85 fFirstTimeStamp(calib.fFirstTimeStamp),
86 fLastTimeStamp(calib.fLastTimeStamp),
c3066940 87 fTimeStamp(0),
880c3382 88 fEventType(0),
89 fAltroL1Phase(0),
90 fAltroL1PhaseTB(0),
c3066940 91 fCurrRCUId(-1),
92 fPrevRCUId(-1),
93 fCurrDDLNum(-1),
94 fPrevDDLNum(-1),
880c3382 95 fUseL1Phase(kTRUE),
96 fDebugStreamer(0x0),
97 fAltroRawStream(0x0),
98 fMapping(0x0),
99 fROC(AliTPCROC::Instance())
100{
101 //
102 // copy ctor
103 //
104
105}
106//_____________________________________________________________________
107AliTPCCalibRawBase::~AliTPCCalibRawBase()
108{
109 //
110 // dtor
111 //
112 if (fDebugStreamer) delete fDebugStreamer;
113}
114//_____________________________________________________________________
115 AliTPCCalibRawBase& AliTPCCalibRawBase::operator = (const AliTPCCalibRawBase &source)
116 {
117 //
118 // assignment operator
119 //
120 if (&source == this) return *this;
121 new (this) AliTPCCalibRawBase(source);
122
123 return *this;
124 }
125//_____________________________________________________________________
7442bceb 126Bool_t AliTPCCalibRawBase::ProcessEvent(AliTPCRawStreamV3 * const rawStreamV3)
c3066940 127{
128 //
129 // Event Processing loop - AliTPCRawStreamV3
130 //
131 ResetEvent();
132 Bool_t withInput = kFALSE;
133 fAltroL1Phase=0;
134 fAltroL1PhaseTB=0;
135// fAltroRawStream = static_cast<AliAltroRawStream*>(rawStreamV3);
136 while ( rawStreamV3->NextDDL() ){
137 if (AliLog::GetGlobalDebugLevel()>2) rawStreamV3->PrintRCUTrailer();
5312f439 138 fPrevDDLNum=-1;
139 fCurrRCUId=rawStreamV3->GetRCUId();
140 fCurrDDLNum=rawStreamV3->GetDDLNumber();
c3066940 141 if (fUseL1Phase){
142// fAltroL1Phase = fAltroRawStream->GetL1Phase();
143 fAltroL1Phase = rawStreamV3->GetL1Phase();
144 fAltroL1PhaseTB = (fAltroL1Phase*1e09/100.);
5312f439 145 AliDebug(1, Form("L1Phase: %.2e (%03d)\n",fAltroL1PhaseTB,fCurrDDLNum));
c3066940 146 }
5312f439 147 UpdateDDL();
c3066940 148 while ( rawStreamV3->NextChannel() ){
149 Int_t isector = rawStreamV3->GetSector(); // current sector
150 Int_t iRow = rawStreamV3->GetRow(); // current row
151 Int_t iPad = rawStreamV3->GetPad(); // current pad
152 while ( rawStreamV3->NextBunch() ){
96bf9029 153 UInt_t startTbin = rawStreamV3->GetStartTimeBin();
c3066940 154// Int_t endTbin = (Int_t)rawStreamV3->GetEndTimeBin();
96bf9029 155 Int_t bunchlength = rawStreamV3->GetBunchLength();
c3066940 156 const UShort_t *sig = rawStreamV3->GetSignals();
96bf9029 157 ProcessBunch(isector,iRow,iPad,bunchlength,startTbin,sig);
c3066940 158 for (Int_t iTimeBin = 0; iTimeBin<bunchlength; iTimeBin++){
159 Float_t signal=(Float_t)sig[iTimeBin];
160// printf("%02d - %03d - %03d - %04d: %.1f\n",isector,iRow,iPad,startTbin,signal);
161 Update(isector,iRow,iPad,startTbin--,signal);
162 fPrevRCUId=fCurrRCUId;
163 fPrevDDLNum=fCurrDDLNum;
164 withInput = kTRUE;
165 }
166 }
167 }
168 }
169 if (withInput){
170 EndEvent();
171 }
172 return withInput;
173}
174//_____________________________________________________________________
7442bceb 175Bool_t AliTPCCalibRawBase::ProcessEvent(AliRawReader * const rawReader)
c3066940 176{
177 //
178 // Event processing loop - AliRawReader
179 //
180 AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
181 if (eventHeader){
182 fTimeStamp = eventHeader->Get("Timestamp");
183 fRunNumber = eventHeader->Get("RunNb");
184 fEventType = eventHeader->Get("Type");
185 }
78f17711 186 if (!fFirstTimeStamp) fFirstTimeStamp=fTimeStamp;
187
c3066940 188 AliTPCRawStreamV3 *rawStreamV3 = new AliTPCRawStreamV3(rawReader, (AliAltroMapping**)fMapping);
189 Bool_t res=ProcessEvent(rawStreamV3);
78f17711 190
191 fLastTimeStamp=fTimeStamp;
192
c3066940 193 delete rawStreamV3;
194 return res;
195}
196//_____________________________________________________________________
7442bceb 197Bool_t AliTPCCalibRawBase::ProcessEvent(AliTPCRawStream * const rawStream)
880c3382 198{
199 //
200 // Event Processing loop - AliTPCRawStream
201 //
202
203 ResetEvent();
204
205 Bool_t withInput = kFALSE;
206 fAltroL1Phase=0;
207 fAltroL1PhaseTB=0;
208 fAltroRawStream = static_cast<AliAltroRawStream*>(rawStream);
209 while (rawStream->Next()) {
210 if (fUseL1Phase){
211 fAltroL1Phase = fAltroRawStream->GetL1Phase();
212 fAltroL1PhaseTB = (fAltroL1Phase*1e09/100.);
213 }
c3066940 214 fPrevRCUId=fCurrRCUId;
215 fCurrRCUId=rawStream->GetRCUId();
216 fPrevDDLNum=fCurrDDLNum;
217 fCurrDDLNum=rawStream->GetDDLNumber();
880c3382 218 Int_t isector = rawStream->GetSector(); // current sector
219 Int_t iRow = rawStream->GetRow(); // current row
220 Int_t iPad = rawStream->GetPad(); // current pad
221 Int_t iTimeBin = rawStream->GetTime(); // current time bin
222 Float_t signal = rawStream->GetSignal(); // current ADC signal
223
224 Update(isector,iRow,iPad,iTimeBin,signal);
225 withInput = kTRUE;
226 }
227 fAltroRawStream=0x0;
228 if (withInput){
229 EndEvent();
230 }
231 return withInput;
232}
233//_____________________________________________________________________
7442bceb 234Bool_t AliTPCCalibRawBase::ProcessEventOld(AliRawReader * const rawReader)
880c3382 235{
236 //
237 // Event processing loop - AliRawReader
238 //
239 AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
240 if (eventHeader){
241 fTimeStamp = eventHeader->Get("Timestamp");
242 fRunNumber = eventHeader->Get("RunNb");
243 fEventType = eventHeader->Get("Type");
244 }
245
246 AliTPCRawStream rawStream(rawReader, (AliAltroMapping**)fMapping);
247 rawReader->Select("TPC");
248 return ProcessEvent(&rawStream);
249}
250//_____________________________________________________________________
7442bceb 251Bool_t AliTPCCalibRawBase::ProcessEvent(eventHeaderStruct * const event)
880c3382 252{
253 //
254 // Event processing loop - date event
255 //
5312f439 256
257 fRunNumber=event->eventRunNb;
258 fTimeStamp=event->eventTimestamp;
78f17711 259 if (!fFirstTimeStamp) fFirstTimeStamp=fTimeStamp;
260 fLastTimeStamp=fTimeStamp;
5312f439 261 fEventType=event->eventType;
262 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
263 AliTPCRawStreamV3 *rawStreamV3 = new AliTPCRawStreamV3(rawReader, (AliAltroMapping**)fMapping);
264 Bool_t result=ProcessEvent(rawStreamV3);
265 delete rawStreamV3;
266 delete rawReader;
267 return result;
880c3382 268
269}
270//_____________________________________________________________________
271void AliTPCCalibRawBase::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append)
272{
273 //
274 // Write class to file
275 //
276
277 TString sDir(dir);
278 TString option;
279
280 if ( append )
281 option = "update";
282 else
283 option = "recreate";
284
285 TDirectory *backup = gDirectory;
286 TFile f(filename,option.Data());
287 f.cd();
288 if ( !sDir.IsNull() ){
289 f.mkdir(sDir.Data());
290 f.cd(sDir);
291 }
292 this->Write();
293 f.Close();
294
295 if ( backup ) backup->cd();
296}
297//_____________________________________________________________________
298TTreeSRedirector *AliTPCCalibRawBase::GetDebugStreamer(){
299 //
300 // Get Debug streamer
301 // In case debug streamer not yet initialized and StreamLevel>0 create new one
302 //
303 if (fStreamLevel==0) return 0;
304 if (fDebugStreamer) return fDebugStreamer;
305 TString dsName;
306 dsName=GetName();
307 dsName+="Debug.root";
308 dsName.ReplaceAll(" ","");
309 fDebugStreamer = new TTreeSRedirector(dsName.Data());
310 return fDebugStreamer;
311}
78f17711 312//_____________________________________________________________________
313void AliTPCCalibRawBase::MergeBase(const AliTPCCalibRawBase *calib)
314{
315 //
316 // merge this with base
317 //
318 if (calib->fFirstTimeStamp<fFirstTimeStamp) fFirstTimeStamp=calib->fFirstTimeStamp;
319 if (calib->fLastTimeStamp>fLastTimeStamp) fLastTimeStamp =calib->fLastTimeStamp;
320}
321