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