1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONTriggerCrateStore.h"
20 #include "AliMUONTriggerCrate.h"
21 #include "AliMUONLocalTriggerBoard.h"
22 #include "AliMUONRegionalTriggerBoard.h"
24 #include "AliMpTriggerCrate.h"
25 #include "AliMpLocalBoard.h"
26 #include "AliMpDDLStore.h"
27 #include "AliMpExMap.h"
32 #include <Riostream.h>
35 /// \class AliMUONTriggerCrateStore
37 /// A container of trigger crate objects that offers iteration
38 /// over both the crates themselves and the local boards they contain
40 /// \author Laurent Aphecetche
43 ClassImp(AliMUONTriggerCrateStore)
46 //_____________________________________________________________________________
47 AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
54 fCurrentLocalBoard(-1)
56 /// Default constructor
59 //_____________________________________________________________________________
60 AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
63 delete fCrateIterator;
69 //_____________________________________________________________________________
71 AliMUONTriggerCrateStore::AddCrate(const char *name)
73 /// create and add a crate to our map
76 AliError("Object not properly initialized");
80 AliDebug(1,Form("Adding crate %s",name));
81 TObject* there = fCrates->GetValue(name);
84 AliError(Form("Cannot add crate %s because it's already there !",name));
88 fCrates->Add(name,new AliMUONTriggerCrate(name,17));
92 //_____________________________________________________________________________
93 AliMUONLocalTriggerBoard*
94 AliMUONTriggerCrateStore::LocalBoard(Int_t boardNumber) const
96 /// return a board by number
100 AliError("Object not properly initialized");
104 return static_cast<AliMUONLocalTriggerBoard*>(fLocalBoards->GetValue(boardNumber));
107 //_____________________________________________________________________________
109 AliMUONTriggerCrateStore::Crate(const char *name) const
111 /// return a crate by name
114 AliError("Object not properly initialized");
117 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
120 // to be removed once AliMUONDigitMaker is linked with new mapping
121 //_____________________________________________________________________________
123 AliMUONTriggerCrateStore::Crate(Int_t ddl, Int_t reg) const
125 /// return a crate by name
128 AliError("Object not properly initialized");
131 TString name = GetCrateName(ddl, reg);
132 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name.Data()));
134 //____________________________________________________________________
135 TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
137 /// set crate name from DDL & reg number
143 sprintf(name,"%d", reg+1);
153 sprintf(name,"%d", reg);
157 // crate Right for first DDL
163 return TString(name);
165 //_____________________________________________________________________________
167 AliMUONTriggerCrateStore::FirstCrate()
169 /// initialize iteration
172 AliError("Object not properly initialized");
177 fCrateIterator = new TExMapIter(fCrates->GetIterator());
179 fCrateIterator->Reset();
182 //_____________________________________________________________________________
184 AliMUONTriggerCrateStore::FirstLocalBoard()
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
191 fCurrentLocalBoard = 0;
195 fLBIterator = new TExMapIter(fCrates->GetIterator());
197 fLBIterator->Reset();
199 Bool_t ok = fLBIterator->Next(key,value);
202 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
203 fCurrentLocalBoard = 1;
207 //_____________________________________________________________________________
209 AliMUONTriggerCrateStore::NextCrate()
211 /// Return the next crate in iteration, or 0 if iteration is ended.
212 if (!fCrateIterator) return 0x0;
215 Bool_t ok = fCrateIterator->Next(key,value);
218 return reinterpret_cast<AliMUONTriggerCrate*>(value);
226 //_____________________________________________________________________________
227 AliMUONLocalTriggerBoard*
228 AliMUONTriggerCrateStore::NextLocalBoard()
230 /// Return the next local board in iteration, or 0 if iteration is ended.
231 if ( !fLBIterator ) return 0x0;
233 if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() +1)
234 // if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() )
236 // try to go to next crate, if some are left
238 Bool_t ok = fLBIterator->Next(key,value);
241 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
242 fCurrentLocalBoard = 1;
246 fCurrentLocalBoard = 0;
251 AliMUONLocalTriggerBoard* lb = static_cast<AliMUONLocalTriggerBoard*>
252 (fCurrentCrate->Boards()->At(fCurrentLocalBoard));
254 ++fCurrentLocalBoard;
259 //_____________________________________________________________________________
261 AliMUONTriggerCrateStore::NumberOfCrates() const
263 /// Number of crates we're holding
264 if ( fCrates ) return fCrates->GetSize();
268 //_____________________________________________________________________________
270 AliMUONTriggerCrateStore::NumberOfLocalBoards() const
272 /// Number of local boards we're holding
273 if ( fLocalBoards ) return fLocalBoards->GetSize();
277 //_____________________________________________________________________________
279 AliMUONTriggerCrateStore::ReadFromFile(const char* /*file*/) // keep old name for the moment
281 /// create crate and local board objects from mapping (Ch.F)
282 fCrates = new AliMpExMap(kTRUE);
283 fCrates->SetOwner(kTRUE);
284 fLocalBoards = new AliMpExMap(kTRUE);
285 fLocalBoards->SetOwner(kFALSE);
287 TExMapIter itr = AliMpDDLStore::Instance()->GetTriggerCrateItr();
291 while(itr.Next(key, value))
293 AliMpTriggerCrate* crateMapping = reinterpret_cast<AliMpTriggerCrate*>(value);
295 TString crateName = crateMapping->GetName();
296 AliMUONTriggerCrate *crate = Crate(crateName.Data());
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);
307 for(Int_t iLocal = 0; iLocal < crateMapping->GetNofLocalBoards(); ++iLocal) {
309 Int_t localBoardId = crateMapping->GetLocalBoardId(iLocal);
310 if (!localBoardId) continue; //empty slot, should not happen
312 AliMpLocalBoard* localBoardMapping = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
313 AliDebug(3, Form("local name %s id %d\n", localBoardMapping->GetName(), localBoardId));
315 Int_t slot = localBoardMapping->GetSlot();
316 AliMUONLocalTriggerBoard *board =
317 new AliMUONLocalTriggerBoard(localBoardMapping);
319 if (localBoardMapping->IsNotified()) {
320 fLocalBoards->Add(localBoardId, board);
323 crate->AddBoard(board, slot);