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 "AliMUONTriggerIO.h"
19 #include "AliMUONTriggerLut.h"
20 #include "AliMUONCalibParamNI.h"
21 #include "AliMUONVStore.h"
24 #include "AliMpHelper.h"
25 #include "AliMpConstants.h"
27 #include "AliMpFiles.h"
28 #include "AliMpDDLStore.h"
29 #include "AliMpLocalBoard.h"
30 #include "AliMpTriggerCrate.h"
31 #include "AliMUONGlobalCrateConfig.h"
32 #include "AliMUONRegionalTriggerConfig.h"
33 #include "AliMUONTriggerCrateConfig.h"
34 #include "AliMUONTriggerScalers.h"
38 #include <Riostream.h>
40 #include <TClonesArray.h>
42 /// \class AliMUONTriggerIO
44 /// Handles read/write of masks and LUT to/from online files,
45 /// to be used by Shuttle and Trigger DA.
47 /// \author Laurent Aphecetche, Christian Finck Subatech
48 /// \author Bogdan Vulpescu, LPC Clermont-Ferrand
54 ClassImp(AliMUONTriggerIO)
58 const UInt_t AliMUONTriggerIO::fgkLocalLutSize = 1 << 14; // 16384
60 //_____________________________________________________________________________
61 AliMUONTriggerIO::AliMUONTriggerIO()
68 //_____________________________________________________________________________
69 AliMUONTriggerIO::AliMUONTriggerIO(const char* regionalFileToRead)
74 ReadRegionalConfig(regionalFileToRead,0);
77 //_____________________________________________________________________________
78 AliMUONTriggerIO::~AliMUONTriggerIO()
83 //_____________________________________________________________________________
85 AliMUONTriggerIO::DeCompAddress(UChar_t &ypos, UChar_t &ytri, UChar_t &xdev, UChar_t &xpos,
86 UShort_t address) const
88 /// decompose the 15-bits address
93 // UChar_t bitsXpos = 5;
95 UShort_t maskYpos = 0x000F; // ...0 00001111
96 UShort_t maskYtri = 0x0001; // ...0 00000001
97 UShort_t maskXdev = 0x001F; // ...0 00011111
98 UShort_t maskXpos = 0x001F; // ...0 00011111
100 ypos = address & maskYpos;
101 ytri = (address >> bitsYpos) & maskYtri;
102 xdev = (address >> (bitsYpos+bitsYtri)) & maskXdev;
103 xpos = (address >> (bitsYpos+bitsYtri+bitsXdev)) & maskXpos;
105 // convert deviation format
106 // online: sign 1bit , dev 4bit
110 // 0 0 mu+, mu- infinite momentum (unde)
116 // - 15 mu+, mu- infinite momentum (unde)
118 Int_t iXdevOff, iXdevOn, iXdev, sign;
124 iXdevOn += iXdev & 0x0F;
125 sign += (iXdev >> 4) & 0x01;
137 iXdevOff = - iXdevOn + 15; // gives range 0-14
139 iXdevOff = + iXdevOn + 15; // gives range 16-30 !
149 //_____________________________________________________________________________
151 AliMUONTriggerIO::FillLut(AliMUONTriggerLut& lut,
152 Int_t icirc, UChar_t istripX, UChar_t idev,
153 Int_t lutLpt[16][2], Int_t lutHpt[16][2])
155 /// Fill the LUT histograms
157 if (icirc == 0 && istripX == 0 && idev == 0)
159 AliDebug(1,"Copy board, not filled ...");
163 Short_t iLptPlus, iLptMinu, iLptUnde;
164 Short_t iHptPlus, iHptMinu, iHptUnde;
166 iLptPlus = iLptMinu = iLptUnde = 0;
167 iHptPlus = iHptMinu = iHptUnde = 0;
169 for (Int_t istripY=0; istripY<16; istripY++)
171 if (lutLpt[istripY][1] == 0 && lutLpt[istripY][0] ==1)
172 iLptMinu=iLptMinu+(1 << istripY);
173 if (lutLpt[istripY][1] == 1 && lutLpt[istripY][0] ==0)
174 iLptPlus=iLptPlus+(1 << istripY);
175 if (lutLpt[istripY][1] == 1 && lutLpt[istripY][0] ==1)
176 iLptUnde=iLptUnde+(1 << istripY);
178 if (lutHpt[istripY][1] == 0 && lutHpt[istripY][0] ==1)
179 iHptMinu=iHptMinu+(1 << istripY);
180 if (lutHpt[istripY][1] == 1 && lutHpt[istripY][0] ==0)
181 iHptPlus=iHptPlus+(1 << istripY);
182 if (lutHpt[istripY][1] == 1 && lutHpt[istripY][0] ==1)
183 iHptUnde=iHptUnde+(1 << istripY);
187 lut.SetContent("LptMinu",icirc,istripX,idev,iLptMinu);
188 lut.SetContent("LptUnde",icirc,istripX,idev,iLptUnde);
189 lut.SetContent("LptPlus",icirc,istripX,idev,iLptPlus);
191 lut.SetContent("HptMinu",icirc,istripX,idev,iHptMinu);
192 lut.SetContent("HptUnde",icirc,istripX,idev,iHptUnde);
193 lut.SetContent("HptPlus",icirc,istripX,idev,iHptPlus);
196 //_____________________________________________________________________________
198 AliMUONTriggerIO::ReadLocalMasks(const char* localFile, AliMUONVStore& localMasks) const
200 /// Fills the local masks store from file
202 if ( !NofLocalBoards() )
204 AliError("No local board to read");
208 FILE* fp = fopen(gSystem->ExpandPathName(localFile),"r");
211 AliError(Form("Could not read file %s",localFile));
215 UShort_t maskBuffer[8];
217 Int_t localBoardIndex(0);
219 while ( fread ( maskBuffer, 2, 8, fp ) )
221 Int_t localBoardId = fRegionalTrigger.LocalBoardId(localBoardIndex);
222 AliDebug(1,Form("LB %03d X1 %4x X2 %4x X3 %4x X4 %4x "
223 "Y1 %4x Y2 %4x Y3 %4x Y4 %4x",
234 if ( localBoardId > 0 )
236 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,localBoardId,0,0);
237 for ( Int_t index = 0; index < 8; ++index )
239 localBoard->SetValueAsInt(index,0,maskBuffer[index]);
241 localMasks.Add(localBoard);
245 AliError(Form("Oups. Got localBoardId=%d for index=%d",localBoardId,localBoardIndex));
251 if ( localBoardIndex != NofLocalBoards() )
253 AliError(Form("Read %d out of %d local boards",
254 localBoardIndex, NofLocalBoards()));
259 return localBoardIndex+1;
262 //_____________________________________________________________________________
264 AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
268 /// Read the LUT for one local board from an online file
272 UChar_t buffer[fgkLocalLutSize]; // 32768 hpt/lpt addresses divided by two
273 UChar_t mask1 = 0xF0;
274 UChar_t mask2 = 0x0F;
275 UChar_t maskHpt = 0x0C;
276 UChar_t maskLpt = 0x03;
277 UChar_t lh, lpt, hpt;
279 UChar_t xpos, xdev, ypos, ytri;
281 Int_t lutLpt[16][2], lutHpt[16][2];
283 Int_t boardnr = localBoardId;
285 AliDebug(1,Form("Reading LUT values for local board %d",boardnr));
288 Bool_t trigx = kFALSE;
290 // read two lut addresses at once, 32768/2=16384 times
291 if (fread(buffer,fgkLocalLutSize,1,flut) == 0) {
292 AliWarning("Error reading the LUT file");
296 // create the 32767 addresses for the 4-bits lpt and hpt half-bytes
297 for (UShort_t ilut = 0; ilut < fgkLocalLutSize*2; ilut += 2)
300 // 1st 4-bits half-byte
302 lh = (buffer[ilut/2] & mask1) >> 4;
304 // Lpt and Hpt response
305 hpt = (lh & maskHpt) >> 2;
308 // decompose the 15-bits address
309 trigx = DeCompAddress(ypos,ytri,xdev,xpos,address);
311 // calculate group of y-strips
312 if (trigx && (ny < 16))
314 lutLpt[ny][0] = lpt & 1;
315 lutLpt[ny][1] = (lpt & 2) >> 1;
316 lutHpt[ny][0] = hpt & 1;
317 lutHpt[ny][1] = (hpt & 2) >> 1;
322 // ytri == 1 means no trigger in y-direction
325 FillLut(lut,boardnr,xpos,xdev,lutLpt,lutHpt);
330 // 2nd 4-bits half-byte
332 lh = (buffer[ilut/2] & mask2);
334 // Lpt and Hpt response
335 hpt = (lh & maskHpt) >> 2;
338 // decompose the 15-bits address
339 trigx = DeCompAddress(ypos,ytri,xdev,xpos,address);
341 // calculate group of y-strips
342 if (trigx && (ny < 16))
344 lutLpt[ny][0] = lpt & 1;
345 lutLpt[ny][1] = (lpt & 2) >> 1;
346 lutHpt[ny][0] = hpt & 1;
347 lutHpt[ny][1] = (hpt & 2) >> 1;
352 // ytri == 1 means no trigger in y-direction
355 FillLut(lut,boardnr,xpos,xdev,lutLpt,lutHpt);
362 //_____________________________________________________________________________
364 AliMUONTriggerIO::ReadLUT(const char* lutFileToRead, AliMUONTriggerLut& lut)
366 /// Fill the LUT object from online file
368 if ( !NofLocalBoards() )
370 AliError("No local board id defined. Must read a regional file first");
374 FILE* flut = fopen(gSystem->ExpandPathName(lutFileToRead),"rb");
377 AliError(Form("Could not read LUT file %s",lutFileToRead));
381 for ( Int_t i = 0; i < NofLocalBoards(); ++i )
383 ReadLocalLUT(lut,fRegionalTrigger.LocalBoardId(i),flut);
387 // 1st/2nd cut code pt cut [GeV/c]
389 // 0 0.5 (a.k.a. Apt)
390 // 1 1.0 (a.k.a. Lpt)
391 // 2 1.7 (a.k.a. Hpt)
392 // 3 4.2 (a.k.a. infinity)
397 //15 default (for backward compatibility)
399 UChar_t lutCode = 0xFF;
401 if (!fread(&lutCode,1,1,flut)) {
402 AliWarning("No LUT info in the file (old version)");
404 AliInfo(Form("LUT code: 0x%02x",lutCode));
408 lut.SetLutCode(lutCode);
414 //_____________________________________________________________________________
416 AliMUONTriggerIO::ReadTrigScalers(const char* scfile, TClonesArray& scalers) const
418 /// Fill the trigger scalers object from online file
420 FILE* fp = fopen(gSystem->ExpandPathName(scfile),"r");
423 AliError(Form("Could not read file %s",scfile));
430 const Int_t nCathodes = 2;
431 const Int_t nTriChambers = 4;
432 const Int_t nLocBoards = 234;
433 UInt_t locLptScaler[nLocBoards];
434 ULong64_t locStripScaler[nTriChambers][nLocBoards][nCathodes];
435 UInt_t locStripOver[nTriChambers][nLocBoards][nCathodes];
437 const Int_t bufflen =
439 nLocBoards*sizeof(UInt_t)+
440 nLocBoards*nCathodes*nTriChambers*(sizeof(UInt_t)+sizeof(ULong64_t));
441 UChar_t buffer[bufflen];
446 AliInfo(Form("Data buffer length = %d",bufflen));
449 while (fread(buffer,bufflen,1,fp)) {
451 AliMUONTriggerScalers *scaler = new(scalers[isc++]) AliMUONTriggerScalers();
457 bftmpUI = buffer[ibr++]; nCalibEvents |= (bftmpUI << 24);
458 bftmpUI = buffer[ibr++]; nCalibEvents |= (bftmpUI << 16);
459 bftmpUI = buffer[ibr++]; nCalibEvents |= (bftmpUI << 8);
460 bftmpUI = buffer[ibr++]; nCalibEvents |= (bftmpUI << 0);
461 scaler->SetNCalibEvents(nCalibEvents);
463 bftmpUI = buffer[ibr++]; deltaT |= (bftmpUI << 24);
464 bftmpUI = buffer[ibr++]; deltaT |= (bftmpUI << 16);
465 bftmpUI = buffer[ibr++]; deltaT |= (bftmpUI << 8);
466 bftmpUI = buffer[ibr++]; deltaT |= (bftmpUI << 0);
467 scaler->SetDeltaT(deltaT);
468 for (Int_t bit = 0; bit < 6; bit++) {
470 bftmpUI = buffer[ibr++]; glSc[bit] |= (bftmpUI << 24);
471 bftmpUI = buffer[ibr++]; glSc[bit] |= (bftmpUI << 16);
472 bftmpUI = buffer[ibr++]; glSc[bit] |= (bftmpUI << 8);
473 bftmpUI = buffer[ibr++]; glSc[bit] |= (bftmpUI << 0);
474 scaler->SetGloScaler(glSc[bit],bit);
478 for (Int_t iLoc = 0; iLoc < nLocBoards; iLoc++) {
480 locLptScaler[iLoc] = 0;
481 bftmpUI = buffer[ibr++]; locLptScaler[iLoc] |= (bftmpUI << 24);
482 bftmpUI = buffer[ibr++]; locLptScaler[iLoc] |= (bftmpUI << 16);
483 bftmpUI = buffer[ibr++]; locLptScaler[iLoc] |= (bftmpUI << 8);
484 bftmpUI = buffer[ibr++]; locLptScaler[iLoc] |= (bftmpUI << 0);
486 scaler->SetLocScalerLpt(locLptScaler[iLoc],iLoc);
488 for (Int_t iCath = 0; iCath < nCathodes; iCath++) {
489 for (Int_t iCha = 0; iCha < nTriChambers; iCha++) {
491 locStripScaler[iCha][iLoc][iCath] = 0;
492 bftmpUL = buffer[ibr++];
493 locStripScaler[iCha][iLoc][iCath] |= (bftmpUL << 56);
494 bftmpUL = buffer[ibr++];
495 locStripScaler[iCha][iLoc][iCath] |= (bftmpUL << 48);
496 bftmpUL = buffer[ibr++];
497 locStripScaler[iCha][iLoc][iCath] |= (bftmpUL << 40);
498 bftmpUL = buffer[ibr++];
499 locStripScaler[iCha][iLoc][iCath] |= (bftmpUL << 32);
500 bftmpUL = buffer[ibr++];
501 locStripScaler[iCha][iLoc][iCath] |= (bftmpUL << 24);
502 bftmpUL = buffer[ibr++];
503 locStripScaler[iCha][iLoc][iCath] |= (bftmpUL << 16);
504 bftmpUL = buffer[ibr++];
505 locStripScaler[iCha][iLoc][iCath] |= (bftmpUL << 8);
506 bftmpUL = buffer[ibr++];
507 locStripScaler[iCha][iLoc][iCath] |= (bftmpUL << 0);
509 scaler->SetLocScalerStrip(locStripScaler[iCha][iLoc][iCath],iCath,iCha,iLoc);
511 locStripOver[iCha][iLoc][iCath] = 0;
512 bftmpUI = buffer[ibr++];
513 locStripOver[iCha][iLoc][iCath] |= (bftmpUI << 24);
514 bftmpUI = buffer[ibr++];
515 locStripOver[iCha][iLoc][iCath] |= (bftmpUI << 16);
516 bftmpUI = buffer[ibr++];
517 locStripOver[iCha][iLoc][iCath] |= (bftmpUI << 8);
518 bftmpUI = buffer[ibr++];
519 locStripOver[iCha][iLoc][iCath] |= (bftmpUI << 0);
521 scaler->SetLocScalerStripOver(locStripOver[iCha][iLoc][iCath],iCath,iCha,iLoc);
527 //AliInfo("Read from buffer %d bytes",ibr);
537 //_____________________________________________________________________________
539 AliMUONTriggerIO::ReadConfig(const char* localFile,
540 const char* regionalFile,
541 const char* globalFile,
542 AliMUONVStore* localMasks,
543 AliMUONRegionalTriggerConfig* regionalConfig,
544 AliMUONGlobalCrateConfig* globalConfig)
546 /// Fill the various masks store from files
548 if ( !regionalConfig || !regionalFile || strlen(regionalFile)==0 )
550 AliError("Must have a regional file name to proceeed");
554 AliDebug(1,Form("regionalConfig=%p",regionalConfig));
556 Int_t nCrates = ReadRegionalConfig(regionalFile, regionalConfig);
560 AliError("nCrates=0 !");
564 if (localMasks && localFile && strlen(localFile) > 0 )
566 Int_t nLocal = ReadLocalMasks(localFile,*localMasks);
567 AliDebug(1,Form("Read masks for %d local boards",nLocal));
570 Int_t nDarc = ReadGlobalConfig(globalFile, globalConfig);
571 AliDebug(1,Form("Read config for %d DARC boards",nDarc));
573 if (!nDarc) return kFALSE;
580 //_____________________________________________________________________________
582 AliMUONTriggerIO::ReadGlobalConfig(const char* globalFile, AliMUONGlobalCrateConfig* globalConfig) const
584 /// read the global crate file
585 /// the masks are disable bit for each crate, 8 per darc board
586 /// bit value 0 means enable, 1 means disable *
589 if ( !(nDarc = globalConfig->ReadData(globalFile)) ) return 0;
594 //_____________________________________________________________________________
596 AliMUONTriggerIO::ReadRegionalConfig(const char* regionalFile, AliMUONRegionalTriggerConfig* regionalConfig)
598 /// Read regional file to fill
600 AliDebug(1,Form("regionalConfig=%p",regionalConfig));
603 if ( !(nCrates = regionalConfig->ReadData(regionalFile)) ) return 0;
605 // read the mapping file also
606 if ( ! fRegionalTrigger.ReadData(regionalFile) ) return 0;
612 //_____________________________________________________________________________
614 AliMUONTriggerIO::WriteLUT(const AliMUONTriggerLut& lut,
615 const char* lutFileToWrite)
617 /// Convert an offline lut into an online (binary) lut file
619 if ( !NofLocalBoards() )
621 AliError("No local board id defined. Must read a regional file first");
625 FILE* flut = fopen(gSystem->ExpandPathName(lutFileToWrite),"wb");
628 AliError(Form("Could not create output LUT file %s",lutFileToWrite));
632 for ( Int_t i = 0; i < NofLocalBoards(); ++i )
634 WriteLocalLUT(lut,fRegionalTrigger.LocalBoardId(i),flut);
643 //_____________________________________________________________________________
645 AliMUONTriggerIO::WriteTrigScalers(const TClonesArray& scalers,
646 const char* scfile) const
648 /// Convert offline scalers into an online (binary) file
650 FILE* fp = fopen(gSystem->ExpandPathName(scfile),"wb");
653 AliError(Form("Could not create output local file %s",scfile));
660 const Int_t nCathodes = 2;
661 const Int_t nTriChambers = 4;
662 const Int_t nLocBoards = 234;
663 UInt_t locLptScaler[nLocBoards];
664 ULong64_t locStripScaler[nTriChambers][nLocBoards][nCathodes];
665 UInt_t locStripOver[nTriChambers][nLocBoards][nCathodes];
667 const Int_t bufflen =
669 nLocBoards*sizeof(UInt_t)+
670 nLocBoards*nCathodes*nTriChambers*(sizeof(UInt_t)+sizeof(ULong64_t));
671 UChar_t buffer[bufflen];
673 AliInfo(Form("Data buffer length = %d",bufflen));
675 Int_t entries = scalers.GetEntries();
677 for (; isc < entries; isc++) {
679 AliMUONTriggerScalers *sc = (AliMUONTriggerScalers*)scalers.At(isc);
680 nCalibEvents = sc->GetNCalibEvents();
681 AliInfo(Form("nCalibEvents = %d",sc->GetNCalibEvents()));
682 buffer[ibr++] = (nCalibEvents >> 24) & 0xFF;
683 buffer[ibr++] = (nCalibEvents >> 16) & 0xFF;
684 buffer[ibr++] = (nCalibEvents >> 8) & 0xFF;
685 buffer[ibr++] = (nCalibEvents >> 0) & 0xFF;
686 deltaT = sc->GetDeltaT();
687 buffer[ibr++] = (deltaT >> 24) & 0xFF;
688 buffer[ibr++] = (deltaT >> 16) & 0xFF;
689 buffer[ibr++] = (deltaT >> 8) & 0xFF;
690 buffer[ibr++] = (deltaT >> 0) & 0xFF;
691 for (Int_t bit = 0; bit < 6; bit++) {
692 glSc[bit] = sc->GetGloScal(bit);
693 buffer[ibr++] = (glSc[bit] >> 24) & 0xFF;
694 buffer[ibr++] = (glSc[bit] >> 16) & 0xFF;
695 buffer[ibr++] = (glSc[bit] >> 8) & 0xFF;
696 buffer[ibr++] = (glSc[bit] >> 0) & 0xFF;
698 for (Int_t iLoc = 0; iLoc < nLocBoards; iLoc++) {
699 locLptScaler[iLoc] = sc->GetLocScalLpt(iLoc);
700 buffer[ibr++] = (locLptScaler[iLoc] >> 24) & 0xFF;
701 buffer[ibr++] = (locLptScaler[iLoc] >> 16) & 0xFF;
702 buffer[ibr++] = (locLptScaler[iLoc] >> 8) & 0xFF;
703 buffer[ibr++] = (locLptScaler[iLoc] >> 0) & 0xFF;
704 for (Int_t iCath = 0; iCath < nCathodes; iCath++) {
705 for (Int_t iCha = 0; iCha < nTriChambers; iCha++) {
706 locStripScaler[iCath][iCha][iLoc] = sc->GetLocScalStrip(iCath,iCha,iLoc);
707 buffer[ibr++] = (locStripScaler[iCath][iCha][iLoc] >> 56) & 0xFF;
708 buffer[ibr++] = (locStripScaler[iCath][iCha][iLoc] >> 48) & 0xFF;
709 buffer[ibr++] = (locStripScaler[iCath][iCha][iLoc] >> 40) & 0xFF;
710 buffer[ibr++] = (locStripScaler[iCath][iCha][iLoc] >> 32) & 0xFF;
711 buffer[ibr++] = (locStripScaler[iCath][iCha][iLoc] >> 24) & 0xFF;
712 buffer[ibr++] = (locStripScaler[iCath][iCha][iLoc] >> 16) & 0xFF;
713 buffer[ibr++] = (locStripScaler[iCath][iCha][iLoc] >> 8) & 0xFF;
714 buffer[ibr++] = (locStripScaler[iCath][iCha][iLoc] >> 0) & 0xFF;
715 locStripOver[iCath][iCha][iLoc] = sc->GetLocScalStripOver(iCath,iCha,iLoc);
716 buffer[ibr++] = (locStripOver[iCath][iCha][iLoc] >> 24) & 0xFF;
717 buffer[ibr++] = (locStripOver[iCath][iCha][iLoc] >> 16) & 0xFF;
718 buffer[ibr++] = (locStripOver[iCath][iCha][iLoc] >> 8) & 0xFF;
719 buffer[ibr++] = (locStripOver[iCath][iCha][iLoc] >> 0) & 0xFF;
724 fwrite(buffer,ibr,1,fp);
725 //AliInfo("Read to buffer %d bytes",ibr);
735 //_____________________________________________________________________________
737 AliMUONTriggerIO::WriteConfig(const char* localFile,
738 const char* regionalFile,
739 const char* globalFile,
740 const AliMUONVStore* localMasks,
741 AliMUONRegionalTriggerConfig* regionalConfig,
742 AliMUONGlobalCrateConfig* globalConfig) const
744 /// write config files
747 ok = WriteLocalMasks(localFile, *localMasks);
748 ok &= WriteRegionalConfig(regionalFile, regionalConfig);
749 ok &= WriteGlobalConfig(globalFile, globalConfig);
757 //_____________________________________________________________________________
759 AliMUONTriggerIO::WriteGlobalConfig(const char* globalFile, AliMUONGlobalCrateConfig* globalConfig) const
761 /// write global config
766 out.open(globalFile);
769 AliError(Form("Could not create output global file %s", globalFile));
773 out << globalConfig->GetName() << endl;
774 out << Form("0x%x",globalConfig->GetGlobalCrateEnable()) << endl;
777 out << globalConfig->GetJtagName() << endl;
778 out << Form("0x%08lx", globalConfig->GetJtagVmeAddr()) << endl;
779 out << Form("%d %d %d", globalConfig->GetJtagClockDiv(),
780 globalConfig->GetJtagRxPhase(), globalConfig->GetJtagRdDelay()) << endl;
782 for (Int_t i = 0; i < globalConfig->GetJtagNofLines(); ++i)
783 out << Form("%d ", globalConfig->GetEnableJtag(i));
787 for (Int_t i = 0; i < globalConfig->GetJtagNofLines(); ++i)
790 for (Int_t j = 0; j < globalConfig->GetJtagNofLines(); ++j)
791 out << Form(" %s", globalConfig->GetJtagCrateName(i,j).Data()) << endl;
795 out << globalConfig->GetFirstDarcName() << endl;
796 out << Form("0x%08lx", globalConfig->GetFirstDarcVmeAddr()) << endl;
797 out << globalConfig->GetFirstDarcType() << endl;
798 disable = globalConfig->GetFirstDarcDisable();
799 out << Form("0x%02x", disable) << endl;
800 out << Form("0x%x", globalConfig->GetFirstDarcL0Delay()) << endl;
801 out << Form("0x%x", globalConfig->GetFirstDarcL1TimeOut()) << endl;
802 out << Form("0x%x", globalConfig->GetFirstDarcGlobalL0()) << endl;
803 out << Form("0x%x", globalConfig->GetFirstDarcConfig()) << endl;
806 out << globalConfig->GetSecondDarcName() << endl;
807 out << Form("0x%08lx", globalConfig->GetSecondDarcVmeAddr()) << endl;
808 out << globalConfig->GetSecondDarcType() << endl;
809 disable = globalConfig->GetSecondDarcDisable();
810 out << Form("0x%02x", disable) << endl;
811 out << Form("0x%x", globalConfig->GetSecondDarcL0Delay()) << endl;
812 out << Form("0x%x", globalConfig->GetSecondDarcL1TimeOut()) << endl;
813 out << Form("0x%x", globalConfig->GetSecondDarcGlobalL0()) << endl;
814 out << Form("0x%x", globalConfig->GetSecondDarcConfig()) << endl;
817 out << globalConfig->GetGlobalName() << endl;
818 out << Form("0x%08lx", globalConfig->GetGlobalVmeAddr()) << endl;
819 for (Int_t i = 0; i < globalConfig->GetGlobalNofRegisters(); ++i)
820 out << Form("0x%x", globalConfig->GetGlobalRegister(i)) << endl;
823 out << globalConfig->GetFetName() << endl;
824 out << Form("0x%08lx", globalConfig->GetFetVmeAddr()) << endl;
825 for (Int_t i = 0; i < globalConfig->GetFetNofRegisters(); ++i)
826 out << Form("0x%x", globalConfig->GetFetRegister(i)) << endl;
831 //_____________________________________________________________________________
833 AliMUONTriggerIO::WriteRegionalConfig(const char* regionalFile, AliMUONRegionalTriggerConfig* regionalConfig) const
836 /// write regional mask with the current configuration
837 /// if regional masks not defined, take the one from current configuration
840 out.open(regionalFile);
844 AliError(Form("Could not create output regional file %s",regionalFile));
848 Int_t nCrate = fRegionalTrigger.GetNofTriggerCrates();
851 AliError("Could not write regional no configuration in memory");
857 AliMpTriggerCrate* crate;
858 for (Int_t ddlId = 0; ddlId < 2; ddlId++) // right & left side
860 for (Int_t crateId = 0; crateId < 8; crateId++) // 8 crates/regional boards for each side.
863 name = AliMpTriggerCrate::GenerateName(crateId, ddlId, nofDDLs);
865 crate = fRegionalTrigger.FindTriggerCrate(name, false);
867 AliMUONTriggerCrateConfig* crateConfig = regionalConfig->FindTriggerCrate(crate->GetName());
870 AliError(Form("Cannot find crate %s in CDB", crate->GetName()));
874 out << crate->GetName() << endl;
875 out << Form("%02x", crate->GetId()) << endl;
876 out << crateConfig->GetMode() << endl;
877 out << crateConfig->GetCoinc() << endl;
878 out << Form("%04x", crateConfig->GetMask()) << endl;
879 out << Form("%02d",crate->GetNofLocalBoards()) << endl;
881 for (Int_t iLocal = 0; iLocal < crate->GetNofLocalBoards(); ++iLocal)
883 Int_t localBoardId = crate->GetLocalBoardId(iLocal);
885 AliMpLocalBoard* board = fRegionalTrigger.FindLocalBoard(localBoardId);
887 out << Form("%02d ", board->GetSlot())
889 << Form(" %03d ", localBoardId)
890 << Form("%03x", board->GetSwitch())
895 if (board->IsNotified()) {
896 for (Int_t i = 0; i < board->GetNofDEs(); ++i)
897 out << Form("%4d ", board->GetDEId(i));
899 out << Form("%4d ", 0);
903 // print copy card numbers & TC
904 out << Form(" %4d %4d", board->GetInputXfrom(), board->GetInputXto());
905 out << Form(" %4d %4d", board->GetInputYfrom(), board->GetInputYto());
906 out << Form(" %4d", board->GetTC()) << endl;
917 //_____________________________________________________________________________
919 AliMUONTriggerIO::WriteLocalMasks(const char* localFile, const AliMUONVStore& localMasks) const
922 /// removing/adding enable for a local board need a update of the configuration
923 /// before calling this method
924 /// mask are written for all boards including the copy card (Ch.F.)
926 FILE* fp = fopen(gSystem->ExpandPathName(localFile),"wb");
929 AliError(Form("Could not create output local file %s",localFile));
933 UShort_t maskBuffer[8];
934 Int_t localBoardIndex(0);
935 while (localBoardIndex < NofLocalBoards()) {
937 Int_t localBoardId = fRegionalTrigger.LocalBoardId(localBoardIndex);
939 AliMUONVCalibParam* localMask =
940 static_cast<AliMUONVCalibParam*>(localMasks.FindObject(localBoardId));
942 for (Int_t index = 0; index < 8; ++index)
944 maskBuffer[index] = localMask->ValueAsInt(index,0);
947 fwrite ( maskBuffer, 2, 8, fp);
959 //_____________________________________________________________________________
961 AliMUONTriggerIO::WriteLocalLUT(const AliMUONTriggerLut& lut,
965 /// loop over the address for the 4-bits lpt and hpt decisions
967 const Int_t kMaskYpos = 0x0F;
968 const Int_t kMaskYtri = 0x01;
969 const Int_t kMaskXdev = 0x1F;
970 const Int_t kMaskXpos = 0x1F;
972 UChar_t buffer[fgkLocalLutSize]; // 32768 hpt/lpt addresses divided by two
975 for (UInt_t i = 0; i < fgkLocalLutSize*2; ++i)
977 Int_t lutLpt[2] = { 0 };
978 Int_t lutHpt[2] = { 0 };
981 Int_t iYpos = i & kMaskYpos;
982 Int_t iYtri = ( i >> 4 ) & kMaskYtri;
983 Int_t iXdev = ( i >> ( 4 + 1 ) ) & kMaskXdev;
984 Int_t iXpos = ( i >> ( 4 + 1 + 5 ) ) & kMaskXpos;
986 // convert deviation format
987 // online: sign 1bit , dev 4bit
991 // 0 0 mu+, mu- infinite momentum (unde)
997 // - 15 mu+, mu- infinite momentum (unde)
1001 Bool_t trigx = kFALSE;
1002 iXdevOn += iXdev & 0x0F;
1003 sign += (iXdev >> 4) & 0x01;
1015 iXdevOff = - iXdevOn + 15; // gives range 0-14
1017 iXdevOff = + iXdevOn + 15; // gives range 16-30 !
1022 // iYtri == 1 means no trigger in y-direction
1023 if (iYtri == 0 && trigx)
1025 lut.GetLutOutput(localBoardId,iXpos,iXdev,iYpos,lutLpt,lutHpt);
1033 buffer[bc] += lutHpt[1] << 7;
1034 buffer[bc] += lutHpt[0] << 6;
1035 buffer[bc] += lutLpt[1] << 5;
1036 buffer[bc] += lutLpt[0] << 4;
1039 buffer[bc] += lutHpt[1] << 3;
1040 buffer[bc] += lutHpt[0] << 2;
1041 buffer[bc] += lutLpt[1] << 1;
1042 buffer[bc] += lutLpt[0] << 0;
1046 fwrite(&buffer,bc,1,flut);
1049 //_____________________________________________________________________________
1051 AliMUONTriggerIO::LocalBoardId(Int_t index) const
1053 /// Return the i-th localBoardId, or -1 if index is out of bounds
1055 return fRegionalTrigger.LocalBoardId(index);
1059 //______________________________________________________________________________
1061 Int_t AliMUONTriggerIO::LocalBoardId(Int_t ddlId, Int_t crateId, Int_t localId) const
1063 /// Return local board id from crate and local indexes.
1066 TString name = AliMpTriggerCrate::GenerateName(crateId, ddlId, nofDDLs);
1068 AliMpTriggerCrate* crate = fRegionalTrigger.FindTriggerCrate(name, false);
1069 return crate->GetLocalBoardId(localId);