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