Line data Source code
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 : // $MpId: AliMpTrigger.cxx,v 1.4 2006/05/24 13:58:52 ivana Exp $
18 :
19 : //-----------------------------------------------------------------------------
20 : // Class AliMUONGlobalCrateConfig
21 : // --------------------
22 : // The class defines the configuration of trigger crate
23 : // Author: Ch. Finck, Subatech Nantes
24 : //-----------------------------------------------------------------------------
25 :
26 : #include "AliMUONGlobalCrateConfig.h"
27 : #include "AliMpConstants.h"
28 : #include "AliMpFiles.h"
29 : #include "AliMpHelper.h"
30 :
31 : #include "AliLog.h"
32 :
33 : #include <TArrayI.h>
34 : #include <Riostream.h>
35 : #include <TSystem.h>
36 :
37 : using std::ifstream;
38 : using std::endl;
39 : using std::ios;
40 : /// \cond CLASSIMP
41 18 : ClassImp(AliMUONGlobalCrateConfig)
42 : /// \endcond
43 :
44 : const Char_t* AliMUONGlobalCrateConfig::fgkJtagName = "JtagBoard";
45 : const Char_t* AliMUONGlobalCrateConfig::fgkFirstDarcName = "LeftDarcBoard";
46 : const Char_t* AliMUONGlobalCrateConfig::fgkSecondDarcName = "RightDarcBoard";
47 : const Char_t* AliMUONGlobalCrateConfig::fgkGlobalName = "GlobalBoard";
48 : const Char_t* AliMUONGlobalCrateConfig::fgkFetName = "FetBoard";
49 :
50 : const Int_t AliMUONGlobalCrateConfig::fgkGlobalNofRegisters = 13;
51 : const Int_t AliMUONGlobalCrateConfig::fgkFetNofRegisters = 7;
52 : const Int_t AliMUONGlobalCrateConfig::fgkJtagNofLines = 4;
53 : const Int_t AliMUONGlobalCrateConfig::fgkDarcNofLines = 8;
54 : //______________________________________________________________________________
55 : AliMUONGlobalCrateConfig::AliMUONGlobalCrateConfig()
56 3 : : TNamed("GlobalCrate", "mapping trigger global crate"),
57 3 : fGlobalCrateEnable(0x0),
58 3 : fJtagVmeAddr(0x0),
59 3 : fJtagClockDiv(0),
60 3 : fJtagRxPhase(0),
61 3 : fJtagRdDelay(0),
62 3 : fEnableJtag(0),
63 99 : fJtagCrateName(),
64 51 : fFirstDarcCrateName(),
65 51 : fSecondDarcCrateName(),
66 3 : fFirstDarcVmeAddr(0x0),
67 3 : fFirstDarcType(0),
68 3 : fFirstDarcDisable(0),
69 3 : fFirstDarcL0Delay(0),
70 3 : fFirstDarcL1TimeOut(0),
71 3 : fFirstDarcGlobalL0(0),
72 3 : fFirstDarcConfig(0),
73 3 : fSecondDarcVmeAddr(0x0),
74 3 : fSecondDarcType(0),
75 3 : fSecondDarcDisable(0),
76 3 : fSecondDarcL0Delay(0),
77 3 : fSecondDarcL1TimeOut(0),
78 3 : fSecondDarcGlobalL0(0),
79 3 : fSecondDarcConfig(0),
80 3 : fGlobalVmeAddr(0x0),
81 3 : fFetVmeAddr(0x0),
82 3 : fEnableFirstDarc(0),
83 3 : fEnableSecondDarc(0)
84 15 : {
85 : /// Standard constructor
86 :
87 84 : for (Int_t i = 0; i < fgkGlobalNofRegisters; ++i)
88 39 : fGlobalRegisters[i] = 0;
89 :
90 48 : for (Int_t j = 0; j < fgkFetNofRegisters; ++j)
91 21 : fFetRegisters[j] = 0;
92 6 : }
93 :
94 : //______________________________________________________________________________
95 : AliMUONGlobalCrateConfig::~AliMUONGlobalCrateConfig()
96 0 : {
97 : /// Destructor
98 0 : }
99 :
100 : //______________________________________________________________________________
101 : Int_t AliMUONGlobalCrateConfig::ReadData(const TString& fileName)
102 : {
103 : /// Fill trigger global crate object from ascii file
104 : /// put the method static to be used by other class w/o initializing object
105 :
106 0 : TString inFileName(fileName);
107 0 : if ( inFileName == "" )
108 0 : inFileName = AliMpFiles::GlobalTriggerBoardMapping();
109 :
110 0 : inFileName = gSystem->ExpandPathName(inFileName.Data());
111 :
112 0 : ifstream in(inFileName.Data(), ios::in);
113 :
114 0 : if (!in) {
115 0 : AliErrorStream()
116 0 : << "Global Trigger Board Mapping File " << fileName.Data() << " not found" << endl;
117 0 : return kFALSE;
118 : }
119 :
120 : Int_t nDarc = 0;
121 :
122 0 : ULong_t addr;
123 0 : UInt_t item;
124 0 : TArrayI list;
125 : Bool_t oldFormat = kFALSE;
126 :
127 0 : char line[255];
128 0 : in.getline(line, 255);
129 0 : TString tmp(AliMpHelper::Normalize(line));
130 :
131 0 : if (!tmp.Contains(GetName()))
132 0 : AliWarning("Wrong Global Crate File");
133 :
134 : // enable
135 0 : in.getline(line, 255);
136 0 : tmp = AliMpHelper::Normalize(line);
137 0 : UInt_t en = 0;
138 0 : sscanf(tmp.Data(), "%x", &en);
139 0 : SetGlobalCrateEnable(en);
140 :
141 0 : in.getline(line, 255);
142 0 : tmp = AliMpHelper::Normalize(line);
143 :
144 0 : if (tmp.Contains(GetJtagName())) {
145 :
146 : // old version, old regional boards
147 :
148 : oldFormat = kTRUE;
149 0 : AliInfo(Form("Old format of global config"));
150 :
151 : } else {
152 :
153 0 : if (tmp.Contains(GetFirstDarcName())) {
154 :
155 : // new version, new regional boards
156 :
157 : oldFormat = kFALSE;
158 0 : AliInfo(Form("New format of global config"));
159 :
160 : }
161 :
162 : }
163 :
164 0 : if (oldFormat) {
165 :
166 : // vme addr
167 0 : in.getline(line, 255);
168 0 : tmp = AliMpHelper::Normalize(line);
169 0 : ULong_t addr;
170 0 : sscanf(tmp.Data(), "%lx", &addr);
171 0 : SetJtagVmeAddr(addr);
172 0 : AliDebug(1, Form("Jtag Vme Address: 0x%lx", addr));
173 :
174 : // clk div, rx phase, read delay
175 0 : in.getline(line, 255);
176 0 : tmp = AliMpHelper::Normalize(line);
177 0 : TArrayI list;
178 0 : AliMpHelper::DecodeName(line, ' ', list);
179 0 : SetJtagClockDiv(list[0]);
180 0 : SetJtagRxPhase(list[1]);
181 0 : SetJtagRdDelay(list[2]);
182 0 : AliDebug(1, Form("Jtag Clock Div: %d, Rx Phase: %d, Read Delay %d", list[0], list[1], list[2]));
183 :
184 : // enable
185 0 : in.getline(line, 255);
186 0 : tmp = AliMpHelper::Normalize(line);
187 0 : AliMpHelper::DecodeName(line, ' ', list);
188 : UChar_t enable = 0;
189 0 : for (Int_t i = 0; i < GetJtagNofLines(); ++i)
190 0 : enable |= (list[i] << i);
191 0 : SetEnableJtag(enable);
192 0 : AliDebug(1, Form("Jtag Enable: 0x%x", enable));
193 :
194 0 : for (Int_t i = 0; i < GetJtagNofLines(); ++i) {
195 0 : in.getline(line, 255);
196 0 : for (Int_t j = 0; j < GetJtagNofLines(); ++j) {
197 0 : in.getline(line, 255);
198 0 : tmp = AliMpHelper::Normalize(line);
199 0 : SetJtagCrateName(i*GetJtagNofLines() + j, tmp);
200 : //AliDebug(1, Form("Jtag Crate Name: %s", tmp.Data()));
201 : }
202 : }
203 :
204 0 : in.getline(line, 255);
205 0 : tmp = AliMpHelper::Normalize(line);
206 :
207 0 : } // end old format
208 :
209 : // vme addr
210 0 : in.getline(line, 255);
211 0 : tmp = AliMpHelper::Normalize(line);
212 0 : sscanf(tmp.Data(), "%lx", &addr);
213 0 : if (addr) nDarc++;
214 0 : SetFirstDarcVmeAddr(addr);
215 0 : AliDebug(1, Form("First Darc Vme Address: 0x%lx", addr));
216 :
217 : // type
218 0 : in.getline(line, 255);
219 0 : tmp = AliMpHelper::Normalize(line);
220 0 : SetFirstDarcType(tmp.Atoi());
221 0 : AliDebug(1, Form("First Darc Type: %d", tmp.Atoi()));
222 :
223 : // disable
224 0 : in.getline(line, 255);
225 0 : tmp = AliMpHelper::Normalize(line);
226 0 : sscanf(tmp.Data(), "%x", &item);
227 0 : SetFirstDarcDisable(item);
228 0 : AliDebug(1, Form("First Darc Disable: 0x%x", item));
229 :
230 : // L0
231 0 : in.getline(line, 255);
232 0 : tmp = AliMpHelper::Normalize(line);
233 0 : sscanf(tmp.Data(), "%x", &item);
234 0 : SetFirstDarcL0Delay(item);
235 0 : AliDebug(1, Form("First Darc L0 Delay: 0x%x", item));
236 :
237 : // L1
238 0 : in.getline(line, 255);
239 0 : tmp = AliMpHelper::Normalize(line);
240 0 : sscanf(tmp.Data(), "%x", &item);
241 0 : SetFirstDarcL1TimeOut(item);
242 0 : AliDebug(1, Form("First Darc L1 Time Out: 0x%x", item));
243 :
244 : // Global L0 delay
245 0 : in.getline(line, 255);
246 0 : tmp = AliMpHelper::Normalize(line);
247 0 : sscanf(tmp.Data(), "%x", &item);
248 0 : SetFirstDarcGlobalL0(item);
249 0 : AliDebug(1, Form("First Darc Global L0 delay: 0x%x", item));
250 :
251 : // Trigger configuration
252 0 : in.getline(line, 255);
253 0 : tmp = AliMpHelper::Normalize(line);
254 0 : sscanf(tmp.Data(), "%x", &item);
255 0 : SetFirstDarcConfig(item);
256 0 : AliDebug(1, Form("First Darc Config: 0x%x", item));
257 :
258 0 : if (!oldFormat) {
259 :
260 : // enable
261 0 : in.getline(line, 255);
262 0 : tmp = AliMpHelper::Normalize(line);
263 0 : AliMpHelper::DecodeName(line, ' ', list);
264 : UChar_t enable = 0;
265 0 : for (Int_t i = 0; i < GetDarcNofLines(); ++i)
266 0 : enable |= (list[i] << i);
267 0 : SetEnableFirstDarc(enable);
268 0 : AliDebug(1, Form("First Darc Enable: 0x%x", enable));
269 :
270 0 : for (Int_t i = 0; i < GetDarcNofLines(); ++i) {
271 0 : in.getline(line, 255);
272 0 : tmp = AliMpHelper::Normalize(line);
273 0 : SetFirstDarcCrateName(i, tmp);
274 : //AliInfo(Form("First Darc Crate Name: %s", tmp.Data()));
275 : }
276 :
277 0 : } // end new format First Darc
278 :
279 0 : in.getline(line, 255);
280 0 : tmp = AliMpHelper::Normalize(line);
281 0 : if (tmp.Contains(GetSecondDarcName())) {
282 :
283 : // vme addr
284 0 : in.getline(line, 255);
285 0 : tmp = AliMpHelper::Normalize(line);
286 0 : sscanf(tmp.Data(), "%lx", &addr);
287 0 : if (addr) nDarc++;
288 0 : SetSecondDarcVmeAddr(addr);
289 0 : AliDebug(1, Form("Second Darc Vme Address: 0x%lx", addr));
290 :
291 : // type
292 0 : in.getline(line, 255);
293 0 : tmp = AliMpHelper::Normalize(line);
294 0 : SetSecondDarcType(tmp.Atoi());
295 0 : AliDebug(1, Form("Second Darc Type: %d", tmp.Atoi()));
296 :
297 : // enable
298 0 : in.getline(line, 255);
299 0 : tmp = AliMpHelper::Normalize(line);
300 0 : sscanf(tmp.Data(), "%x", &item);
301 0 : SetSecondDarcDisable(item);
302 0 : AliDebug(1, Form("Second Darc Disable: 0x%x", item));
303 :
304 : // L0
305 0 : in.getline(line, 255);
306 0 : tmp = AliMpHelper::Normalize(line);
307 0 : sscanf(tmp.Data(), "%x", &item);
308 0 : SetSecondDarcL0Delay(item);
309 0 : AliDebug(1, Form("Second Darc L0 Delay: 0x%x", item));
310 :
311 : // L1
312 0 : in.getline(line, 255);
313 0 : tmp = AliMpHelper::Normalize(line);
314 0 : sscanf(tmp.Data(), "%x", &item);
315 0 : SetSecondDarcL1TimeOut(item);
316 0 : AliDebug(1, Form("Second Darc L1 Time Out: 0x%x", item));
317 :
318 : // Global L0 delay
319 0 : in.getline(line, 255);
320 0 : tmp = AliMpHelper::Normalize(line);
321 0 : sscanf(tmp.Data(), "%x", &item);
322 0 : SetSecondDarcGlobalL0(item);
323 0 : AliDebug(1, Form("Second Darc Global L0 delay: 0x%x", item));
324 :
325 : // Trigger configuration
326 0 : in.getline(line, 255);
327 0 : tmp = AliMpHelper::Normalize(line);
328 0 : sscanf(tmp.Data(), "%x", &item);
329 0 : SetSecondDarcConfig(item);
330 0 : AliDebug(1, Form("Second Darc Config: 0x%x", item));
331 :
332 : } // end Second Darc old and new format
333 :
334 0 : if (!oldFormat) {
335 :
336 : // enable
337 0 : in.getline(line, 255);
338 0 : tmp = AliMpHelper::Normalize(line);
339 0 : AliMpHelper::DecodeName(line, ' ', list);
340 : UChar_t enable = 0;
341 0 : for (Int_t i = 0; i < GetDarcNofLines(); ++i)
342 0 : enable |= (list[i] << i);
343 0 : SetEnableSecondDarc(enable);
344 0 : AliDebug(1, Form("Second Darc Enable: 0x%x", enable));
345 :
346 0 : for (Int_t i = 0; i < GetDarcNofLines(); ++i) {
347 0 : in.getline(line, 255);
348 0 : tmp = AliMpHelper::Normalize(line);
349 0 : SetSecondDarcCrateName(i, tmp);
350 : //AliInfo(Form("Second Darc Crate Name: %s", tmp.Data()));
351 : }
352 :
353 0 : } // end new format Second Darc
354 :
355 0 : in.getline(line, 255);
356 0 : tmp = AliMpHelper::Normalize(line);
357 0 : if (tmp.Contains(GetGlobalName())) {
358 :
359 0 : in.getline(line, 255);
360 0 : tmp = AliMpHelper::Normalize(line);
361 0 : sscanf(tmp.Data(), "%lx", &addr);
362 0 : SetGlobalVmeAddr(addr);
363 0 : AliDebug(1, Form("Global Vme Address: 0x%lx", addr));
364 :
365 0 : for (Int_t i = 0; i < GetGlobalNofRegisters(); ++i) {
366 0 : in.getline(line, 255);
367 0 : tmp = AliMpHelper::Normalize(line);
368 0 : UInt_t reg;
369 0 : sscanf(tmp.Data(), "%x", ®);
370 0 : SetGlobalRegister(i, reg);
371 0 : AliDebug(1, Form("Global Register %d: 0x%x", i, reg));
372 0 : }
373 :
374 0 : } // end Global board old and new format
375 :
376 0 : in.getline(line, 255);
377 0 : tmp = AliMpHelper::Normalize(line);
378 0 : if (tmp.Contains(GetFetName())) {
379 :
380 0 : in.getline(line, 255);
381 0 : tmp = AliMpHelper::Normalize(line);
382 0 : sscanf(tmp.Data(), "%lx", &addr);
383 0 : SetFetVmeAddr(addr);
384 0 : AliDebug(1, Form("Fet Vme Address: 0x%lx", addr));
385 :
386 0 : for (Int_t i = 0; i < GetFetNofRegisters(); ++i) {
387 0 : in.getline(line, 255);
388 0 : tmp = AliMpHelper::Normalize(line);
389 0 : UInt_t reg;
390 0 : sscanf(tmp.Data(), "%x", ®);
391 0 : SetFetRegister(i, reg);
392 0 : AliDebug(1, Form("Fet Register %d: 0x%x", i, reg));
393 0 : }
394 :
395 0 : } // end Fet board old and new format
396 :
397 : return nDarc;
398 0 : }
399 :
400 : //______________________________________________________________________________
401 : Bool_t AliMUONGlobalCrateConfig::GetEnableJtag(Int_t index) const
402 : {
403 : /// returns enable mask for a given Jtag line
404 :
405 0 : if (index > fgkJtagNofLines) {
406 0 : AliWarning("Index size too big for Jtag line");
407 0 : return kFALSE;
408 : }
409 0 : return ((fEnableJtag >> index) & 0x1);
410 :
411 0 : }
412 :
413 : //______________________________________________________________________________
414 : void AliMUONGlobalCrateConfig::SetJtagCrateName(Int_t index, TString name)
415 : {
416 : /// Set Jtag crate name for a given index
417 0 : if (index > AliMpConstants::LocalBoardNofChannels()) {
418 0 : AliWarning("Index size too big for Jtag line");
419 0 : return;
420 : }
421 0 : fJtagCrateName[index] = name;
422 0 : }
423 :
424 : //______________________________________________________________________________
425 : TString AliMUONGlobalCrateConfig::GetJtagCrateName(Int_t jtagLine, Int_t index) const
426 : {
427 : /// Get the crate name for a given line and a given index
428 0 : if (jtagLine > AliMpConstants::LocalBoardNofChannels() || index > AliMpConstants::LocalBoardNofChannels())
429 0 : return "";
430 : else
431 0 : return fJtagCrateName[jtagLine*fgkJtagNofLines + index];
432 0 : }
433 :
434 : //______________________________________________________________________________
435 : Bool_t AliMUONGlobalCrateConfig::GetEnableFirstDarc(Int_t index) const
436 : {
437 : /// returns enable mask for a given First Darc line
438 :
439 0 : if (index >= fgkDarcNofLines) {
440 0 : AliWarning("Index size too big for First Darc line");
441 0 : return kFALSE;
442 : }
443 0 : return ((fEnableFirstDarc >> index) & 0x1);
444 :
445 0 : }
446 :
447 : //______________________________________________________________________________
448 : void AliMUONGlobalCrateConfig::SetFirstDarcCrateName(Int_t index, TString name)
449 : {
450 : /// Set First Darc crate name for a given index
451 0 : if (index >= AliMpConstants::LocalBoardNofChannels()/2) {
452 0 : AliWarning("Index size too big for First Darc line");
453 0 : return;
454 : }
455 0 : fFirstDarcCrateName[index] = name;
456 0 : }
457 :
458 : //______________________________________________________________________________
459 : TString AliMUONGlobalCrateConfig::GetFirstDarcCrateName(Int_t index) const
460 : {
461 : /// Get the First Darc crate name for a given index
462 0 : if (index >= AliMpConstants::LocalBoardNofChannels()/2)
463 0 : return "";
464 : else
465 0 : return fFirstDarcCrateName[index];
466 0 : }
467 :
468 : //______________________________________________________________________________
469 : Bool_t AliMUONGlobalCrateConfig::GetEnableSecondDarc(Int_t index) const
470 : {
471 : /// returns enable mask for a given Second Darc line
472 :
473 0 : if (index >= fgkDarcNofLines) {
474 0 : AliWarning("Index size too big for Second Darc line");
475 0 : return kFALSE;
476 : }
477 0 : return ((fEnableSecondDarc >> index) & 0x1);
478 :
479 0 : }
480 :
481 : //______________________________________________________________________________
482 : void AliMUONGlobalCrateConfig::SetSecondDarcCrateName(Int_t index, TString name)
483 : {
484 : /// Set Second Darc crate name for a given index
485 0 : if (index >= AliMpConstants::LocalBoardNofChannels()/2) {
486 0 : AliWarning("Index size too big for Second Darc line");
487 0 : return;
488 : }
489 0 : fSecondDarcCrateName[index] = name;
490 0 : }
491 :
492 : //______________________________________________________________________________
493 : TString AliMUONGlobalCrateConfig::GetSecondDarcCrateName(Int_t index) const
494 : {
495 : /// Get the Second Darc crate name for a given index
496 0 : if (index >= AliMpConstants::LocalBoardNofChannels()/2)
497 0 : return "";
498 : else
499 0 : return fSecondDarcCrateName[index];
500 0 : }
501 :
502 : //______________________________________________________________________________
503 : UInt_t AliMUONGlobalCrateConfig::GetGlobalRegister(Int_t index) const
504 : {
505 : /// return global register for a given index
506 0 : if (index >= fgkGlobalNofRegisters) {
507 0 : AliWarning("Index size too big for Global Register");
508 0 : return 0;
509 : } else
510 0 : return fGlobalRegisters[index];
511 0 : }
512 :
513 : //______________________________________________________________________________
514 : void AliMUONGlobalCrateConfig::SetGlobalRegister(Int_t index, UInt_t reg)
515 : {
516 : /// set Global register for a given index
517 0 : if (index >= fgkGlobalNofRegisters) {
518 0 : AliWarning("Index size too big for Global Register");
519 0 : return;
520 : }
521 0 : fGlobalRegisters[index] = reg;
522 0 : }
523 :
524 : //______________________________________________________________________________
525 : void AliMUONGlobalCrateConfig::SetGlobalMask(Int_t index, UInt_t mask)
526 : {
527 : /// set one word of the global mask
528 :
529 0 : if (index >= 0 && index < 4) {
530 0 : SetGlobalRegister(index,mask);
531 0 : } else {
532 0 : AliWarning(Form("Check register number of the mask (%d) \n",index));
533 : }
534 :
535 0 : }
536 :
537 : //______________________________________________________________________________
538 : UInt_t AliMUONGlobalCrateConfig::GetGlobalMask(Int_t index) const
539 : {
540 : /// return one word of the global mask
541 48 : if (index >= 0 && index < 4) {
542 24 : return fGlobalRegisters[index];
543 : } else {
544 0 : AliWarning(Form("Check register number of the mask (%d) \n",index));
545 0 : return 0;
546 : }
547 24 : }
548 :
549 : //______________________________________________________________________________
550 : Bool_t AliMUONGlobalCrateConfig::GetMasksOn() const
551 : {
552 : /// indicates if global masks are active on global inputs
553 :
554 : // test 7th lsb
555 0 : if (fGlobalRegisters[4] & 0x40) return kTRUE;
556 :
557 0 : return kFALSE;
558 :
559 0 : }
560 :
561 : //______________________________________________________________________________
562 : UInt_t AliMUONGlobalCrateConfig::GetFetRegister(Int_t index) const
563 : {
564 : /// return global register for a given index
565 0 : if (index >= fgkFetNofRegisters) {
566 0 : AliWarning("Index size too big for Fet Register");
567 0 : return 0;
568 : } else
569 0 : return fFetRegisters[index];
570 0 : }
571 :
572 : //______________________________________________________________________________
573 : void AliMUONGlobalCrateConfig::SetFetRegister(Int_t index, UInt_t reg)
574 : {
575 : /// set Global register for a given index
576 0 : if (index >= fgkFetNofRegisters) {
577 0 : AliWarning("Index size too big for Global Register");
578 0 : return;
579 : }
580 0 : fFetRegisters[index] = reg;
581 0 : }
|