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