]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGlobalCrateConfig.cxx
- Fix ratio 44/34 (in AliMUONTriggerQADataMakerRec)
[u/mrichter/AliRoot.git] / MUON / AliMUONGlobalCrateConfig.cxx
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 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 //______________________________________________________________________________
54 AliMUONGlobalCrateConfig::AliMUONGlobalCrateConfig()
55   : TNamed("GlobalCrate", "mapping trigger global crate"),
56     fGlobalCrateEnable(0x0), 
57     fJtagVmeAddr(0x0),
58     fJtagClockDiv(0),
59     fJtagRxPhase(0),
60     fJtagRdDelay(0),
61     fEnableJtag(0),
62     fJtagCrateName(),                  
63     fFirstDarcVmeAddr(0x0),
64     fFirstDarcType(0),
65     fFirstDarcDisable(0),
66     fFirstDarcL0Delay(0),
67     fFirstDarcL1TimeOut(0),
68     fFirstDarcGlobalL0(0),
69     fFirstDarcConfig(0), 
70     fSecondDarcVmeAddr(0x0),
71     fSecondDarcType(0),
72     fSecondDarcDisable(0),
73     fSecondDarcL0Delay(0),
74     fSecondDarcL1TimeOut(0),
75     fSecondDarcGlobalL0(0),
76     fSecondDarcConfig(0),
77     fGlobalVmeAddr(0x0),
78     fFetVmeAddr(0x0)
79 {
80 /// Standard constructor
81
82   for (Int_t i = 0; i < fgkGlobalNofRegisters; ++i)
83     fGlobalRegisters[i] = 0;
84   
85   for (Int_t j = 0; j < fgkFetNofRegisters; ++j)
86     fFetRegisters[j] = 0;
87 }
88
89 //______________________________________________________________________________
90 AliMUONGlobalCrateConfig::~AliMUONGlobalCrateConfig()
91 {
92 /// Destructor
93 }
94
95 //______________________________________________________________________________
96 Int_t AliMUONGlobalCrateConfig::ReadData(const TString& fileName)
97 {
98     /// Fill trigger global crate object from ascii file
99     /// put the method static to be used by other class w/o initializing object
100   
101     TString inFileName(fileName);
102     if ( inFileName == "" )
103       inFileName = AliMpFiles::GlobalTriggerBoardMapping();
104     
105     inFileName = gSystem->ExpandPathName(inFileName.Data());
106
107     ifstream in(inFileName.Data(), ios::in);
108
109     if (!in) {
110       AliErrorStream()
111          << "Global Trigger Board Mapping File " << fileName.Data() << " not found" << endl;
112       return kFALSE;
113     }
114
115     Int_t nDarc = 0;
116
117     char line[255];
118     in.getline(line, 255);
119     TString tmp(AliMpHelper::Normalize(line));
120
121     if (!tmp.Contains(GetName()))
122         AliWarning("Wrong Global Crate File");
123
124     // enable
125     in.getline(line, 255);
126     tmp = AliMpHelper::Normalize(line);
127     UInt_t en = 0;
128     sscanf(tmp.Data(), "%x", &en);
129     SetGlobalCrateEnable(en);
130
131     in.getline(line, 255);
132     tmp = AliMpHelper::Normalize(line);
133     
134     if (tmp.Contains(GetJtagName())) {
135         // vme addr
136         in.getline(line, 255);
137         tmp = AliMpHelper::Normalize(line);
138         ULong_t addr;
139         sscanf(tmp.Data(), "%lx", &addr);
140         SetJtagVmeAddr(addr);
141         AliDebug(1, Form("Jtag Vme Address: 0x%lx", addr));
142
143         // clk div, rx phase, read delay
144         in.getline(line, 255);
145         tmp = AliMpHelper::Normalize(line);
146         TArrayI list;
147         AliMpHelper::DecodeName(line, ' ', list);
148         SetJtagClockDiv(list[0]);
149         SetJtagRxPhase(list[1]);
150         SetJtagRdDelay(list[2]);
151         AliDebug(1, Form("Jtag Clock Div: %d, Rx Phase: %d, Read Delay %d", list[0], list[1], list[2]));
152
153         // enable
154         in.getline(line, 255);
155         tmp = AliMpHelper::Normalize(line);
156         AliMpHelper::DecodeName(line, ' ', list);
157         UChar_t enable = 0;
158         for (Int_t i = 0; i < GetJtagNofLines(); ++i)
159             enable |= (list[i] << i);
160         SetEnableJtag(enable);
161         AliDebug(1, Form("Jtag Enable: 0x%x", enable));
162
163         for (Int_t i = 0; i < GetJtagNofLines(); ++i) {
164             in.getline(line, 255);
165             for (Int_t j = 0; j < GetJtagNofLines(); ++j) {
166                 in.getline(line, 255);
167                 tmp = AliMpHelper::Normalize(line);
168                 SetJtagCrateName(i*GetJtagNofLines() + j, tmp);
169                 //AliDebug(1, Form("Jtag Crate Name: %s", tmp.Data()));
170             }
171         }
172     }
173
174     in.getline(line, 255);
175     tmp = AliMpHelper::Normalize(line);
176     if (tmp.Contains(GetFirstDarcName())) {
177         // vme addr
178         in.getline(line, 255);
179         tmp = AliMpHelper::Normalize(line);
180         ULong_t addr;
181         sscanf(tmp.Data(), "%lx", &addr);
182         if (addr) nDarc++;
183         SetFirstDarcVmeAddr(addr);
184         AliDebug(1, Form("First Darc Vme Address: 0x%lx", addr));
185
186         // type
187         in.getline(line, 255);
188         tmp = AliMpHelper::Normalize(line);
189         SetFirstDarcType(tmp.Atoi());
190         AliDebug(1, Form("First Darc Type: %d", tmp.Atoi()));
191
192         // disable
193         in.getline(line, 255);
194         UInt_t item;
195         tmp = AliMpHelper::Normalize(line);
196         sscanf(tmp.Data(), "%x", &item);
197         SetFirstDarcDisable(item);
198         AliDebug(1, Form("First Darc Disable: 0x%x", item));
199
200         // L0
201         in.getline(line, 255);
202         tmp = AliMpHelper::Normalize(line);
203         sscanf(tmp.Data(), "%x", &item);
204         SetFirstDarcL0Delay(item);
205         AliDebug(1, Form("First Darc L0 Delay: 0x%x", item));
206
207         // L1
208         in.getline(line, 255);
209         tmp = AliMpHelper::Normalize(line);
210         sscanf(tmp.Data(), "%x", &item);
211         SetFirstDarcL1TimeOut(item);
212         AliDebug(1, Form("First Darc L1 Time Out: 0x%x", item));
213         
214         // Global L0 delay
215         in.getline(line, 255);
216         tmp = AliMpHelper::Normalize(line);
217         sscanf(tmp.Data(), "%x", &item);
218         SetFirstDarcGlobalL0(item);
219         AliDebug(1, Form("First Darc Global L0 delay: 0x%x", item));
220         
221         // Trigger configuration
222         in.getline(line, 255);
223         tmp = AliMpHelper::Normalize(line);
224         sscanf(tmp.Data(), "%x", &item);
225         SetFirstDarcConfig(item);
226         AliDebug(1, Form("First Darc Config: 0x%x", item));    
227         
228     }
229
230     in.getline(line, 255);
231     tmp = AliMpHelper::Normalize(line);
232     if (tmp.Contains(GetSecondDarcName())) {
233         // vme addr
234         in.getline(line, 255);
235         tmp = AliMpHelper::Normalize(line);
236         ULong_t addr;
237         sscanf(tmp.Data(), "%lx", &addr);
238         if (addr) nDarc++;
239         SetSecondDarcVmeAddr(addr);
240         AliDebug(1, Form("Second Darc Vme Address: 0x%lx", addr));
241         
242         // type
243         in.getline(line, 255);
244         tmp = AliMpHelper::Normalize(line);
245         SetSecondDarcType(tmp.Atoi());
246         AliDebug(1, Form("Second Darc Type: %d", tmp.Atoi()));
247         
248         // enable
249         in.getline(line, 255);
250         UInt_t item;
251         tmp = AliMpHelper::Normalize(line);
252         sscanf(tmp.Data(), "%x", &item);
253         SetSecondDarcDisable(item);
254         AliDebug(1, Form("Second Darc Disable: 0x%x", item));
255         
256         // L0
257         in.getline(line, 255);
258         tmp = AliMpHelper::Normalize(line);
259         sscanf(tmp.Data(), "%x", &item);
260         SetSecondDarcL0Delay(item);
261         AliDebug(1, Form("Second Darc L0 Delay: 0x%x", item));
262         
263         // L1
264         in.getline(line, 255);
265         tmp = AliMpHelper::Normalize(line);
266         sscanf(tmp.Data(), "%x", &item);
267         SetSecondDarcL1TimeOut(item);
268         AliDebug(1, Form("Second Darc L1 Time Out: 0x%x", item));
269         
270         // Global L0 delay
271         in.getline(line, 255);
272         tmp = AliMpHelper::Normalize(line);
273         sscanf(tmp.Data(), "%x", &item);
274         SetSecondDarcGlobalL0(item);
275         AliDebug(1, Form("Second Darc Global L0 delay: 0x%x", item));
276         
277         // Trigger configuration
278         in.getline(line, 255);
279         tmp = AliMpHelper::Normalize(line);
280         sscanf(tmp.Data(), "%x", &item);
281         SetSecondDarcConfig(item);
282         AliDebug(1, Form("Second Darc Config: 0x%x", item));    
283     }
284
285     in.getline(line, 255);
286     tmp = AliMpHelper::Normalize(line);
287     if (tmp.Contains(GetGlobalName())) {
288         in.getline(line, 255);
289         tmp = AliMpHelper::Normalize(line);
290         ULong_t addr;
291         sscanf(tmp.Data(), "%lx", &addr);
292         SetGlobalVmeAddr(addr);
293         AliDebug(1, Form("Global Vme Address: 0x%lx", addr));
294
295         for (Int_t i = 0; i < GetGlobalNofRegisters(); ++i) {
296             in.getline(line, 255);
297             tmp = AliMpHelper::Normalize(line);
298             UInt_t reg;
299             sscanf(tmp.Data(), "%x", &reg);
300             SetGlobalRegister(i, reg);
301             AliDebug(1, Form("Global Register %d: 0x%x", i, reg));
302         }
303     }
304
305     in.getline(line, 255);
306     tmp = AliMpHelper::Normalize(line);
307     if (tmp.Contains(GetFetName())) {
308         in.getline(line, 255);
309         tmp = AliMpHelper::Normalize(line);
310         ULong_t addr;
311         sscanf(tmp.Data(), "%lx", &addr);
312         SetFetVmeAddr(addr);
313         AliDebug(1, Form("Fet Vme Address: 0x%lx", addr));
314
315         for (Int_t i = 0; i < GetFetNofRegisters(); ++i) {
316             in.getline(line, 255);
317             tmp = AliMpHelper::Normalize(line);
318             UInt_t reg;
319             sscanf(tmp.Data(), "%x", &reg);
320             SetFetRegister(i, reg);
321             AliDebug(1, Form("Fet Register %d: 0x%x", i, reg));
322         }
323     }
324
325     return nDarc;
326 }
327
328 //______________________________________________________________________________
329 Bool_t AliMUONGlobalCrateConfig::GetEnableJtag(Int_t index) const 
330 {
331   /// returns enable mask for a given Jtag line
332
333   if (index > fgkJtagNofLines) {
334     AliWarning("Index size too big for Jtag line");
335     return kFALSE;
336   }
337   return ((fEnableJtag >> index) & 0x1);
338
339 }
340
341 //______________________________________________________________________________
342 void AliMUONGlobalCrateConfig::SetJtagCrateName(Int_t index, TString name) 
343 {
344   /// Get Jtag crate name for a given index 
345   if (index > AliMpConstants::LocalBoardNofChannels()) {
346     AliWarning("Index size too big for Jtag line");
347     return;
348   }                                                 
349   fJtagCrateName[index] = name;
350 }
351
352 //______________________________________________________________________________
353 TString AliMUONGlobalCrateConfig::GetJtagCrateName(Int_t jtagLine, Int_t index) const 
354
355   /// Get the crate name for a given line and a given index 
356   if (jtagLine > AliMpConstants::LocalBoardNofChannels() || index > AliMpConstants::LocalBoardNofChannels())
357     return "";
358   else                                       
359     return fJtagCrateName[jtagLine*fgkJtagNofLines + index];
360 }
361
362 //______________________________________________________________________________
363 UInt_t AliMUONGlobalCrateConfig::GetGlobalRegister(Int_t index) const       
364 {
365   /// return global register for a given index
366   if (index >= fgkGlobalNofRegisters) {
367     AliWarning("Index size too big for Global Register");
368     return 0;
369   } else 
370     return fGlobalRegisters[index];
371 }
372
373 //______________________________________________________________________________
374 void AliMUONGlobalCrateConfig::SetGlobalRegister(Int_t index, UInt_t reg) 
375 {
376   /// set Global register for a given index
377   if (index >= fgkGlobalNofRegisters) {
378     AliWarning("Index size too big for Global Register");
379     return;
380   } 
381   fGlobalRegisters[index] = reg;
382 }
383    
384 //______________________________________________________________________________
385 void AliMUONGlobalCrateConfig::SetGlobalMask(Int_t index, UInt_t mask)  
386 {
387   /// set one word of the global mask
388
389   if (index >= 0 && index < 4) {
390     SetGlobalRegister(index,mask);
391   } else {
392     AliWarning(Form("Check register number of the mask (%d) \n",index));
393   }
394
395 }
396
397 //______________________________________________________________________________
398 UInt_t AliMUONGlobalCrateConfig::GetGlobalMask(Int_t index) const       
399 {
400   /// return one word of the global mask
401   if (index >= 0 && index < 4) {
402     return fGlobalRegisters[index];
403   } else {
404     AliWarning(Form("Check register number of the mask (%d) \n",index));
405     return 0;
406   }
407 }
408
409 //______________________________________________________________________________
410 Bool_t AliMUONGlobalCrateConfig::GetMasksOn() const       
411 {
412   /// indicates if global masks are active on global inputs
413
414   // test 7th lsb
415   if (fGlobalRegisters[4] & 0x40) return kTRUE;
416
417   return kFALSE;
418
419 }
420
421 //______________________________________________________________________________
422 UInt_t AliMUONGlobalCrateConfig::GetFetRegister(Int_t index) const       
423 {
424   /// return global register for a given index
425   if (index >= fgkFetNofRegisters) {
426     AliWarning("Index size too big for Fet Register");
427     return 0;
428   } else 
429     return fFetRegisters[index];
430 }
431
432 //______________________________________________________________________________
433 void AliMUONGlobalCrateConfig::SetFetRegister(Int_t index, UInt_t reg) 
434 {
435   /// set Global register for a given index
436   if (index >= fgkFetNofRegisters) {
437     AliWarning("Index size too big for Global Register");
438     return;
439   } 
440   fFetRegisters[index] = reg;
441 }