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