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 //-----------------------------------------------------------------------------
21 /// \class AliMUONDigitStoreV1
23 /// (Legacy) Implementation of AliMUONVDigitStore.
24 /// Called legacy as the internal structure corresponds to what we
25 /// used to write as MUON.(S)Digits.root files, before the switch
28 // \author Laurent Aphecetche, Subatech
29 //-----------------------------------------------------------------------------
32 #include "AliMUONDigit.h"
33 #include "AliMUONDigitStoreV1Iterator.h"
34 #include "AliMUONTOTCAStoreIterator.h"
35 #include "AliMUONTreeManager.h"
36 #include "AliMpConstants.h"
37 #include "AliMpDEManager.h"
38 #include "AliMpDEManager.h"
39 #include "AliMpStationType.h"
40 #include <Riostream.h>
41 #include <TClonesArray.h>
42 #include <TObjArray.h>
46 ClassImp(AliMUONDigitStoreV1)
51 TString BaseName(const TString& name)
53 if ( name == "TreeS" ) return "MUONSDigit";
54 if ( name == "TreeD" ) return "MUONDigit";
59 //_____________________________________________________________________________
60 AliMUONDigitStoreV1::AliMUONDigitStoreV1(TRootIOCtor* /*dummy*/)
61 : AliMUONVDigitStore(),
68 //_____________________________________________________________________________
69 AliMUONDigitStoreV1::AliMUONDigitStoreV1()
70 : AliMUONVDigitStore(),
71 fDigits(new TObjArray(AliMpConstants::NofChambers())),
75 fDigits->SetOwner(kTRUE);
76 for ( Int_t i = 0; i < fDigits->GetSize(); ++i )
78 TClonesArray* tca = new TClonesArray("AliMUONDigit",100);
80 fDigits->AddAt(tca,i);
86 //_____________________________________________________________________________
87 AliMUONDigitStoreV1::AliMUONDigitStoreV1(const AliMUONDigitStoreV1&)
88 : AliMUONVDigitStore(),
93 AliError("Please implement me");
96 //_____________________________________________________________________________
98 AliMUONDigitStoreV1::operator=(const AliMUONDigitStoreV1&)
100 /// assignement operator
101 AliError("Please implement me");
105 //_____________________________________________________________________________
106 AliMUONDigitStoreV1::~AliMUONDigitStoreV1()
113 //_____________________________________________________________________________
115 AliMUONDigitStoreV1::Clear(Option_t* /*opt*/)
117 /// Clear the tclonesarray, but keep the tobjarray's size constant.
119 for ( Int_t i = 0; i <= fDigits->GetLast(); ++i )
121 ChamberDigits(i)->Clear("C");
125 //_____________________________________________________________________________
127 AliMUONDigitStoreV1::Add(const AliMUONVDigit& vdigit, EReplacePolicy replace)
129 /// Try to add a digit to the store. Return whether the try was successfull
132 /// If the digit is already there, the action taken depends on "replace"
133 /// kAllow -> replacement will occur (i.e. return kTRUE)
134 /// kDeny -> replacement will *not* occur (and returned value is kFALSE)
135 /// kMerge -> both digits will be merged into one (return kTRUE)
138 const AliMUONDigit* digit = dynamic_cast<const AliMUONDigit*>(&vdigit);
142 AliError(Form("Digit is not of the expected type (%s vs AliMUONdigit)",
143 vdigit.ClassName()));
149 if ( replace != kIgnore )
151 AliMUONVDigit* alreadyThere = Find(*digit,index);
155 if ( replace == kDeny )
159 if ( replace == kMerge )
161 alreadyThere->MergeWith(*digit);
167 Int_t detElemId = digit->DetElemId();
168 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
169 TClonesArray* array = ChamberDigits(iChamber);
172 index = array->GetLast()+1;
174 return (new((*array)[index]) AliMUONDigit(*digit));
177 //_____________________________________________________________________________
179 AliMUONDigitStoreV1::Connect(TTree& tree, Bool_t alone) const
181 /// Connect this to the tree.
183 AliMUONTreeManager tman;
186 TString baseName(BaseName(tree.GetName()));
188 // Search for branch MUON(S)Digits1 to know if we need to set branch addresses
190 TBranch* branch = tree.GetBranch(Form("%ss%d",baseName.Data(),1));
192 Bool_t isMaking = (branch==0);
196 for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
198 TString branchName(Form("%ss%d",baseName.Data(),i+1));
199 ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
200 branchName.Data(),ChamberDigitsPtr(i));
205 if ( alone && baseName != "MUONSDigit" )
207 // TreeS only has digits, so there's not need to play the branch status
209 tman.UpdateBranchStatuses(tree,baseName.Data());
211 for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
213 TString branchName(Form("%ss%d",baseName.Data(),i+1));
214 ok = ok && tman.SetAddress(tree,branchName.Data(),ChamberDigitsPtr(i));
221 //_____________________________________________________________________________
223 AliMUONDigitStoreV1::ChamberDigitsPtr(Int_t chamberId) const
225 /// Get the address of the TClonesArray storing digits for chamberId.
227 TObject* object = fDigits->At(chamberId);
231 AliError(Form("Cannot get digits for chamberId=%d",chamberId));
236 return fDigits->GetObjectRef(object);
240 //_____________________________________________________________________________
242 AliMUONDigitStoreV1::ChamberDigits(Int_t chamberId)
244 /// Returns the tclonesarray storing digits for chamberId
245 return static_cast<TClonesArray*>(fDigits->At(chamberId));
248 //_____________________________________________________________________________
250 AliMUONDigitStoreV1::ChamberDigits(Int_t chamberId) const
252 /// Returns the tclonesarray storing digits for chamberId
253 return static_cast<TClonesArray*>(fDigits->At(chamberId));
256 //_____________________________________________________________________________
258 AliMUONDigitStoreV1::CreateDigit(Int_t detElemId, Int_t manuId,
259 Int_t manuChannel, Int_t cathode) const
261 return new AliMUONDigit(detElemId,manuId,manuChannel,cathode);
264 //_____________________________________________________________________________
266 AliMUONDigitStoreV1::Remove(AliMUONVDigit& digit)
268 /// Remove one digit, and returns it, thus returning 0x0 if digit
272 AliMUONVDigit* d(0x0);
273 if ( ( d = FindIndex(digit.DetElemId(),digit.ManuId(),
274 digit.ManuChannel(),digit.Cathode(),index) ) )
276 Int_t iChamber = AliMpDEManager::GetChamberId(digit.DetElemId());
277 TClonesArray* array = ChamberDigits(iChamber);
278 array->RemoveAt(index);
284 //_____________________________________________________________________________
286 AliMUONDigitStoreV1::Find(const AliMUONVDigit& digit, Int_t& index) const
288 /// Find a digit, and return its index.
289 return FindIndex(digit.DetElemId(),digit.ManuId(),digit.ManuChannel(),digit.Cathode(),index);
292 //_____________________________________________________________________________
294 AliMUONDigitStoreV1::FindObject(Int_t detElemId, Int_t manuId,
295 Int_t manuChannel, Int_t cathode) const
297 /// Find a (trigger) digit
299 return FindIndex(detElemId,manuId,manuChannel,cathode,index);
302 //_____________________________________________________________________________
304 AliMUONDigitStoreV1::FindIndex(Int_t detElemId, Int_t manuId,
305 Int_t manuChannel, Int_t cathode, Int_t& index) const
307 /// Find and return the index of a digit
309 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
310 const TClonesArray* array = ChamberDigits(iChamber);
311 if (!array) return 0x0;
313 AliMUONVDigit* digit;
315 while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
317 if ( digit->DetElemId() == detElemId &&
318 digit->ManuId() == manuId &&
319 digit->ManuChannel() == manuChannel &&
320 digit->Cathode() == cathode )
330 //_____________________________________________________________________________
332 AliMUONDigitStoreV1::CreateIterator() const
334 /// Return an iterator on the full store
335 return new AliMUONTOTCAStoreIterator(fDigits,0,13);
338 //_____________________________________________________________________________
340 AliMUONDigitStoreV1::CreateTrackerIterator() const
342 /// Return an iterator on the tracker part of the store
343 return new AliMUONTOTCAStoreIterator(fDigits,0,9);
346 //_____________________________________________________________________________
348 AliMUONDigitStoreV1::CreateTriggerIterator() const
350 /// Return an iterator on the trigger part of the store
351 return new AliMUONTOTCAStoreIterator(fDigits,10,13);
354 //_____________________________________________________________________________
356 AliMUONDigitStoreV1::CreateIterator(Int_t firstDetElemId, Int_t lastDetElemId,
359 /// Return an iterator on part of the store
360 return new AliMUONDigitStoreV1Iterator(fDigits,firstDetElemId,lastDetElemId,cathode);
363 //_____________________________________________________________________________
365 AliMUONDigitStoreV1::GetSize() const
367 /// Return the number of digits we store
370 for ( Int_t i = 0; i <= fDigits->GetLast(); ++i )
372 n += ChamberDigits(i)->GetEntries();
377 //_____________________________________________________________________________
379 AliMUONDigitStoreV1::HasMCInformation() const
381 /// As this class is legacy, don't care about looping and loosing a bit of
383 TIter next(CreateIterator());
384 AliMUONVDigit* digit;
385 while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
387 if ( digit->HasMCInformation() ) return kTRUE;