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 //-----------------------------------------------------------------------------
19 /// \class AliMUONDigitStoreVImpl
21 /// Base implementation of VDigitStore, where digits are simply put
22 /// within a single TClonesArray (to get compact output on disk) and
23 /// fast search is achieved by using a separate index (a 2Dmap)
25 /// Note that this class is a base implementation only, because to add
26 /// a digit to a TClonesArray, you need to give the concrete class
27 /// name (made in subclass by overriding :
29 /// AliMUONVDigit* AddConcreteDigit(TClonesArray&,const AliMUONVDigit&, Int_t)
33 /// AliMUONVDigit* CreateDigit((Int_t detElemId, Int_t manuId,
34 /// Int_t manuChannel, Int_t cathode) const
38 /// \author Laurent Aphecetche
39 //-----------------------------------------------------------------------------
41 #include "AliMUONDigitStoreVImpl.h"
44 #include "AliMUONDigitStoreVImplIterator.h"
45 #include "AliMUON2DMap.h"
46 #include "AliMUONTreeManager.h"
47 #include "AliMUONCalibParamNI.h"
48 #include "AliMpConstants.h"
49 #include <TClonesArray.h>
52 #include <Riostream.h>
55 ClassImp(AliMUONDigitStoreVImpl)
60 TString BaseName(const TString& name)
62 /// Name of the branch, depending on the tree name
63 if ( name == "TreeS" ) return "MUONSDigit";
64 if ( name == "TreeD" ) return "MUONDigit";
68 Int_t InternalManuId(Int_t cathode, Int_t manuId)
70 /// Very local convention to insure that trigger digits are not
71 /// mixed (as by default a same manuId can be in cath 0 or 1, which
72 /// is never the case for tracker)
74 /// WARNING : the resulting manuId must still be contained within 16 bits !
76 return manuId | ( cathode << 15 );
81 //_____________________________________________________________________________
82 AliMUONDigitStoreVImpl::AliMUONDigitStoreVImpl(const char* concreteClassName)
83 : AliMUONVDigitStore(),
84 fDigits(new TClonesArray(concreteClassName,100)),
91 //_____________________________________________________________________________
92 AliMUONDigitStoreVImpl::AliMUONDigitStoreVImpl(const AliMUONDigitStoreVImpl&)
93 : AliMUONVDigitStore(),
99 AliError("Please implement me");
102 //_____________________________________________________________________________
103 AliMUONDigitStoreVImpl&
104 AliMUONDigitStoreVImpl::operator=(const AliMUONDigitStoreVImpl&)
106 /// assignement operator
107 AliError("Please implement me");
112 //_____________________________________________________________________________
113 AliMUONDigitStoreVImpl::~AliMUONDigitStoreVImpl()
120 //_____________________________________________________________________________
122 AliMUONDigitStoreVImpl::Connect(TTree& tree, Bool_t alone) const
124 /// Connect this to the tree.
126 TString branchName(BaseName(tree.GetName()));
128 AliMUONTreeManager tman;
131 if (tree.GetBranch(branchName.Data()))
133 if ( alone ) tman.UpdateBranchStatuses(tree,BaseName(tree.GetName()));
134 ok = tman.SetAddress(tree,branchName.Data(),
135 const_cast<TClonesArray**>(&fDigits));
139 ok = tman.MakeBranch(tree,ClassName(),"TClonesArray",branchName.Data(),
140 const_cast<TClonesArray**>(&fDigits));
146 //_____________________________________________________________________________
148 AliMUONDigitStoreVImpl::Clear(Option_t*)
150 /// Clear the internal digit array AND the index
155 //_____________________________________________________________________________
157 AliMUONDigitStoreVImpl::ClearIndex()
159 /// Clear our internal index
166 fMap = new AliMUON2DMap(true);
171 //_____________________________________________________________________________
173 AliMUONDigitStoreVImpl::Add(const AliMUONVDigit& vdigit, EReplacePolicy replace)
175 /// Try to add a digit to the store. Return whether the try was successfull
178 /// If the digit is already there, the action taken depends on "replace"
179 /// kAllow -> replacement will occur (i.e. return kTRUE)
180 /// kDeny -> replacement will *not* occur (and returned value is kFALSE)
181 /// kMerge -> both digits will be merged into one (return kTRUE)
184 if ( replace != kIgnore )
186 AliMUONVDigit* alreadyThere = Find(vdigit);
189 if ( replace == kDeny ) return 0x0;
190 if ( replace == kMerge )
192 alreadyThere->MergeWith(vdigit);
199 Int_t n = fDigits->GetLast()+1;
201 AliMUONVDigit* d = AddConcreteDigit(*fDigits,vdigit,n);
211 //_____________________________________________________________________________
213 AliMUONDigitStoreVImpl::CreateIterator() const
215 /// Create an iterator over the full store
216 return fDigits->MakeIterator();
219 //_____________________________________________________________________________
221 AliMUONDigitStoreVImpl::CreateIterator(Int_t firstDetElemId,
225 /// Create an iterator on a given part of the store
226 (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
228 return new AliMUONDigitStoreVImplIterator(this,firstDetElemId,lastDetElemId,cathode);
231 //_____________________________________________________________________________
233 AliMUONDigitStoreVImpl::CreateTrackerIterator() const
235 /// Create an iterator to loop over tracker digits only
237 (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
239 return new AliMUONDigitStoreVImplIterator(this,100,1025);
242 //_____________________________________________________________________________
244 AliMUONDigitStoreVImpl::CreateTriggerIterator() const
246 /// Create an iterator to loop over trigger digits only
247 (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
249 return new AliMUONDigitStoreVImplIterator(this,1100,1417);
252 //_____________________________________________________________________________
254 AliMUONDigitStoreVImpl::Find(const AliMUONVDigit& digit) const
256 /// Find a given digit
257 /// Note that we only check for the id of the digit (i.e. de,manu,...)
258 /// not for the actual content (charge, ...) to decide whether
259 /// it's the same digit or not
261 return FindObject(digit.DetElemId(),digit.ManuId(),digit.ManuChannel(),
265 //_____________________________________________________________________________
267 AliMUONDigitStoreVImpl::ReIndex()
269 /// Recompute the fMap, which map (de,manu,ch) to an index within
270 /// the fDigits array
272 if ( fIndexed ) return;
280 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
282 UpdateIndex(*d,digitIndex++);
288 //_____________________________________________________________________________
290 AliMUONDigitStoreVImpl::UpdateIndex(const AliMUONVDigit& digit, Int_t index)
292 /// Update the internal index given this new digit
293 if (!fMap) fMap = new AliMUON2DMap(true);
295 Int_t manuId = InternalManuId(digit.Cathode(),digit.ManuId());
297 AliMUONVCalibParam* param =
298 static_cast<AliMUONVCalibParam*>
299 (fMap->FindObject(digit.DetElemId(),manuId));
303 param = new AliMUONCalibParamNI(1,64,digit.DetElemId(),manuId,-1);
306 param->SetValueAsInt(digit.ManuChannel(),0,index);
310 //_____________________________________________________________________________
312 AliMUONDigitStoreVImpl::FindIndex(Int_t detElemId, Int_t internalManuId,
313 Int_t manuChannel) const
315 /// Find the index of a given (de,internalManu,ch) triplet
317 AliMUONVCalibParam* param =
318 static_cast<AliMUONVCalibParam*>
319 (fMap->FindObject(detElemId,internalManuId));
323 return param->ValueAsInt(manuChannel);
329 //_____________________________________________________________________________
331 AliMUONDigitStoreVImpl::FindIndex(const AliMUONVDigit& digit) const
333 /// Find the index of a given digit
334 return FindIndex(digit.DetElemId(),
335 InternalManuId(digit.Cathode(),digit.ManuId()),
336 digit.ManuChannel());
339 //_____________________________________________________________________________
341 AliMUONDigitStoreVImpl::FindObject(UInt_t uniqueID) const
343 /// Find digit by its uniqueID
345 return FindObject(AliMUONVDigit::DetElemId(uniqueID),
346 AliMUONVDigit::ManuId(uniqueID),
347 AliMUONVDigit::ManuChannel(uniqueID),
348 AliMUONVDigit::Cathode(uniqueID));
351 //_____________________________________________________________________________
353 AliMUONDigitStoreVImpl::FindObject(Int_t detElemId, Int_t manuId, Int_t manuChannel,
358 (const_cast<AliMUONDigitStoreVImpl*>(this))->ReIndex();
360 Int_t index = FindIndex(detElemId,InternalManuId(cathode,manuId),manuChannel);
364 return static_cast<AliMUONVDigit*>(fDigits->UncheckedAt(index));
370 //_____________________________________________________________________________
372 AliMUONDigitStoreVImpl::GetSize() const
374 /// Return the number of digits we hold
375 return fDigits->GetLast()+1;
378 //_____________________________________________________________________________
380 AliMUONDigitStoreVImpl::Remove(AliMUONVDigit& digit)
383 AliMUONVDigit* d = static_cast<AliMUONVDigit*>(fDigits->Remove(&digit));