AliRoot Core  3abf5b4 (3abf5b4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONDigitStoreVImpl.cxx
Go to the documentation of this file.
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 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
40 
41 #include "AliMUONDigitStoreVImpl.h"
42 
43 #include "AliLog.h"
45 #include "AliMUON2DMap.h"
46 #include "AliMUONTreeManager.h"
47 #include "AliMUONCalibParamNI.h"
48 #include "AliMpConstants.h"
49 #include <TClonesArray.h>
50 #include <TTree.h>
51 #include <TString.h>
52 #include <Riostream.h>
53 
57 
58 namespace
59 {
60  TString BaseName(const TString& name)
61  {
63  if ( name == "TreeS" ) return "MUONSDigit";
64  if ( name == "TreeD" ) return "MUONDigit";
65  return "";
66  }
67 
68  Int_t InternalManuId(Int_t cathode, Int_t manuId)
69  {
76  return manuId | ( cathode << 15 );
77  }
78 
79 }
80 
81 //_____________________________________________________________________________
82 AliMUONDigitStoreVImpl::AliMUONDigitStoreVImpl(const char* concreteClassName)
84  fDigits(new TClonesArray(concreteClassName,100)),
85  fMap(0x0),
86  fIndexed(kFALSE)
87 {
89 }
90 
91 //_____________________________________________________________________________
94 fDigits(0x0),
95 fMap(0x0),
96 fIndexed(kFALSE)
97 {
99  AliError("Please implement me");
100 }
101 
102 //_____________________________________________________________________________
105 {
107  AliError("Please implement me");
108  return *this;
109 }
110 
111 
112 //_____________________________________________________________________________
114 {
116  delete fDigits;
117  delete fMap;
118 }
119 
120 //_____________________________________________________________________________
121 Bool_t
122 AliMUONDigitStoreVImpl::Connect(TTree& tree, Bool_t alone) const
123 {
125 
126  TString branchName(BaseName(tree.GetName()));
127  branchName += ".";
128  AliMUONTreeManager tman;
129  Bool_t ok;
130 
131  if (tree.GetBranch(branchName.Data()))
132  {
133  if ( alone ) tman.UpdateBranchStatuses(tree,BaseName(tree.GetName()));
134  ok = tman.SetAddress(tree,branchName.Data(),
135  const_cast<TClonesArray**>(&fDigits));
136  }
137  else
138  {
139  ok = tman.MakeBranch(tree,ClassName(),"TClonesArray",branchName.Data(),
140  const_cast<TClonesArray**>(&fDigits));
141  }
142 
143  return ok;
144 }
145 
146 //_____________________________________________________________________________
147 void
149 {
151  fDigits->Clear("C");
152  ClearIndex();
153 }
154 
155 //_____________________________________________________________________________
156 void
158 {
160  if ( fMap )
161  {
162  fMap->Clear();
163  }
164  else
165  {
166  fMap = new AliMUON2DMap(true);
167  }
168  fIndexed = kFALSE;
169 }
170 
171 //_____________________________________________________________________________
174 {
183 
184  if ( replace != kIgnore )
185  {
186  AliMUONVDigit* alreadyThere = Find(vdigit);
187  if ( alreadyThere )
188  {
189  if ( replace == kDeny ) return 0x0;
190  if ( replace == kMerge )
191  {
192  alreadyThere->MergeWith(vdigit);
193  return alreadyThere;
194  }
195  }
196  }
197 
198 
199  Int_t n = fDigits->GetLast()+1;
200 
201  AliMUONVDigit* d = AddConcreteDigit(*fDigits,vdigit,n);
202 
203  if ( d )
204  {
205  UpdateIndex(*d,n);
206  }
207 
208  return d;
209 }
210 
211 //_____________________________________________________________________________
212 TIterator*
214 {
216  return fDigits->MakeIterator();
217 }
218 
219 //_____________________________________________________________________________
220 TIterator*
222  Int_t lastDetElemId,
223  Int_t cathode) const
224 {
226  (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
227 
228  return new AliMUONDigitStoreVImplIterator(this,firstDetElemId,lastDetElemId,cathode);
229 }
230 
231 //_____________________________________________________________________________
232 TIterator*
234 {
236 
237  (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
238 
239  return new AliMUONDigitStoreVImplIterator(this,100,1025);
240 }
241 
242 //_____________________________________________________________________________
243 TIterator*
245 {
247  (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
248 
249  return new AliMUONDigitStoreVImplIterator(this,1100,1417);
250 }
251 
252 //_____________________________________________________________________________
255 {
260 
261  return FindObject(digit.DetElemId(),digit.ManuId(),digit.ManuChannel(),
262  digit.Cathode());
263 }
264 
265 //_____________________________________________________________________________
266 void
268 {
271 
272  if ( fIndexed ) return;
273 
274  ClearIndex();
275 
276  TIter next(fDigits);
277  AliMUONVDigit* d;
278  Int_t digitIndex(0);
279 
280  while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
281  {
282  UpdateIndex(*d,digitIndex++);
283  }
284 
285  fIndexed = kTRUE;
286 }
287 
288 //_____________________________________________________________________________
289 void
291 {
293  if (!fMap) fMap = new AliMUON2DMap(true);
294 
295  Int_t manuId = InternalManuId(digit.Cathode(),digit.ManuId());
296 
297  AliMUONVCalibParam* param =
298  static_cast<AliMUONVCalibParam*>
299  (fMap->FindObject(digit.DetElemId(),manuId));
300 
301  if (!param)
302  {
303  param = new AliMUONCalibParamNI(1,64,digit.DetElemId(),manuId,-1);
304  fMap->Add(param);
305  }
306  param->SetValueAsInt(digit.ManuChannel(),0,index);
307  fIndexed = kTRUE;
308 }
309 
310 //_____________________________________________________________________________
311 Int_t
312 AliMUONDigitStoreVImpl::FindIndex(Int_t detElemId, Int_t internalManuId,
313  Int_t manuChannel) const
314 {
316 
317  AliMUONVCalibParam* param =
318  static_cast<AliMUONVCalibParam*>
319  (fMap->FindObject(detElemId,internalManuId));
320 
321  if (param)
322  {
323  return param->ValueAsInt(manuChannel);
324  }
325 
326  return -1;
327 }
328 
329 //_____________________________________________________________________________
330 Int_t
332 {
334  return FindIndex(digit.DetElemId(),
335  InternalManuId(digit.Cathode(),digit.ManuId()),
336  digit.ManuChannel());
337 }
338 
339 //_____________________________________________________________________________
342 {
344 
345  return FindObject(AliMUONVDigit::DetElemId(uniqueID),
346  AliMUONVDigit::ManuId(uniqueID),
347  AliMUONVDigit::ManuChannel(uniqueID),
348  AliMUONVDigit::Cathode(uniqueID));
349 }
350 
351 //_____________________________________________________________________________
353 AliMUONDigitStoreVImpl::FindObject(Int_t detElemId, Int_t manuId, Int_t manuChannel,
354  Int_t cathode) const
355 {
357 
358  (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
359 
360  Int_t index = FindIndex(detElemId,InternalManuId(cathode,manuId),manuChannel);
361 
362  if (index>=0 )
363  {
364  return static_cast<AliMUONVDigit*>(fDigits->UncheckedAt(index));
365  }
366 
367  return 0x0;
368 }
369 
370 //_____________________________________________________________________________
371 Int_t
373 {
375  return fDigits->GetLast()+1;
376 }
377 
378 //_____________________________________________________________________________
381 {
383  AliMUONVDigit* d = static_cast<AliMUONVDigit*>(fDigits->Remove(&digit));
384  if (d)
385  {
386  UpdateIndex(*d,-1);
387  }
388  return d;
389 }
390 
Bool_t fIndexed
! whether our internal indices fDEs and fManus are uptodate
virtual Int_t ManuChannel() const =0
The channel within ManuId() this digit belongs to (manuChannel for tracker, localBoardChannel for tri...
Bool_t SetAddress(TTree &tree, const char *branchName, void *address) const
virtual Int_t GetSize() const
Number of digits we store.
Interface for a digit container.
virtual TIterator * CreateTriggerIterator() const
Create an iterator to loop over trigger digits only.
virtual void Clear(Option_t *opt="")
Clear ourselves (i.e. Reset)
AliMUONDigitStoreVImpl & operator=(const AliMUONDigitStoreVImpl &rhs)
Base implementation of VDigitStore.
virtual AliMUONVDigit * AddConcreteDigit(TClonesArray &a, const AliMUONVDigit &digit, Int_t index)=0
Add concrete digit.
TTree * tree
virtual Int_t DetElemId() const =0
The detection element this digit belongs to.
Helper class to ease TTree (MUON) branches manipulations.
AliMUON2DMap * fMap
! index map for fast digit retrieval
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
virtual Bool_t Connect(TTree &tree, Bool_t alone=kTRUE) const
Connect us to a TTree (only valid if CanConnect()==kTRUE)
virtual AliMUONVDigit * Add(const AliMUONVDigit &digit, EReplacePolicy replace)
Container of calibration values for a given number of channels.
AliMUONVDigit * Find(const AliMUONVDigit &digit) const
virtual TObject * FindObject(Int_t i, Int_t j) const
Find an object using 2 ids.
Implementation of AliMUONVCalibParam for tuples of ints.
void UpdateIndex(const AliMUONVDigit &digit, Int_t index)
TClonesArray * fDigits
collection of digits
virtual Int_t Cathode() const =0
Cathode number this digit is on (0 or 1)
virtual TIterator * CreateTrackerIterator() const
Create an iterator to loop over tracker digits only.
virtual TIterator * CreateIterator() const
Create an iterator to loop over all our digits.
Int_t FindIndex(const AliMUONVDigit &digit) const
virtual Int_t ValueAsInt(Int_t i, Int_t j=0) const =0
Basic implementation of AliMUONVStore container using AliMpExMap internally.
Definition: AliMUON2DMap.h:20
virtual Bool_t Add(TObject *object)
Add an object to the store.
void UpdateBranchStatuses(TTree &tree, const char *pattern) const
friend class AliMUONDigitStoreVImplIterator
virtual AliMUONVDigit * Remove(AliMUONVDigit &digit)
Remove an element.
virtual AliMUONVDigit * FindObject(UInt_t uniqueID) const
Find an object by its uniqueID.
virtual Int_t ManuId() const =0
The electronic card id this digit belongs to (manuId for tracker, localboardId for trigger) ...
ABC of a MUON digit.
Definition: AliMUONVDigit.h:18
AliMUONDigitStoreVImpl(const char *concreteClassName)
Bool_t MakeBranch(TTree &tree, const char *storeClassName, const char *branchClassName, const char *branchName, void *address, Int_t bufferSize=4000, Int_t splitLevel=99) const
EReplacePolicy
Replacement policy : what to do when adding a digit to the store.
virtual void Clear(Option_t *opt="")
Mandatory methods from TCollection.
virtual Bool_t MergeWith(const AliMUONVDigit &other)=0
Merge this with other.