]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALLoader.cxx
Coding conventions
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALLoader.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$ */
17
18 //_________________________________________________________________________
19 //  The AliEMCALLoader gets the TClonesArray and TObjArray for reading
20 //  Hits, Dgits, SDigits and RecPoints. Filling is managed in the GetEvent()
21 //  method.
22 //  It also provides acces methods to the calibration and simulation OCDB parameters 
23 //
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
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
32 //*-- GCB: Remove TClonesArrays and TObjArrays data members, they are created elsewhere.
33 //*--      Provide access to OCDB calibration and simulation parameters.          
34 //
35 //////////////////////////////////////////////////////////////////////////////
36
37 // --- ROOT system ---
38 #include "TMath.h"
39 #include "TTree.h"
40 // --- Standard library ---
41
42 // --- AliRoot header files ---
43 #include "AliEMCALLoader.h"
44 #include "AliLog.h"
45 #include "AliCDBLocal.h"
46 #include "AliCDBStorage.h"
47 #include "AliCDBManager.h"
48 #include "AliCDBEntry.h"
49
50  ClassImp(AliEMCALLoader)
51   
52 const TString         AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
53 const TString         AliEMCALLoader::fgkECADigitsBranchName("DIGITS");//Name for branch with ECA Digits
54 const TString         AliEMCALLoader::fgkECASDigitsBranchName("SDIGITS");//Name for branch with ECA SDigits
55
56 AliEMCALCalibData*    AliEMCALLoader::fgCalibData = 0; //calibration data
57 //AliCaloCalibPedestal* AliEMCALLoader::fgCaloPed   = 0; //dead map data
58 AliEMCALSimParam*     AliEMCALLoader::fgSimParam  = 0; //simulation parameters
59
60 //____________________________________________________________________________ 
61 AliEMCALLoader::AliEMCALLoader()
62 : fDebug(0)
63 {
64   //Default constructor for EMCAL Loader Class
65
66 }
67
68 //____________________________________________________________________________ 
69 AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername)
70   : AliLoader(detname,eventfoldername), fDebug(0)
71 {
72   //Specific constructor for EMCAL Loader class
73
74 }
75
76 //____________________________________________________________________________
77 AliEMCALLoader::AliEMCALLoader(const Char_t *name, TFolder *topfolder)
78   : AliLoader(name,topfolder), fDebug(0)
79 {
80   //Specific constructor for EMCAL Loader class
81
82 }
83
84 //____________________________________________________________________________ 
85 AliEMCALLoader::~AliEMCALLoader()
86 {
87   // Disconnect trees and remove arrays
88   if (TreeH())
89     TreeH()->SetBranchAddress(fDetectorName,0);
90 //  if (TreeD())
91 //    TreeD()->SetBranchAddress(fDetectorName,0);
92 //  if (TreeS())
93 //    TreeS()->SetBranchAddress(fDetectorName,0);
94 //  if (TreeR())
95 //    TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
96         
97         Clean(fgkECASDigitsBranchName);
98         Clean(fgkECADigitsBranchName);
99         Clean(fgkECARecPointsBranchName);
100         
101         AliLoader::CleanFolders();
102                 
103 }
104
105 //____________________________________________________________________________ 
106 AliEMCALCalibData* AliEMCALLoader::CalibData()
107
108   // Check if the instance of AliEMCALCalibData exists, if not, create it if 
109   // the OCDB is available, and finally return it.
110   
111   if(!fgCalibData && (AliCDBManager::Instance()->IsDefaultStorageSet()))
112     {
113       AliCDBEntry *entry = (AliCDBEntry*) 
114         AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
115       if (entry) fgCalibData =  (AliEMCALCalibData*) entry->GetObject();
116     }
117   
118   if(!fgCalibData)
119     AliFatal("Calibration parameters not found in CDB!");
120   
121   return fgCalibData;
122   
123 }
124
125 //____________________________________________________________________________ 
126 //AliCaloCalibPedestal* AliEMCALLoader::PedestalData()
127 //{ 
128 //      // Check if the instance of AliCaloCalibPedestal exists, if not, create it if 
129 //      // the OCDB is available, and finally return it.
130 //      
131 //      if(!fgCaloPed && (AliCDBManager::Instance()->IsDefaultStorageSet()))
132 //    {
133 //              AliCDBEntry *entry = (AliCDBEntry*) 
134 //              AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
135 //              if (entry) fgCaloPed =  (AliCaloCalibPedestal*) entry->GetObject();
136 //    }
137 //      
138 //      if(!fgCaloPed)
139 //              AliFatal("Pedestal info not found in CDB!");
140 //      
141 //      return fgCaloPed;
142 //      
143 //}
144
145 //____________________________________________________________________________ 
146 AliEMCALSimParam* AliEMCALLoader::SimulationParameters()
147
148   // Check if the instance of AliEMCALSimParam exists, if not, create it if 
149   // the OCDB is available, and finally return it.
150   
151   if(!fgSimParam && (AliCDBManager::Instance()->IsDefaultStorageSet()))
152     {
153       AliCDBEntry *entry = (AliCDBEntry*) 
154         AliCDBManager::Instance()->Get("EMCAL/Calib/SimParam");
155       if (entry) fgSimParam =  (AliEMCALSimParam*) entry->GetObject();
156       
157     }
158   
159   if(!fgSimParam)
160     AliFatal("Simulations parameters not found in CDB!");
161   
162   return fgSimParam;
163   
164 }
165
166 //____________________________________________________________________________ 
167 Int_t AliEMCALLoader::GetEvent() 
168 {
169   //Method to load all of the data
170   //members of the EMCAL for a given
171   //event from the Trees
172   
173   AliLoader::GetEvent();  // First call AliLoader to do all the groundwork
174   
175   // *** Hits ***
176   // Hits are now handled directly on the AliEMCALSDigitizer, the only place it is requested.
177   // together with AliEveEMCALData
178         
179   // *** SDigits ***
180   // Initialize the SDigits TClonesArray, only if it did not existed before
181   MakeSDigitsArray();
182   
183   TTree *treeS = TreeS();
184   if (treeS) {
185     TBranch * branchS = treeS->GetBranch(fDetectorName);
186     
187     // Reset SDigits array and branch
188     branchS->ResetAddress();
189     TClonesArray* sdigits = const_cast<AliEMCALLoader *>(this)->SDigits();
190     if (sdigits) sdigits->Clear("C");
191     
192     branchS->SetAddress(&sdigits);
193     branchS->GetEntry(0);
194   }
195   
196   // *** Digits ***
197   // Initialize the Digits TClonesArray, only if it did not existed before
198   MakeDigitsArray();
199   
200   TTree *treeD = TreeD();
201   if (treeD) {
202     TBranch * branchD = treeD->GetBranch(fDetectorName);
203     
204     // Reset Digits array and branch
205     branchD->ResetAddress();
206     TClonesArray* digits = const_cast<AliEMCALLoader *>(this)->Digits();
207     if (digits) digits->Clear("C");
208     
209     branchD->SetAddress(&digits);
210     branchD->GetEntry(0);
211   }
212   
213   // *** RecPoints ***  
214   // Initialize the RecPoints TObjArray, only if it did not existed before
215   MakeRecPointsArray();
216   
217   TTree *treeR = TreeR();
218   if (treeR) {
219     TBranch * branchR = treeR->GetBranch(fgkECARecPointsBranchName);
220     
221     // Reset RecPoints array and branch
222     branchR->ResetAddress();
223     TObjArray* rp = const_cast<AliEMCALLoader *>(this)->RecPoints();
224     if (rp) rp->Clear();
225     
226     branchR->SetAddress(&rp);
227     branchR->GetEntry(0);
228   }
229   
230   return 0;
231 }
232
233 //____________________________________________________________________________
234 void AliEMCALLoader::MakeSDigitsArray(){
235   // Add SDigits array to the data folder
236   if (SDigits()) return;
237   TClonesArray* sdigits = new TClonesArray("AliEMCALDigit",0);
238   sdigits->SetName(fgkECASDigitsBranchName);
239   GetDetectorDataFolder()->Add(sdigits);
240 }
241
242 //____________________________________________________________________________
243 void AliEMCALLoader::MakeDigitsArray(){
244   // Add Digits array to the data folder
245   if (Digits()) return;
246   TClonesArray* digits = new TClonesArray("AliEMCALDigit",0);
247   digits->SetName(fgkECADigitsBranchName);
248   GetDetectorDataFolder()->Add(digits);
249 }
250
251 //____________________________________________________________________________
252 void AliEMCALLoader::MakeRecPointsArray(){
253   // Add RecPoints array to the data folder
254   if (RecPoints()) return;
255   TObjArray* rp = new TObjArray(0);
256   rp->SetName(fgkECARecPointsBranchName);
257   GetDetectorDataFolder()->Add(rp);
258 }