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 //-----------------------------------------------------------------------------
36 /// \class AliMUONTriggerCrateStore
38 /// A container of trigger crate objects that offers iteration
39 /// over both the crates themselves and the local boards they contain
41 /// \author Laurent Aphecetche
42 //-----------------------------------------------------------------------------
45 ClassImp(AliMUONTriggerCrateStore)
48 //_____________________________________________________________________________
49 AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
56 fCurrentLocalBoard(-1)
58 /// Default constructor
61 //_____________________________________________________________________________
62 AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
65 delete fCrateIterator;
71 //_____________________________________________________________________________
73 AliMUONTriggerCrateStore::AddCrate(const char *name)
75 /// create and add a crate to our map
78 AliError("Object not properly initialized");
82 AliDebug(1,Form("Adding crate %s",name));
83 TObject* there = fCrates->GetValue(name);
86 AliError(Form("Cannot add crate %s because it's already there !",name));
90 fCrates->Add(name,new AliMUONTriggerCrate(name,17));
94 //_____________________________________________________________________________
95 AliMUONLocalTriggerBoard*
96 AliMUONTriggerCrateStore::LocalBoard(Int_t boardNumber) const
98 /// return a board by number
102 AliError("Object not properly initialized");
106 return static_cast<AliMUONLocalTriggerBoard*>(fLocalBoards->GetValue(boardNumber));
109 //_____________________________________________________________________________
111 AliMUONTriggerCrateStore::Crate(const char *name) const
113 /// return a crate by name
116 AliError("Object not properly initialized");
119 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
122 // to be removed once AliMUONDigitMaker is linked with new mapping
123 //_____________________________________________________________________________
125 AliMUONTriggerCrateStore::Crate(Int_t ddl, Int_t reg) const
127 /// return a crate by name
130 AliError("Object not properly initialized");
133 TString name = GetCrateName(ddl, reg);
134 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name.Data()));
136 //____________________________________________________________________
137 TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
139 /// set crate name from DDL & reg number
145 sprintf(name,"%d", reg+1);
155 sprintf(name,"%d", reg);
159 // crate Right for first DDL
165 return TString(name);
167 //_____________________________________________________________________________
169 AliMUONTriggerCrateStore::FirstCrate()
171 /// initialize iteration
174 AliError("Object not properly initialized");
179 fCrateIterator = new TExMapIter(fCrates->GetIterator());
181 fCrateIterator->Reset();
184 //_____________________________________________________________________________
186 AliMUONTriggerCrateStore::FirstLocalBoard()
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
193 fCurrentLocalBoard = 0;
197 fLBIterator = new TExMapIter(fCrates->GetIterator());
199 fLBIterator->Reset();
201 Bool_t ok = fLBIterator->Next(key,value);
204 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
205 fCurrentLocalBoard = 1;
209 //_____________________________________________________________________________
211 AliMUONTriggerCrateStore::NextCrate()
213 /// Return the next crate in iteration, or 0 if iteration is ended.
214 if (!fCrateIterator) return 0x0;
217 Bool_t ok = fCrateIterator->Next(key,value);
220 return reinterpret_cast<AliMUONTriggerCrate*>(value);
228 //_____________________________________________________________________________
229 AliMUONLocalTriggerBoard*
230 AliMUONTriggerCrateStore::NextLocalBoard()
232 /// Return the next local board in iteration, or 0 if iteration is ended.
233 if ( !fLBIterator ) return 0x0;
235 if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() +1)
236 // if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() )
238 // try to go to next crate, if some are left
240 Bool_t ok = fLBIterator->Next(key,value);
243 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
244 fCurrentLocalBoard = 1;
248 fCurrentLocalBoard = 0;
253 AliMUONLocalTriggerBoard* lb = static_cast<AliMUONLocalTriggerBoard*>
254 (fCurrentCrate->Boards()->At(fCurrentLocalBoard));
256 ++fCurrentLocalBoard;
261 //_____________________________________________________________________________
263 AliMUONTriggerCrateStore::NumberOfCrates() const
265 /// Number of crates we're holding
266 if ( fCrates ) return fCrates->GetSize();
270 //_____________________________________________________________________________
272 AliMUONTriggerCrateStore::NumberOfLocalBoards() const
274 /// Number of local boards we're holding
275 if ( fLocalBoards ) return fLocalBoards->GetSize();
279 //_____________________________________________________________________________
281 AliMUONTriggerCrateStore::ReadFromFile(const char* /*file*/) // keep old name for the moment
283 /// create crate and local board objects from mapping (Ch.F)
284 fCrates = new AliMpExMap(kTRUE);
285 fCrates->SetOwner(kTRUE);
286 fLocalBoards = new AliMpExMap(kTRUE);
287 fLocalBoards->SetOwner(kFALSE);
289 TExMapIter itr = AliMpDDLStore::Instance()->GetTriggerCrateItr();
293 while(itr.Next(key, value))
295 AliMpTriggerCrate* crateMapping = reinterpret_cast<AliMpTriggerCrate*>(value);
297 TString crateName = crateMapping->GetName();
298 AliMUONTriggerCrate *crate = Crate(crateName.Data());
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);
309 for(Int_t iLocal = 0; iLocal < crateMapping->GetNofLocalBoards(); ++iLocal) {
311 Int_t localBoardId = crateMapping->GetLocalBoardId(iLocal);
312 if (!localBoardId) continue; //empty slot, should not happen
314 AliMpLocalBoard* localBoardMapping = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
315 AliDebug(3, Form("local name %s id %d\n", localBoardMapping->GetName(), localBoardId));
317 Int_t slot = localBoardMapping->GetSlot();
318 AliMUONLocalTriggerBoard *board =
319 new AliMUONLocalTriggerBoard(localBoardMapping);
321 if (localBoardMapping->IsNotified()) {
322 fLocalBoards->Add(localBoardId, board);
325 crate->AddBoard(board, slot);