]>
Commit | Line | Data |
---|---|---|
4d3f0fd0 | 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 | #include "AliMUONDigitStoreV1.h" | |
19 | ||
3d1463c8 | 20 | //----------------------------------------------------------------------------- |
4d3f0fd0 | 21 | /// \class AliMUONDigitStoreV1 |
22 | /// | |
23 | /// (Legacy) Implementation of AliMUONVDigitStore. | |
24 | /// Called legacy as the internal structure corresponds to what we | |
25 | /// used to write as MUON.(S)Digits.root files, before the switch | |
26 | /// to data stores. | |
27 | /// | |
28 | // \author Laurent Aphecetche, Subatech | |
3d1463c8 | 29 | //----------------------------------------------------------------------------- |
4d3f0fd0 | 30 | |
31 | #include "AliLog.h" | |
32 | #include "AliMUONDigit.h" | |
33 | #include "AliMUONDigitStoreV1Iterator.h" | |
34 | #include "AliMUONTOTCAStoreIterator.h" | |
35 | #include "AliMUONTreeManager.h" | |
36 | #include "AliMpConstants.h" | |
37 | #include "AliMpDEManager.h" | |
38 | #include "AliMpDEManager.h" | |
39 | #include "AliMpStationType.h" | |
40 | #include <Riostream.h> | |
41 | #include <TClonesArray.h> | |
42 | #include <TObjArray.h> | |
43 | #include <TTree.h> | |
44 | ||
45 | /// \cond CLASSIMP | |
46 | ClassImp(AliMUONDigitStoreV1) | |
47 | /// \endcond | |
48 | ||
49 | namespace | |
50 | { | |
51 | TString BaseName(const TString& name) | |
52 | { | |
53 | if ( name == "TreeS" ) return "MUONSDigit"; | |
54 | if ( name == "TreeD" ) return "MUONDigit"; | |
55 | return ""; | |
56 | } | |
57 | } | |
58 | ||
59 | //_____________________________________________________________________________ | |
60 | AliMUONDigitStoreV1::AliMUONDigitStoreV1() | |
61 | : AliMUONVDigitStore(), | |
62 | fDigits(new TObjArray(AliMpConstants::NofChambers())), | |
63 | fChamberDigits(0x0) | |
64 | { | |
65 | /// ctor | |
66 | fDigits->SetOwner(kTRUE); | |
67 | for ( Int_t i = 0; i < fDigits->GetSize(); ++i ) | |
68 | { | |
69 | TClonesArray* tca = new TClonesArray("AliMUONDigit",100); | |
70 | tca->SetOwner(kTRUE); | |
71 | fDigits->AddAt(tca,i); | |
72 | } | |
73 | Clear(); | |
74 | AliDebug(1,""); | |
75 | } | |
76 | ||
77 | //_____________________________________________________________________________ | |
78 | AliMUONDigitStoreV1::AliMUONDigitStoreV1(const AliMUONDigitStoreV1&) | |
79 | : AliMUONVDigitStore(), | |
80 | fDigits(0x0), | |
81 | fChamberDigits(0x0) | |
82 | { | |
83 | /// copy ctor | |
84 | AliError("Please implement me"); | |
85 | } | |
86 | ||
87 | //_____________________________________________________________________________ | |
88 | AliMUONDigitStoreV1& | |
89 | AliMUONDigitStoreV1::operator=(const AliMUONDigitStoreV1&) | |
90 | { | |
91 | /// assignement operator | |
92 | AliError("Please implement me"); | |
93 | return *this; | |
94 | } | |
95 | ||
96 | //_____________________________________________________________________________ | |
97 | AliMUONDigitStoreV1::~AliMUONDigitStoreV1() | |
98 | { | |
99 | /// dtor | |
100 | delete fDigits; | |
101 | } | |
102 | ||
103 | ||
104 | //_____________________________________________________________________________ | |
105 | void | |
106 | AliMUONDigitStoreV1::Clear(Option_t* /*opt*/) | |
107 | { | |
108 | /// Clear the tclonesarray, but keep the tobjarray's size constant. | |
109 | ||
110 | for ( Int_t i = 0; i <= fDigits->GetLast(); ++i ) | |
111 | { | |
112 | ChamberDigits(i)->Clear("C"); | |
113 | } | |
114 | } | |
115 | ||
116 | //_____________________________________________________________________________ | |
117 | AliMUONVDigit* | |
118 | AliMUONDigitStoreV1::Add(const AliMUONVDigit& vdigit, EReplacePolicy replace) | |
119 | { | |
120 | /// Try to add a digit to the store. Return whether the try was successfull | |
121 | /// or not. | |
122 | /// | |
123 | /// If the digit is already there, the action taken depends on "replace" | |
124 | /// kAllow -> replacement will occur (i.e. return kTRUE) | |
125 | /// kDeny -> replacement will *not* occur (and returned value is kFALSE) | |
126 | /// kMerge -> both digits will be merged into one (return kTRUE) | |
127 | /// | |
128 | ||
129 | const AliMUONDigit* digit = dynamic_cast<const AliMUONDigit*>(&vdigit); | |
130 | ||
131 | if (!digit) | |
132 | { | |
133 | AliError(Form("Digit is not of the expected type (%s vs AliMUONdigit)", | |
134 | vdigit.ClassName())); | |
135 | return 0x0; | |
136 | } | |
137 | ||
138 | Int_t index(-1); | |
139 | ||
140 | if ( replace != kIgnore ) | |
141 | { | |
142 | AliMUONVDigit* alreadyThere = Find(*digit,index); | |
143 | ||
144 | if ( alreadyThere ) | |
145 | { | |
146 | if ( replace == kDeny ) | |
147 | { | |
148 | return 0x0; | |
149 | } | |
150 | if ( replace == kMerge ) | |
151 | { | |
152 | alreadyThere->MergeWith(*digit); | |
153 | return alreadyThere; | |
154 | } | |
155 | } | |
156 | } | |
157 | ||
158 | Int_t detElemId = digit->DetElemId(); | |
159 | Int_t iChamber = AliMpDEManager::GetChamberId(detElemId); | |
160 | TClonesArray* array = ChamberDigits(iChamber); | |
161 | if ( index < 0 ) | |
162 | { | |
163 | index = array->GetLast()+1; | |
164 | } | |
165 | return (new((*array)[index]) AliMUONDigit(*digit)); | |
166 | } | |
167 | ||
168 | //_____________________________________________________________________________ | |
169 | Bool_t | |
170 | AliMUONDigitStoreV1::Connect(TTree& tree, Bool_t alone) const | |
171 | { | |
172 | /// Connect this to the tree. | |
173 | ||
174 | AliMUONTreeManager tman; | |
175 | Bool_t ok(kTRUE); | |
176 | ||
177 | TString baseName(BaseName(tree.GetName())); | |
178 | ||
179 | // Search for branch MUON(S)Digits1 to know if we need to set branch addresses | |
180 | // or to make them. | |
181 | TBranch* branch = tree.GetBranch(Form("%ss%d",baseName.Data(),1)); | |
182 | ||
183 | Bool_t isMaking = (branch==0); | |
184 | ||
185 | if ( isMaking ) | |
186 | { | |
187 | for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i ) | |
188 | { | |
189 | TString branchName(Form("%ss%d",baseName.Data(),i+1)); | |
190 | ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray", | |
191 | branchName.Data(),ChamberDigitsPtr(i)); | |
192 | } | |
193 | } | |
194 | else | |
195 | { | |
196 | if ( alone && baseName != "MUONSDigit" ) | |
197 | { | |
198 | // TreeS only has digits, so there's not need to play the branch status | |
199 | // game | |
200 | tman.UpdateBranchStatuses(tree,baseName.Data()); | |
201 | } | |
202 | for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i ) | |
203 | { | |
204 | TString branchName(Form("%ss%d",baseName.Data(),i+1)); | |
205 | ok = ok && tman.SetAddress(tree,branchName.Data(),ChamberDigitsPtr(i)); | |
206 | } | |
207 | } | |
208 | ||
209 | return ok; | |
210 | } | |
211 | ||
212 | //_____________________________________________________________________________ | |
213 | TObject** | |
214 | AliMUONDigitStoreV1::ChamberDigitsPtr(Int_t chamberId) const | |
215 | { | |
216 | /// Get the address of the TClonesArray storing digits for chamberId. | |
217 | ||
218 | return fDigits->GetObjectRef(fDigits->UncheckedAt(chamberId)); | |
219 | ||
220 | TObject* object = fDigits->At(chamberId); | |
221 | ||
222 | if (!object) | |
223 | { | |
224 | AliError(Form("Cannot get digits for chamberId=%d",chamberId)); | |
225 | return 0x0; | |
226 | } | |
227 | else | |
228 | { | |
229 | return fDigits->GetObjectRef(object); | |
230 | } | |
231 | } | |
232 | ||
233 | //_____________________________________________________________________________ | |
234 | TClonesArray* | |
235 | AliMUONDigitStoreV1::ChamberDigits(Int_t chamberId) | |
236 | { | |
237 | /// Returns the tclonesarray storing digits for chamberId | |
238 | return static_cast<TClonesArray*>(fDigits->At(chamberId)); | |
239 | } | |
240 | ||
241 | //_____________________________________________________________________________ | |
242 | const TClonesArray* | |
243 | AliMUONDigitStoreV1::ChamberDigits(Int_t chamberId) const | |
244 | { | |
245 | /// Returns the tclonesarray storing digits for chamberId | |
246 | return static_cast<TClonesArray*>(fDigits->At(chamberId)); | |
247 | } | |
248 | ||
249 | //_____________________________________________________________________________ | |
250 | AliMUONVDigit* | |
251 | AliMUONDigitStoreV1::CreateDigit(Int_t detElemId, Int_t manuId, | |
252 | Int_t manuChannel, Int_t cathode) const | |
253 | { | |
254 | return new AliMUONDigit(detElemId,manuId,manuChannel,cathode); | |
255 | } | |
256 | ||
257 | //_____________________________________________________________________________ | |
258 | AliMUONVDigit* | |
259 | AliMUONDigitStoreV1::Remove(AliMUONVDigit& digit) | |
260 | { | |
261 | /// Remove one digit, and returns it, thus returning 0x0 if digit | |
262 | /// is not present. | |
263 | ||
264 | Int_t index; | |
265 | AliMUONVDigit* d(0x0); | |
02ab99ac | 266 | if ( ( d = FindIndex(digit.DetElemId(),digit.ManuId(), |
267 | digit.ManuChannel(),digit.Cathode(),index) ) ) | |
4d3f0fd0 | 268 | { |
269 | Int_t iChamber = AliMpDEManager::GetChamberId(digit.DetElemId()); | |
270 | TClonesArray* array = ChamberDigits(iChamber); | |
271 | array->RemoveAt(index); | |
272 | array->Compress(); | |
273 | } | |
274 | return d; | |
275 | } | |
276 | ||
4d3f0fd0 | 277 | //_____________________________________________________________________________ |
278 | AliMUONVDigit* | |
279 | AliMUONDigitStoreV1::Find(const AliMUONVDigit& digit, Int_t& index) const | |
280 | { | |
281 | /// Find a digit, and return its index. | |
02ab99ac | 282 | return FindIndex(digit.DetElemId(),digit.ManuId(),digit.ManuChannel(),digit.Cathode(),index); |
4d3f0fd0 | 283 | } |
284 | ||
285 | //_____________________________________________________________________________ | |
286 | AliMUONVDigit* | |
02ab99ac | 287 | AliMUONDigitStoreV1::FindObject(Int_t detElemId, Int_t manuId, |
288 | Int_t manuChannel, Int_t cathode) const | |
4d3f0fd0 | 289 | { |
290 | /// Find a (trigger) digit | |
291 | Int_t index; | |
02ab99ac | 292 | return FindIndex(detElemId,manuId,manuChannel,cathode,index); |
4d3f0fd0 | 293 | } |
294 | ||
295 | //_____________________________________________________________________________ | |
296 | AliMUONVDigit* | |
02ab99ac | 297 | AliMUONDigitStoreV1::FindIndex(Int_t detElemId, Int_t manuId, |
298 | Int_t manuChannel, Int_t cathode, Int_t& index) const | |
4d3f0fd0 | 299 | { |
02ab99ac | 300 | /// Find and return the index of a digit |
4d3f0fd0 | 301 | |
4d3f0fd0 | 302 | Int_t iChamber = AliMpDEManager::GetChamberId(detElemId); |
303 | const TClonesArray* array = ChamberDigits(iChamber); | |
304 | if (!array) return 0x0; | |
305 | TIter next(array); | |
306 | AliMUONVDigit* digit; | |
307 | index=0; | |
308 | while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) ) | |
309 | { | |
310 | if ( digit->DetElemId() == detElemId && | |
02ab99ac | 311 | digit->ManuId() == manuId && |
312 | digit->ManuChannel() == manuChannel && | |
4d3f0fd0 | 313 | digit->Cathode() == cathode ) |
314 | { | |
315 | return digit; | |
316 | } | |
317 | ++index; | |
318 | } | |
319 | return 0x0; | |
320 | ||
321 | } | |
322 | ||
4d3f0fd0 | 323 | //_____________________________________________________________________________ |
324 | TIterator* | |
325 | AliMUONDigitStoreV1::CreateIterator() const | |
326 | { | |
327 | /// Return an iterator on the full store | |
328 | return new AliMUONTOTCAStoreIterator(fDigits,0,13); | |
329 | } | |
330 | ||
331 | //_____________________________________________________________________________ | |
332 | TIterator* | |
333 | AliMUONDigitStoreV1::CreateTrackerIterator() const | |
334 | { | |
335 | /// Return an iterator on the tracker part of the store | |
336 | return new AliMUONTOTCAStoreIterator(fDigits,0,9); | |
337 | } | |
338 | ||
339 | //_____________________________________________________________________________ | |
340 | TIterator* | |
341 | AliMUONDigitStoreV1::CreateTriggerIterator() const | |
342 | { | |
343 | /// Return an iterator on the trigger part of the store | |
344 | return new AliMUONTOTCAStoreIterator(fDigits,10,13); | |
345 | } | |
346 | ||
347 | //_____________________________________________________________________________ | |
348 | TIterator* | |
349 | AliMUONDigitStoreV1::CreateIterator(Int_t firstDetElemId, Int_t lastDetElemId, | |
350 | Int_t cathode) const | |
351 | { | |
352 | /// Return an iterator on part of the store | |
353 | return new AliMUONDigitStoreV1Iterator(fDigits,firstDetElemId,lastDetElemId,cathode); | |
354 | } | |
355 | ||
356 | //_____________________________________________________________________________ | |
357 | Int_t | |
358 | AliMUONDigitStoreV1::GetSize() const | |
359 | { | |
360 | /// Return the number of digits we store | |
361 | Int_t n(0); | |
362 | ||
363 | for ( Int_t i = 0; i <= fDigits->GetLast(); ++i ) | |
364 | { | |
365 | n += ChamberDigits(i)->GetEntries(); | |
366 | } | |
367 | return n; | |
368 | } |