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