]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONVDigitStore.cxx
Change names of sections to avoid confusion with MCH DA sections
[u/mrichter/AliRoot.git] / MUON / AliMUONVDigitStore.cxx
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 //-----------------------------------------------------------------------------
19 /// \class AliMUONVDigitStore
20 ///
21 /// Interface for a digit (or sdigit) container
22 ///
23 /// It offers methods to Add, Find and Remove single elements, and
24 /// can create iterators to loop over (part of) the elements.
25 ///
26 /// \author Laurent Aphecetche, Subatech
27 //-----------------------------------------------------------------------------
28
29 #include "AliMUONVDigitStore.h"
30
31 #include "AliLog.h"
32 #include "AliMUONVDigit.h"
33 #include <TClass.h>
34 #include <TString.h>
35 #include <TTree.h>
36
37 /// \cond CLASSIMP
38 ClassImp(AliMUONVDigitStore)
39 /// \endcond
40
41 //_____________________________________________________________________________
42 AliMUONVDigitStore::AliMUONVDigitStore()
43 {
44   /// ctor
45 }
46
47 //_____________________________________________________________________________
48 AliMUONVDigitStore::~AliMUONVDigitStore()
49 {
50   /// dtor
51 }
52
53 //_____________________________________________________________________________
54 Bool_t 
55 AliMUONVDigitStore::Add(TObject* object)
56 {
57   /// Add an object, if it is of type AliMUONVDigit
58   if (object)
59   {
60     AliMUONVDigit* digit = dynamic_cast<AliMUONVDigit*>(object);
61     if (digit)
62     {
63       AliMUONVDigit* added = Add(*digit,AliMUONVDigitStore::kIgnore);
64       if (!added)
65       {
66         AliError("Could not add digit through Add(TObject*) method");
67       }
68       else
69       {
70         return kTRUE;
71       }
72     }
73   }
74   return kFALSE;
75 }
76
77 //_____________________________________________________________________________
78 AliMUONVDigit* 
79 AliMUONVDigitStore::Add(Int_t detElemId, 
80                        Int_t manuId,
81                        Int_t manuChannel,
82                        Int_t cathode,
83                        EReplacePolicy replace)
84 {
85   /// Add a digit and return it
86   AliMUONVDigit* digit = CreateDigit(detElemId,manuId,manuChannel,cathode);
87   if (digit)
88   {
89     AliMUONVDigit* d = Add(*digit,replace);
90     delete digit;
91     return d;
92   }
93   return 0x0;
94 }
95
96 //____________________________________________________________________________
97 AliMUONVDigitStore* 
98 AliMUONVDigitStore::Create(const char* digitstoreclassname)
99 {
100   /// Create a concrete digitStore, given its classname
101   
102   TClass* classPtr = TClass::GetClass(digitstoreclassname);
103   if (!classPtr || !classPtr->InheritsFrom("AliMUONVDigitStore"))
104   {
105     return 0x0;
106   }
107   
108   AliMUONVDigitStore* digitStore = 
109     reinterpret_cast<AliMUONVDigitStore*>(classPtr->New());
110   
111   return digitStore;
112 }
113
114 //_____________________________________________________________________________
115 AliMUONVDigitStore*
116 AliMUONVDigitStore::Create(TTree& tree)
117 {
118   /// Create store from the given tree (if possible).
119   TString dataType = ( strcmp(tree.GetName(),"TreeD") == 0 ? "Digit" : 
120                        (strcmp(tree.GetName(),"TreeS")== 9 ? "SDigit" : "")
121                        );
122   return static_cast<AliMUONVDigitStore*>(AliMUONVStore::Create(tree,dataType.Data()));
123 }
124
125 //_____________________________________________________________________________
126 AliMUONVDigit* 
127 AliMUONVDigitStore::FindObject(const TObject* object) const
128 {
129   /// Find an object, if of AliMUONVDigit type.
130   const AliMUONVDigit* digit = dynamic_cast<const AliMUONVDigit*>(object);
131   if (digit)
132   {
133     return FindObject(digit->GetUniqueID());
134   }
135   return 0x0;
136 }
137
138 //_____________________________________________________________________________
139 AliMUONVDigit* 
140 AliMUONVDigitStore::FindObject(UInt_t uniqueID) const
141 {
142   /// Find digit by its uniqueID
143   
144   return FindObject(AliMUONVDigit::DetElemId(uniqueID),
145                     AliMUONVDigit::ManuId(uniqueID),
146                     AliMUONVDigit::ManuChannel(uniqueID),
147                     AliMUONVDigit::Cathode(uniqueID));
148 }
149
150 //_____________________________________________________________________________
151 Int_t 
152 AliMUONVDigitStore::GetSize(Int_t detElemId, Int_t cathode) const
153 {
154   /// Return the number of digits we have for a given detection element
155   TIter next(CreateIterator(detElemId,detElemId,cathode));
156   AliMUONVDigit* digit;
157   Int_t n(0);
158   while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
159   {
160     ++n;
161   }
162   return n;
163 }
164