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()
61 : AliMUONVDigitStore(),
62 fDigits(new TObjArray(AliMpConstants::NofChambers())),
66 fDigits->SetOwner(kTRUE);
67 for ( Int_t i = 0; i < fDigits->GetSize(); ++i )
69 TClonesArray* tca = new TClonesArray("AliMUONDigit",100);
71 fDigits->AddAt(tca,i);
77 //_____________________________________________________________________________
78 AliMUONDigitStoreV1::AliMUONDigitStoreV1(const AliMUONDigitStoreV1&)
79 : AliMUONVDigitStore(),
84 AliError("Please implement me");
87 //_____________________________________________________________________________
89 AliMUONDigitStoreV1::operator=(const AliMUONDigitStoreV1&)
91 /// assignement operator
92 AliError("Please implement me");
96 //_____________________________________________________________________________
97 AliMUONDigitStoreV1::~AliMUONDigitStoreV1()
104 //_____________________________________________________________________________
106 AliMUONDigitStoreV1::Clear(Option_t* /*opt*/)
108 /// Clear the tclonesarray, but keep the tobjarray's size constant.
110 for ( Int_t i = 0; i <= fDigits->GetLast(); ++i )
112 ChamberDigits(i)->Clear("C");
116 //_____________________________________________________________________________
118 AliMUONDigitStoreV1::Add(const AliMUONVDigit& vdigit, EReplacePolicy replace)
120 /// Try to add a digit to the store. Return whether the try was successfull
123 /// If the digit is already there, the action taken depends on "replace"
124 /// kAllow -> replacement will occur (i.e. return kTRUE)
125 /// kDeny -> replacement will *not* occur (and returned value is kFALSE)
126 /// kMerge -> both digits will be merged into one (return kTRUE)
129 const AliMUONDigit* digit = dynamic_cast<const AliMUONDigit*>(&vdigit);
133 AliError(Form("Digit is not of the expected type (%s vs AliMUONdigit)",
134 vdigit.ClassName()));
140 if ( replace != kIgnore )
142 AliMUONVDigit* alreadyThere = Find(*digit,index);
146 if ( replace == kDeny )
150 if ( replace == kMerge )
152 alreadyThere->MergeWith(*digit);
158 Int_t detElemId = digit->DetElemId();
159 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
160 TClonesArray* array = ChamberDigits(iChamber);
163 index = array->GetLast()+1;
165 return (new((*array)[index]) AliMUONDigit(*digit));
168 //_____________________________________________________________________________
170 AliMUONDigitStoreV1::Connect(TTree& tree, Bool_t alone) const
172 /// Connect this to the tree.
174 AliMUONTreeManager tman;
177 TString baseName(BaseName(tree.GetName()));
179 // Search for branch MUON(S)Digits1 to know if we need to set branch addresses
181 TBranch* branch = tree.GetBranch(Form("%ss%d",baseName.Data(),1));
183 Bool_t isMaking = (branch==0);
187 for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
189 TString branchName(Form("%ss%d",baseName.Data(),i+1));
190 ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
191 branchName.Data(),ChamberDigitsPtr(i));
196 if ( alone && baseName != "MUONSDigit" )
198 // TreeS only has digits, so there's not need to play the branch status
200 tman.UpdateBranchStatuses(tree,baseName.Data());
202 for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
204 TString branchName(Form("%ss%d",baseName.Data(),i+1));
205 ok = ok && tman.SetAddress(tree,branchName.Data(),ChamberDigitsPtr(i));
212 //_____________________________________________________________________________
214 AliMUONDigitStoreV1::ChamberDigitsPtr(Int_t chamberId) const
216 /// Get the address of the TClonesArray storing digits for chamberId.
218 return fDigits->GetObjectRef(fDigits->UncheckedAt(chamberId));
220 TObject* object = fDigits->At(chamberId);
224 AliError(Form("Cannot get digits for chamberId=%d",chamberId));
229 return fDigits->GetObjectRef(object);
233 //_____________________________________________________________________________
235 AliMUONDigitStoreV1::ChamberDigits(Int_t chamberId)
237 /// Returns the tclonesarray storing digits for chamberId
238 return static_cast<TClonesArray*>(fDigits->At(chamberId));
241 //_____________________________________________________________________________
243 AliMUONDigitStoreV1::ChamberDigits(Int_t chamberId) const
245 /// Returns the tclonesarray storing digits for chamberId
246 return static_cast<TClonesArray*>(fDigits->At(chamberId));
249 //_____________________________________________________________________________
251 AliMUONDigitStoreV1::CreateDigit(Int_t detElemId, Int_t manuId,
252 Int_t manuChannel, Int_t cathode) const
254 return new AliMUONDigit(detElemId,manuId,manuChannel,cathode);
257 //_____________________________________________________________________________
259 AliMUONDigitStoreV1::Remove(AliMUONVDigit& digit)
261 /// Remove one digit, and returns it, thus returning 0x0 if digit
265 AliMUONVDigit* d(0x0);
266 if ( ( d = FindIndex(digit.DetElemId(),digit.ManuId(),
267 digit.ManuChannel(),digit.Cathode(),index) ) )
269 Int_t iChamber = AliMpDEManager::GetChamberId(digit.DetElemId());
270 TClonesArray* array = ChamberDigits(iChamber);
271 array->RemoveAt(index);
277 //_____________________________________________________________________________
279 AliMUONDigitStoreV1::Find(const AliMUONVDigit& digit, Int_t& index) const
281 /// Find a digit, and return its index.
282 return FindIndex(digit.DetElemId(),digit.ManuId(),digit.ManuChannel(),digit.Cathode(),index);
285 //_____________________________________________________________________________
287 AliMUONDigitStoreV1::FindObject(Int_t detElemId, Int_t manuId,
288 Int_t manuChannel, Int_t cathode) const
290 /// Find a (trigger) digit
292 return FindIndex(detElemId,manuId,manuChannel,cathode,index);
295 //_____________________________________________________________________________
297 AliMUONDigitStoreV1::FindIndex(Int_t detElemId, Int_t manuId,
298 Int_t manuChannel, Int_t cathode, Int_t& index) const
300 /// Find and return the index of a digit
302 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
303 const TClonesArray* array = ChamberDigits(iChamber);
304 if (!array) return 0x0;
306 AliMUONVDigit* digit;
308 while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
310 if ( digit->DetElemId() == detElemId &&
311 digit->ManuId() == manuId &&
312 digit->ManuChannel() == manuChannel &&
313 digit->Cathode() == cathode )
323 //_____________________________________________________________________________
325 AliMUONDigitStoreV1::CreateIterator() const
327 /// Return an iterator on the full store
328 return new AliMUONTOTCAStoreIterator(fDigits,0,13);
331 //_____________________________________________________________________________
333 AliMUONDigitStoreV1::CreateTrackerIterator() const
335 /// Return an iterator on the tracker part of the store
336 return new AliMUONTOTCAStoreIterator(fDigits,0,9);
339 //_____________________________________________________________________________
341 AliMUONDigitStoreV1::CreateTriggerIterator() const
343 /// Return an iterator on the trigger part of the store
344 return new AliMUONTOTCAStoreIterator(fDigits,10,13);
347 //_____________________________________________________________________________
349 AliMUONDigitStoreV1::CreateIterator(Int_t firstDetElemId, Int_t lastDetElemId,
352 /// Return an iterator on part of the store
353 return new AliMUONDigitStoreV1Iterator(fDigits,firstDetElemId,lastDetElemId,cathode);
356 //_____________________________________________________________________________
358 AliMUONDigitStoreV1::GetSize() const
360 /// Return the number of digits we store
363 for ( Int_t i = 0; i <= fDigits->GetLast(); ++i )
365 n += ChamberDigits(i)->GetEntries();