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"
23 #include "AliMpExMap.h"
27 #include "Riostream.h"
30 /// \class AliMUONTriggerCrateStore
32 /// A container of trigger crate objects that offers iteration
33 /// over both the crates themselves and the local boards they contain
35 /// \author Laurent Aphecetche
38 ClassImp(AliMUONTriggerCrateStore)
41 //_____________________________________________________________________________
42 AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
49 fCurrentLocalBoard(-1)
51 /// Default constructor
54 //_____________________________________________________________________________
55 AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
58 delete fCrateIterator;
64 //_____________________________________________________________________________
66 AliMUONTriggerCrateStore::AddCrate(const char *name)
68 /// create and add a crate to our map
71 AliError("Object not properly initialized");
75 AliDebug(1,Form("Adding crate %s",name));
76 TObject* there = fCrates->GetValue(name);
79 AliError(Form("Cannot add crate %s because it's already there !",name));
83 fCrates->Add(name,new AliMUONTriggerCrate(name,17));
87 //_____________________________________________________________________________
88 AliMUONLocalTriggerBoard*
89 AliMUONTriggerCrateStore::LocalBoard(Int_t boardNumber) const
91 /// return a board by number
95 AliError("Object not properly initialized");
99 return static_cast<AliMUONLocalTriggerBoard*>(fLocalBoards->GetValue(boardNumber));
102 //_____________________________________________________________________________
104 AliMUONTriggerCrateStore::Crate(const char *name) const
106 /// return a crate by name
109 AliError("Object not properly initialized");
112 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
115 //_____________________________________________________________________________
117 AliMUONTriggerCrateStore::Crate(Int_t ddl, Int_t reg) const
119 /// return a crate by name
122 AliError("Object not properly initialized");
125 TString name = GetCrateName(ddl, reg);
126 return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name.Data()));
128 // //____________________________________________________________________
129 TString AliMUONTriggerCrateStore::GetCrateName(Int_t ddl, Int_t reg) const
131 // set crate name from DDL & reg number
137 sprintf(name,"%d", reg+1);
147 sprintf(name,"%d", reg);
151 // crate Right for first DDL
157 return TString(name);
159 //_____________________________________________________________________________
161 AliMUONTriggerCrateStore::FirstCrate()
163 /// initialize iteration
166 AliError("Object not properly initialized");
171 fCrateIterator = new TExMapIter(fCrates->GetIterator());
173 fCrateIterator->Reset();
176 //_____________________________________________________________________________
178 AliMUONTriggerCrateStore::FirstLocalBoard()
180 /// Initialize iterator on local boards.
181 /// Please note that we're not using directly the FirstCrate() and
182 /// NextCrate() methods here to avoid mix and match between crate iterator
183 /// and local board iterator
185 fCurrentLocalBoard = 0;
189 fLBIterator = new TExMapIter(fCrates->GetIterator());
191 fLBIterator->Reset();
193 Bool_t ok = fLBIterator->Next(key,value);
196 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
197 fCurrentLocalBoard = 1;
201 //_____________________________________________________________________________
203 AliMUONTriggerCrateStore::NextCrate()
205 /// Return the next crate in iteration, or 0 if iteration is ended.
206 if (!fCrateIterator) return 0x0;
209 Bool_t ok = fCrateIterator->Next(key,value);
212 return reinterpret_cast<AliMUONTriggerCrate*>(value);
220 //_____________________________________________________________________________
221 AliMUONLocalTriggerBoard*
222 AliMUONTriggerCrateStore::NextLocalBoard()
224 /// Return the next local board in iteration, or 0 if iteration is ended.
225 if ( !fLBIterator ) return 0x0;
227 if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() +1)
228 // if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() )
230 // try to go to next crate, if some are left
232 Bool_t ok = fLBIterator->Next(key,value);
235 fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
236 fCurrentLocalBoard = 1;
240 fCurrentLocalBoard = 0;
245 AliMUONLocalTriggerBoard* lb = static_cast<AliMUONLocalTriggerBoard*>
246 (fCurrentCrate->Boards()->At(fCurrentLocalBoard));
248 ++fCurrentLocalBoard;
253 //_____________________________________________________________________________
255 AliMUONTriggerCrateStore::NumberOfCrates() const
257 /// Number of crates we're holding
258 if ( fCrates ) return fCrates->GetSize();
262 //_____________________________________________________________________________
264 AliMUONTriggerCrateStore::NumberOfLocalBoards() const
266 /// Number of local boards we're holding
267 if ( fLocalBoards ) return fLocalBoards->GetSize();
271 //_____________________________________________________________________________
273 AliMUONTriggerCrateStore::ReadFromFile(const char* file)
275 /// Read crate and local board information from file.
276 fCrates = new AliMpExMap(kTRUE);
277 fLocalBoards = new AliMpExMap(kFALSE);
279 ifstream myInputFile(gSystem->ExpandPathName(file), ios::in);
281 string sLine, sValue;
285 AliError("TRIGGER ELECTRONICS CONFIGURATION FILE COULD NOT BE OPENED");
289 while (getline(myInputFile,sLine))
291 if (sLine.empty()) continue; // Ignore empty lines
294 const Int_t kMaxfields = 15; char **fields = new char*[kMaxfields];
298 if (sLine.find("Board",0) != string::npos)
300 strcpy(s,sLine.c_str());
304 for (char *token = strtok(s, " ");
306 token = strtok(NULL, " "))
308 fields[numlines] = new char[strlen(token)+1];
309 strcpy(fields[numlines++],token);
312 char str[10]; strcpy(str, fields[6]); strcat(str, fields[7]);
314 AliMUONTriggerCrate *crate = Crate(str);
318 AddCrate(str); crate = Crate(str);
320 AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
321 crate->AddBoard(rboard, 0);
324 // CONVENTION: SLOT 0 HOLDS THE REGIONAL BOARD
325 Int_t sl = atoi(fields[10]);
327 // AliMUONTriggerLut* lut = calibData->TriggerLut();
329 AliMUONLocalTriggerBoard *board =
330 new AliMUONLocalTriggerBoard(fields[4], sl, 0x0);
332 if (strcmp(fields[1],"nn"))
334 Int_t sboard = atoi(fields[1]);
336 board->SetNumber(sboard);
337 fLocalBoards->Add(sboard,board);
339 // fCrateMap[sboard-1] = new char[strlen(str)+1]; strcpy(fCrateMap[sboard-1], str);
340 // fBoardMap[sboard-1] = sl;
343 board->SetCrate(str);
345 crate->AddBoard(board, sl);
347 while (getline(myInputFile,sLine)) if (sLine.find("transv",0) != string::npos) break;
349 strcpy(s,sLine.c_str());
351 for (char *token = strtok(s, " ");
353 token = strtok(NULL, " ")) if (!strcmp(token,"NONE")) board->SetTC(kFALSE);
355 while (getline(myInputFile,sLine)) if (sLine.find("Switch",0) != string::npos) break;
357 while (getline(myInputFile,sLine)) if (!sLine.empty()) break;
359 strcpy(s,sLine.c_str());
363 for (char *token = strtok(s, " ");
365 token = strtok(NULL, " ")) board->SetSwitch(lines++, atoi(token));
367 for (Int_t i = 0; i<numlines; i++)
368 if (fields[i]) {delete [] fields[i]; fields[i] = 0;}
370 delete [] fields; fields = 0;