]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCCalibRawBase.cxx
1. Adding sorting of the Points in point array
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibRawBase.cxx
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"
37 #include "AliTPCRawStreamFast.h"
38 #include "AliTPCRawStreamV3.h"
39 #include "AliTPCRawStream.h"
40 #include "AliLog.h"
41 #include "TTreeStream.h"
42 #include "event.h"
43
44 #include "AliTPCCalibRawBase.h"
45
46 ClassImp(AliTPCCalibRawBase)
47
48 AliTPCCalibRawBase::AliTPCCalibRawBase() :
49   TNamed(),
50   fFirstTimeBin(0),
51   fLastTimeBin(1000),
52   fNevents(0),
53   fDebugLevel(0),
54   fStreamLevel(0),
55   fRunNumber(0),
56   fTimeStamp(0),
57   fEventType(0),
58   fAltroL1Phase(0),
59   fAltroL1PhaseTB(0),
60   fCurrRCUId(-1),
61   fPrevRCUId(-1),
62   fCurrDDLNum(-1),
63   fPrevDDLNum(-1),
64   fUseL1Phase(kTRUE),
65   fDebugStreamer(0x0),
66   fAltroRawStream(0x0),
67   fMapping(0x0),
68   fROC(AliTPCROC::Instance())
69 {
70     //
71     // default ctor
72     //
73
74 }
75 //_____________________________________________________________________
76 AliTPCCalibRawBase::AliTPCCalibRawBase(const AliTPCCalibRawBase &calib) :
77   TNamed(calib),
78   fFirstTimeBin(calib.fFirstTimeBin),
79   fLastTimeBin(calib.fLastTimeBin),
80   fNevents(calib.fNevents),
81   fDebugLevel(calib.fDebugLevel),
82   fStreamLevel(calib.fStreamLevel),
83   fRunNumber(0),
84   fTimeStamp(0),
85   fEventType(0),
86   fAltroL1Phase(0),
87   fAltroL1PhaseTB(0),
88   fCurrRCUId(-1),
89   fPrevRCUId(-1),
90   fCurrDDLNum(-1),
91   fPrevDDLNum(-1),
92   fUseL1Phase(kTRUE),
93   fDebugStreamer(0x0),
94   fAltroRawStream(0x0),
95   fMapping(0x0),
96   fROC(AliTPCROC::Instance())
97 {
98     //
99     // copy ctor
100     //
101   
102 }
103 //_____________________________________________________________________
104 AliTPCCalibRawBase::~AliTPCCalibRawBase()
105 {
106   //
107   // dtor
108   //
109   if (fDebugStreamer) delete fDebugStreamer;
110 }
111 //_____________________________________________________________________
112   AliTPCCalibRawBase& AliTPCCalibRawBase::operator = (const  AliTPCCalibRawBase &source)
113   {
114     //
115     // assignment operator
116     //
117     if (&source == this) return *this;
118     new (this) AliTPCCalibRawBase(source);
119     
120     return *this;
121   }
122 //_____________________________________________________________________
123 Bool_t AliTPCCalibRawBase::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
124 {
125   //
126   // Event Processing loop - AliTPCRawStreamFast
127   //
128   ResetEvent();
129   Bool_t withInput = kFALSE;
130   while ( rawStreamFast->NextDDL() ){
131     while ( rawStreamFast->NextChannel() ){
132       Int_t isector  = rawStreamFast->GetSector();                       //  current sector
133       Int_t iRow     = rawStreamFast->GetRow();                          //  current row
134       Int_t iPad     = rawStreamFast->GetPad();                          //  current pad
135       
136       while ( rawStreamFast->NextBunch() ){
137         Int_t startTbin = (Int_t)rawStreamFast->GetStartTimeBin();
138         Int_t endTbin = (Int_t)rawStreamFast->GetEndTimeBin();
139         for (Int_t iTimeBin = startTbin; iTimeBin < endTbin; iTimeBin++){
140           Float_t signal=(Float_t)rawStreamFast->GetSignals()[iTimeBin-startTbin];
141             Update(isector,iRow,iPad,iTimeBin+1,signal);
142           withInput = kTRUE;
143         }
144       }
145     }
146   }
147   if (withInput){
148     EndEvent();
149   }
150   return withInput;
151 }
152 //_____________________________________________________________________
153 Bool_t AliTPCCalibRawBase::ProcessEventFast(AliRawReader *rawReader)
154 {
155   //
156   //  Event processing loop - AliRawReader
157   //
158   AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
159   if (eventHeader){
160     fTimeStamp   = eventHeader->Get("Timestamp");
161     fRunNumber = eventHeader->Get("RunNb");
162     fEventType = eventHeader->Get("Type");
163   }
164   AliTPCRawStreamFast *rawStreamFast = new AliTPCRawStreamFast(rawReader, (AliAltroMapping**)fMapping);
165   Bool_t res=ProcessEventFast(rawStreamFast);
166   delete rawStreamFast;
167   return res;
168 }
169 //_____________________________________________________________________
170 Bool_t AliTPCCalibRawBase::ProcessEvent(AliTPCRawStreamV3 *rawStreamV3)
171 {
172   //
173   // Event Processing loop - AliTPCRawStreamV3
174   //
175   ResetEvent();
176   Bool_t withInput = kFALSE;
177   fAltroL1Phase=0;
178   fAltroL1PhaseTB=0;
179 //   fAltroRawStream = static_cast<AliAltroRawStream*>(rawStreamV3);
180   while ( rawStreamV3->NextDDL() ){
181     if (AliLog::GetGlobalDebugLevel()>2) rawStreamV3->PrintRCUTrailer();
182     if (fUseL1Phase){
183 //         fAltroL1Phase  = fAltroRawStream->GetL1Phase();
184       fAltroL1Phase  = rawStreamV3->GetL1Phase();
185       fAltroL1PhaseTB = (fAltroL1Phase*1e09/100.);
186       AliDebug(1, Form("L1Phase: %.2e\n",fAltroL1PhaseTB));
187     }
188     fCurrRCUId=rawStreamV3->GetRCUId();
189     fCurrDDLNum=rawStreamV3->GetDDLNumber();
190     while ( rawStreamV3->NextChannel() ){
191       Int_t isector  = rawStreamV3->GetSector();                       //  current sector
192       Int_t iRow     = rawStreamV3->GetRow();                          //  current row
193       Int_t iPad     = rawStreamV3->GetPad();                          //  current pad
194       while ( rawStreamV3->NextBunch() ){
195         Int_t  startTbin    = (Int_t)rawStreamV3->GetStartTimeBin();
196 //         Int_t  endTbin      = (Int_t)rawStreamV3->GetEndTimeBin();
197         Int_t  bunchlength  = (Int_t)rawStreamV3->GetBunchLength();
198         const UShort_t *sig = rawStreamV3->GetSignals();
199         for (Int_t iTimeBin = 0; iTimeBin<bunchlength; iTimeBin++){
200           Float_t signal=(Float_t)sig[iTimeBin];
201 //            printf("%02d - %03d - %03d - %04d: %.1f\n",isector,iRow,iPad,startTbin,signal);
202           Update(isector,iRow,iPad,startTbin--,signal);
203           fPrevRCUId=fCurrRCUId;
204           fPrevDDLNum=fCurrDDLNum;
205           withInput = kTRUE;
206         }
207       }
208     }
209   }
210   if (withInput){
211     EndEvent();
212   }
213   return withInput;
214 }
215 //_____________________________________________________________________
216 Bool_t AliTPCCalibRawBase::ProcessEvent(AliRawReader *rawReader)
217 {
218   //
219   //  Event processing loop - AliRawReader
220   //
221   AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
222   if (eventHeader){
223     fTimeStamp   = eventHeader->Get("Timestamp");
224     fRunNumber = eventHeader->Get("RunNb");
225     fEventType = eventHeader->Get("Type");
226   }
227   AliTPCRawStreamV3 *rawStreamV3 = new AliTPCRawStreamV3(rawReader, (AliAltroMapping**)fMapping);
228   Bool_t res=ProcessEvent(rawStreamV3);
229   delete rawStreamV3;
230   return res;
231 }
232 //_____________________________________________________________________
233 Bool_t AliTPCCalibRawBase::ProcessEvent(AliTPCRawStream *rawStream)
234 {
235   //
236   // Event Processing loop - AliTPCRawStream
237   //
238
239   ResetEvent();
240
241   Bool_t withInput = kFALSE;
242   fAltroL1Phase=0;
243   fAltroL1PhaseTB=0;
244   fAltroRawStream = static_cast<AliAltroRawStream*>(rawStream);
245   while (rawStream->Next()) {
246     if (fUseL1Phase){
247       fAltroL1Phase  = fAltroRawStream->GetL1Phase();
248       fAltroL1PhaseTB = (fAltroL1Phase*1e09/100.);
249     }
250     fPrevRCUId=fCurrRCUId;
251     fCurrRCUId=rawStream->GetRCUId();
252     fPrevDDLNum=fCurrDDLNum;
253     fCurrDDLNum=rawStream->GetDDLNumber();
254     Int_t isector  = rawStream->GetSector();                       //  current sector
255     Int_t iRow     = rawStream->GetRow();                          //  current row
256     Int_t iPad     = rawStream->GetPad();                          //  current pad
257     Int_t iTimeBin = rawStream->GetTime();                         //  current time bin
258     Float_t signal = rawStream->GetSignal();                       //  current ADC signal
259     
260     Update(isector,iRow,iPad,iTimeBin,signal);
261     withInput = kTRUE;
262   }
263   fAltroRawStream=0x0;
264   if (withInput){
265     EndEvent();
266   }
267   return withInput;
268 }
269 //_____________________________________________________________________
270 Bool_t AliTPCCalibRawBase::ProcessEventOld(AliRawReader *rawReader)
271 {
272   //
273   //  Event processing loop - AliRawReader
274   //
275   AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
276   if (eventHeader){
277     fTimeStamp   = eventHeader->Get("Timestamp");
278     fRunNumber = eventHeader->Get("RunNb");
279     fEventType = eventHeader->Get("Type");
280   }
281
282   AliTPCRawStream rawStream(rawReader, (AliAltroMapping**)fMapping);
283   rawReader->Select("TPC");
284   return ProcessEvent(&rawStream);
285 }
286 //_____________________________________________________________________
287 Bool_t AliTPCCalibRawBase::ProcessEvent(eventHeaderStruct *event)
288 {
289   //
290   //  Event processing loop - date event
291   //
292     AliRawReader *rawReader = new AliRawReaderDate((void*)event);
293     Bool_t result=ProcessEvent(rawReader);
294     delete rawReader;
295     return result;
296
297 }
298 //_____________________________________________________________________
299 void AliTPCCalibRawBase::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append)
300 {
301     //
302     //  Write class to file
303     //
304   
305   TString sDir(dir);
306   TString option;
307   
308   if ( append )
309     option = "update";
310   else
311     option = "recreate";
312   
313   TDirectory *backup = gDirectory;
314   TFile f(filename,option.Data());
315   f.cd();
316   if ( !sDir.IsNull() ){
317     f.mkdir(sDir.Data());
318     f.cd(sDir);
319   }
320   this->Write();
321   f.Close();
322   
323   if ( backup ) backup->cd();
324 }
325 //_____________________________________________________________________
326 TTreeSRedirector *AliTPCCalibRawBase::GetDebugStreamer(){
327   //
328   // Get Debug streamer
329   // In case debug streamer not yet initialized and StreamLevel>0 create new one
330   //
331   if (fStreamLevel==0) return 0;
332   if (fDebugStreamer) return fDebugStreamer;
333   TString dsName;
334   dsName=GetName();
335   dsName+="Debug.root";
336   dsName.ReplaceAll(" ","");
337   fDebugStreamer = new TTreeSRedirector(dsName.Data());
338   return fDebugStreamer;
339 }