- Adding comment lines to class description needed for Root documentation
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerCrateStore.cxx
CommitLineData
30dd09e2 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 "AliMUONTriggerCrateStore.h"
19
20#include "AliMUONTriggerCrate.h"
21#include "AliMUONLocalTriggerBoard.h"
22#include "AliMUONRegionalTriggerBoard.h"
ac809573 23
24#include "AliMpTriggerCrate.h"
25#include "AliMpLocalBoard.h"
26#include "AliMpDDLStore.h"
30dd09e2 27#include "AliMpExMap.h"
30dd09e2 28#include "AliLog.h"
ac809573 29
30#include <TString.h>
31#include <TSystem.h>
32#include <Riostream.h>
30dd09e2 33
34///
35/// \class AliMUONTriggerCrateStore
36///
37/// A container of trigger crate objects that offers iteration
38/// over both the crates themselves and the local boards they contain
39///
40/// \author Laurent Aphecetche
41
5398f946 42/// \cond CLASSIMP
30dd09e2 43ClassImp(AliMUONTriggerCrateStore)
5398f946 44/// \endcond
30dd09e2 45
46//_____________________________________________________________________________
47AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
48: TObject(),
49fCrates(0x0),
50fLocalBoards(0x0),
51fCrateIterator(0x0),
52fLBIterator(0x0),
53fCurrentCrate(0x0),
54fCurrentLocalBoard(-1)
55{
5398f946 56/// Default constructor
30dd09e2 57}
58
59//_____________________________________________________________________________
60AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
61{
5398f946 62/// Destructor
30dd09e2 63 delete fCrateIterator;
64 delete fLBIterator;
65 delete fCrates;
66 delete fLocalBoards;
67}
68
69//_____________________________________________________________________________
70void
71AliMUONTriggerCrateStore::AddCrate(const char *name)
72{
73 /// create and add a crate to our map
74 if (!fCrates)
75 {
76 AliError("Object not properly initialized");
77 return;
78 }
79
80 AliDebug(1,Form("Adding crate %s",name));
81 TObject* there = fCrates->GetValue(name);
82 if (there)
83 {
84 AliError(Form("Cannot add crate %s because it's already there !",name));
85 }
86 else
87 {
88 fCrates->Add(name,new AliMUONTriggerCrate(name,17));
89 }
90}
91
92//_____________________________________________________________________________
93AliMUONLocalTriggerBoard*
94AliMUONTriggerCrateStore::LocalBoard(Int_t boardNumber) const
95{
96 /// return a board by number
97
98 if ( !fLocalBoards )
99 {
100 AliError("Object not properly initialized");
101 return 0x0;
102 }
103
104 return static_cast<AliMUONLocalTriggerBoard*>(fLocalBoards->GetValue(boardNumber));
105}
106
107//_____________________________________________________________________________
108AliMUONTriggerCrate*
109AliMUONTriggerCrateStore::Crate(const char *name) const
110{
111 /// return a crate by name
112 if ( !fCrates )
113 {
114 AliError("Object not properly initialized");
115 return 0x0;
116 }
117 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
118}
119
ac809573 120// to be removed once AliMUONDigitMaker is linked with new mapping
30dd09e2 121//_____________________________________________________________________________
aa6ecf89 122AliMUONTriggerCrate*
123AliMUONTriggerCrateStore::Crate(Int_t ddl, Int_t reg) const
124{
125 /// return a crate by name
126 if ( !fCrates )
127 {
128 AliError("Object not properly initialized");
129 return 0x0;
130 }
131 TString name = GetCrateName(ddl, reg);
132 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name.Data()));
133}
ac809573 134//____________________________________________________________________
aa6ecf89 135TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
136{
71a2d3aa 137 /// set crate name from DDL & reg number
aa6ecf89 138
139 Char_t name[10];
140 switch(reg) {
141 case 0:
142 case 1:
143 sprintf(name,"%d", reg+1);
144 break;
145 case 2:
146 strcpy(name, "2-3");
147 break;
148 case 3:
149 case 4:
150 case 5:
151 case 6:
152 case 7:
153 sprintf(name,"%d", reg);
154 break;
155 }
156
157 // crate Right for first DDL
158 if (ddl == 0)
159 strcat(name, "R");
160 else
161 strcat(name, "L");
162
163 return TString(name);
164}
165//_____________________________________________________________________________
30dd09e2 166void
167AliMUONTriggerCrateStore::FirstCrate()
168{
169 /// initialize iteration
170 if ( !fCrates )
171 {
172 AliError("Object not properly initialized");
173 return;
174 }
175 if (!fCrateIterator)
176 {
177 fCrateIterator = new TExMapIter(fCrates->GetIterator());
178 }
179 fCrateIterator->Reset();
180}
181
182//_____________________________________________________________________________
183void
184AliMUONTriggerCrateStore::FirstLocalBoard()
185{
186 /// Initialize iterator on local boards.
187 /// Please note that we're not using directly the FirstCrate() and
188 /// NextCrate() methods here to avoid mix and match between crate iterator
189 /// and local board iterator
190 fCurrentCrate = 0x0;
191 fCurrentLocalBoard = 0;
192
193 if ( !fLBIterator )
194 {
195 fLBIterator = new TExMapIter(fCrates->GetIterator());
196 }
197 fLBIterator->Reset();
198 Long_t key, value;
199 Bool_t ok = fLBIterator->Next(key,value);
200 if ( ok )
201 {
202 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
203 fCurrentLocalBoard = 1;
204 }
205}
206
207//_____________________________________________________________________________
208AliMUONTriggerCrate*
209AliMUONTriggerCrateStore::NextCrate()
210{
211 /// Return the next crate in iteration, or 0 if iteration is ended.
212 if (!fCrateIterator) return 0x0;
213
214 Long_t key, value;
215 Bool_t ok = fCrateIterator->Next(key,value);
216 if (ok)
217 {
218 return reinterpret_cast<AliMUONTriggerCrate*>(value);
219 }
220 else
221 {
222 return 0x0;
223 }
224}
225
226//_____________________________________________________________________________
227AliMUONLocalTriggerBoard*
228AliMUONTriggerCrateStore::NextLocalBoard()
229{
230 /// Return the next local board in iteration, or 0 if iteration is ended.
231 if ( !fLBIterator ) return 0x0;
232
233 if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() +1)
234// if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() )
235 {
236 // try to go to next crate, if some are left
237 Long_t key, value;
238 Bool_t ok = fLBIterator->Next(key,value);
239 if ( ok )
240 {
241 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
242 fCurrentLocalBoard = 1;
243 }
244 else
245 {
246 fCurrentLocalBoard = 0;
247 return 0x0;
248 }
249 }
250
251 AliMUONLocalTriggerBoard* lb = static_cast<AliMUONLocalTriggerBoard*>
252 (fCurrentCrate->Boards()->At(fCurrentLocalBoard));
253
254 ++fCurrentLocalBoard;
255
256 return lb;
257}
258
259//_____________________________________________________________________________
260Int_t
261AliMUONTriggerCrateStore::NumberOfCrates() const
262{
263 /// Number of crates we're holding
264 if ( fCrates ) return fCrates->GetSize();
265 return 0;
266}
267
268//_____________________________________________________________________________
269Int_t
270AliMUONTriggerCrateStore::NumberOfLocalBoards() const
271{
272 /// Number of local boards we're holding
273 if ( fLocalBoards ) return fLocalBoards->GetSize();
274 return 0;
275}
276
277//_____________________________________________________________________________
278void
ac809573 279AliMUONTriggerCrateStore::ReadFromFile(const char* /*file*/) // keep old name for the moment
30dd09e2 280{
ac809573 281 /// create crate and local board objects from mapping (Ch.F)
5a92f8e6 282 fCrates = new AliMpExMap(kTRUE);
6e241007 283 fCrates->SetOwner(kTRUE);
284 fLocalBoards = new AliMpExMap(kTRUE);
285 fLocalBoards->SetOwner(kFALSE);
30dd09e2 286
ac809573 287 TExMapIter itr = AliMpDDLStore::Instance()->GetTriggerCrateItr();
288
289 Long_t key, value;
290
291 while(itr.Next(key, value))
5a92f8e6 292 {
ac809573 293 AliMpTriggerCrate* crateMapping = reinterpret_cast<AliMpTriggerCrate*>(value);
294
295 TString crateName = crateMapping->GetName();
296 AliMUONTriggerCrate *crate = Crate(crateName.Data());
297
298 if (!crate)
30dd09e2 299 {
ac809573 300 AddCrate(crateName.Data());
301 crate = Crate(crateName.Data());
302 AliDebug(3, Form("crate name %s\n", crateName.Data()));
303 AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
304 crate->AddBoard(rboard, 0);
305 }
306
307 for(Int_t iLocal = 0; iLocal < crateMapping->GetNofLocalBoards(); ++iLocal) {
308
309 Int_t localBoardId = crateMapping->GetLocalBoardId(iLocal);
310 if (!localBoardId) continue; //empty slot, should not happen
311
312 AliMpLocalBoard* localBoardMapping = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
313 AliDebug(3, Form("local name %s id %d\n", localBoardMapping->GetName(), localBoardId));
314
315 Int_t slot = localBoardMapping->GetSlot();
316 AliMUONLocalTriggerBoard *board =
317 new AliMUONLocalTriggerBoard(localBoardMapping);
318
319 if (localBoardMapping->IsNotified()) {
320 fLocalBoards->Add(localBoardId, board);
5a92f8e6 321 }
ac809573 322
323 crate->AddBoard(board, slot);
324
325 } // iLocal
326 } // while
30dd09e2 327}