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