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 #include "AliMUONDigitStoreV1.h"
20 /// \class AliMUONDigitStoreV1
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
27 // \author Laurent Aphecetche, Subatech
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>
45 ClassImp(AliMUONDigitStoreV1)
50 TString BaseName(const TString& name)
52 if ( name == "TreeS" ) return "MUONSDigit";
53 if ( name == "TreeD" ) return "MUONDigit";
58 //_____________________________________________________________________________
59 AliMUONDigitStoreV1::AliMUONDigitStoreV1()
60 : AliMUONVDigitStore(),
61 fDigits(new TObjArray(AliMpConstants::NofChambers())),
65 fDigits->SetOwner(kTRUE);
66 for ( Int_t i = 0; i < fDigits->GetSize(); ++i )
68 TClonesArray* tca = new TClonesArray("AliMUONDigit",100);
70 fDigits->AddAt(tca,i);
76 //_____________________________________________________________________________
77 AliMUONDigitStoreV1::AliMUONDigitStoreV1(const AliMUONDigitStoreV1&)
78 : AliMUONVDigitStore(),
83 AliError("Please implement me");
86 //_____________________________________________________________________________
88 AliMUONDigitStoreV1::operator=(const AliMUONDigitStoreV1&)
90 /// assignement operator
91 AliError("Please implement me");
95 //_____________________________________________________________________________
96 AliMUONDigitStoreV1::~AliMUONDigitStoreV1()
103 //_____________________________________________________________________________
105 AliMUONDigitStoreV1::Clear(Option_t* /*opt*/)
107 /// Clear the tclonesarray, but keep the tobjarray's size constant.
109 for ( Int_t i = 0; i <= fDigits->GetLast(); ++i )
111 ChamberDigits(i)->Clear("C");
115 //_____________________________________________________________________________
117 AliMUONDigitStoreV1::Add(const AliMUONVDigit& vdigit, EReplacePolicy replace)
119 /// Try to add a digit to the store. Return whether the try was successfull
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)
128 const AliMUONDigit* digit = dynamic_cast<const AliMUONDigit*>(&vdigit);
132 AliError(Form("Digit is not of the expected type (%s vs AliMUONdigit)",
133 vdigit.ClassName()));
139 if ( replace != kIgnore )
141 AliMUONVDigit* alreadyThere = Find(*digit,index);
145 if ( replace == kDeny )
149 if ( replace == kMerge )
151 alreadyThere->MergeWith(*digit);
157 Int_t detElemId = digit->DetElemId();
158 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
159 TClonesArray* array = ChamberDigits(iChamber);
162 index = array->GetLast()+1;
164 return (new((*array)[index]) AliMUONDigit(*digit));
167 //_____________________________________________________________________________
169 AliMUONDigitStoreV1::Connect(TTree& tree, Bool_t alone) const
171 /// Connect this to the tree.
173 AliMUONTreeManager tman;
176 TString baseName(BaseName(tree.GetName()));
178 // Search for branch MUON(S)Digits1 to know if we need to set branch addresses
180 TBranch* branch = tree.GetBranch(Form("%ss%d",baseName.Data(),1));
182 Bool_t isMaking = (branch==0);
186 for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
188 TString branchName(Form("%ss%d",baseName.Data(),i+1));
189 ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
190 branchName.Data(),ChamberDigitsPtr(i));
195 if ( alone && baseName != "MUONSDigit" )
197 // TreeS only has digits, so there's not need to play the branch status
199 tman.UpdateBranchStatuses(tree,baseName.Data());
201 for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
203 TString branchName(Form("%ss%d",baseName.Data(),i+1));
204 ok = ok && tman.SetAddress(tree,branchName.Data(),ChamberDigitsPtr(i));
211 //_____________________________________________________________________________
213 AliMUONDigitStoreV1::ChamberDigitsPtr(Int_t chamberId) const
215 /// Get the address of the TClonesArray storing digits for chamberId.
217 return fDigits->GetObjectRef(fDigits->UncheckedAt(chamberId));
219 TObject* object = fDigits->At(chamberId);
223 AliError(Form("Cannot get digits for chamberId=%d",chamberId));
228 return fDigits->GetObjectRef(object);
232 //_____________________________________________________________________________
234 AliMUONDigitStoreV1::ChamberDigits(Int_t chamberId)
236 /// Returns the tclonesarray storing digits for chamberId
237 return static_cast<TClonesArray*>(fDigits->At(chamberId));
240 //_____________________________________________________________________________
242 AliMUONDigitStoreV1::ChamberDigits(Int_t chamberId) const
244 /// Returns the tclonesarray storing digits for chamberId
245 return static_cast<TClonesArray*>(fDigits->At(chamberId));
248 //_____________________________________________________________________________
250 AliMUONDigitStoreV1::CreateDigit(Int_t detElemId, Int_t manuId,
251 Int_t manuChannel, Int_t cathode) const
253 return new AliMUONDigit(detElemId,manuId,manuChannel,cathode);
256 //_____________________________________________________________________________
258 AliMUONDigitStoreV1::Remove(AliMUONVDigit& digit)
260 /// Remove one digit, and returns it, thus returning 0x0 if digit
264 AliMUONVDigit* d(0x0);
265 if ( ( d = FindIndex(digit.DetElemId(),digit.ManuId(),
266 digit.ManuChannel(),digit.Cathode(),index) ) )
268 Int_t iChamber = AliMpDEManager::GetChamberId(digit.DetElemId());
269 TClonesArray* array = ChamberDigits(iChamber);
270 array->RemoveAt(index);
276 //_____________________________________________________________________________
278 AliMUONDigitStoreV1::Find(const AliMUONVDigit& digit, Int_t& index) const
280 /// Find a digit, and return its index.
281 return FindIndex(digit.DetElemId(),digit.ManuId(),digit.ManuChannel(),digit.Cathode(),index);
284 //_____________________________________________________________________________
286 AliMUONDigitStoreV1::FindObject(Int_t detElemId, Int_t manuId,
287 Int_t manuChannel, Int_t cathode) const
289 /// Find a (trigger) digit
291 return FindIndex(detElemId,manuId,manuChannel,cathode,index);
294 //_____________________________________________________________________________
296 AliMUONDigitStoreV1::FindIndex(Int_t detElemId, Int_t manuId,
297 Int_t manuChannel, Int_t cathode, Int_t& index) const
299 /// Find and return the index of a digit
301 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
302 const TClonesArray* array = ChamberDigits(iChamber);
303 if (!array) return 0x0;
305 AliMUONVDigit* digit;
307 while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
309 if ( digit->DetElemId() == detElemId &&
310 digit->ManuId() == manuId &&
311 digit->ManuChannel() == manuChannel &&
312 digit->Cathode() == cathode )
322 //_____________________________________________________________________________
324 AliMUONDigitStoreV1::CreateIterator() const
326 /// Return an iterator on the full store
327 return new AliMUONTOTCAStoreIterator(fDigits,0,13);
330 //_____________________________________________________________________________
332 AliMUONDigitStoreV1::CreateTrackerIterator() const
334 /// Return an iterator on the tracker part of the store
335 return new AliMUONTOTCAStoreIterator(fDigits,0,9);
338 //_____________________________________________________________________________
340 AliMUONDigitStoreV1::CreateTriggerIterator() const
342 /// Return an iterator on the trigger part of the store
343 return new AliMUONTOTCAStoreIterator(fDigits,10,13);
346 //_____________________________________________________________________________
348 AliMUONDigitStoreV1::CreateIterator(Int_t firstDetElemId, Int_t lastDetElemId,
351 /// Return an iterator on part of the store
352 return new AliMUONDigitStoreV1Iterator(fDigits,firstDetElemId,lastDetElemId,cathode);
355 //_____________________________________________________________________________
357 AliMUONDigitStoreV1::GetSize() const
359 /// Return the number of digits we store
362 for ( Int_t i = 0; i <= fDigits->GetLast(); ++i )
364 n += ChamberDigits(i)->GetEntries();