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"
39 #include "TTreeStream.h"
42 #include "AliTPCCalibRawBase.h"
44 ClassImp(AliTPCCalibRawBase)
46 AliTPCCalibRawBase::AliTPCCalibRawBase() :
68 fROC(AliTPCROC::Instance())
75 //_____________________________________________________________________
76 AliTPCCalibRawBase::AliTPCCalibRawBase(const AliTPCCalibRawBase &calib) :
78 fFirstTimeBin(calib.fFirstTimeBin),
79 fLastTimeBin(calib.fLastTimeBin),
80 fNevents(calib.fNevents),
81 fDebugLevel(calib.fDebugLevel),
82 fStreamLevel(calib.fStreamLevel),
83 fRunNumber(calib.fRunNumber),
84 fFirstTimeStamp(calib.fFirstTimeStamp),
85 fLastTimeStamp(calib.fLastTimeStamp),
98 fROC(AliTPCROC::Instance())
105 //_____________________________________________________________________
106 AliTPCCalibRawBase::~AliTPCCalibRawBase()
111 if (fDebugStreamer) delete fDebugStreamer;
113 //_____________________________________________________________________
114 AliTPCCalibRawBase& AliTPCCalibRawBase::operator = (const AliTPCCalibRawBase &source)
117 // assignment operator
119 if (&source == this) return *this;
120 new (this) AliTPCCalibRawBase(source);
124 //_____________________________________________________________________
125 Bool_t AliTPCCalibRawBase::ProcessEvent(AliTPCRawStreamV3 * const rawStreamV3)
128 // Event Processing loop - AliTPCRawStreamV3
131 Bool_t withInput = kFALSE;
134 // fAltroRawStream = static_cast<AliAltroRawStream*>(rawStreamV3);
135 while ( rawStreamV3->NextDDL() ){
136 if (AliLog::GetGlobalDebugLevel()>2) rawStreamV3->PrintRCUTrailer();
138 fCurrRCUId=rawStreamV3->GetRCUId();
139 fCurrDDLNum=rawStreamV3->GetDDLNumber();
141 // fAltroL1Phase = fAltroRawStream->GetL1Phase();
142 fAltroL1Phase = rawStreamV3->GetL1Phase();
143 fAltroL1PhaseTB = (fAltroL1Phase*1e09/100.);
144 AliDebug(1, Form("L1Phase: %.2e (%03d)\n",fAltroL1PhaseTB,fCurrDDLNum));
147 while ( rawStreamV3->NextChannel() ){
148 Int_t isector = rawStreamV3->GetSector(); // current sector
149 Int_t iRow = rawStreamV3->GetRow(); // current row
150 Int_t iPad = rawStreamV3->GetPad(); // current pad
151 while ( rawStreamV3->NextBunch() ){
152 UInt_t startTbin = rawStreamV3->GetStartTimeBin();
153 // Int_t endTbin = (Int_t)rawStreamV3->GetEndTimeBin();
154 Int_t bunchlength = rawStreamV3->GetBunchLength();
155 const UShort_t *sig = rawStreamV3->GetSignals();
156 ProcessBunch(isector,iRow,iPad,bunchlength,startTbin,sig);
157 for (Int_t iTimeBin = 0; iTimeBin<bunchlength; iTimeBin++){
158 Float_t signal=(Float_t)sig[iTimeBin];
159 // printf("%02d - %03d - %03d - %04d: %.1f\n",isector,iRow,iPad,startTbin,signal);
160 Update(isector,iRow,iPad,startTbin--,signal);
161 fPrevRCUId=fCurrRCUId;
162 fPrevDDLNum=fCurrDDLNum;
173 //_____________________________________________________________________
174 Bool_t AliTPCCalibRawBase::ProcessEvent(AliRawReader * const rawReader)
177 // Event processing loop - AliRawReader
179 AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
181 fTimeStamp = eventHeader->Get("Timestamp");
182 fRunNumber = eventHeader->Get("RunNb");
183 fEventType = eventHeader->Get("Type");
185 if (!fFirstTimeStamp) fFirstTimeStamp=fTimeStamp;
187 AliTPCRawStreamV3 *rawStreamV3 = new AliTPCRawStreamV3(rawReader, (AliAltroMapping**)fMapping);
188 Bool_t res=ProcessEvent(rawStreamV3);
190 fLastTimeStamp=fTimeStamp;
195 //_____________________________________________________________________
196 Bool_t AliTPCCalibRawBase::ProcessEvent(eventHeaderStruct * const event)
199 // Event processing loop - date event
202 fRunNumber=event->eventRunNb;
203 fTimeStamp=event->eventTimestamp;
204 if (!fFirstTimeStamp) fFirstTimeStamp=fTimeStamp;
205 fLastTimeStamp=fTimeStamp;
206 fEventType=event->eventType;
207 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
208 AliTPCRawStreamV3 *rawStreamV3 = new AliTPCRawStreamV3(rawReader, (AliAltroMapping**)fMapping);
209 Bool_t result=ProcessEvent(rawStreamV3);
215 //_____________________________________________________________________
216 void AliTPCCalibRawBase::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append)
219 // Write class to file
230 TDirectory *backup = gDirectory;
231 TFile f(filename,option.Data());
233 if ( !sDir.IsNull() ){
234 f.mkdir(sDir.Data());
240 if ( backup ) backup->cd();
242 //_____________________________________________________________________
243 TTreeSRedirector *AliTPCCalibRawBase::GetDebugStreamer(){
245 // Get Debug streamer
246 // In case debug streamer not yet initialized and StreamLevel>0 create new one
248 if (fStreamLevel==0) return 0;
249 if (fDebugStreamer) return fDebugStreamer;
252 dsName+="Debug.root";
253 dsName.ReplaceAll(" ","");
254 fDebugStreamer = new TTreeSRedirector(dsName.Data());
255 return fDebugStreamer;
257 //_____________________________________________________________________
258 void AliTPCCalibRawBase::MergeBase(const AliTPCCalibRawBase *calib)
261 // merge this with base
263 if (calib->fFirstTimeStamp<fFirstTimeStamp) fFirstTimeStamp=calib->fFirstTimeStamp;
264 if (calib->fLastTimeStamp>fLastTimeStamp) fLastTimeStamp =calib->fLastTimeStamp;