1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliTPCCalibRawBase.cxx */
18 /////////////////////////////////////////////////////////////////////////////////////////
20 // Base class for the calibration algorithms using raw data as input //
22 // Origin: Jens Wiechula J.Wiechula@gsi.de //
24 /////////////////////////////////////////////////////////////////////////////////////////
27 #include <TDirectory.h>
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 "AliTPCRawStreamV3.h"
38 #include "AliTPCRawStream.h"
40 #include "TTreeStream.h"
43 #include "AliTPCCalibRawBase.h"
45 ClassImp(AliTPCCalibRawBase)
47 AliTPCCalibRawBase::AliTPCCalibRawBase() :
69 fROC(AliTPCROC::Instance())
76 //_____________________________________________________________________
77 AliTPCCalibRawBase::AliTPCCalibRawBase(const AliTPCCalibRawBase &calib) :
79 fFirstTimeBin(calib.fFirstTimeBin),
80 fLastTimeBin(calib.fLastTimeBin),
81 fNevents(calib.fNevents),
82 fDebugLevel(calib.fDebugLevel),
83 fStreamLevel(calib.fStreamLevel),
84 fRunNumber(calib.fRunNumber),
85 fFirstTimeStamp(calib.fFirstTimeStamp),
86 fLastTimeStamp(calib.fLastTimeStamp),
99 fROC(AliTPCROC::Instance())
106 //_____________________________________________________________________
107 AliTPCCalibRawBase::~AliTPCCalibRawBase()
112 if (fDebugStreamer) delete fDebugStreamer;
114 //_____________________________________________________________________
115 AliTPCCalibRawBase& AliTPCCalibRawBase::operator = (const AliTPCCalibRawBase &source)
118 // assignment operator
120 if (&source == this) return *this;
121 new (this) AliTPCCalibRawBase(source);
125 //_____________________________________________________________________
126 Bool_t AliTPCCalibRawBase::ProcessEvent(AliTPCRawStreamV3 * const rawStreamV3)
129 // Event Processing loop - AliTPCRawStreamV3
132 Bool_t withInput = kFALSE;
135 // fAltroRawStream = static_cast<AliAltroRawStream*>(rawStreamV3);
136 while ( rawStreamV3->NextDDL() ){
137 if (AliLog::GetGlobalDebugLevel()>2) rawStreamV3->PrintRCUTrailer();
139 fCurrRCUId=rawStreamV3->GetRCUId();
140 fCurrDDLNum=rawStreamV3->GetDDLNumber();
142 // fAltroL1Phase = fAltroRawStream->GetL1Phase();
143 fAltroL1Phase = rawStreamV3->GetL1Phase();
144 fAltroL1PhaseTB = (fAltroL1Phase*1e09/100.);
145 AliDebug(1, Form("L1Phase: %.2e (%03d)\n",fAltroL1PhaseTB,fCurrDDLNum));
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() ){
153 UInt_t startTbin = rawStreamV3->GetStartTimeBin();
154 // Int_t endTbin = (Int_t)rawStreamV3->GetEndTimeBin();
155 Int_t bunchlength = rawStreamV3->GetBunchLength();
156 const UShort_t *sig = rawStreamV3->GetSignals();
157 ProcessBunch(isector,iRow,iPad,bunchlength,startTbin,sig);
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;
174 //_____________________________________________________________________
175 Bool_t AliTPCCalibRawBase::ProcessEvent(AliRawReader * const rawReader)
178 // Event processing loop - AliRawReader
180 AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
182 fTimeStamp = eventHeader->Get("Timestamp");
183 fRunNumber = eventHeader->Get("RunNb");
184 fEventType = eventHeader->Get("Type");
186 if (!fFirstTimeStamp) fFirstTimeStamp=fTimeStamp;
188 AliTPCRawStreamV3 *rawStreamV3 = new AliTPCRawStreamV3(rawReader, (AliAltroMapping**)fMapping);
189 Bool_t res=ProcessEvent(rawStreamV3);
191 fLastTimeStamp=fTimeStamp;
196 //_____________________________________________________________________
197 Bool_t AliTPCCalibRawBase::ProcessEvent(AliTPCRawStream * const rawStream)
200 // Event Processing loop - AliTPCRawStream
205 Bool_t withInput = kFALSE;
208 fAltroRawStream = static_cast<AliAltroRawStream*>(rawStream);
209 while (rawStream->Next()) {
211 fAltroL1Phase = fAltroRawStream->GetL1Phase();
212 fAltroL1PhaseTB = (fAltroL1Phase*1e09/100.);
214 fPrevRCUId=fCurrRCUId;
215 fCurrRCUId=rawStream->GetRCUId();
216 fPrevDDLNum=fCurrDDLNum;
217 fCurrDDLNum=rawStream->GetDDLNumber();
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
224 Update(isector,iRow,iPad,iTimeBin,signal);
233 //_____________________________________________________________________
234 Bool_t AliTPCCalibRawBase::ProcessEventOld(AliRawReader * const rawReader)
237 // Event processing loop - AliRawReader
239 AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
241 fTimeStamp = eventHeader->Get("Timestamp");
242 fRunNumber = eventHeader->Get("RunNb");
243 fEventType = eventHeader->Get("Type");
246 AliTPCRawStream rawStream(rawReader, (AliAltroMapping**)fMapping);
247 rawReader->Select("TPC");
248 return ProcessEvent(&rawStream);
250 //_____________________________________________________________________
251 Bool_t AliTPCCalibRawBase::ProcessEvent(eventHeaderStruct * const event)
254 // Event processing loop - date event
257 fRunNumber=event->eventRunNb;
258 fTimeStamp=event->eventTimestamp;
259 if (!fFirstTimeStamp) fFirstTimeStamp=fTimeStamp;
260 fLastTimeStamp=fTimeStamp;
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);
270 //_____________________________________________________________________
271 void AliTPCCalibRawBase::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append)
274 // Write class to file
285 TDirectory *backup = gDirectory;
286 TFile f(filename,option.Data());
288 if ( !sDir.IsNull() ){
289 f.mkdir(sDir.Data());
295 if ( backup ) backup->cd();
297 //_____________________________________________________________________
298 TTreeSRedirector *AliTPCCalibRawBase::GetDebugStreamer(){
300 // Get Debug streamer
301 // In case debug streamer not yet initialized and StreamLevel>0 create new one
303 if (fStreamLevel==0) return 0;
304 if (fDebugStreamer) return fDebugStreamer;
307 dsName+="Debug.root";
308 dsName.ReplaceAll(" ","");
309 fDebugStreamer = new TTreeSRedirector(dsName.Data());
310 return fDebugStreamer;
312 //_____________________________________________________________________
313 void AliTPCCalibRawBase::MergeBase(const AliTPCCalibRawBase *calib)
316 // merge this with base
318 if (calib->fFirstTimeStamp<fFirstTimeStamp) fFirstTimeStamp=calib->fFirstTimeStamp;
319 if (calib->fLastTimeStamp>fLastTimeStamp) fLastTimeStamp =calib->fLastTimeStamp;