Legacy implementation of AliMUONVTriggerStore (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerStoreV1.cxx
CommitLineData
f6bdb753 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 AliMUONTriggerStoreV1
20///
21/// Implementation of AliMUONVTriggerStore, which is backward compatible,
22/// i.e. should be able to read back old TreeR and TreeD files, produced
23/// before the introduction of the AliMUONVStore concept.
24///
25/// \author Laurent Aphecetche, Subatech
26
27#include "AliMUONTriggerStoreV1.h"
28
29#include "AliMUONGlobalTrigger.h"
30#include "AliMUONLocalTrigger.h"
31#include "AliMUONRegionalTrigger.h"
32#include "AliMUONTreeManager.h"
33#include <Riostream.h>
34#include <TClonesArray.h>
35#include <TTree.h>
36
37/// \cond CLASSIMP
38ClassImp(AliMUONTriggerStoreV1)
39/// \endcond
40
41//_____________________________________________________________________________
42AliMUONTriggerStoreV1::AliMUONTriggerStoreV1() : AliMUONVTriggerStore(),
43fLocal(new TClonesArray("AliMUONLocalTrigger",234)),
44fRegional(new TClonesArray("AliMUONRegionalTrigger",16)),
45fGlobal(new TClonesArray("AliMUONGlobalTrigger",1)),
46fEmptyLocal(new TClonesArray("AliMUONLocalTrigger",234))
47{
48 /// ctor
49 fLocal->SetOwner(kTRUE);
50 fRegional->SetOwner(kTRUE);
51 fGlobal->SetOwner(kTRUE);
52 fEmptyLocal->SetOwner(kTRUE);
53}
54
55//_____________________________________________________________________________
56AliMUONTriggerStoreV1::~AliMUONTriggerStoreV1()
57{
58 /// dtor
59 delete fLocal;
60 delete fRegional;
61 delete fGlobal;
62 delete fEmptyLocal;
63}
64
65//_____________________________________________________________________________
66void
67AliMUONTriggerStoreV1::Add(const AliMUONLocalTrigger& localTrigger)
68{
69 /// Add local information
70 /// If the local board has no information (IsNull), we
71 /// add it in the fEmpty array
72 /// This is really an implementation choice, to store empty boards
73 /// in order to be able to return them, if asked for, as is the case
74 /// in some client code. Note that only the non-empty boards
75 /// are streamed to disk.
76 ///
77
78 if ( !localTrigger.IsNull() )
79 {
80 new((*fLocal)[fLocal->GetLast()+1]) AliMUONLocalTrigger(localTrigger);
81
82 }
83 else
84 {
85 new((*fEmptyLocal)[fEmptyLocal->GetLast()+1]) AliMUONLocalTrigger(localTrigger);
86 }
87}
88
89//_____________________________________________________________________________
90Bool_t
91AliMUONTriggerStoreV1::Connect(TTree& tree, Bool_t alone) const
92{
93 /// Connect this store to the tree
94 AliMUONTreeManager tman;
95 Bool_t ok(kTRUE);
96
97 Bool_t isMaking = ( tree.GetBranch("MUONLocalTrigger") == 0 );
98
99 if ( isMaking )
100 {
101 ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
102 "MUONLocalTrigger",LocalPtr());
103 ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
104 "MUONRegionalTrigger",RegionalPtr());
105 ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
106 "MUONGlobalTrigger",GlobalPtr());
107 }
108 else
109 {
110 if ( alone ) tman.UpdateBranchStatuses(tree,"Trigger");
111 ok = ok && tman.SetAddress(tree,"MUONLocalTrigger",LocalPtr());
112 ok = ok && tman.SetAddress(tree,"MUONRegionalTrigger",RegionalPtr());
113 ok = ok && tman.SetAddress(tree,"MUONGlobalTrigger",GlobalPtr());
114 }
115 return ok;
116}
117
118//_____________________________________________________________________________
119void
120AliMUONTriggerStoreV1::SetGlobal(const AliMUONGlobalTrigger& globalTrigger)
121{
122 /// Set the global information
123 new((*fGlobal)[0]) AliMUONGlobalTrigger(globalTrigger);
124}
125
126//_____________________________________________________________________________
127void
128AliMUONTriggerStoreV1::Add(const AliMUONRegionalTrigger& regionalTrigger)
129{
130 /// Add regional information
131 new((*fRegional)[fRegional->GetLast()+1]) AliMUONRegionalTrigger(regionalTrigger);
132}
133
134//_____________________________________________________________________________
135TIterator*
136AliMUONTriggerStoreV1::CreateLocalIterator() const
137{
138 /// Return iterator on local cards
139 return fLocal->MakeIterator();
140}
141
142//_____________________________________________________________________________
143TIterator*
144AliMUONTriggerStoreV1::CreateRegionalIterator() const
145{
146 /// Return iterator on regional cards
147 return fRegional->MakeIterator();
148}
149
150//_____________________________________________________________________________
151AliMUONLocalTrigger*
152AliMUONTriggerStoreV1::FindLocal(Int_t boardNumber) const
153{
154 /// Find a local board, by its *number* (not to be confused with its index,
155 /// which used to be the key)
156 ///
157
158 for ( Int_t i = 0; i <= fLocal->GetLast(); ++i )
159 {
160 AliMUONLocalTrigger* local = static_cast<AliMUONLocalTrigger*>(fLocal->At(i));
161 if (local && local->LoCircuit()==boardNumber)
162 {
163 return local;
164 }
165 }
166
167 for ( Int_t i = 0; i <= fEmptyLocal->GetLast(); ++i )
168 {
169 AliMUONLocalTrigger* local = static_cast<AliMUONLocalTrigger*>(fEmptyLocal->At(i));
170 if (local && local->LoCircuit()==boardNumber)
171 {
172 return local;
173 }
174 }
175
176 if ( boardNumber>=1 && boardNumber<=234 )
177 {
178 AliMUONLocalTrigger empty;
179 empty.SetLoCircuit(boardNumber);
180 new((*fEmptyLocal)[fEmptyLocal->GetLast()+1]) AliMUONLocalTrigger(empty);
181 return FindLocal(boardNumber);
182 }
183
184 return 0x0;
185}
186
187//_____________________________________________________________________________
188AliMUONRegionalTrigger*
189AliMUONTriggerStoreV1::FindRegional(Int_t boardNumber) const
190{
191 /// Return a given regional board
192 for ( Int_t i = 0; i <= fRegional->GetLast(); ++i )
193 {
194 AliMUONRegionalTrigger* regional = static_cast<AliMUONRegionalTrigger*>(fRegional->At(i));
195 if (regional && regional->GetId()==boardNumber)
196 {
197 return regional;
198 }
199 }
200 return 0x0;
201}
202
203//_____________________________________________________________________________
204AliMUONGlobalTrigger*
205AliMUONTriggerStoreV1::Global() const
206{
207 /// Return global trigger
208 return static_cast<AliMUONGlobalTrigger*>(fGlobal->At(0));
209}
210
211//_____________________________________________________________________________
212void
213AliMUONTriggerStoreV1::Clear(Option_t*)
214{
215 /// Reset
216 fLocal->Clear("C");
217 fRegional->Clear("C");
218 fGlobal->Clear("C");
219 fEmptyLocal->Clear("C");
220}
221
222//_____________________________________________________________________________
223Int_t
224AliMUONTriggerStoreV1::GetSize() const
225{
226 /// Number of non-empty local boards we hold
227 return fLocal->GetSize();
228}
229
230//_____________________________________________________________________________
231void
232AliMUONTriggerStoreV1::Print(Option_t* what, Option_t* opt) const
233{
234 /// Printout
235 /// \param what used to tell what to print, can be GLOBAL, LOCAL, REGIONAL
236 /// or ALL
237 /// \param opt is passed to the local, regional, global object
238 ///
239
240 TString swhat(what);
241 swhat.ToUpper();
242
243 if ( swhat.Length() == 0 ) swhat = "ALL";
244
245 if ( swhat.Contains("GLOBAL") || swhat.Contains("ALL") )
246 {
247 if ( fGlobal )
248 {
249 cout << "Global:" << endl;
250 fGlobal->Print("",opt);
251 }
252 else
253 {
254 cout << "No GlobalTrigger information" << endl;
255 }
256 }
257
258 if ( fLocal && ( swhat.Contains("LOCAL")|| swhat.Contains("ALL") ) )
259 {
260 // make loops instead of just relying on fLocal
261 // to insure backward compatibility with trees where all local boards where
262 // stored (even null ones)
263
264 TIter next(fLocal);
265 AliMUONLocalTrigger* local;
266 Int_t n(0);
267
268 while ( ( local = static_cast<AliMUONLocalTrigger*>(next()) ) )
269 {
270 if ( local->IsNull() ) ++n;
271 }
272
273 cout << Form("Local: %d cards (and %d null ones)",
274 fLocal->GetLast()+1,n) << endl;
275
276 next.Reset();
277
278 while ( ( local = static_cast<AliMUONLocalTrigger*>(next()) ) )
279 {
280 if ( !local->IsNull() )
281 {
282 local->Print(opt);
283 }
284 }
285 }
286
287 if ( fRegional && ( swhat.Contains("REGIONAL") || swhat.Contains("ALL") ) )
288 {
289 fRegional->Print("",opt);
290 }
291}
292