ce4bef701d7815c8fc415fce8fee34056f0d93d7
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerData.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 purpeateose. It is      *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17  
18  
19 EMCal trigger data container
20 for data (both raw & rec) persistency
21 Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22 */
23
24 #include "AliEMCALTriggerData.h"
25 #include "AliEMCALTriggerPatch.h"
26 #include "AliLog.h"
27 #include "TIterator.h"
28 #include "Riostream.h"
29
30 ClassImp(AliEMCALTriggerData)
31
32 //_____________
33 AliEMCALTriggerData::AliEMCALTriggerData() : TObject(),
34 fMode(0),
35 fL0Patches(),
36 fL0Region(),
37 fL1GammaPatches(),
38 fL1JetPatches(),
39 fL1Region(),
40 fL1GammaThreshold(0),
41 fL1JetThreshold(0)
42 {  
43         //
44         for (Int_t i = 0; i < 2; i++)
45         {
46                        fL0Patches[i] = new TClonesArray("AliEMCALTriggerPatch");
47                   fL1GammaPatches[i] = new TClonesArray("AliEMCALTriggerPatch");
48                     fL1JetPatches[i] = new TClonesArray("AliEMCALTriggerPatch");
49         }
50         
51         for (Int_t i = 0; i < 32; i++) for (Int_t j = 0; j < 24; j++) for (Int_t k = 0; k <  4; k++) fL0Region[i][j][k] = 0;
52         for (Int_t i = 0; i <  2; i++) for (Int_t j = 0; j < 48; j++) for (Int_t k = 0; k < 64; k++) fL1Region[i][j][k] = 0;
53 }
54
55 //_____________
56 AliEMCALTriggerData::~AliEMCALTriggerData()
57 {
58         //
59         for (Int_t i = 0; i < 2; i++)
60         {
61                 if (     fL0Patches[i])      fL0Patches[i]->Delete();
62                 if (fL1GammaPatches[i]) fL1GammaPatches[i]->Delete();
63                 if (  fL1JetPatches[i])   fL1JetPatches[i]->Delete();
64         }
65 }
66
67 //_____________
68 void AliEMCALTriggerData::SetL0Region(Int_t i, const Int_t**& region)
69 {
70         //
71         if (i < 0 || i > 31) 
72         {
73                 AliError("Bad index!");
74                 return;
75         }
76         
77         for (Int_t j=0;j<24;j++)
78                 for (Int_t k=0;k<4;k++) fL0Region[i][j][k] = region[j][k];
79 }
80
81 //_____________
82 void AliEMCALTriggerData::GetPatches(TriggerType_t type, Int_t i, TClonesArray& patches) const
83 {
84         //
85         if (i < 0 || i > 1) 
86         {
87                 AliError("Bad index!");
88                 return;
89         }
90         
91         switch (type)
92         {
93                 case kL0:
94                         patches =  *fL0Patches[i];
95                         break;
96                 case kL1Gamma:
97                         patches =  *fL1GammaPatches[i];
98                         break;
99                 case kL1Jet:
100                         patches =  *fL1JetPatches[i];
101                         break;
102                 default:
103                         AliError("Unknown trigger type!");
104                         break;
105         }
106 }
107
108 //_____________
109 TClonesArray* AliEMCALTriggerData::GetPatches(TriggerType_t type, Int_t i) const
110 {
111         //
112         if (i < 0 || i > 1) 
113         {
114                 AliError("Bad index!");
115                 return 0x0;
116         }
117         
118         switch (type)
119         {
120                 case kL0:
121                         return fL0Patches[i];
122                         break;
123                 case kL1Gamma:
124                         return fL1GammaPatches[i];
125                         break;
126                 case kL1Jet:
127                         return fL1JetPatches[i];
128                         break;
129                 default:
130                         AliError("Unknown trigger type!");
131                         break;
132         }
133
134         return 0x0;
135 }
136
137 //_____________
138 void AliEMCALTriggerData::SetPatches(TriggerType_t type, Int_t i, const TClonesArray& patches)
139 {
140         //
141         if (i < 0 || i > 1) 
142         {
143                 AliError("Bad index!");
144                 return;
145         }
146         
147         if (patches.GetEntriesFast())
148         {
149                 TClonesArray* arr = 0x0;
150                 
151                 switch (type)
152                 {
153                         case kL0:
154                                 arr = fL0Patches[i];
155                                 break;
156                         case kL1Gamma:
157                                 arr = fL1GammaPatches[i];
158                                 break;
159                         case kL1Jet:
160                                 arr = fL1JetPatches[i];
161                                 break;
162                         default:
163                                 AliError("Unknown trigger type!");
164                                 return;
165                 }
166                 
167                 if (arr)
168                 {
169                         Int_t size = arr->GetSize() + patches.GetSize();
170                 
171                         arr->Expand(size);
172                 
173                         for (Int_t k = 0; k < patches.GetEntriesFast(); k++)
174                         {
175                                 AliEMCALTriggerPatch* p = static_cast<AliEMCALTriggerPatch*>(patches.At(k));
176                                 new((*arr)[arr->GetEntriesFast()]) AliEMCALTriggerPatch(*p);
177                         }
178                 }
179                 else
180                 {
181                         AliError("TClonesArray is NULL!");
182                 }
183         }
184 }
185
186 //_____________
187 void AliEMCALTriggerData::SetL1Region(Int_t i, Int_t**& region)
188 {
189         //
190         if (i < 0 || i > 1) 
191         {
192                 AliError("Bad index!");
193                 return;
194         }
195                 
196         for (Int_t j = 0; j < 48; j++)
197                 for (Int_t k = 0; k < 64; k++) fL1Region[i][j][k] = region[j][k];
198 }
199
200 //_____________
201 void AliEMCALTriggerData::GetL1Region(Int_t i, Int_t arr[][64]) const 
202
203         //
204         if (i < 0 || i > 1) 
205         {
206                 AliError("Bad index!");
207                 return;
208         }
209         
210         for (Int_t j = 0; j < 48; j++) for (Int_t k = 0; k < 64; k++) { arr[j][k] = fL1Region[i][j][k]; } 
211 }
212
213
214 //_____________
215 void AliEMCALTriggerData::Scan() const
216 {
217         //
218         TIterator* nP;
219
220         printf("L0:\n");
221         printf("\tFound (%2d,%2d) patches\n", fL0Patches[1]->GetEntriesFast(), fL0Patches[0]->GetEntriesFast());
222         printf("\tRAW:\n");
223         nP = fL0Patches[1]->MakeIterator();
224         while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) {printf("\t"); p->Print("");}
225         printf("\tREC:\n");
226         nP = fL0Patches[0]->MakeIterator();
227         while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) {printf("\t"); p->Print("");}
228         printf("L1:\n");
229         printf("\tFound (%4d,%4d) gamma patches\n",fL1GammaPatches[1]->GetEntriesFast(), fL1GammaPatches[0]->GetEntriesFast());
230         printf("\tRAW:\n");
231         nP = fL1GammaPatches[1]->MakeIterator();
232         while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) {printf("\t"); p->Print("");}
233         printf("\tREC:\n");
234         nP = fL1GammaPatches[0]->MakeIterator();
235         while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) {printf("\t"); p->Print("");}
236         printf("\tFound (%4d,%4d) jet patches\n",fL1JetPatches[1]->GetEntriesFast(), fL1JetPatches[0]->GetEntriesFast());
237         printf("\tRAW:\n");
238         nP = fL1JetPatches[1]->MakeIterator();
239         while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) {printf("\t"); p->Print("");}
240         printf("\tREC:\n");
241         nP = fL1JetPatches[0]->MakeIterator();
242         while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) {printf("\t"); p->Print("");}
243 }
244
245 //_____________
246 void AliEMCALTriggerData::Reset()
247 {
248         //
249         for (Int_t i = 0; i < 2; i++)
250         {
251                 if (     fL0Patches[i])      fL0Patches[i]->Delete();
252                 if (fL1GammaPatches[i]) fL1GammaPatches[i]->Delete();
253                 if (  fL1JetPatches[i])   fL1JetPatches[i]->Delete();   
254         }
255                 
256         for (Int_t i = 0; i < 2; i++) for (Int_t j = 0; j < 48; j++) for (Int_t k = 0; k < 64; k++) fL1Region[i][j][k] = 0;
257 }
258
259
260