]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRawWriter.cxx
Adding the functionality to check the consistency of the CDHs
[u/mrichter/AliRoot.git] / MUON / AliMUONRawWriter.cxx
CommitLineData
a19e2543 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
da8d4b6d 16/* $Id$ */
17
3d1463c8 18//-----------------------------------------------------------------------------
9265505b 19/// \class AliMUONRawWriter
20/// MUON Raw Data generaton in ALICE-MUON
5cab551d 21/// Raw data structure could be found in Alice-note.
9265505b 22///
23/// Implemented non-constant buspatch numbers for tracking
24/// with correct DDL id (first guess)
25/// (Ch. Finck, dec 2005)
26///
27/// Digits2Raw:
28/// Generates raw data for MUON tracker and finally for trigger
29/// Using real mapping (inverse) for tracker
30/// For trigger there is no mapping (mapping could be found in AliMUONTriggerCircuit)
31/// Ch. Finck, July 04
32/// Use memcpy instead of assignment elt by elt
33/// Introducing variable DSP numbers, real manu numbers per buspatch for st12
34/// Implemented scaler event for Trigger
35/// Ch. Finck, Jan. 06
36/// Using bus itr in DDL instead of simple incrementation
37/// treat correctly the DDL & buspatch for station 3.
38/// Using informations from AliMUONTriggerCrateStore for
39/// empty slots and non-notified cards in trigger crates.
40/// Ch. Finck, August 06.
5cab551d 41/// Using AliMpDDLStore::GetBusPatchId.
78649106 42///
43/// \author Ch. Finck, Feb. 07.
3d1463c8 44//-----------------------------------------------------------------------------
5cab551d 45
a19e2543 46
2cbb173f 47#include "AliMUONRawWriter.h"
a19e2543 48
344ef20f 49#include "AliMUONBlockHeader.h"
50#include "AliMUONBusStruct.h"
a19e2543 51#include "AliMUONConstants.h"
2cf44ef3 52#include "AliMUONDarcHeader.h"
48217459 53#include "AliMUONVDigit.h"
54#include "AliMUONVDigitStore.h"
344ef20f 55#include "AliMUONDspHeader.h"
2cbb173f 56#include "AliMUONGlobalTrigger.h"
344ef20f 57#include "AliMUONLocalStruct.h"
2cbb173f 58#include "AliMUONLocalTrigger.h"
a844d67f 59#include "AliMUONLocalTriggerBoard.h"
4798d385 60#include "AliMUONRegionalTrigger.h"
344ef20f 61#include "AliMUONRegHeader.h"
2ed86fc4 62
48217459 63#include "AliMUONVTriggerStore.h"
134d2964 64#include "AliCodeTimer.h"
9265505b 65
e5ced899 66#include "AliMpDDLStore.h"
67#include "AliMpDDL.h"
2ed86fc4 68#include "AliMpTriggerCrate.h"
69#include "AliMpLocalBoard.h"
e5ced899 70#include "AliMpDetElement.h"
2cbb173f 71#include "AliMpDEManager.h"
344ef20f 72#include "AliMpExMap.h"
1c80232e 73#include "AliMpConstants.h"
a19e2543 74#include "AliMpPlaneType.h"
9265505b 75#include "AliMpSegmentation.h"
2cbb173f 76#include "AliMpStationType.h"
a19e2543 77#include "AliMpVSegmentation.h"
9265505b 78
344ef20f 79#include "AliRawReader.h"
9265505b 80#include "AliBitPacking.h"
81#include "AliDAQ.h"
82#include "AliLog.h"
83
a844d67f 84#include "TObjArray.h"
1c80232e 85#include "TStopwatch.h"
c4860b34 86#include <Riostream.h>
2cf44ef3 87
9265505b 88/// \cond CLASSIMP
a19e2543 89ClassImp(AliMUONRawWriter) // Class implementation in ROOT context
9265505b 90/// \endcond
ced309a5 91
a19e2543 92//__________________________________________________________________________
48217459 93AliMUONRawWriter::AliMUONRawWriter()
9f5dcca3 94 : TObject(),
9f5dcca3 95 fBlockHeader(new AliMUONBlockHeader()),
96 fDspHeader(new AliMUONDspHeader()),
9f5dcca3 97 fDarcHeader(new AliMUONDarcHeader()),
98 fRegHeader(new AliMUONRegHeader()),
99 fLocalStruct(new AliMUONLocalStruct()),
5cab551d 100 fDDLStore(AliMpDDLStore::Instance()),
9f5dcca3 101 fScalerEvent(kFALSE),
102 fHeader(),
48217459 103 fBufferSize((((43*AliMpConstants::ManuNofChannels() + 4)*5 + 10)*5 + 8)*2),
104 fBuffer(new Int_t [fBufferSize])
a19e2543 105{
9265505b 106 /// Standard Constructor
107
2cbb173f 108 AliDebug(1,"Standard ctor");
a19e2543 109
84ceeb06 110 // setting data key to default value (only for writting)
111 fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
112 fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
84ceeb06 113
a19e2543 114}
115
a19e2543 116//__________________________________________________________________________
117AliMUONRawWriter::~AliMUONRawWriter(void)
118{
9265505b 119 /// Destructor
120
2cbb173f 121 AliDebug(1,"dtor");
122
2cf44ef3 123 delete fBlockHeader;
124 delete fDspHeader;
2cf44ef3 125 delete fDarcHeader;
126 delete fRegHeader;
127 delete fLocalStruct;
48217459 128 delete[] fBuffer;
a19e2543 129}
2cbb173f 130
2ed86fc4 131//____________________________________________________________________
132void AliMUONRawWriter::LocalWordPacking(UInt_t& word, UInt_t locId, UInt_t locDec,
133 UInt_t trigY, UInt_t posY, UInt_t posX,
134 UInt_t sdevX, UInt_t devX)
135{
136/// pack local trigger word
137
138 AliBitPacking::PackWord(locId,word,19,22); //card id number in crate
139 AliBitPacking::PackWord(locDec,word,15,18);
140 AliBitPacking::PackWord(trigY,word,14,14);
141 AliBitPacking::PackWord(posY,word,10,13);
142 AliBitPacking::PackWord(sdevX,word,9,9);
143 AliBitPacking::PackWord(devX,word,5,8);
144 AliBitPacking::PackWord(posX,word,0,4);
145
146}
147
a19e2543 148//____________________________________________________________________
48217459 149Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
150 AliMUONVTriggerStore* triggerStore)
a19e2543 151{
9265505b 152 /// convert digits of the current event to raw data
153
134d2964 154 AliCodeTimerAuto("")
48217459 155
a19e2543 156 Int_t idDDL;
1d81a83f 157 Char_t name[255];
a19e2543 158
344ef20f 159 // tracking chambers
160
48217459 161 if ( digitStore )
162 {
134d2964 163 AliCodeTimerAuto("for Tracker")
1d81a83f 164
48217459 165 AliMpExMap busPatchMap(true);
1d81a83f 166
48217459 167 Int_t nDDLs = AliDAQ::NumberOfDdls("MUONTRK");
168
169 Int_t nofBusPatches(0);
170
171 for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL )
172 {
173 AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
174 nofBusPatches += ddl->GetNofBusPatches();
175 }
176
177 busPatchMap.SetSize(nofBusPatches);
178
179 Digits2BusPatchMap(*digitStore,busPatchMap);
1d81a83f 180
48217459 181 for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL )
182 {
183 WriteTrackerDDL(busPatchMap,iDDL);
184 }
185 AliDebug(1,"Tracker written");
a19e2543 186 }
187
48217459 188 if ( triggerStore )
189 {
134d2964 190 AliCodeTimerAuto("for Trigger")
a19e2543 191
48217459 192 // trigger chambers
193
b672bf31 194 AliFstream* file[2];
48217459 195
196 // open files
197 idDDL = 0;// MUTR
198 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
b672bf31 199 file[0] = new AliFstream(name);
48217459 200
201 idDDL = 1;// MUTR
202 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
b672bf31 203 file[1] = new AliFstream(name);
48217459 204
205 WriteTriggerDDL(*triggerStore,file);
206
207 // reset and close
b672bf31 208 delete file[0];
209 delete file[1];
48217459 210
211 AliDebug(1,"Trigger written");
212 }
344ef20f 213
a19e2543 214 return kTRUE;
215}
2cbb173f 216
48217459 217//______________________________________________________________________________
218void
219AliMUONRawWriter::Digits2BusPatchMap(const AliMUONVDigitStore& digitStore,
220 AliMpExMap& busPatchMap)
a19e2543 221{
48217459 222 /// Create bus patch structures corresponding to digits in the store
223
134d2964 224 AliCodeTimerAuto("")
2cbb173f 225
84aac932 226 static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
48217459 227
2cf44ef3 228 // DDL event one per half chamber
48217459 229
2cf44ef3 230 // raw data
a19e2543 231 Char_t parity = 0x4;
232 UShort_t manuId = 0;
233 UChar_t channelId = 0;
234 UShort_t charge = 0;
235 Int_t busPatchId = 0;
a19e2543 236 UInt_t word;
2cf44ef3 237
48217459 238 TIter next(digitStore.CreateTrackerIterator());
239 AliMUONVDigit* digit;
240
241 while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
242 {
243 charge = digit->ADC();
244 if ( charge > kMAXADC )
245 {
246 // This is most probably an error in the digitizer (which should insure
247 // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
a3eb0a94 248 AliError(Form("adc value %d above 0x%x for DE %d . Setting to 0x%x. Digit is:",
249 charge,kMAXADC,digit->DetElemId(),kMAXADC));
48217459 250 StdoutToAliError(digit->Print());
251 charge = kMAXADC;
252 }
253
254 // inverse mapping
255 busPatchId = GetBusPatch(*digit);
2cf44ef3 256
48217459 257 if (busPatchId<0) continue;
258
259 if ( digit->ManuId() > 0x7FF ||
260 digit->ManuChannel() > 0x3F )
261 {
262 StdoutToAliError(digit->Print(););
263 AliFatal("ManuId,ManuChannel are invalid for the digit above.");
264 }
265
266 manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
267 channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
268
269 //packing word
270 word = 0;
271 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
272 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
273 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
274
275 // parity word
276 parity = word & 0x1;
277 for (Int_t i = 1; i <= 30; ++i)
278 {
279 parity ^= ((word >> i) & 0x1);
280 }
281 AliBitPacking::PackWord((UInt_t)parity,word,31,31);
282
283 AliMUONBusStruct* busStruct =
284 static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
285
286 if (!busStruct)
287 {
288 busStruct = new AliMUONBusStruct;
289 busStruct->SetDataKey(busStruct->GetDefaultDataKey());
290 busStruct->SetBusPatchId(busPatchId);
291 busStruct->SetLength(0);
292 busPatchMap.Add(busPatchId,busStruct);
293 }
294
295 // set sub Event
296 busStruct->AddData(word);
297 }
298}
2cf44ef3 299
48217459 300//______________________________________________________________________________
301void
302AliMUONRawWriter::WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL)
303{
304 /// Write DDL file for one tracker DDL
305
344ef20f 306 // buffer size (max'ed out)
307 // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch
308 // + 10 dsp words)*5 dsps + 8 block words)*2 blocks
48217459 309
134d2964 310 AliCodeTimerAuto("")
a19e2543 311
48217459 312 memset(fBuffer,0,fBufferSize*sizeof(Int_t));
344ef20f 313
48217459 314 AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
315 Int_t iDspMax = ddl->GetMaxDsp();
316 Int_t iBusPerDSP[5]; //number of bus patches per DSP
317 ddl->GetBusPerDsp(iBusPerDSP);
318 Int_t busIter = 0;
344ef20f 319
48217459 320 Int_t totalDDLLength = 0;
a19e2543 321
48217459 322 Int_t index = 0;
323
324 // two blocks A and B per DDL
325 for (Int_t iBlock = 0; iBlock < 2; ++iBlock)
326 {
327 // block header
328 Int_t length = fBlockHeader->GetHeaderLength();
329 memcpy(&fBuffer[index],fBlockHeader->GetHeader(),length*4);
330 Int_t indexBlk = index;
331 index += length;
344ef20f 332
48217459 333 // 5 DSP's max per block
334 for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp)
335 {
336 // DSP header
337 Int_t length = fDspHeader->GetHeaderLength();
338 memcpy(&fBuffer[index],fDspHeader->GetHeader(),length*4);
339 Int_t indexDsp = index;
a19e2543 340 index += length;
344ef20f 341
48217459 342 // 5 buspatches max per DSP
343 for (Int_t i = 0; i < iBusPerDSP[iDsp]; ++i)
344 {
345 Int_t iBusPatch = ddl->GetBusPatchId(busIter++);
344ef20f 346
48217459 347 // iteration over bus patch in DDL
348 if (iBusPatch == -1)
349 {
350 AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
351 continue;
344ef20f 352 }
353
48217459 354 AliMUONBusStruct* busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
344ef20f 355
48217459 356 // check if buspatchid has digit
357 if (busStructPtr)
358 {
359 // add bus patch structure header
360 Int_t length = busStructPtr->GetHeaderLength();
361 memcpy(&fBuffer[index],busStructPtr->GetHeader(),length*4);
362 index += length;
363
364 // add bus patch data
365 length = busStructPtr->GetLength();
366 memcpy(&fBuffer[index],busStructPtr->GetData(),length*4);
367 index += length;
368 }
369 else
370 {
371 // writting anyhow buspatch structure (empty ones)
372 fBuffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
373 fBuffer[index++] = busStructPtr->GetHeaderLength(); // header length
374 fBuffer[index++] = 0; // raw data length
375 fBuffer[index++] = iBusPatch; // bus patch
376 }
377 } // bus patch
344ef20f 378
48217459 379 // check if totalLength even
380 // set padding word in case
381 // Add one word 0xBEEFFACE at the end of DSP structure
382 Int_t totalDspLength = index - indexDsp;
383 if ((totalDspLength % 2) == 1)
384 {
385 fBuffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
386 fBuffer[index++] = fDspHeader->GetDefaultPaddingWord();
387 totalDspLength++;
388 }
344ef20f 389
48217459 390 Int_t dspLength = totalDspLength - fDspHeader->GetHeaderLength();
344ef20f 391
48217459 392 fBuffer[indexDsp+1] = totalDspLength; // dsp total length
393 fBuffer[indexDsp+2] = dspLength; // data length
344ef20f 394
48217459 395 } // dsp
396
397 Int_t totalBlkLength = index - indexBlk;
398 Int_t blkLength = totalBlkLength - fBlockHeader->GetHeaderLength();
399 totalDDLLength += totalBlkLength;
400
401 fBuffer[indexBlk+1] = totalBlkLength; // total block length
402 fBuffer[indexBlk+2] = blkLength;
403
404 } // block
344ef20f 405
48217459 406 // writting onto disk
407 // total length in bytes
408 // DDL header
409 Int_t headerSize = sizeof(fHeader)/4;
410
411 fHeader.fSize = (totalDDLLength + headerSize) * 4;
412
b672bf31 413 AliFstream* file = new AliFstream(AliDAQ::DdlFileName("MUONTRK",iDDL));
48217459 414
b672bf31 415 file->WriteBuffer((char*)(&fHeader),headerSize*4);
416 file->WriteBuffer((char*)fBuffer,sizeof(int)*index);
417 delete file;
a19e2543 418}
ced309a5 419
48217459 420//______________________________________________________________________________
421Int_t AliMUONRawWriter::GetBusPatch(const AliMUONVDigit& digit) const
344ef20f 422{
9265505b 423 /// Determine the BusPatch this digit belongs to.
424
5cab551d 425 return fDDLStore->GetBusPatchId(digit.DetElemId(),digit.ManuId());
344ef20f 426}
427
48217459 428//______________________________________________________________________________
b672bf31 429Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore, AliFstream* file[2])
a19e2543 430{
9265505b 431 /// Write trigger DDL
2cbb173f 432
134d2964 433 AliCodeTimerAuto("")
48217459 434
a19e2543 435 // DDL event one per half chamber
a19e2543 436
2cf44ef3 437 // DDL header size
438 Int_t headerSize = sizeof(AliRawDataHeader)/4;
ced309a5 439
a19e2543 440 // global trigger for trigger pattern
48217459 441 AliMUONGlobalTrigger* gloTrg = triggerStore.Global();
344ef20f 442 if (!gloTrg)
443 {
344ef20f 444 return 0;
445 }
446
073695a9 447 Int_t gloTrigResp = gloTrg->GetGlobalResponse();
a19e2543 448
a19e2543 449 UInt_t word;
450 Int_t* buffer = 0;
451 Int_t index;
2ed86fc4 452 Int_t locCard;
1afc1008 453 UChar_t locDec, trigY, posY, posX, regOut;
bebe0279 454 UInt_t regInpLpt;
455 UInt_t regInpHpt;
456
1afc1008 457 UInt_t devX;
c4860b34 458 UChar_t sdevX;
1afc1008 459 UInt_t version = 1; // software version
460 UInt_t eventPhys = 1; // trigger type: 1 for physics, 0 for software
461 UInt_t serialNb = 0xF; // serial nb of card: all bits on for the moment
d622a0ec 462 Int_t globalFlag = 0; // set to 1 if global info present in DDL else set to 0
463
464 // size of headers
465 static const Int_t kDarcHeaderLength = fDarcHeader->GetDarcHeaderLength();
466 static const Int_t kGlobalHeaderLength = fDarcHeader->GetGlobalHeaderLength();
467 static const Int_t kDarcScalerLength = fDarcHeader->GetDarcScalerLength();
468 static const Int_t kGlobalScalerLength = fDarcHeader->GetGlobalScalerLength();
469 static const Int_t kRegHeaderLength = fRegHeader->GetHeaderLength();
470 static const Int_t kRegScalerLength = fRegHeader->GetScalerLength();
471 static const Int_t kLocHeaderLength = fLocalStruct->GetLength();
472 static const Int_t kLocScalerLength = fLocalStruct->GetScalerLength();
473
474 // [16(local)*6 words + 6 words]*8(reg) + 8 words = 824
475 static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) + (kRegHeaderLength+1))* 8
476 + kDarcHeaderLength + kGlobalHeaderLength + 2;
477
478 // [16(local)*51 words + 16 words]*8(reg) + 8 + 10 + 8 words scaler event 6682 words
479 static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength + kLocScalerLength +1) +
480 (kRegHeaderLength + kRegScalerLength +1))* 8 +
481 (kDarcHeaderLength + kDarcScalerLength +
482 kGlobalHeaderLength + kGlobalScalerLength + 2);
ced309a5 483 if(fScalerEvent)
d622a0ec 484 eventPhys = 0; //set to generate scaler events
ced309a5 485
ced309a5 486 if(fScalerEvent)
d622a0ec 487 buffer = new Int_t [kScalerBufferSize];
ced309a5 488 else
d622a0ec 489 buffer = new Int_t [kBufferSize];
ced309a5 490
a844d67f 491 // reset crate
a19e2543 492
493 // open DDL file, on per 1/2 chamber
48217459 494 for ( Int_t iDDL = 0; iDDL < 2; ++iDDL )
495 {
a19e2543 496 index = 0;
497
a19e2543 498 if (iDDL == 0) // suppose global info in DDL one
a19e2543 499 globalFlag = 1;
d622a0ec 500 else
501 globalFlag = 0;
ced309a5 502
d622a0ec 503 word = 0;
504 // set darc status word
505 // see AliMUONDarcHeader.h for details
506 AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30);
507 AliBitPacking::PackWord((UInt_t)serialNb,word,20,23);
508 AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10);
509 AliBitPacking::PackWord((UInt_t)version,word,12,19);
2cf44ef3 510 fDarcHeader->SetWord(word);
18d3ded7 511
d622a0ec 512 memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4);
bebe0279 513 index += kDarcHeaderLength;
a19e2543 514
073695a9 515 // no global input for the moment....
a19e2543 516 if (iDDL == 0)
073695a9 517 fDarcHeader->SetGlobalOutput(gloTrigResp);
a19e2543 518 else
2cf44ef3 519 fDarcHeader->SetGlobalOutput(0);
ced309a5 520
521 if (fScalerEvent) {
522 // 6 DARC scaler words
d622a0ec 523 memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4);
bebe0279 524 index += kDarcScalerLength;
ced309a5 525 }
2cf44ef3 526 // end of darc word
527 buffer[index++] = fDarcHeader->GetEndOfDarc();
ced309a5 528
529 // 4 words of global board input + Global board output
d622a0ec 530 memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4);
bebe0279 531 index += kGlobalHeaderLength;
ced309a5 532
533 if (fScalerEvent) {
534 // 10 Global scaler words
d622a0ec 535 memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4);
bebe0279 536 index += kGlobalScalerLength;
ced309a5 537 }
a19e2543 538
2cf44ef3 539 // end of global word
540 buffer[index++] = fDarcHeader->GetEndOfGlobal();
541
a19e2543 542 // 8 regional cards per DDL
2ed86fc4 543 for (Int_t iReg = 0; iReg < 8; ++iReg) {
a19e2543 544
2ed86fc4 545 // crate info
546 AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(iDDL, iReg);
a844d67f 547
548 if (!crate)
2ed86fc4 549 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
a844d67f 550
4798d385 551 // regional info tree, make sure that no reg card missing
48217459 552 AliMUONRegionalTrigger* regTrg = triggerStore.FindRegional(iReg+iDDL*8);
4798d385 553
a19e2543 554 // Regional card header
555 word = 0;
00f56161 556
557 // set darc status word
558 fRegHeader->SetDarcWord(word);
559
4798d385 560 regOut = regTrg->GetOutput();
561 regInpHpt = regTrg->GetLocalOutput(0);
562 regInpLpt = regTrg->GetLocalOutput(1);
563
d622a0ec 564 // fill darc word, not darc status for the moment (empty)
565 //see AliMUONRegHeader.h for details
566 AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31);
567 AliBitPacking::PackWord((UInt_t)serialNb,word,19,24);
2ed86fc4 568 AliBitPacking::PackWord((UInt_t)version,word,7,14);
d622a0ec 569 AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
4798d385 570 AliBitPacking::PackWord((UInt_t)regOut,word,0,7);
2cf44ef3 571 fRegHeader->SetWord(word);
d622a0ec 572
bebe0279 573
574 // fill header later, need local response
575 Int_t indexReg = index;
576 index += kRegHeaderLength;
a19e2543 577
ced309a5 578 // 11 regional scaler word
579 if (fScalerEvent) {
bebe0279 580 memcpy(&buffer[index], fRegHeader->GetScalers(), kRegScalerLength*4);
581 index += kRegScalerLength;
ced309a5 582 }
a19e2543 583
2cf44ef3 584 // end of regional word
585 buffer[index++] = fRegHeader->GetEndOfReg();
a844d67f 586
a19e2543 587 // 16 local card per regional board
4798d385 588 // UShort_t localMask = 0x0;
c4860b34 589
a19e2543 590 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
c4860b34 591
2ed86fc4 592 // slot zero for Regional card
593 Int_t localBoardId = crate->GetLocalBoardId(iLoc);
594
595 if (localBoardId) { // if not empty slot
596 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
597
598 if (localBoard->IsNotified()) {// if notified board
599 AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(localBoardId);
600
601 locCard = locTrg->LoCircuit();
602 locDec = locTrg->GetLoDecision();
603 trigY = locTrg->LoTrigY();
604 posY = locTrg->LoStripY();
605 posX = locTrg->LoStripX();
606 devX = locTrg->LoDev();
607 sdevX = locTrg->LoSdev();
608
609 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
610 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
611 //packing word
612 word = 0;
613 LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY,
614 (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
615
616 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
617 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
618 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
619 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
620 buffer[index++] = (Int_t)word; // data word
621
622
623 }
624 // fill copy card X-Y inputs from the notified cards
625 if (localBoard->GetInputXfrom() && localBoard->GetInputYfrom())
626 {
627 // not triggered
628 locDec = 0; trigY = 1; posY = 15;
629 posX = 0; devX = 0; sdevX = 1;
630 LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY,
631 (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
632
633 Int_t localFromId = localBoard->GetInputXfrom();
634 AliMUONLocalTrigger* locTrgfrom = triggerStore.FindLocal(localFromId);
635
636 buffer[index++] = 0; // copy only X3-4 & Y1-4
637 buffer[index++] = (locTrgfrom->GetX3Pattern() | (locTrgfrom->GetX4Pattern() << 16));
638 buffer[index++] = (locTrgfrom->GetY1Pattern() | (locTrgfrom->GetY2Pattern() << 16));
639 buffer[index++] = (locTrgfrom->GetY3Pattern() | (locTrgfrom->GetY4Pattern() << 16));
640 buffer[index++] = word;
a844d67f 641 }
2ed86fc4 642
643 } else {
644 // fill with 10CDEAD word for empty slots
645 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
646 buffer[index++] = fLocalStruct->GetDisableWord();
647 }// condition localBoard
648
649 // 45 regional scaler word
650 if (fScalerEvent) {
651 memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
652 index += kLocScalerLength;
653 }
c4860b34 654
2ed86fc4 655 // end of local structure words
656 buffer[index++] = fLocalStruct->GetEndOfLocal();
c4860b34 657
2cf44ef3 658 } // local card
bebe0279 659 // fill regional header with local output
4798d385 660 fRegHeader->SetInput(regInpHpt, 0);
bebe0279 661 fRegHeader->SetInput(regInpHpt, 1);
bebe0279 662 memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);
c4860b34 663
a19e2543 664 } // Regional card
665
a19e2543 666
667 // writting onto disk
a844d67f 668 // write DDL's
2cf44ef3 669 fHeader.fSize = (index + headerSize) * 4;// total length in bytes
b672bf31 670 file[iDDL]->WriteBuffer((char*)(&fHeader),headerSize*4);
671 file[iDDL]->WriteBuffer((char*)buffer,sizeof(int)*index);
a19e2543 672
673 }
674 delete[] buffer;
675
ced309a5 676 return kTRUE;
a19e2543 677}
48217459 678
84ceeb06 679//____________________________________________________________________
680void AliMUONRawWriter::SetScalersNumbers()
681{
9265505b 682 /// set numbers for scaler events for trigger headers
683 /// since this is provided by the experiment
684 /// put dummy numbers to check the monitoring
84ceeb06 685
686 fDarcHeader->SetScalersNumbers();
687 fRegHeader->SetScalersNumbers();
688 fLocalStruct->SetScalersNumbers();
689
690 fScalerEvent = kTRUE;
691}
a844d67f 692