]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawWriter.cxx
AliMUONDigitCalibrator
[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;
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   Int_t currentBusPatchId = -1;
239   UInt_t word;
240   
241   AliMUONBusStruct* busStruct(0x0);
242   
243   TIter next(digitStore.CreateTrackerIterator());
244   AliMUONVDigit* digit;
245   
246   while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
247   {
248     charge = digit->ADC();
249     if ( charge > kMAXADC )
250     {
251       // This is most probably an error in the digitizer (which should insure
252       // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
253       AliError(Form("adc value %d above 0x%x for DE %d . Setting to 0x%x. Digit is:",
254                     charge,kMAXADC,digit->DetElemId(),kMAXADC));
255       StdoutToAliError(digit->Print());
256       charge = kMAXADC;
257     }
258     
259     // inverse mapping
260     busPatchId = GetBusPatch(*digit);
261
262     if (busPatchId<0) continue;
263     
264     if ( digit->ManuId() > 0x7FF ||
265          digit->ManuChannel() > 0x3F )
266     {
267       StdoutToAliError(digit->Print(););
268       AliFatal("ManuId,ManuChannel are invalid for the digit above.");
269     }
270     
271     manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
272     channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
273     
274     //packing word
275     word = 0;
276     AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
277     AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
278     AliBitPacking::PackWord((UInt_t)charge,word,0,11);
279     
280     // parity word
281     parity = word & 0x1;
282     for (Int_t i = 1; i <= 30; ++i) 
283     {
284       parity ^=  ((word >> i) & 0x1);
285     }
286     AliBitPacking::PackWord((UInt_t)parity,word,31,31);
287
288     if ( currentBusPatchId != busPatchId ) 
289     {
290       busStruct = 
291         static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
292       currentBusPatchId = busPatchId;
293     }
294     
295     if (!busStruct)
296     {
297       busStruct = new AliMUONBusStruct;
298       busStruct->SetDataKey(busStruct->GetDefaultDataKey());
299       busStruct->SetBusPatchId(busPatchId);
300       busStruct->SetLength(0);
301       busPatchMap.Add(busPatchId,busStruct);
302     }
303     
304     // set sub Event
305     busStruct->AddData(word);
306   }
307 }
308
309 //______________________________________________________________________________
310 void
311 AliMUONRawWriter::WriteTrackerDDL(AliMpExMap& busPatchMap, Int_t iDDL)
312 {
313   /// Write DDL file for one tracker DDL
314   
315   // buffer size (max'ed out)
316   // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch 
317   //   + 10 dsp words)*5 dsps + 8 block words)*2 blocks 
318  
319   AliCodeTimerAuto("")
320
321   if (fHeader == 0x0) {
322     AliError("Raw data header must be set");
323     return;
324   }
325   memset(fBuffer,0,fBufferSize*sizeof(Int_t));
326   
327   AliMpDDL* ddl = fDDLStore->GetDDL(iDDL);
328   Int_t iDspMax = ddl->GetMaxDsp();
329   Int_t iBusPerDSP[5]; //number of bus patches per DSP
330   ddl->GetBusPerDsp(iBusPerDSP);
331   Int_t busIter = 0;
332   
333   Int_t totalDDLLength = 0;
334   
335   Int_t index = 0;
336   
337   // two blocks A and B per DDL
338   for (Int_t iBlock = 0; iBlock < 2; ++iBlock) 
339   {
340     // block header
341     Int_t length = fBlockHeader->GetHeaderLength();
342     memcpy(&fBuffer[index],fBlockHeader->GetHeader(),length*4);
343     Int_t indexBlk = index;
344     index += length; 
345     
346     // 5 DSP's max per block
347     for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp) 
348     {
349       // DSP header
350       Int_t dspHeaderLength = fDspHeader->GetHeaderLength();
351       memcpy(&fBuffer[index],fDspHeader->GetHeader(),dspHeaderLength*4);
352       Int_t indexDsp = index;
353       index += dspHeaderLength; 
354       
355       // 5 buspatches max per DSP
356       for (Int_t i = 0; i < iBusPerDSP[iDsp]; ++i) 
357       {
358         Int_t iBusPatch = ddl->GetBusPatchId(busIter++);
359         
360         // iteration over bus patch in DDL
361         if (iBusPatch == -1) 
362         {
363           AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
364           continue;
365         }
366         
367         AliMUONBusStruct* busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
368         
369         // check if buspatchid has digit
370         if (busStructPtr) 
371         {
372           // add bus patch structure header
373           Int_t busHeaderLength = busStructPtr->GetHeaderLength();
374           memcpy(&fBuffer[index],busStructPtr->GetHeader(),busHeaderLength*4);
375           index += busHeaderLength;
376           
377           // add bus patch data
378           Int_t busLength = busStructPtr->GetLength();
379           memcpy(&fBuffer[index],busStructPtr->GetData(),busLength*4);
380           index += busLength;
381         } 
382         else 
383         {
384           // writting anyhow buspatch structure (empty ones)
385           fBuffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
386           fBuffer[index++] = busStructPtr->GetHeaderLength(); // header length
387           fBuffer[index++] = 0; // raw data length
388           fBuffer[index++] = iBusPatch; // bus patch
389         }
390       } // bus patch
391       
392       // check if totalLength even
393       // set padding word in case
394       // Add one word 0xBEEFFACE at the end of DSP structure
395       Int_t totalDspLength  = index - indexDsp;
396       if ((totalDspLength % 2) == 1) 
397       { 
398         fBuffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
399         fBuffer[index++] = fDspHeader->GetDefaultPaddingWord();
400         totalDspLength++;
401       }
402       
403       Int_t dspLength     = totalDspLength - fDspHeader->GetHeaderLength();
404       
405       fBuffer[indexDsp+1] = totalDspLength; // dsp total length
406       fBuffer[indexDsp+2] = dspLength; // data length  
407       
408     } // dsp
409     
410     Int_t totalBlkLength  = index - indexBlk;
411     Int_t blkLength       = totalBlkLength - fBlockHeader->GetHeaderLength();
412     totalDDLLength       += totalBlkLength;
413     
414     fBuffer[indexBlk+1] = totalBlkLength; // total block length
415     fBuffer[indexBlk+2] = blkLength;
416         
417   } // block
418   
419     // add twice the end of CRT structure data key
420     // hope it's good placed (ChF)
421     fBuffer[index++] = fBlockHeader->GetDdlDataKey();
422     fBuffer[index++] = fBlockHeader->GetDdlDataKey();
423     totalDDLLength  += 2;
424   
425   // writting onto disk
426   // total length in bytes
427   // DDL header
428
429   Int_t headerSize = sizeof(AliRawDataHeader)/4;
430   
431   fHeader->fSize = (totalDDLLength + headerSize) * 4;
432   
433   AliFstream* file = new AliFstream(AliDAQ::DdlFileName("MUONTRK",iDDL));
434   
435   file->WriteBuffer((char*)fHeader,headerSize*4);
436   file->WriteBuffer((char*)fBuffer,sizeof(int)*index);
437   delete file;
438 }
439
440 //______________________________________________________________________________
441 Int_t AliMUONRawWriter::GetBusPatch(const AliMUONVDigit& digit) const
442 {
443   /// Determine the BusPatch this digit belongs to.
444
445     return fDDLStore->GetBusPatchId(digit.DetElemId(),digit.ManuId());
446 }
447
448 //______________________________________________________________________________
449 Int_t AliMUONRawWriter::WriteTriggerDDL(const AliMUONVTriggerStore& triggerStore, AliFstream* file[2])
450 {
451   /// Write trigger DDL
452   
453   AliCodeTimerAuto("")
454
455   if (fHeader == 0x0) {
456     AliError("Raw data header must be set");
457     return 0;
458   }
459
460  // DDL event one per half chamber
461
462  // DDL header size
463   Int_t headerSize = sizeof(AliRawDataHeader)/4;
464
465   // global trigger for trigger pattern
466   AliMUONGlobalTrigger* gloTrg = triggerStore.Global();
467   if (!gloTrg) 
468   {
469     return 0;
470   }
471   
472   Int_t gloTrigResp = gloTrg->GetGlobalResponse();
473
474   UInt_t word;
475   Int_t* buffer = 0;
476   Int_t index;
477   Int_t locCard;
478   UChar_t locDec, trigY, posY, posX, regOut;
479   UInt_t regInpLpt;
480   UInt_t regInpHpt;
481
482   UInt_t devX;
483   UChar_t sdevX;
484   UInt_t version = 1; // software version
485   UInt_t eventPhys = 1; // trigger type: 1 for physics, 0 for software
486   UInt_t serialNb = 0xF; // serial nb of card: all bits on for the moment
487   Int_t globalFlag = 0; // set to 1 if global info present in DDL else set to 0
488
489   // size of headers
490   static const Int_t kDarcHeaderLength   = fDarcHeader->GetDarcHeaderLength();
491   static const Int_t kGlobalHeaderLength = fDarcHeader->GetGlobalHeaderLength();
492   static const Int_t kDarcScalerLength   = fDarcHeader->GetDarcScalerLength();
493   static const Int_t kGlobalScalerLength = fDarcHeader->GetGlobalScalerLength();
494   static const Int_t kRegHeaderLength    = fRegHeader->GetHeaderLength();
495   static const Int_t kRegScalerLength    = fRegHeader->GetScalerLength();
496   static const Int_t kLocHeaderLength    = fLocalStruct->GetLength();
497   static const Int_t kLocScalerLength    = fLocalStruct->GetScalerLength();
498
499   // [16(local)*6 words + 6 words]*8(reg) + 8 words = 824 
500   static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) +  (kRegHeaderLength+1))* 8 
501       +  kDarcHeaderLength + kGlobalHeaderLength + 2;
502
503   // [16(local)*51 words + 16 words]*8(reg) + 8 + 10 + 8 words scaler event 6682 words
504   static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength +  kLocScalerLength +1) +  
505                                          (kRegHeaderLength + kRegScalerLength +1))* 8 +
506                                          (kDarcHeaderLength + kDarcScalerLength + 
507                                           kGlobalHeaderLength + kGlobalScalerLength + 2);
508   if(fScalerEvent) {
509     eventPhys = 0; //set to generate scaler events
510     fHeader->fWord2 |= (0x1 << 14); // set L1SwC bit on
511   }
512   if(fScalerEvent)
513     buffer = new Int_t [kScalerBufferSize];
514   else
515     buffer = new Int_t [kBufferSize];
516
517   // reset crate
518
519   // open DDL file, on per 1/2 chamber
520   for ( Int_t iDDL = 0; iDDL < 2; ++iDDL ) 
521   {
522     index = 0; 
523
524     if (iDDL == 0) // suppose global info in DDL one
525       globalFlag = 1;
526     else 
527       globalFlag = 0;
528
529     word = 0;
530     // set darc status word
531     // see AliMUONDarcHeader.h for details
532     AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30);
533     AliBitPacking::PackWord((UInt_t)serialNb,word,20,23);
534     AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10);
535     AliBitPacking::PackWord((UInt_t)version,word,12,19);
536     fDarcHeader->SetWord(word);
537
538     memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4); 
539     index += kDarcHeaderLength;
540
541     // no global input for the moment....
542     if (iDDL == 0)
543      fDarcHeader->SetGlobalOutput(gloTrigResp);
544     else 
545      fDarcHeader->SetGlobalOutput(0);
546
547     if (fScalerEvent) {
548       // 6 DARC scaler words
549       memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4);
550       index += kDarcScalerLength;
551     }
552     // end of darc word
553     buffer[index++] = fDarcHeader->GetEndOfDarc();
554
555     // 4 words of global board input + Global board output
556     memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4); 
557     index += kGlobalHeaderLength; 
558
559     if (fScalerEvent) {
560       // 10 Global scaler words
561       memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4);
562       index += kGlobalScalerLength;
563     }
564
565     // end of global word
566     buffer[index++] = fDarcHeader->GetEndOfGlobal();
567     const AliMpRegionalTrigger* reg = AliMpDDLStore::Instance()->GetRegionalTrigger(); 
568
569     Int_t nCrate = reg->GetNofTriggerCrates()/2;
570     // 8 regional cards per DDL
571     for (Int_t iReg = 0; iReg < nCrate; ++iReg) {
572
573         // crate info
574       AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(iDDL, iReg);
575
576       if (!crate) 
577         AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
578
579       // regional info tree, make sure that no reg card missing
580       AliMUONRegionalTrigger* regTrg  = triggerStore.FindRegional(crate->GetId());
581       if (!regTrg) 
582         AliError(Form("Missing regional board %d in trigger Store\n", crate->GetId()));
583     
584       // Regional card header
585       word = 0;
586
587       // set darc status word
588       fRegHeader->SetDarcWord(word);
589
590       regOut    = regTrg->GetOutput();
591       regInpHpt = regTrg->GetLocalOutput(0);
592       regInpLpt = regTrg->GetLocalOutput(1);
593
594       // fill darc word, not darc status for the moment (empty)
595       //see  AliMUONRegHeader.h for details
596       AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31); 
597       AliBitPacking::PackWord((UInt_t)serialNb,word,19,24); 
598       AliBitPacking::PackWord((UInt_t)version,word,7,14);
599       AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
600       AliBitPacking::PackWord((UInt_t)regOut,word,0,7); 
601       fRegHeader->SetWord(word);
602
603
604       // fill header later, need local response
605       Int_t indexReg = index;
606       index += kRegHeaderLength;
607
608       // 11 regional scaler word
609       if (fScalerEvent) {
610         memcpy(&buffer[index], fRegHeader->GetScalers(), kRegScalerLength*4);
611         index += kRegScalerLength;
612       }
613
614       // end of regional word
615       buffer[index++] = fRegHeader->GetEndOfReg();
616       
617       // 16 local card per regional board
618       //      UShort_t localMask = 0x0;
619       
620       Int_t nLocalBoard = AliMpConstants::LocalBoardNofChannels();
621
622       for (Int_t iLoc = 0; iLoc < nLocalBoard; iLoc++) {
623           
624         // slot zero for Regional card
625         Int_t localBoardId = crate->GetLocalBoardId(iLoc);
626
627         if (localBoardId) { // if not empty slot
628           AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(localBoardId);
629
630           if (localBoard->IsNotified()) {// if notified board 
631             AliMUONLocalTrigger* locTrg = triggerStore.FindLocal(localBoardId);
632
633             locCard = locTrg->LoCircuit();
634             locDec  = locTrg->GetLoDecision();
635             trigY   = locTrg->LoTrigY();
636             posY    = locTrg->LoStripY();
637             posX    = locTrg->LoStripX();
638             devX    = locTrg->LoDev();
639             sdevX   = locTrg->LoSdev();
640                   
641             AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n", 
642                             locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));  
643             //packing word
644             word = 0;
645             LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY, 
646                              (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
647
648             buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
649             buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
650             buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
651             buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
652             buffer[index++] = (Int_t)word; // data word
653                       
654                 
655           }
656           // fill copy card X-Y inputs from the notified cards 
657           if (localBoard->GetInputXfrom() && localBoard->GetInputYfrom()) 
658           {
659             // not triggered
660             locDec = 0; trigY = 1; posY = 15;    
661             posX   = 0; devX  = 0; sdevX = 1;
662             LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY, 
663                              (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
664
665             Int_t localFromId = localBoard->GetInputXfrom();
666             AliMUONLocalTrigger* locTrgfrom  = triggerStore.FindLocal(localFromId);
667
668             buffer[index++] = 0; // copy only X3-4 & Y1-4
669             buffer[index++] = (locTrgfrom->GetX3Pattern() | (locTrgfrom->GetX4Pattern() << 16));
670             buffer[index++] = (locTrgfrom->GetY1Pattern() | (locTrgfrom->GetY2Pattern() << 16));
671             buffer[index++] = (locTrgfrom->GetY3Pattern() | (locTrgfrom->GetY4Pattern() << 16));
672             buffer[index++] = word;
673           }
674
675         } else { 
676           // fill with 10CDEAD word for empty slots
677           for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
678               buffer[index++] = fLocalStruct->GetDisableWord(); 
679         }// condition localBoard
680           
681         // 45 regional scaler word
682         if (fScalerEvent) {
683           memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
684           index += kLocScalerLength;
685         }
686           
687         // end of local structure words
688         buffer[index++] = fLocalStruct->GetEndOfLocal();
689           
690       } // local card 
691       // fill regional header with local output
692       fRegHeader->SetInput(regInpHpt, 0);
693       fRegHeader->SetInput(regInpHpt, 1);
694       memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);
695       
696     } // Regional card
697     
698
699     // writting onto disk
700     // write DDL's
701     fHeader->fSize = (index + headerSize) * 4;// total length in bytes
702     file[iDDL]->WriteBuffer((char*)fHeader,headerSize*4);
703     file[iDDL]->WriteBuffer((char*)buffer,sizeof(int)*index);
704   
705   }
706   delete[] buffer;
707
708   return kTRUE;
709 }
710
711 //____________________________________________________________________
712 void AliMUONRawWriter::SetScalersNumbers()
713 {
714   /// set numbers for scaler events for trigger headers
715   /// since this is provided by the experiment
716   /// put dummy numbers to check the monitoring
717
718   fDarcHeader->SetScalersNumbers();
719   fRegHeader->SetScalersNumbers();
720   fLocalStruct->SetScalersNumbers();
721  
722   fScalerEvent = kTRUE;
723 }
724