1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// \class AliMUONDigitStoreVImpl
20 /// Base implementation of VDigitStore, where digits are simply put
21 /// within a single TClonesArray (to get compact output on disk) and
22 /// fast search is achieved by using a separate index (a 2Dmap)
24 /// Note that this class is a base implementation only, because to add
25 /// a digit to a TClonesArray, you need to give the concrete class
26 /// name (made in subclass by overriding :
28 /// AliMUONVDigit* AddConcreteDigit(TClonesArray&,const AliMUONVDigit&, Int_t)
32 /// AliMUONVDigit* CreateDigit((Int_t detElemId, Int_t manuId,
33 /// Int_t manuChannel, Int_t cathode) const
37 /// \author Laurent Aphecetche
39 #include "AliMUONDigitStoreVImpl.h"
42 #include "AliMUONDigitStoreVImplIterator.h"
43 #include "AliMUON2DMap.h"
44 #include "AliMUONTreeManager.h"
45 #include "AliMUONCalibParamNI.h"
46 #include "AliMpConstants.h"
47 #include <TClonesArray.h>
50 #include <Riostream.h>
53 ClassImp(AliMUONDigitStoreVImpl)
58 TString BaseName(const TString& name)
60 /// Name of the branch, depending on the tree name
61 if ( name == "TreeS" ) return "MUONSDigit";
62 if ( name == "TreeD" ) return "MUONDigit";
66 Int_t InternalManuId(Int_t cathode, Int_t manuId)
68 /// Very local convention to insure that trigger digits are not
69 /// mixed (as by default a same manuId can be in cath 0 or 1, which
70 /// is never the case for tracker)
72 /// WARNING : the resulting manuId must still be contained within 16 bits !
74 return manuId | ( cathode << 15 );
79 //_____________________________________________________________________________
80 AliMUONDigitStoreVImpl::AliMUONDigitStoreVImpl(const char* concreteClassName)
81 : AliMUONVDigitStore(),
82 fDigits(new TClonesArray(concreteClassName,100)),
89 //_____________________________________________________________________________
90 AliMUONDigitStoreVImpl::AliMUONDigitStoreVImpl(const AliMUONDigitStoreVImpl&)
91 : AliMUONVDigitStore(),
97 AliError("Please implement me");
100 //_____________________________________________________________________________
101 AliMUONDigitStoreVImpl&
102 AliMUONDigitStoreVImpl::operator=(const AliMUONDigitStoreVImpl&)
104 /// assignement operator
105 AliError("Please implement me");
110 //_____________________________________________________________________________
111 AliMUONDigitStoreVImpl::~AliMUONDigitStoreVImpl()
118 //_____________________________________________________________________________
120 AliMUONDigitStoreVImpl::Connect(TTree& tree, Bool_t alone) const
122 /// Connect this to the tree.
124 TString branchName(BaseName(tree.GetName()));
126 AliMUONTreeManager tman;
129 if (tree.GetBranch(branchName.Data()))
131 if ( alone ) tman.UpdateBranchStatuses(tree,BaseName(tree.GetName()));
132 ok = tman.SetAddress(tree,branchName.Data(),
133 const_cast<TClonesArray**>(&fDigits));
137 ok = tman.MakeBranch(tree,ClassName(),"TClonesArray",branchName.Data(),
138 const_cast<TClonesArray**>(&fDigits));
144 //_____________________________________________________________________________
146 AliMUONDigitStoreVImpl::Clear(Option_t*)
148 /// Clear the internal digit array AND the index
153 //_____________________________________________________________________________
155 AliMUONDigitStoreVImpl::ClearIndex()
157 /// Clear our internal index
164 fMap = new AliMUON2DMap(true);
169 //_____________________________________________________________________________
171 AliMUONDigitStoreVImpl::Add(const AliMUONVDigit& vdigit, EReplacePolicy replace)
173 /// Try to add a digit to the store. Return whether the try was successfull
176 /// If the digit is already there, the action taken depends on "replace"
177 /// kAllow -> replacement will occur (i.e. return kTRUE)
178 /// kDeny -> replacement will *not* occur (and returned value is kFALSE)
179 /// kMerge -> both digits will be merged into one (return kTRUE)
182 if ( replace != kIgnore )
184 AliMUONVDigit* alreadyThere = Find(vdigit);
187 if ( replace == kDeny ) return 0x0;
188 if ( replace == kMerge )
190 alreadyThere->MergeWith(vdigit);
197 Int_t n = fDigits->GetLast()+1;
199 AliMUONVDigit* d = AddConcreteDigit(*fDigits,vdigit,n);
209 //_____________________________________________________________________________
211 AliMUONDigitStoreVImpl::CreateIterator() const
213 /// Create an iterator over the full store
214 return fDigits->MakeIterator();
217 //_____________________________________________________________________________
219 AliMUONDigitStoreVImpl::CreateIterator(Int_t firstDetElemId,
223 /// Create an iterator on a given part of the store
224 (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
226 return new AliMUONDigitStoreVImplIterator(this,firstDetElemId,lastDetElemId,cathode);
229 //_____________________________________________________________________________
231 AliMUONDigitStoreVImpl::CreateTrackerIterator() const
233 /// Create an iterator to loop over tracker digits only
235 (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
237 return new AliMUONDigitStoreVImplIterator(this,100,1025);
240 //_____________________________________________________________________________
242 AliMUONDigitStoreVImpl::CreateTriggerIterator() const
244 /// Create an iterator to loop over trigger digits only
245 (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
247 return new AliMUONDigitStoreVImplIterator(this,1100,1417);
250 //_____________________________________________________________________________
252 AliMUONDigitStoreVImpl::Find(const AliMUONVDigit& digit) const
254 /// Find a given digit
255 /// Note that we only check for the id of the digit (i.e. de,manu,...)
256 /// not for the actual content (charge, ...) to decide whether
257 /// it's the same digit or not
259 return FindObject(digit.DetElemId(),digit.ManuId(),digit.ManuChannel(),
263 //_____________________________________________________________________________
265 AliMUONDigitStoreVImpl::ReIndex()
267 /// Recompute the fMap, which map (de,manu,ch) to an index within
268 /// the fDigits array
270 if ( fIndexed ) return;
278 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
280 UpdateIndex(*d,digitIndex++);
286 //_____________________________________________________________________________
288 AliMUONDigitStoreVImpl::UpdateIndex(const AliMUONVDigit& digit, Int_t index)
290 /// Update the internal index given this new digit
291 if (!fMap) fMap = new AliMUON2DMap(true);
293 Int_t manuId = InternalManuId(digit.Cathode(),digit.ManuId());
295 AliMUONVCalibParam* param =
296 static_cast<AliMUONVCalibParam*>
297 (fMap->FindObject(digit.DetElemId(),manuId));
301 param = new AliMUONCalibParamNI(1,64,digit.DetElemId(),manuId,-1);
304 param->SetValueAsInt(digit.ManuChannel(),0,index);
308 //_____________________________________________________________________________
310 AliMUONDigitStoreVImpl::FindIndex(Int_t detElemId, Int_t internalManuId,
311 Int_t manuChannel) const
313 /// Find the index of a given (de,internalManu,ch) triplet
315 AliMUONVCalibParam* param =
316 static_cast<AliMUONVCalibParam*>
317 (fMap->FindObject(detElemId,internalManuId));
321 return param->ValueAsInt(manuChannel);
327 //_____________________________________________________________________________
329 AliMUONDigitStoreVImpl::FindIndex(const AliMUONVDigit& digit) const
331 /// Find the index of a given digit
332 return FindIndex(digit.DetElemId(),
333 InternalManuId(digit.Cathode(),digit.ManuId()),
334 digit.ManuChannel());
337 //_____________________________________________________________________________
339 AliMUONDigitStoreVImpl::FindObject(UInt_t uniqueID) const
341 /// Find digit by its uniqueID
343 return FindObject(AliMUONVDigit::DetElemId(uniqueID),
344 AliMUONVDigit::ManuId(uniqueID),
345 AliMUONVDigit::ManuChannel(uniqueID),
346 AliMUONVDigit::Cathode(uniqueID));
349 //_____________________________________________________________________________
351 AliMUONDigitStoreVImpl::FindObject(Int_t detElemId, Int_t manuId, Int_t manuChannel,
356 (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
358 Int_t index = FindIndex(detElemId,InternalManuId(cathode,manuId),manuChannel);
362 return static_cast<AliMUONVDigit*>(fDigits->UncheckedAt(index));
368 //_____________________________________________________________________________
370 AliMUONDigitStoreVImpl::GetSize() const
372 /// Return the number of digits we hold
373 return fDigits->GetLast()+1;
376 //_____________________________________________________________________________
378 AliMUONDigitStoreVImpl::Remove(AliMUONVDigit& digit)
381 AliMUONVDigit* d = static_cast<AliMUONVDigit*>(fDigits->Remove(&digit));