]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawWriter.cxx
eed62c3c441edb08610cd9168c0275831b2f4ed4
[u/mrichter/AliRoot.git] / MUON / AliMUONRawWriter.cxx
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 /// \class AliMUONRawWriter
19 /// MUON Raw Data generaton in ALICE-MUON
20 /// Raw data structure could be found in Alice-note.
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.
40 /// Using AliMpDDLStore::GetBusPatchId.
41 ///
42 /// \author Ch. Finck, Feb. 07.
43
44
45 #include "AliMUONRawWriter.h"
46
47 #include "AliMUONBlockHeader.h"
48 #include "AliMUONBusStruct.h"
49 #include "AliMUONConstants.h"
50 #include "AliMUONDarcHeader.h"
51 #include "AliMUONVDigit.h"
52 #include "AliMUONVDigitStore.h"
53 #include "AliMUONDspHeader.h"
54 #include "AliMUONGlobalTrigger.h"
55 #include "AliMUONLocalStruct.h"
56 #include "AliMUONLocalTrigger.h"
57 #include "AliMUONLocalTriggerBoard.h"
58 #include "AliMUONRegionalTrigger.h"
59 #include "AliMUONRegHeader.h"
60
61 #include "AliMUONVTriggerStore.h"
62 #include "AliCodeTimer.h"
63
64 #include "AliMpDDLStore.h"
65 #include "AliMpDDL.h"
66 #include "AliMpTriggerCrate.h"
67 #include "AliMpLocalBoard.h"
68 #include "AliMpDetElement.h"
69 #include "AliMpDEManager.h"
70 #include "AliMpExMap.h"
71 #include "AliMpConstants.h"
72 #include "AliMpPlaneType.h"
73 #include "AliMpSegmentation.h"
74 #include "AliMpStationType.h"
75 #include "AliMpVSegmentation.h"
76
77 #include "AliRawReader.h"
78 #include "AliBitPacking.h" 
79 #include "AliDAQ.h"
80 #include "AliLog.h"
81
82 #include "TObjArray.h"
83 #include "TStopwatch.h"
84 #include <Riostream.h>
85
86 /// \cond CLASSIMP
87 ClassImp(AliMUONRawWriter) // Class implementation in ROOT context
88 /// \endcond
89
90 //__________________________________________________________________________
91 AliMUONRawWriter::AliMUONRawWriter()
92   : TObject(),
93     fBlockHeader(new AliMUONBlockHeader()),
94     fDspHeader(new AliMUONDspHeader()),
95     fDarcHeader(new AliMUONDarcHeader()),
96     fRegHeader(new AliMUONRegHeader()),
97     fLocalStruct(new AliMUONLocalStruct()),
98     fDDLStore(AliMpDDLStore::Instance()),
99     fScalerEvent(kFALSE),
100     fHeader(),
101     fBufferSize((((43*AliMpConstants::ManuNofChannels() + 4)*5 + 10)*5 + 8)*2),
102     fBuffer(new Int_t [fBufferSize])
103 {
104   /// Standard Constructor
105
106   AliDebug(1,"Standard ctor");
107
108   // setting data key to default value (only for writting)
109   fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
110   fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
111
112 }
113
114 //__________________________________________________________________________
115 AliMUONRawWriter::~AliMUONRawWriter(void)
116 {
117   /// Destructor
118
119   AliDebug(1,"dtor");
120   
121   delete fBlockHeader;
122   delete fDspHeader;
123   delete fDarcHeader;
124   delete fRegHeader;
125   delete fLocalStruct;
126   delete[] fBuffer;
127 }
128
129 //____________________________________________________________________
130 void  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
146 //____________________________________________________________________
147 Int_t AliMUONRawWriter::Digits2Raw(AliMUONVDigitStore* digitStore,
148                                    AliMUONVTriggerStore* triggerStore)
149 {
150   /// convert digits of the current event to raw data
151
152   AliCodeTimerAuto("")
153   
154   Int_t idDDL;
155   Char_t name[255];
156
157   // tracking chambers
158   
159   if ( digitStore ) 
160   {
161     AliCodeTimerAuto("for Tracker")
162
163     AliMpExMap busPatchMap(true);
164
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);
178
179     for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL ) 
180     {
181       WriteTrackerDDL(busPatchMap,iDDL);
182     }
183     AliDebug(1,"Tracker written");
184   }
185  
186   if ( triggerStore )
187   {
188     AliCodeTimerAuto("for Trigger")
189
190     // trigger chambers
191     
192     AliFstream* file[2];
193     
194     // open files
195     idDDL = 0;// MUTR
196     strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
197     file[0] = new AliFstream(name);
198     
199     idDDL = 1;// MUTR
200     strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
201     file[1] = new AliFstream(name);
202       
203     WriteTriggerDDL(*triggerStore,file);
204       
205     // reset and close
206     delete file[0];
207     delete file[1];
208       
209     AliDebug(1,"Trigger written");
210   }
211   
212   return kTRUE;
213 }
214
215 //______________________________________________________________________________
216 void 
217 AliMUONRawWriter::Digits2BusPatchMap(const AliMUONVDigitStore& digitStore,
218                                      AliMpExMap& busPatchMap)
219 {
220   /// Create bus patch structures corresponding to digits in the store
221   
222   AliCodeTimerAuto("")
223   
224   static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
225     
226   // DDL event one per half chamber
227   
228   // raw data
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;
234   UInt_t word;
235   
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.
246       AliError(Form("adc value %d above %x for DE %d . Setting to %x. Digit is:",
247                     digit->DetElemId(),charge,kMAXADC,kMAXADC));
248       StdoutToAliError(digit->Print());
249       charge = kMAXADC;
250     }
251     
252     // inverse mapping
253     busPatchId = GetBusPatch(*digit);
254
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 }
297
298 //______________________________________________________________________________
299 void
300 AliMUONRawWriter::WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL)
301 {
302   /// Write DDL file for one tracker DDL
303   
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 
307  
308   AliCodeTimerAuto("")
309
310   memset(fBuffer,0,fBufferSize*sizeof(Int_t));
311   
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;
317   
318   Int_t totalDDLLength = 0;
319   
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; 
330     
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;
338       index += length; 
339       
340       // 5 buspatches max per DSP
341       for (Int_t i = 0; i < iBusPerDSP[iDsp]; ++i) 
342       {
343         Int_t iBusPatch = ddl->GetBusPatchId(busIter++);
344         
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;
350         }
351         
352         AliMUONBusStruct* busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
353         
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
376       
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       }
387       
388       Int_t dspLength          = totalDspLength - fDspHeader->GetHeaderLength();
389       
390       fBuffer[indexDsp+1] = totalDspLength; // dsp total length
391       fBuffer[indexDsp+2] = dspLength; // data length  
392       
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
403   
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   
411   AliFstream* file = new AliFstream(AliDAQ::DdlFileName("MUONTRK",iDDL));
412   
413   file->WriteBuffer((char*)(&fHeader),headerSize*4);
414   file->WriteBuffer((char*)fBuffer,sizeof(int)*index);
415   delete file;
416 }
417
418 //______________________________________________________________________________
419 Int_t AliMUONRawWriter::GetBusPatch(const AliMUONVDigit& digit) const
420 {
421   /// Determine the BusPatch this digit belongs to.
422
423     return fDDLStore->GetBusPatchId(digit.DetElemId(),digit.ManuId());
424 }
425
426 //______________________________________________________________________________
427 Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore, AliFstream* file[2])
428 {
429   /// Write trigger DDL
430   
431   AliCodeTimerAuto("")
432
433  // DDL event one per half chamber
434
435  // DDL header size
436   Int_t headerSize = sizeof(AliRawDataHeader)/4;
437
438   // global trigger for trigger pattern
439   AliMUONGlobalTrigger* gloTrg = triggerStore.Global();
440   if (!gloTrg) 
441   {
442     return 0;
443   }
444   
445   Int_t gloTrigResp = gloTrg->GetGlobalResponse();
446
447   UInt_t word;
448   Int_t* buffer = 0;
449   Int_t index;
450   Int_t locCard;
451   UChar_t locDec, trigY, posY, posX, regOut;
452   UInt_t regInpLpt;
453   UInt_t regInpHpt;
454
455   UInt_t devX;
456   UChar_t sdevX;
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
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);
481   if(fScalerEvent)
482     eventPhys = 0; //set to generate scaler events
483
484   if(fScalerEvent)
485     buffer = new Int_t [kScalerBufferSize];
486   else
487     buffer = new Int_t [kBufferSize];
488
489   // reset crate
490
491   // open DDL file, on per 1/2 chamber
492   for ( Int_t iDDL = 0; iDDL < 2; ++iDDL ) 
493   {
494     index = 0; 
495
496     if (iDDL == 0) // suppose global info in DDL one
497       globalFlag = 1;
498     else 
499       globalFlag = 0;
500
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);
508     fDarcHeader->SetWord(word);
509
510     memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4); 
511     index += kDarcHeaderLength;
512
513     // no global input for the moment....
514     if (iDDL == 0)
515      fDarcHeader->SetGlobalOutput(gloTrigResp);
516     else 
517      fDarcHeader->SetGlobalOutput(0);
518
519     if (fScalerEvent) {
520       // 6 DARC scaler words
521       memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4);
522       index += kDarcScalerLength;
523     }
524     // end of darc word
525     buffer[index++] = fDarcHeader->GetEndOfDarc();
526
527     // 4 words of global board input + Global board output
528     memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4); 
529     index += kGlobalHeaderLength; 
530
531     if (fScalerEvent) {
532       // 10 Global scaler words
533       memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4);
534       index += kGlobalScalerLength;
535     }
536
537     // end of global word
538     buffer[index++] = fDarcHeader->GetEndOfGlobal();
539
540     // 8 regional cards per DDL
541     for (Int_t iReg = 0; iReg < 8; ++iReg) {
542
543         // crate info
544       AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(iDDL, iReg);
545
546       if (!crate) 
547         AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
548
549       // regional info tree, make sure that no reg card missing
550       AliMUONRegionalTrigger* regTrg  = triggerStore.FindRegional(iReg+iDDL*8);
551
552       // Regional card header
553       word = 0;
554
555       // set darc status word
556       fRegHeader->SetDarcWord(word);
557
558       regOut    = regTrg->GetOutput();
559       regInpHpt = regTrg->GetLocalOutput(0);
560       regInpLpt = regTrg->GetLocalOutput(1);
561
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); 
566       AliBitPacking::PackWord((UInt_t)version,word,7,14);
567       AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
568       AliBitPacking::PackWord((UInt_t)regOut,word,0,7); 
569       fRegHeader->SetWord(word);
570
571
572       // fill header later, need local response
573       Int_t indexReg = index;
574       index += kRegHeaderLength;
575
576       // 11 regional scaler word
577       if (fScalerEvent) {
578         memcpy(&buffer[index], fRegHeader->GetScalers(), kRegScalerLength*4);
579         index += kRegScalerLength;
580       }
581
582       // end of regional word
583       buffer[index++] = fRegHeader->GetEndOfReg();
584       
585       // 16 local card per regional board
586       //      UShort_t localMask = 0x0;
587       
588       for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
589           
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;
639           }
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         }
652           
653         // end of local structure words
654         buffer[index++] = fLocalStruct->GetEndOfLocal();
655           
656       } // local card 
657       // fill regional header with local output
658       fRegHeader->SetInput(regInpHpt, 0);
659       fRegHeader->SetInput(regInpHpt, 1);
660       memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);
661       
662     } // Regional card
663     
664
665     // writting onto disk
666     // write DDL's
667     fHeader.fSize = (index + headerSize) * 4;// total length in bytes
668     file[iDDL]->WriteBuffer((char*)(&fHeader),headerSize*4);
669     file[iDDL]->WriteBuffer((char*)buffer,sizeof(int)*index);
670   
671   }
672   delete[] buffer;
673
674   return kTRUE;
675 }
676
677 //____________________________________________________________________
678 void AliMUONRawWriter::SetScalersNumbers()
679 {
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
683
684   fDarcHeader->SetScalersNumbers();
685   fRegHeader->SetScalersNumbers();
686   fLocalStruct->SetScalersNumbers();
687  
688   fScalerEvent = kTRUE;
689 }
690