-mavoid creation-deletion of TClonesArray per event
[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"
825fa573 49#include "AliEMCALHit.h"
88cb7938 50
64c98165 51 ClassImp(AliEMCALLoader)
d64c959b 52
6569f329 53const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
64c98165 54const TString AliEMCALLoader::fgkECADigitsBranchName("DIGITS");//Name for branch with ECA Digits
55const TString AliEMCALLoader::fgkECASDigitsBranchName("SDIGITS");//Name for branch with ECA SDigits
56const TString AliEMCALLoader::fgkECAHitsBranchName("HITS");//Name for branch with ECA Hits
57
6569f329 58AliEMCALCalibData* AliEMCALLoader::fgCalibData = 0; //calibration data
64c98165 59//AliCaloCalibPedestal* AliEMCALLoader::fgCaloPed = 0; //dead map data
6569f329 60AliEMCALSimParam* AliEMCALLoader::fgSimParam = 0; //simulation parameters
d64c959b 61
88cb7938 62//____________________________________________________________________________
63AliEMCALLoader::AliEMCALLoader()
0c978ad5 64: fDebug(0), fTempArr(0x0)
d64c959b 65{
14ce0a6e 66 //Default constructor for EMCAL Loader Class
0c978ad5 67 fTempArr = new TClonesArray("AliEMCALHit",0);
68
d64c959b 69}
70
88cb7938 71//____________________________________________________________________________
18a21c7c 72AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername)
0c978ad5 73 : AliLoader(detname,eventfoldername), fDebug(0), fTempArr(0x0)
88cb7938 74{
14ce0a6e 75 //Specific constructor for EMCAL Loader class
0c978ad5 76 fTempArr = new TClonesArray("AliEMCALHit",0);
77
88cb7938 78}
88cb7938 79
6b299d9e 80//____________________________________________________________________________
81AliEMCALLoader::AliEMCALLoader(const Char_t *name, TFolder *topfolder)
0c978ad5 82 : AliLoader(name,topfolder), fDebug(0), fTempArr(0x0)
6b299d9e 83{
84 //Specific constructor for EMCAL Loader class
0c978ad5 85 fTempArr = new TClonesArray("AliEMCALHit",0);
86
6b299d9e 87}
88
d64c959b 89//____________________________________________________________________________
88cb7938 90AliEMCALLoader::~AliEMCALLoader()
91{
5dee926e 92 // Disconnect trees and remove arrays
0c978ad5 93// if (TreeH())
94// TreeH()->SetBranchAddress(fDetectorName,0);
95// if (TreeD())
96// TreeD()->SetBranchAddress(fDetectorName,0);
97// if (TreeS())
98// TreeS()->SetBranchAddress(fDetectorName,0);
99// if (TreeR())
100// TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
101
102 Clean(fgkECAHitsBranchName);
103 Clean(fgkECASDigitsBranchName);
104 Clean(fgkECADigitsBranchName);
105 Clean(fgkECARecPointsBranchName);
106
107 AliLoader::CleanFolders();
108
109 if (fTempArr) {
110 fTempArr->Delete();
111 delete fTempArr;
112 }
113
5dee926e 114}
115
f565d89d 116//____________________________________________________________________________
117AliEMCALCalibData* AliEMCALLoader::CalibData()
118{
1f337798 119 // Check if the instance of AliEMCALCalibData exists, if not, create it if
120 // the OCDB is available, and finally return it.
64c98165 121
1f337798 122 if(!fgCalibData && (AliCDBManager::Instance()->IsDefaultStorageSet()))
123 {
124 AliCDBEntry *entry = (AliCDBEntry*)
125 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
126 if (entry) fgCalibData = (AliEMCALCalibData*) entry->GetObject();
127 }
128
129 if(!fgCalibData)
130 AliFatal("Calibration parameters not found in CDB!");
78cbbabb 131
14ce0a6e 132 return fgCalibData;
78cbbabb 133
f565d89d 134}
135
40164976 136//____________________________________________________________________________
64c98165 137//AliCaloCalibPedestal* AliEMCALLoader::PedestalData()
138//{
139// // Check if the instance of AliCaloCalibPedestal exists, if not, create it if
140// // the OCDB is available, and finally return it.
141//
142// if(!fgCaloPed && (AliCDBManager::Instance()->IsDefaultStorageSet()))
143// {
144// AliCDBEntry *entry = (AliCDBEntry*)
145// AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
146// if (entry) fgCaloPed = (AliCaloCalibPedestal*) entry->GetObject();
147// }
148//
149// if(!fgCaloPed)
150// AliFatal("Pedestal info not found in CDB!");
151//
152// return fgCaloPed;
153//
154//}
40164976 155
6569f329 156//____________________________________________________________________________
157AliEMCALSimParam* AliEMCALLoader::SimulationParameters()
158{
64c98165 159 // Check if the instance of AliEMCALSimParam exists, if not, create it if
160 // the OCDB is available, and finally return it.
161
162 if(!fgSimParam && (AliCDBManager::Instance()->IsDefaultStorageSet()))
6569f329 163 {
64c98165 164 AliCDBEntry *entry = (AliCDBEntry*)
165 AliCDBManager::Instance()->Get("EMCAL/Calib/SimParam");
166 if (entry) fgSimParam = (AliEMCALSimParam*) entry->GetObject();
167
6569f329 168 }
f565d89d 169
64c98165 170 if(!fgSimParam)
171 AliFatal("Simulations parameters not found in CDB!");
172
173 return fgSimParam;
174
f565d89d 175}
176
ea6ddc2c 177//____________________________________________________________________________
14ce0a6e 178Int_t AliEMCALLoader::GetEvent()
179{
180 //Method to load all of the data
181 //members of the EMCAL for a given
182 //event from the Trees
64c98165 183
ea6ddc2c 184 AliLoader::GetEvent(); // First call AliLoader to do all the groundwork
185
64c98165 186 // *** Hits ***
187 // Initialize the Hits TClonesArray, only if it did not existed before
188 MakeHitsArray();
189
190 TTree *treeH = TreeH();
191 if (treeH) {
192 Int_t nEnt = treeH->GetEntries(); // TreeH has array of hits for every primary
193 Int_t index = 0;
64c98165 194 TBranch * branchH = treeH->GetBranch(fDetectorName);
0c978ad5 195 branchH->SetAddress(&fTempArr);
64c98165 196 TClonesArray* hits = const_cast<AliEMCALLoader *>(this)->Hits();
197 if (hits) hits->Clear();
198 for (Int_t iEnt = 0; iEnt < nEnt; iEnt++) {
199 branchH->GetEntry(iEnt);
0c978ad5 200 Int_t nHit = fTempArr->GetEntriesFast();
64c98165 201 for (Int_t iHit = 0; iHit < nHit; iHit++) {
0c978ad5 202 new ((*hits)[index]) AliEMCALHit(*((AliEMCALHit*)fTempArr->At(iHit)));
64c98165 203 index++;
204 }
205 }
206 branchH->ResetAddress();
0c978ad5 207 if (fTempArr) {
208 fTempArr->Clear();
209 }
64c98165 210 }
211
212 // *** SDigits ***
213 // Initialize the SDigits TClonesArray, only if it did not existed before
214 MakeSDigitsArray();
215
216 TTree *treeS = TreeS();
217 if (treeS) {
218 TBranch * branchS = treeS->GetBranch(fDetectorName);
219
220 // Reset SDigits array and branch
221 branchS->ResetAddress();
222 TClonesArray* sdigits = const_cast<AliEMCALLoader *>(this)->SDigits();
223 if (sdigits) sdigits->Clear();
224
225 branchS->SetAddress(&sdigits);
226 branchS->GetEntry(0);
227 }
228
229 // *** Digits ***
230 // Initialize the Digits TClonesArray, only if it did not existed before
231 MakeDigitsArray();
232
233 TTree *treeD = TreeD();
234 if (treeD) {
235 TBranch * branchD = treeD->GetBranch(fDetectorName);
236
237 // Reset Digits array and branch
238 branchD->ResetAddress();
239 TClonesArray* digits = const_cast<AliEMCALLoader *>(this)->Digits();
240 if (digits) digits->Clear();
241
242 branchD->SetAddress(&digits);
243 branchD->GetEntry(0);
244 }
245
246 // *** RecPoints ***
247 // Initialize the RecPoints TObjArray, only if it did not existed before
248 MakeRecPointsArray();
825fa573 249
64c98165 250 TTree *treeR = TreeR();
251 if (treeR) {
252 TBranch * branchR = treeR->GetBranch(fgkECARecPointsBranchName);
253
254 // Reset RecPoints array and branch
255 branchR->ResetAddress();
256 TObjArray* rp = const_cast<AliEMCALLoader *>(this)->RecPoints();
257 if (rp) rp->Clear();
258
259 branchR->SetAddress(&rp);
260 branchR->GetEntry(0);
261 }
262
263 return 0;
264}
ea6ddc2c 265
64c98165 266//____________________________________________________________________________
267void AliEMCALLoader::MakeHitsArray(){
268 // Add Hits array to the data folder
269 if (Hits()) return;
270 TClonesArray* hits = new TClonesArray("AliEMCALHit",0);
271 hits->SetName(fgkECAHitsBranchName);
272 GetDetectorDataFolder()->Add(hits);
273}
274
275//____________________________________________________________________________
276void AliEMCALLoader::MakeSDigitsArray(){
277 // Add SDigits array to the data folder
278 if (SDigits()) return;
279 TClonesArray* sdigits = new TClonesArray("AliEMCALDigit",0);
280 sdigits->SetName(fgkECASDigitsBranchName);
281 GetDetectorDataFolder()->Add(sdigits);
282}
283
284//____________________________________________________________________________
285void AliEMCALLoader::MakeDigitsArray(){
286 // Add Digits array to the data folder
287 if (Digits()) return;
288 TClonesArray* digits = new TClonesArray("AliEMCALDigit",0);
289 digits->SetName(fgkECADigitsBranchName);
290 GetDetectorDataFolder()->Add(digits);
291}
292
293//____________________________________________________________________________
294void AliEMCALLoader::MakeRecPointsArray(){
295 // Add RecPoints array to the data folder
296 if (RecPoints()) return;
297 TObjArray* rp = new TObjArray(0);
298 rp->SetName(fgkECARecPointsBranchName);
299 GetDetectorDataFolder()->Add(rp);
88cb7938 300}