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