minor coverity defect: adding self-assignment protection
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALLoader.cxx
CommitLineData
88cb7938 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
803d1ab0 16/* $Id$ */
88cb7938 17
18//_________________________________________________________________________
64c98165 19// The AliEMCALLoader gets the TClonesArray and TObjArray for reading
5dee926e 20// Hits, Dgits, SDigits and RecPoints. Filling is managed in the GetEvent()
21// method.
64c98165 22// It also provides acces methods to the calibration and simulation OCDB parameters
5dee926e 23//
88cb7938 24//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
25//*-- Completely redesigned by Dmitri Peressounko March 2001
26//
27//*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
5dee926e 28//*-- systematic usage of TFolders without changing the interface
29//
30//*-- Marco van Leeuwen, Jan 2006: complete revision to simplify reading
31//*-- and fit better in general ALICE scheme
64c98165 32//*-- GCB: Remove TClonesArrays and TObjArrays data members, they are created elsewhere.
33//*-- Provide access to OCDB calibration and simulation parameters.
5dee926e 34//
88cb7938 35//////////////////////////////////////////////////////////////////////////////
36
88cb7938 37// --- ROOT system ---
090026bf 38#include "TMath.h"
88cb7938 39#include "TTree.h"
88cb7938 40// --- Standard library ---
88cb7938 41
42// --- AliRoot header files ---
a9bbb414 43#include "AliEMCALLoader.h"
44#include "AliLog.h"
f565d89d 45#include "AliCDBLocal.h"
46#include "AliCDBStorage.h"
47#include "AliCDBManager.h"
1f337798 48#include "AliCDBEntry.h"
88cb7938 49
64c98165 50 ClassImp(AliEMCALLoader)
d64c959b 51
6569f329 52const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
64c98165 53const TString AliEMCALLoader::fgkECADigitsBranchName("DIGITS");//Name for branch with ECA Digits
54const TString AliEMCALLoader::fgkECASDigitsBranchName("SDIGITS");//Name for branch with ECA SDigits
64c98165 55
6569f329 56AliEMCALCalibData* AliEMCALLoader::fgCalibData = 0; //calibration data
6cc75819 57AliCaloCalibPedestal* AliEMCALLoader::fgCaloPed = 0; //dead map data
6569f329 58AliEMCALSimParam* AliEMCALLoader::fgSimParam = 0; //simulation parameters
6cc75819 59AliEMCALRecParam* AliEMCALLoader::fgRecParam = 0; //reconstruction parameters
d64c959b 60
88cb7938 61//____________________________________________________________________________
62AliEMCALLoader::AliEMCALLoader()
e44d51bd 63: fDebug(0)
d64c959b 64{
14ce0a6e 65 //Default constructor for EMCAL Loader Class
0c978ad5 66
d64c959b 67}
68
88cb7938 69//____________________________________________________________________________
18a21c7c 70AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername)
e44d51bd 71 : AliLoader(detname,eventfoldername), fDebug(0)
88cb7938 72{
14ce0a6e 73 //Specific constructor for EMCAL Loader class
0c978ad5 74
88cb7938 75}
88cb7938 76
0a4cb131 77//____________________________________________________________________________
6b299d9e 78AliEMCALLoader::AliEMCALLoader(const Char_t *name, TFolder *topfolder)
e44d51bd 79 : AliLoader(name,topfolder), fDebug(0)
6b299d9e 80{
81 //Specific constructor for EMCAL Loader class
0c978ad5 82
6b299d9e 83}
84
d64c959b 85//____________________________________________________________________________
88cb7938 86AliEMCALLoader::~AliEMCALLoader()
87{
5dee926e 88 // Disconnect trees and remove arrays
e44d51bd 89 if (TreeH())
90 TreeH()->SetBranchAddress(fDetectorName,0);
0c978ad5 91// if (TreeD())
92// TreeD()->SetBranchAddress(fDetectorName,0);
93// if (TreeS())
94// TreeS()->SetBranchAddress(fDetectorName,0);
95// if (TreeR())
96// TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
97
0c978ad5 98 Clean(fgkECASDigitsBranchName);
99 Clean(fgkECADigitsBranchName);
100 Clean(fgkECARecPointsBranchName);
101
102 AliLoader::CleanFolders();
e44d51bd 103
5dee926e 104}
105
106//____________________________________________________________________________
f565d89d 107AliEMCALCalibData* AliEMCALLoader::CalibData()
108{
1f337798 109 // Check if the instance of AliEMCALCalibData exists, if not, create it if
110 // the OCDB is available, and finally return it.
64c98165 111
1f337798 112 if(!fgCalibData && (AliCDBManager::Instance()->IsDefaultStorageSet()))
113 {
114 AliCDBEntry *entry = (AliCDBEntry*)
115 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
116 if (entry) fgCalibData = (AliEMCALCalibData*) entry->GetObject();
117 }
118
119 if(!fgCalibData)
120 AliFatal("Calibration parameters not found in CDB!");
78cbbabb 121
14ce0a6e 122 return fgCalibData;
78cbbabb 123
f565d89d 124}
125
40164976 126//____________________________________________________________________________
6cc75819 127AliCaloCalibPedestal* AliEMCALLoader::PedestalData()
128{
129 // Check if the instance of AliCaloCalibPedestal exists, if not, create it if
130 // the OCDB is available, and finally return it.
131
132 if(!fgCaloPed && (AliCDBManager::Instance()->IsDefaultStorageSet()))
133 {
134 AliCDBEntry *entry = (AliCDBEntry*)
135 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
136 if (entry) fgCaloPed = (AliCaloCalibPedestal*) entry->GetObject();
137 }
138
139 if(!fgCaloPed)
140 AliFatal("Pedestal info not found in CDB!");
141
142 return fgCaloPed;
143
144}
40164976 145
6569f329 146//____________________________________________________________________________
147AliEMCALSimParam* AliEMCALLoader::SimulationParameters()
148{
64c98165 149 // Check if the instance of AliEMCALSimParam exists, if not, create it if
150 // the OCDB is available, and finally return it.
151
152 if(!fgSimParam && (AliCDBManager::Instance()->IsDefaultStorageSet()))
6569f329 153 {
64c98165 154 AliCDBEntry *entry = (AliCDBEntry*)
6cc75819 155 AliCDBManager::Instance()->Get("EMCAL/Calib/SimParam");
64c98165 156 if (entry) fgSimParam = (AliEMCALSimParam*) entry->GetObject();
157
6569f329 158 }
f565d89d 159
64c98165 160 if(!fgSimParam)
161 AliFatal("Simulations parameters not found in CDB!");
162
163 return fgSimParam;
164
f565d89d 165}
166
6cc75819 167
168//____________________________________________________________________________
169AliEMCALRecParam* AliEMCALLoader::ReconstructionParameters(Int_t eventType = 0)
170{
171 // Check if the instance of AliEMCALRecParam exists, if not, create it if
172 // the OCDB is available, and finally return it.
173 // The event type must be provided.
174
175 if(!fgRecParam && (AliCDBManager::Instance()->IsDefaultStorageSet()))
176 {
177 AliCDBEntry *entry = (AliCDBEntry*)
178 AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
179 if (entry) fgRecParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(eventType);
180
181 }
182
183 if(!fgRecParam)
184 AliFatal("Reconstruction parameters not found in CDB!");
185
186 return fgRecParam;
187
188}
189
190
f565d89d 191//____________________________________________________________________________
14ce0a6e 192Int_t AliEMCALLoader::GetEvent()
193{
194 //Method to load all of the data
195 //members of the EMCAL for a given
196 //event from the Trees
6cc75819 197
ea6ddc2c 198 AliLoader::GetEvent(); // First call AliLoader to do all the groundwork
199
64c98165 200 // *** Hits ***
e44d51bd 201 // Hits are now handled directly on the AliEMCALSDigitizer, the only place it is requested.
202 // together with AliEveEMCALData
203
64c98165 204 // *** SDigits ***
205 // Initialize the SDigits TClonesArray, only if it did not existed before
206 MakeSDigitsArray();
207
208 TTree *treeS = TreeS();
209 if (treeS) {
210 TBranch * branchS = treeS->GetBranch(fDetectorName);
211
212 // Reset SDigits array and branch
213 branchS->ResetAddress();
214 TClonesArray* sdigits = const_cast<AliEMCALLoader *>(this)->SDigits();
e0dc3f7d 215 if (sdigits) sdigits->Clear("C");
64c98165 216
217 branchS->SetAddress(&sdigits);
218 branchS->GetEntry(0);
219 }
220
221 // *** Digits ***
222 // Initialize the Digits TClonesArray, only if it did not existed before
223 MakeDigitsArray();
224
225 TTree *treeD = TreeD();
226 if (treeD) {
227 TBranch * branchD = treeD->GetBranch(fDetectorName);
228
229 // Reset Digits array and branch
230 branchD->ResetAddress();
231 TClonesArray* digits = const_cast<AliEMCALLoader *>(this)->Digits();
e0dc3f7d 232 if (digits) digits->Clear("C");
64c98165 233
234 branchD->SetAddress(&digits);
235 branchD->GetEntry(0);
236 }
237
238 // *** RecPoints ***
239 // Initialize the RecPoints TObjArray, only if it did not existed before
240 MakeRecPointsArray();
825fa573 241
64c98165 242 TTree *treeR = TreeR();
243 if (treeR) {
244 TBranch * branchR = treeR->GetBranch(fgkECARecPointsBranchName);
245
246 // Reset RecPoints array and branch
247 branchR->ResetAddress();
248 TObjArray* rp = const_cast<AliEMCALLoader *>(this)->RecPoints();
249 if (rp) rp->Clear();
250
251 branchR->SetAddress(&rp);
252 branchR->GetEntry(0);
253 }
254
255 return 0;
256}
ea6ddc2c 257
64c98165 258//____________________________________________________________________________
64c98165 259void AliEMCALLoader::MakeSDigitsArray(){
260 // Add SDigits array to the data folder
261 if (SDigits()) return;
262 TClonesArray* sdigits = new TClonesArray("AliEMCALDigit",0);
263 sdigits->SetName(fgkECASDigitsBranchName);
264 GetDetectorDataFolder()->Add(sdigits);
265}
266
267//____________________________________________________________________________
268void AliEMCALLoader::MakeDigitsArray(){
269 // Add Digits array to the data folder
270 if (Digits()) return;
271 TClonesArray* digits = new TClonesArray("AliEMCALDigit",0);
272 digits->SetName(fgkECADigitsBranchName);
273 GetDetectorDataFolder()->Add(digits);
274}
275
276//____________________________________________________________________________
277void AliEMCALLoader::MakeRecPointsArray(){
278 // Add RecPoints array to the data folder
279 if (RecPoints()) return;
280 TObjArray* rp = new TObjArray(0);
281 rp->SetName(fgkECARecPointsBranchName);
282 GetDetectorDataFolder()->Add(rp);
88cb7938 283}