]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTriggerIO.cxx
Setting a dummy number of contributors for the MC primary vertex
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerIO.cxx
CommitLineData
2ab3623b 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
18#include "AliMUONTriggerIO.h"
acdc80b6 19#include "AliMUONTriggerLut.h"
20#include "AliMUONCalibParamNI.h"
21#include "AliMUONVStore.h"
2ab3623b 22
890cc210 23#include "AliMpCDB.h"
5dde41b3 24#include "AliMpHelper.h"
5eff9abc 25#include "AliMpConstants.h"
aed0186b 26#include "AliMpDDL.h"
5dde41b3 27#include "AliMpFiles.h"
2ab3623b 28#include "AliMpDDLStore.h"
5eff9abc 29#include "AliMpLocalBoard.h"
2ab3623b 30#include "AliMpTriggerCrate.h"
92c23b09 31#include "AliMUONGlobalCrateConfig.h"
32#include "AliMUONRegionalTriggerConfig.h"
33#include "AliMUONTriggerCrateConfig.h"
5eff9abc 34
acdc80b6 35#include "AliLog.h"
5eff9abc 36
2ab3623b 37#include <Riostream.h>
38#include <TSystem.h>
39
40/// \class AliMUONTriggerIO
41///
42/// Handles read/write of masks and LUT to/from online files,
43/// to be used by Shuttle and Trigger DA.
44///
5eff9abc 45/// \author Laurent Aphecetche, Christian Finck Subatech
890cc210 46/// \author Bogdan Vulpescu, LPC Clermont-Ferrand
2ab3623b 47
b80faac0 48using std::endl;
49using std::cout;
50using std::ofstream;
2ab3623b 51/// \cond CLASSIMP
52ClassImp(AliMUONTriggerIO)
53/// \endcond
54
92c23b09 55
56const UInt_t AliMUONTriggerIO::fgkLocalLutSize = 1 << 14; // 16384
57
2ab3623b 58//_____________________________________________________________________________
5eff9abc 59AliMUONTriggerIO::AliMUONTriggerIO()
60 : TObject(),
33245d2c 61 fRegionalTrigger()
2ab3623b 62{
63 /// ctor
64}
65
890cc210 66//_____________________________________________________________________________
5eff9abc 67AliMUONTriggerIO::AliMUONTriggerIO(const char* regionalFileToRead)
68 :TObject(),
33245d2c 69 fRegionalTrigger()
890cc210 70{
71 /// ctor
92c23b09 72 ReadRegionalConfig(regionalFileToRead,0);
890cc210 73}
74
2ab3623b 75//_____________________________________________________________________________
76AliMUONTriggerIO::~AliMUONTriggerIO()
77{
78 /// dtor
79}
80
890cc210 81//_____________________________________________________________________________
e26b1a52 82Bool_t
890cc210 83AliMUONTriggerIO::DeCompAddress(UChar_t &ypos, UChar_t &ytri, UChar_t &xdev, UChar_t &xpos,
84 UShort_t address) const
85{
86 /// decompose the 15-bits address
87
88 UChar_t bitsYpos = 4;
89 UChar_t bitsYtri = 1;
90 UChar_t bitsXdev = 5;
91 // UChar_t bitsXpos = 5;
92
93 UShort_t maskYpos = 0x000F; // ...0 00001111
94 UShort_t maskYtri = 0x0001; // ...0 00000001
95 UShort_t maskXdev = 0x001F; // ...0 00011111
96 UShort_t maskXpos = 0x001F; // ...0 00011111
97
98 ypos = address & maskYpos;
99 ytri = (address >> bitsYpos) & maskYtri;
100 xdev = (address >> (bitsYpos+bitsYtri)) & maskXdev;
101 xpos = (address >> (bitsYpos+bitsYtri+bitsXdev)) & maskXpos;
e26b1a52 102
103 // convert deviation format
104 // online: sign 1bit , dev 4bit
105 // sign dev trigger
106 // 0 1-15 mu-
107 // 1 1-15 mu+
108 // 0 0 mu+, mu- infinite momentum (unde)
109 // 1 0 no x-trigger
110 // offline: dev 5bit
111 // sign dev trigger
112 // - 0-14 mu-
113 // - 16-31 mu+
114 // - 15 mu+, mu- infinite momentum (unde)
115
116 Int_t iXdevOff, iXdevOn, iXdev, sign;
117 Bool_t trigx;
118
119 iXdev = xdev;
120
121 iXdevOn = sign = 0;
122 iXdevOn += iXdev & 0x0F;
123 sign += (iXdev >> 4) & 0x01;
124 if (iXdevOn == 0) {
125 if (sign == 0) {
126 iXdevOff = 15;
127 trigx = kTRUE;
128 } else {
129 iXdevOff = 15;
130 trigx = kFALSE;
131 }
132 } else {
133 trigx = kTRUE;
134 if (sign == 0) {
135 iXdevOff = - iXdevOn + 15; // gives range 0-14
136 } else {
137 iXdevOff = + iXdevOn + 15; // gives range 16-30 !
138 }
139 }
140
141 xdev = iXdevOff;
142
143 return trigx;
144
890cc210 145}
146
147//_____________________________________________________________________________
148void
149AliMUONTriggerIO::FillLut(AliMUONTriggerLut& lut,
150 Int_t icirc, UChar_t istripX, UChar_t idev,
151 Int_t lutLpt[16][2], Int_t lutHpt[16][2])
152{
153 /// Fill the LUT histograms
154
155 if (icirc == 0 && istripX == 0 && idev == 0)
156 {
157 AliDebug(1,"Copy board, not filled ...");
158 return;
159 }
160
161 Short_t iLptPlus, iLptMinu, iLptUnde;
162 Short_t iHptPlus, iHptMinu, iHptUnde;
163
164 iLptPlus = iLptMinu = iLptUnde = 0;
165 iHptPlus = iHptMinu = iHptUnde = 0;
166
167 for (Int_t istripY=0; istripY<16; istripY++)
168 {
169 if (lutLpt[istripY][1] == 0 && lutLpt[istripY][0] ==1)
170 iLptMinu=iLptMinu+(1 << istripY);
171 if (lutLpt[istripY][1] == 1 && lutLpt[istripY][0] ==0)
172 iLptPlus=iLptPlus+(1 << istripY);
173 if (lutLpt[istripY][1] == 1 && lutLpt[istripY][0] ==1)
174 iLptUnde=iLptUnde+(1 << istripY);
175
176 if (lutHpt[istripY][1] == 0 && lutHpt[istripY][0] ==1)
177 iHptMinu=iHptMinu+(1 << istripY);
178 if (lutHpt[istripY][1] == 1 && lutHpt[istripY][0] ==0)
179 iHptPlus=iHptPlus+(1 << istripY);
180 if (lutHpt[istripY][1] == 1 && lutHpt[istripY][0] ==1)
181 iHptUnde=iHptUnde+(1 << istripY);
182
183 } // loop on istripY
184
185 lut.SetContent("LptMinu",icirc,istripX,idev,iLptMinu);
186 lut.SetContent("LptUnde",icirc,istripX,idev,iLptUnde);
187 lut.SetContent("LptPlus",icirc,istripX,idev,iLptPlus);
188
e26b1a52 189 lut.SetContent("HptMinu",icirc,istripX,idev,iHptMinu);
190 lut.SetContent("HptUnde",icirc,istripX,idev,iHptUnde);
191 lut.SetContent("HptPlus",icirc,istripX,idev,iHptPlus);
890cc210 192}
193
2ab3623b 194//_____________________________________________________________________________
195Int_t
196AliMUONTriggerIO::ReadLocalMasks(const char* localFile, AliMUONVStore& localMasks) const
197{
198 /// Fills the local masks store from file
199
200 if ( !NofLocalBoards() )
201 {
202 AliError("No local board to read");
203 return 0;
204 }
205
206 FILE* fp = fopen(gSystem->ExpandPathName(localFile),"r");
207 if (!fp)
208 {
209 AliError(Form("Could not read file %s",localFile));
210 return 0;
211 }
212
213 UShort_t maskBuffer[8];
214
5cf57a25 215 Int_t localBoardIndex(0);
630711ed 216
2ab3623b 217 while ( fread ( maskBuffer, 2, 8, fp ) )
218 {
5cf57a25 219 Int_t localBoardId = fRegionalTrigger.LocalBoardId(localBoardIndex);
2ab3623b 220 AliDebug(1,Form("LB %03d X1 %4x X2 %4x X3 %4x X4 %4x "
221 "Y1 %4x Y2 %4x Y3 %4x Y4 %4x",
222 localBoardId,
223 maskBuffer[0],
224 maskBuffer[1],
225 maskBuffer[2],
226 maskBuffer[3],
227 maskBuffer[4],
228 maskBuffer[5],
229 maskBuffer[6],
230 maskBuffer[7]));
231
5cf57a25 232 if ( localBoardId > 0 )
2ab3623b 233 {
234 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,localBoardId,0,0);
5eff9abc 235 for ( Int_t index = 0; index < 8; ++index )
2ab3623b 236 {
5cf57a25 237 localBoard->SetValueAsInt(index,0,maskBuffer[index]);
2ab3623b 238 }
239 localMasks.Add(localBoard);
240 }
5cf57a25 241 else
242 {
243 AliError(Form("Oups. Got localBoardId=%d for index=%d",localBoardId,localBoardIndex));
244 }
2ab3623b 245
5cf57a25 246 ++localBoardIndex;
2ab3623b 247 }
248
5cf57a25 249 if ( localBoardIndex != NofLocalBoards() )
2ab3623b 250 {
251 AliError(Form("Read %d out of %d local boards",
5cf57a25 252 localBoardIndex, NofLocalBoards()));
2ab3623b 253 }
254
255 fclose(fp);
256
5cf57a25 257 return localBoardIndex+1;
2ab3623b 258}
259
890cc210 260//_____________________________________________________________________________
261void
262AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
263 Int_t localBoardId,
264 FILE* flut)
265{
266 /// Read the LUT for one local board from an online file
267
268 UShort_t address;
269
92c23b09 270 UChar_t buffer[fgkLocalLutSize]; // 32768 hpt/lpt addresses divided by two
890cc210 271 UChar_t mask1 = 0xF0;
272 UChar_t mask2 = 0x0F;
e26b1a52 273 UChar_t maskHpt = 0x0C;
274 UChar_t maskLpt = 0x03;
890cc210 275 UChar_t lh, lpt, hpt;
276
277 UChar_t xpos, xdev, ypos, ytri;
278
279 Int_t lutLpt[16][2], lutHpt[16][2];
280
281 Int_t boardnr = localBoardId;
282
283 AliDebug(1,Form("Reading LUT values for local board %d",boardnr));
284
285 Int_t ny = 0;
e26b1a52 286 Bool_t trigx = kFALSE;
890cc210 287
97c4e962 288 // read two lut addresses at once, 32768/2=16384 times
cbcc4fb0 289 if (fread(buffer,fgkLocalLutSize,1,flut) == 0) {
290 AliWarning("Error reading the LUT file");
291 return;
292 }
97c4e962 293
890cc210 294 // create the 32767 addresses for the 4-bits lpt and hpt half-bytes
92c23b09 295 for (UShort_t ilut = 0; ilut < fgkLocalLutSize*2; ilut += 2)
890cc210 296 {
890cc210 297
298 // 1st 4-bits half-byte
299 address = ilut;
97c4e962 300 lh = (buffer[ilut/2] & mask1) >> 4;
890cc210 301
302 // Lpt and Hpt response
e26b1a52 303 hpt = (lh & maskHpt) >> 2;
304 lpt = lh & maskLpt;
890cc210 305
306 // decompose the 15-bits address
e26b1a52 307 trigx = DeCompAddress(ypos,ytri,xdev,xpos,address);
890cc210 308
309 // calculate group of y-strips
e26b1a52 310 if (trigx && (ny < 16))
890cc210 311 {
312 lutLpt[ny][0] = lpt & 1;
313 lutLpt[ny][1] = (lpt & 2) >> 1;
314 lutHpt[ny][0] = hpt & 1;
315 lutHpt[ny][1] = (hpt & 2) >> 1;
316 ny++;
317 if (ny == 16)
318 {
319 ny = 0;
320 // ytri == 1 means no trigger in y-direction
321 if (ytri == 0)
322 {
323 FillLut(lut,boardnr,xpos,xdev,lutLpt,lutHpt);
324 }
325 }
326 }
327
328 // 2nd 4-bits half-byte
329 address = ilut+1;
97c4e962 330 lh = (buffer[ilut/2] & mask2);
890cc210 331
332 // Lpt and Hpt response
e26b1a52 333 hpt = (lh & maskHpt) >> 2;
334 lpt = lh & maskLpt;
890cc210 335
336 // decompose the 15-bits address
e26b1a52 337 trigx = DeCompAddress(ypos,ytri,xdev,xpos,address);
890cc210 338
339 // calculate group of y-strips
e26b1a52 340 if (trigx && (ny < 16))
890cc210 341 {
342 lutLpt[ny][0] = lpt & 1;
343 lutLpt[ny][1] = (lpt & 2) >> 1;
344 lutHpt[ny][0] = hpt & 1;
345 lutHpt[ny][1] = (hpt & 2) >> 1;
346 ny++;
347 if (ny == 16)
348 {
349 ny = 0;
350 // ytri == 1 means no trigger in y-direction
351 if (ytri == 0)
352 {
353 FillLut(lut,boardnr,xpos,xdev,lutLpt,lutHpt);
354 }
355 }
356 }
357 }
358}
359
360//_____________________________________________________________________________
361Bool_t
362AliMUONTriggerIO::ReadLUT(const char* lutFileToRead, AliMUONTriggerLut& lut)
363{
364 /// Fill the LUT object from online file
365
366 if ( !NofLocalBoards() )
367 {
368 AliError("No local board id defined. Must read a regional file first");
369 return kFALSE;
370 }
371
372 FILE* flut = fopen(gSystem->ExpandPathName(lutFileToRead),"rb");
373 if (!flut)
374 {
ca6cee23 375 AliError(Form("Could not read LUT file %s",lutFileToRead));
890cc210 376 return kFALSE;
377 }
378
379 for ( Int_t i = 0; i < NofLocalBoards(); ++i )
380 {
630711ed 381 ReadLocalLUT(lut,fRegionalTrigger.LocalBoardId(i),flut);
890cc210 382 }
383
b0ac3c26 384 //
385 // 1st/2nd cut code pt cut [GeV/c]
386 //
387 // 0 0.5 (a.k.a. Apt)
388 // 1 1.0 (a.k.a. Lpt)
389 // 2 1.7 (a.k.a. Hpt)
390 // 3 4.2 (a.k.a. infinity)
391 // 4 free
392 // .
393 // .
394 // .
395 //15 default (for backward compatibility)
396
397 UChar_t lutCode = 0xFF;
398
399 if (!fread(&lutCode,1,1,flut)) {
400 AliWarning("No LUT info in the file (old version)");
401 }
402 AliInfo(Form("LUT code: 0x%02x",lutCode));
403
890cc210 404 fclose(flut);
b0ac3c26 405
406 lut.SetLutCode(lutCode);
407
890cc210 408 return kTRUE;
409
410}
411
2ab3623b 412//_____________________________________________________________________________
413Bool_t
92c23b09 414AliMUONTriggerIO::ReadConfig(const char* localFile,
11ee2085 415 const char* regionalFile,
416 const char* globalFile,
417 AliMUONVStore* localMasks,
418 AliMUONRegionalTriggerConfig* regionalConfig,
419 AliMUONGlobalCrateConfig* globalConfig)
2ab3623b 420{
421 /// Fill the various masks store from files
422
5a26af27 423 if ( !regionalConfig || !regionalFile || strlen(regionalFile)==0 )
2ab3623b 424 {
425 AliError("Must have a regional file name to proceeed");
426 return kFALSE;
427 }
428
5cf57a25 429 AliDebug(1,Form("regionalConfig=%p",regionalConfig));
430
92c23b09 431 Int_t nCrates = ReadRegionalConfig(regionalFile, regionalConfig);
113ad708 432
5cf57a25 433 if (!nCrates)
434 {
435 AliError("nCrates=0 !");
436 return kFALSE;
437 }
2ab3623b 438
11ee2085 439 if (localMasks && localFile && strlen(localFile) > 0 )
2ab3623b 440 {
441 Int_t nLocal = ReadLocalMasks(localFile,*localMasks);
442 AliDebug(1,Form("Read masks for %d local boards",nLocal));
443 }
444
92c23b09 445 Int_t nDarc = ReadGlobalConfig(globalFile, globalConfig);
5cf57a25 446 AliDebug(1,Form("Read config for %d DARC boards",nDarc));
5dde41b3 447
448 if (!nDarc) return kFALSE;
449
2ab3623b 450 return kTRUE;
451}
452
92c23b09 453
454
5dde41b3 455//_____________________________________________________________________________
456 Int_t
40a42243 457 AliMUONTriggerIO::ReadGlobalConfig(const char* globalFile, AliMUONGlobalCrateConfig* globalConfig) const
5dde41b3 458{
92c23b09 459 /// read the global crate file
5dde41b3 460 /// the masks are disable bit for each crate, 8 per darc board
461 /// bit value 0 means enable, 1 means disable *
462
463 Int_t nDarc = 0;
92c23b09 464 if ( !(nDarc = globalConfig->ReadData(globalFile)) ) return 0;
5dde41b3 465
466 return nDarc;
467}
468
2ab3623b 469//_____________________________________________________________________________
470Int_t
92c23b09 471AliMUONTriggerIO::ReadRegionalConfig(const char* regionalFile, AliMUONRegionalTriggerConfig* regionalConfig)
2ab3623b 472{
92c23b09 473 /// Read regional file to fill
5cf57a25 474
475 AliDebug(1,Form("regionalConfig=%p",regionalConfig));
476
92c23b09 477 Int_t nCrates = 0;
478 if ( !(nCrates = regionalConfig->ReadData(regionalFile)) ) return 0;
acdc80b6 479
92c23b09 480 // read the mapping file also
481 if ( ! fRegionalTrigger.ReadData(regionalFile) ) return 0;
2ab3623b 482
2ab3623b 483 return nCrates;
484}
890cc210 485
92c23b09 486
890cc210 487//_____________________________________________________________________________
488Bool_t
489AliMUONTriggerIO::WriteLUT(const AliMUONTriggerLut& lut,
490 const char* lutFileToWrite)
491{
492 /// Convert an offline lut into an online (binary) lut file
493
494 if ( !NofLocalBoards() )
495 {
496 AliError("No local board id defined. Must read a regional file first");
497 return kFALSE;
498 }
499
500 FILE* flut = fopen(gSystem->ExpandPathName(lutFileToWrite),"wb");
501 if (!flut)
502 {
503 AliError(Form("Could not create output LUT file %s",lutFileToWrite));
504 return kFALSE;
505 }
506
507 for ( Int_t i = 0; i < NofLocalBoards(); ++i )
508 {
630711ed 509 WriteLocalLUT(lut,fRegionalTrigger.LocalBoardId(i),flut);
890cc210 510 }
511
512 fclose(flut);
513
514 return kTRUE;
515}
516
92c23b09 517
5eff9abc 518//_____________________________________________________________________________
92c23b09 519Bool_t
520AliMUONTriggerIO::WriteConfig(const char* localFile,
5eff9abc 521 const char* regionalFile,
5dde41b3 522 const char* globalFile,
57e2ad1a 523 const AliMUONVStore* localMasks,
92c23b09 524 AliMUONRegionalTriggerConfig* regionalConfig,
525 AliMUONGlobalCrateConfig* globalConfig) const
5eff9abc 526{
92c23b09 527/// write config files
528
5dde41b3 529 Bool_t ok;
79abc6a9 530 ok = WriteLocalMasks(localFile, *localMasks);
92c23b09 531 ok &= WriteRegionalConfig(regionalFile, regionalConfig);
532 ok &= WriteGlobalConfig(globalFile, globalConfig);
5dde41b3 533
534 return ok;
92c23b09 535
536
5dde41b3 537}
5eff9abc 538
92c23b09 539
5dde41b3 540 //_____________________________________________________________________________
541Bool_t
92c23b09 542AliMUONTriggerIO::WriteGlobalConfig(const char* globalFile, AliMUONGlobalCrateConfig* globalConfig) const
5dde41b3 543{
92c23b09 544 /// write global config
5dde41b3 545
546 ofstream out;
547 Int_t disable = 0;
548
549 out.open(globalFile);
550 if (!out.good())
551 {
92c23b09 552 AliError(Form("Could not create output global file %s", globalFile));
5dde41b3 553 return kFALSE;
554 }
555
92c23b09 556 out << globalConfig->GetName() << endl;
41a38dec 557 out << Form("0x%x",globalConfig->GetGlobalCrateEnable()) << endl;
92c23b09 558
5dde41b3 559 // Jtag
92c23b09 560 out << globalConfig->GetJtagName() << endl;
1130977f 561 out << Form("0x%08lx", globalConfig->GetJtagVmeAddr()) << endl;
92c23b09 562 out << Form("%d %d %d", globalConfig->GetJtagClockDiv(),
563 globalConfig->GetJtagRxPhase(), globalConfig->GetJtagRdDelay()) << endl;
5dde41b3 564
92c23b09 565 for (Int_t i = 0; i < globalConfig->GetJtagNofLines(); ++i)
566 out << Form("%d ", globalConfig->GetEnableJtag(i));
5dde41b3 567 out << endl;
568
569
92c23b09 570 for (Int_t i = 0; i < globalConfig->GetJtagNofLines(); ++i)
5dde41b3 571 {
572 out << i << endl;
92c23b09 573 for (Int_t j = 0; j < globalConfig->GetJtagNofLines(); ++j)
574 out << Form(" %s", globalConfig->GetJtagCrateName(i,j).Data()) << endl;
5dde41b3 575 }
576
577 // first darc board
92c23b09 578 out << globalConfig->GetFirstDarcName() << endl;
1130977f 579 out << Form("0x%08lx", globalConfig->GetFirstDarcVmeAddr()) << endl;
92c23b09 580 out << globalConfig->GetFirstDarcType() << endl;
581 disable = globalConfig->GetFirstDarcDisable();
5dde41b3 582 out << Form("0x%02x", disable) << endl;
92c23b09 583 out << Form("0x%x", globalConfig->GetFirstDarcL0Delay()) << endl;
584 out << Form("0x%x", globalConfig->GetFirstDarcL1TimeOut()) << endl;
585 out << Form("0x%x", globalConfig->GetFirstDarcGlobalL0()) << endl;
586 out << Form("0x%x", globalConfig->GetFirstDarcConfig()) << endl;
5dde41b3 587
588 // second darc board
92c23b09 589 out << globalConfig->GetSecondDarcName() << endl;
1130977f 590 out << Form("0x%08lx", globalConfig->GetSecondDarcVmeAddr()) << endl;
92c23b09 591 out << globalConfig->GetSecondDarcType() << endl;
592 disable = globalConfig->GetSecondDarcDisable();
5dde41b3 593 out << Form("0x%02x", disable) << endl;
92c23b09 594 out << Form("0x%x", globalConfig->GetSecondDarcL0Delay()) << endl;
595 out << Form("0x%x", globalConfig->GetSecondDarcL1TimeOut()) << endl;
596 out << Form("0x%x", globalConfig->GetSecondDarcGlobalL0()) << endl;
597 out << Form("0x%x", globalConfig->GetSecondDarcConfig()) << endl;
5dde41b3 598
599 // global board
92c23b09 600 out << globalConfig->GetGlobalName() << endl;
1130977f 601 out << Form("0x%08lx", globalConfig->GetGlobalVmeAddr()) << endl;
92c23b09 602 for (Int_t i = 0; i < globalConfig->GetGlobalNofRegisters(); ++i)
603 out << Form("0x%x", globalConfig->GetGlobalRegister(i)) << endl;
5dde41b3 604
605 // Fet board
92c23b09 606 out << globalConfig->GetFetName() << endl;
1130977f 607 out << Form("0x%08lx", globalConfig->GetFetVmeAddr()) << endl;
92c23b09 608 for (Int_t i = 0; i < globalConfig->GetFetNofRegisters(); ++i)
609 out << Form("0x%x", globalConfig->GetFetRegister(i)) << endl;
5dde41b3 610
611 return kTRUE;
5eff9abc 612}
5dde41b3 613
5eff9abc 614//_____________________________________________________________________________
615Bool_t
92c23b09 616AliMUONTriggerIO::WriteRegionalConfig(const char* regionalFile, AliMUONRegionalTriggerConfig* regionalConfig) const
5eff9abc 617{
618
619 /// write regional mask with the current configuration
5dde41b3 620 /// if regional masks not defined, take the one from current configuration
5eff9abc 621
622 ofstream out;
623 out.open(regionalFile);
5dde41b3 624
5eff9abc 625 if (!out.good())
626 {
627 AliError(Form("Could not create output regional file %s",regionalFile));
628 return kFALSE;
629 }
630
92c23b09 631 Int_t nCrate = fRegionalTrigger.GetNofTriggerCrates();
632 if (!nCrate)
5eff9abc 633 {
92c23b09 634 AliError("Could not write regional no configuration in memory");
635 return kFALSE;
636 }
41a38dec 637
638 Int_t nofDDLs = 0;
639 TString name;
630711ed 640 AliMpTriggerCrate* crate;
41a38dec 641 for (Int_t ddlId = 0; ddlId < 2; ddlId++) // right & left side
92c23b09 642 {
41a38dec 643 for (Int_t crateId = 0; crateId < 8; crateId++) // 8 crates/regional boards for each side.
644 {
645
646 name = AliMpTriggerCrate::GenerateName(crateId, ddlId, nofDDLs);
647
648 crate = fRegionalTrigger.FindTriggerCrate(name, false);
649
650 AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(crate->GetName());
651 if (!crateConfig)
652 {
653 AliError(Form("Cannot find crate %s in CDB", crate->GetName()));
654 return kFALSE;
655 }
656
657 out << crate->GetName() << endl;
658 out << Form("%02x", crate->GetId()) << endl;
659 out << crateConfig->GetMode() << endl;
660 out << crateConfig->GetCoinc() << endl;
661 out << Form("%04x", crateConfig->GetMask()) << endl;
662 out << Form("%02d",crate->GetNofLocalBoards()) << endl;
663
664 for (Int_t iLocal = 0; iLocal < crate->GetNofLocalBoards(); ++iLocal)
665 {
666 Int_t localBoardId = crate->GetLocalBoardId(iLocal);
667
668 AliMpLocalBoard* board = fRegionalTrigger.FindLocalBoard(localBoardId);
669
670 out << Form("%02d ", board->GetSlot())
671 << board->GetName()
672 << Form(" %03d ", localBoardId)
673 << Form("%03x", board->GetSwitch())
674 << endl;
675
676 out << " ";
677
678 if (board->IsNotified()) {
679 for (Int_t i = 0; i < board->GetNofDEs(); ++i)
680 out << Form("%4d ", board->GetDEId(i));
681 } else {
682 out << Form("%4d ", 0);
683 }
684 out << endl;
685
686 // print copy card numbers & TC
687 out << Form(" %4d %4d", board->GetInputXfrom(), board->GetInputXto());
688 out << Form(" %4d %4d", board->GetInputYfrom(), board->GetInputYto());
689 out << Form(" %4d", board->GetTC()) << endl;
690 }
691 }
92c23b09 692 }
693
5eff9abc 694 out.close();
695
696 return kTRUE;
697}
698
92c23b09 699
5eff9abc 700//_____________________________________________________________________________
701Bool_t
57e2ad1a 702AliMUONTriggerIO::WriteLocalMasks(const char* localFile, const AliMUONVStore& localMasks) const
5eff9abc 703{
704 /// write local mask
705 /// removing/adding enable for a local board need a update of the configuration
706 /// before calling this method
707 /// mask are written for all boards including the copy card (Ch.F.)
708
709 FILE* fp = fopen(gSystem->ExpandPathName(localFile),"wb");
710 if (!fp)
711 {
712 AliError(Form("Could not create output local file %s",localFile));
713 return kFALSE;
714 }
715
716 UShort_t maskBuffer[8];
42a52f7b 717 Int_t localBoardIndex(0);
718 while (localBoardIndex < NofLocalBoards()) {
5eff9abc 719
42a52f7b 720 Int_t localBoardId = fRegionalTrigger.LocalBoardId(localBoardIndex);
5eff9abc 721
42a52f7b 722 AliMUONVCalibParam* localMask =
723 static_cast<AliMUONVCalibParam*>(localMasks.FindObject(localBoardId));
5eff9abc 724
42a52f7b 725 for (Int_t index = 0; index < 8; ++index)
5eff9abc 726 {
42a52f7b 727 maskBuffer[index] = localMask->ValueAsInt(index,0);
5eff9abc 728 }
42a52f7b 729
730 fwrite ( maskBuffer, 2, 8, fp);
731
732 ++localBoardIndex;
5eff9abc 733
5eff9abc 734 }
735
736 fclose(fp);
737
738 return kTRUE;
739
740}
741
890cc210 742//_____________________________________________________________________________
743void
744AliMUONTriggerIO::WriteLocalLUT(const AliMUONTriggerLut& lut,
745 Int_t localBoardId,
746 FILE* flut)
747{
748 /// loop over the address for the 4-bits lpt and hpt decisions
749
750 const Int_t kMaskYpos = 0x0F;
751 const Int_t kMaskYtri = 0x01;
752 const Int_t kMaskXdev = 0x1F;
753 const Int_t kMaskXpos = 0x1F;
97c4e962 754
92c23b09 755 UChar_t buffer[fgkLocalLutSize]; // 32768 hpt/lpt addresses divided by two
97c4e962 756 Int_t bc = 0;
890cc210 757
92c23b09 758 for (UInt_t i = 0; i < fgkLocalLutSize*2; ++i)
890cc210 759 {
760 Int_t lutLpt[2] = { 0 };
761 Int_t lutHpt[2] = { 0 };
762
763 // decompose address
764 Int_t iYpos = i & kMaskYpos;
765 Int_t iYtri = ( i >> 4 ) & kMaskYtri;
766 Int_t iXdev = ( i >> ( 4 + 1 ) ) & kMaskXdev;
767 Int_t iXpos = ( i >> ( 4 + 1 + 5 ) ) & kMaskXpos;
768
e26b1a52 769 // convert deviation format
770 // online: sign 1bit , dev 4bit
771 // sign dev trigger
772 // 0 1-15 mu-
773 // 1 1-15 mu+
774 // 0 0 mu+, mu- infinite momentum (unde)
775 // 1 0 no x-trigger
776 // offline: dev 5bit
777 // sign dev trigger
778 // - 0-14 mu-
779 // - 16-31 mu+
780 // - 15 mu+, mu- infinite momentum (unde)
781 Int_t iXdevOn = 0;
782 Int_t iXdevOff = 0;
783 Int_t sign = 0;
784 Bool_t trigx = kFALSE;
785 iXdevOn += iXdev & 0x0F;
786 sign += (iXdev >> 4) & 0x01;
787 if (iXdevOn == 0) {
788 if (sign == 0) {
789 iXdevOff = 15;
790 trigx = kTRUE;
791 } else {
792 iXdevOff = 15;
793 trigx = kFALSE;
794 }
795 } else {
796 trigx = kTRUE;
797 if (sign == 0) {
798 iXdevOff = - iXdevOn + 15; // gives range 0-14
799 } else {
800 iXdevOff = + iXdevOn + 15; // gives range 16-30 !
801 }
802 }
803 iXdev = iXdevOff;
804
890cc210 805 // iYtri == 1 means no trigger in y-direction
e26b1a52 806 if (iYtri == 0 && trigx)
890cc210 807 {
808 lut.GetLutOutput(localBoardId,iXpos,iXdev,iYpos,lutLpt,lutHpt);
809 }
810
890cc210 811 // fill byte
812 if (i%2 == 0)
813 {
814 // upper half-byte
97c4e962 815 buffer[bc] = 0;
816 buffer[bc] += lutHpt[1] << 7;
817 buffer[bc] += lutHpt[0] << 6;
818 buffer[bc] += lutLpt[1] << 5;
819 buffer[bc] += lutLpt[0] << 4;
890cc210 820 } else {
821 // lower half-byte
97c4e962 822 buffer[bc] += lutHpt[1] << 3;
823 buffer[bc] += lutHpt[0] << 2;
824 buffer[bc] += lutLpt[1] << 1;
825 buffer[bc] += lutLpt[0] << 0;
826 bc++;
890cc210 827 }
828 }
97c4e962 829 fwrite(&buffer,bc,1,flut);
890cc210 830}
5eff9abc 831
832//_____________________________________________________________________________
acdc80b6 833Int_t
834AliMUONTriggerIO::LocalBoardId(Int_t index) const
835{
836 /// Return the i-th localBoardId, or -1 if index is out of bounds
aed0186b 837
630711ed 838 return fRegionalTrigger.LocalBoardId(index);
aed0186b 839}
113ad708 840
841
842//______________________________________________________________________________
843
844Int_t AliMUONTriggerIO::LocalBoardId(Int_t ddlId, Int_t crateId, Int_t localId) const
845{
846 /// Return local board id from crate and local indexes.
847
848 Int_t nofDDLs = 0;
849 TString name = AliMpTriggerCrate::GenerateName(crateId, ddlId, nofDDLs);
850
851 AliMpTriggerCrate* crate = fRegionalTrigger.FindTriggerCrate(name, false);
852 return crate->GetLocalBoardId(localId);
853}