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