AliRoot Core  3abf5b4 (3abf5b4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONDigitStoreV1.cxx
Go to the documentation of this file.
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15 
16 // $Id$
17 
18 #include "AliMUONDigitStoreV1.h"
19 
20 //-----------------------------------------------------------------------------
28 // \author Laurent Aphecetche, Subatech
29 //-----------------------------------------------------------------------------
30 
31 #include "AliLog.h"
32 #include "AliMUONDigit.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>
43 #include <TTree.h>
44 
48 
49 namespace
50 {
51  TString BaseName(const TString& name)
52  {
53  if ( name == "TreeS" ) return "MUONSDigit";
54  if ( name == "TreeD" ) return "MUONDigit";
55  return "";
56  }
57 }
58 
59 //_____________________________________________________________________________
62 fDigits(0x0),
63 fChamberDigits(0x0)
64 {
66 }
67 
68 //_____________________________________________________________________________
71 fDigits(new TObjArray(AliMpConstants::NofChambers())),
72 fChamberDigits(0x0)
73 {
75  fDigits->SetOwner(kTRUE);
76  for ( Int_t i = 0; i < fDigits->GetSize(); ++i )
77  {
78  TClonesArray* tca = new TClonesArray("AliMUONDigit",100);
79  tca->SetOwner(kTRUE);
80  fDigits->AddAt(tca,i);
81  }
82  Clear();
83  AliDebug(1,"");
84 }
85 
86 //_____________________________________________________________________________
89 fDigits(0x0),
90 fChamberDigits(0x0)
91 {
93  AliError("Please implement me");
94 }
95 
96 //_____________________________________________________________________________
99 {
101  AliError("Please implement me");
102  return *this;
103 }
104 
105 //_____________________________________________________________________________
107 {
109  delete fDigits;
110 }
111 
112 
113 //_____________________________________________________________________________
114 void
115 AliMUONDigitStoreV1::Clear(Option_t* /*opt*/)
116 {
118 
119  for ( Int_t i = 0; i <= fDigits->GetLast(); ++i )
120  {
121  ChamberDigits(i)->Clear("C");
122  }
123 }
124 
125 //_____________________________________________________________________________
128 {
137 
138  const AliMUONDigit* digit = dynamic_cast<const AliMUONDigit*>(&vdigit);
139 
140  if (!digit)
141  {
142  AliError(Form("Digit is not of the expected type (%s vs AliMUONdigit)",
143  vdigit.ClassName()));
144  return 0x0;
145  }
146 
147  Int_t index(-1);
148 
149  if ( replace != kIgnore )
150  {
151  AliMUONVDigit* alreadyThere = Find(*digit,index);
152 
153  if ( alreadyThere )
154  {
155  if ( replace == kDeny )
156  {
157  return 0x0;
158  }
159  if ( replace == kMerge )
160  {
161  alreadyThere->MergeWith(*digit);
162  return alreadyThere;
163  }
164  }
165  }
166 
167  Int_t detElemId = digit->DetElemId();
168  Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
169  TClonesArray* array = ChamberDigits(iChamber);
170  if ( index < 0 )
171  {
172  index = array->GetLast()+1;
173  }
174  return (new((*array)[index]) AliMUONDigit(*digit));
175 }
176 
177 //_____________________________________________________________________________
178 Bool_t
179 AliMUONDigitStoreV1::Connect(TTree& tree, Bool_t alone) const
180 {
182 
183  AliMUONTreeManager tman;
184  Bool_t ok(kTRUE);
185 
186  TString baseName(BaseName(tree.GetName()));
187 
188  // Search for branch MUON(S)Digits1 to know if we need to set branch addresses
189  // or to make them.
190  TBranch* branch = tree.GetBranch(Form("%ss%d",baseName.Data(),1));
191 
192  Bool_t isMaking = (branch==0);
193 
194  if ( isMaking )
195  {
196  for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
197  {
198  TString branchName(Form("%ss%d",baseName.Data(),i+1));
199  ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
200  branchName.Data(),ChamberDigitsPtr(i));
201  }
202  }
203  else
204  {
205  if ( alone && baseName != "MUONSDigit" )
206  {
207  // TreeS only has digits, so there's not need to play the branch status
208  // game
209  tman.UpdateBranchStatuses(tree,baseName.Data());
210  }
211  for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
212  {
213  TString branchName(Form("%ss%d",baseName.Data(),i+1));
214  ok = ok && tman.SetAddress(tree,branchName.Data(),ChamberDigitsPtr(i));
215  }
216  }
217 
218  return ok;
219 }
220 
221 //_____________________________________________________________________________
222 TObject**
224 {
226 
227  TObject* object = fDigits->At(chamberId);
228 
229  if (!object)
230  {
231  AliError(Form("Cannot get digits for chamberId=%d",chamberId));
232  return 0x0;
233  }
234  else
235  {
236  return fDigits->GetObjectRef(object);
237  }
238 }
239 
240 //_____________________________________________________________________________
241 TClonesArray*
243 {
245  return static_cast<TClonesArray*>(fDigits->At(chamberId));
246 }
247 
248 //_____________________________________________________________________________
249 const TClonesArray*
251 {
253  return static_cast<TClonesArray*>(fDigits->At(chamberId));
254 }
255 
256 //_____________________________________________________________________________
258 AliMUONDigitStoreV1::CreateDigit(Int_t detElemId, Int_t manuId,
259  Int_t manuChannel, Int_t cathode) const
260 {
261  return new AliMUONDigit(detElemId,manuId,manuChannel,cathode);
262 }
263 
264 //_____________________________________________________________________________
267 {
270 
271  Int_t index;
272  AliMUONVDigit* d(0x0);
273  if ( ( d = FindIndex(digit.DetElemId(),digit.ManuId(),
274  digit.ManuChannel(),digit.Cathode(),index) ) )
275  {
276  Int_t iChamber = AliMpDEManager::GetChamberId(digit.DetElemId());
277  TClonesArray* array = ChamberDigits(iChamber);
278  array->RemoveAt(index);
279  array->Compress();
280  }
281  return d;
282 }
283 
284 //_____________________________________________________________________________
286 AliMUONDigitStoreV1::Find(const AliMUONVDigit& digit, Int_t& index) const
287 {
289  return FindIndex(digit.DetElemId(),digit.ManuId(),digit.ManuChannel(),digit.Cathode(),index);
290 }
291 
292 //_____________________________________________________________________________
294 AliMUONDigitStoreV1::FindObject(Int_t detElemId, Int_t manuId,
295  Int_t manuChannel, Int_t cathode) const
296 {
298  Int_t index;
299  return FindIndex(detElemId,manuId,manuChannel,cathode,index);
300 }
301 
302 //_____________________________________________________________________________
304 AliMUONDigitStoreV1::FindIndex(Int_t detElemId, Int_t manuId,
305  Int_t manuChannel, Int_t cathode, Int_t& index) const
306 {
308 
309  Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
310  const TClonesArray* array = ChamberDigits(iChamber);
311  if (!array) return 0x0;
312  TIter next(array);
313  AliMUONVDigit* digit;
314  index=0;
315  while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
316  {
317  if ( digit->DetElemId() == detElemId &&
318  digit->ManuId() == manuId &&
319  digit->ManuChannel() == manuChannel &&
320  digit->Cathode() == cathode )
321  {
322  return digit;
323  }
324  ++index;
325  }
326  return 0x0;
327 
328 }
329 
330 //_____________________________________________________________________________
331 TIterator*
333 {
335  return new AliMUONTOTCAStoreIterator(fDigits,0,13);
336 }
337 
338 //_____________________________________________________________________________
339 TIterator*
341 {
343  return new AliMUONTOTCAStoreIterator(fDigits,0,9);
344 }
345 
346 //_____________________________________________________________________________
347 TIterator*
349 {
351  return new AliMUONTOTCAStoreIterator(fDigits,10,13);
352 }
353 
354 //_____________________________________________________________________________
355 TIterator*
356 AliMUONDigitStoreV1::CreateIterator(Int_t firstDetElemId, Int_t lastDetElemId,
357  Int_t cathode) const
358 {
360  return new AliMUONDigitStoreV1Iterator(fDigits,firstDetElemId,lastDetElemId,cathode);
361 }
362 
363 //_____________________________________________________________________________
364 Int_t
366 {
368  Int_t n(0);
369 
370  for ( Int_t i = 0; i <= fDigits->GetLast(); ++i )
371  {
372  n += ChamberDigits(i)->GetEntries();
373  }
374  return n;
375 }
376 
377 //_____________________________________________________________________________
378 Bool_t
380 {
383  TIter next(CreateIterator());
384  AliMUONVDigit* digit;
385  while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
386  {
387  if ( digit->HasMCInformation() ) return kTRUE;
388  }
389  return kFALSE;
390 }
391 
static Int_t NofChambers()
Return number of chambers.
virtual Bool_t Connect(TTree &tree, Bool_t alone=kTRUE) const
Connect us to a TTree (only valid if CanConnect()==kTRUE)
virtual Int_t ManuChannel() const =0
The channel within ManuId() this digit belongs to (manuChannel for tracker, localBoardChannel for tri...
Iterator on a store composed of a TObjArray of TClonesArrays.
Bool_t SetAddress(TTree &tree, const char *branchName, void *address) const
Interface for a digit container.
virtual Int_t DetElemId() const
Return detection element ID.
Definition: AliMUONDigit.h:33
#define TObjArray
virtual AliMUONVDigit * FindObject(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t cathode) const
Find a digit by the quadruplet (de,manu,channel,cathode)
AliMUONVDigit * FindIndex(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t cathode, Int_t &index) const
virtual TIterator * CreateTriggerIterator() const
Create an iterator to loop over trigger digits only.
TObject ** ChamberDigitsPtr(Int_t chamberId) const
TObjArray * fDigits
array of tclonesarray
TClonesArray * ChamberDigits(Int_t chamberId)
TTree * tree
(Legacy) implementation of AliMUONVDigitStore
virtual Int_t DetElemId() const =0
The detection element this digit belongs to.
Helper class to ease TTree (MUON) branches manipulations.
TObjArray * array
Definition: AnalyzeLaser.C:12
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
virtual Bool_t HasMCInformation() const =0
Below are methods only relevant for MC digigts.
static Int_t GetChamberId(Int_t detElemId, Bool_t warn=true)
Bool_t HasMCInformation() const
Whether we have any MC related information (e.g. at least one simulated digit)
virtual AliMUONVDigit * Remove(AliMUONVDigit &digit)
Remove an element.
virtual Int_t Cathode() const =0
Cathode number this digit is on (0 or 1)
MUON digit.
Definition: AliMUONDigit.h:17
virtual Int_t GetSize() const
Number of digits we store.
virtual TIterator * CreateIterator() const
Create an iterator to loop over all our digits.
virtual void Clear(Option_t *opt="")
Clear ourselves (i.e. Reset)
Implementation of TIterator for AliMUONDigitStoreV1.
AliMUONDigitStoreV1 & operator=(const AliMUONDigitStoreV1 &rhs)
virtual TIterator * CreateTrackerIterator() const
Create an iterator to loop over tracker digits only.
void UpdateBranchStatuses(TTree &tree, const char *pattern) const
virtual AliMUONVDigit * Add(const AliMUONVDigit &digit, EReplacePolicy replace=kDeny)
virtual Int_t ManuId() const =0
The electronic card id this digit belongs to (manuId for tracker, localboardId for trigger) ...
ABC of a MUON digit.
Definition: AliMUONVDigit.h:18
virtual AliMUONVDigit * CreateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t cathode) const
Create a digit.
Bool_t MakeBranch(TTree &tree, const char *storeClassName, const char *branchClassName, const char *branchName, void *address, Int_t bufferSize=4000, Int_t splitLevel=99) const
AliMUONVDigit * Find(const AliMUONVDigit &digit, Int_t &index) const
Globally used constants definition.
EReplacePolicy
Replacement policy : what to do when adding a digit to the store.
virtual Bool_t MergeWith(const AliMUONVDigit &other)=0
Merge this with other.