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