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