1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// \class AliMUONRawWriter
19 /// MUON Raw Data generaton in ALICE-MUON
20 /// This class version 3 (further details could be found in Alice-note)
22 /// Implemented non-constant buspatch numbers for tracking
23 /// with correct DDL id (first guess)
24 /// (Ch. Finck, dec 2005)
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.
41 #include "AliMUONRawWriter.h"
43 #include "AliMUONBlockHeader.h"
44 #include "AliMUONBusStruct.h"
45 #include "AliMUONConstants.h"
46 #include "AliMUONDarcHeader.h"
47 #include "AliMUONData.h"
48 #include "AliMUONDigit.h"
49 #include "AliMUONDspHeader.h"
50 #include "AliMUONGlobalTrigger.h"
51 #include "AliMUONLocalStruct.h"
52 #include "AliMUONLocalTrigger.h"
53 #include "AliMUONLocalTriggerBoard.h"
54 #include "AliMUONRegHeader.h"
55 #include "AliMUONTriggerCrate.h"
56 #include "AliMUONTriggerCrateStore.h"
58 #include "AliMpBusPatch.h"
59 #include "AliMpDEManager.h"
60 #include "AliMpExMap.h"
61 #include "AliMpConstants.h"
62 #include "AliMpPlaneType.h"
63 #include "AliMpSegmentation.h"
64 #include "AliMpStationType.h"
65 #include "AliMpVSegmentation.h"
67 #include "AliRawReader.h"
68 #include "AliBitPacking.h"
73 #include "TObjArray.h"
74 #include "TStopwatch.h"
77 ClassImp(AliMUONRawWriter) // Class implementation in ROOT context
80 Int_t AliMUONRawWriter::fgManuPerBusSwp1B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 224, 232};
81 Int_t AliMUONRawWriter::fgManuPerBusSwp1NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 225, 233};
83 Int_t AliMUONRawWriter::fgManuPerBusSwp2B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 226, 246};
84 Int_t AliMUONRawWriter::fgManuPerBusSwp2NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 227, 245};
88 enum ETimer { kWriteTracker, kWriteTrigger, kDigitLoop, kGetBusPatch, kTest, kLast };
91 //__________________________________________________________________________
92 AliMUONRawWriter::AliMUONRawWriter(AliMUONData* data)
95 fBlockHeader(new AliMUONBlockHeader()),
96 fDspHeader(new AliMUONDspHeader()),
97 fDarcHeader(new AliMUONDarcHeader()),
98 fRegHeader(new AliMUONRegHeader()),
99 fLocalStruct(new AliMUONLocalStruct()),
100 fBusPatchManager(new AliMpBusPatch()),
101 fCrateManager(new AliMUONTriggerCrateStore()),
102 fScalerEvent(kFALSE),
104 fTimers(new TStopwatch[kLast])
107 /// Standard Constructor
109 AliDebug(1,"Standard ctor");
110 fFile[0] = fFile[1] = 0x0;
111 fFile[2] = fFile[3] = 0x0;
113 // setting data key to default value (only for writting)
114 fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
115 fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
117 // bus patch managers
118 fBusPatchManager->ReadBusPatchFile();
121 fCrateManager->ReadFromFile();
124 for ( Int_t i = 0; i < kLast; ++i )
126 fTimers[i].Start(kTRUE);
132 //__________________________________________________________________________
133 AliMUONRawWriter::AliMUONRawWriter()
143 fScalerEvent(kFALSE),
147 /// Default Constructor
149 AliDebug(1,"Default ctor");
150 fFile[0] = fFile[1] = 0x0;
151 fFile[2] = fFile[3] = 0x0;
155 //__________________________________________________________________________
156 AliMUONRawWriter::~AliMUONRawWriter(void)
168 delete fBusPatchManager;
169 delete fCrateManager;
171 for ( Int_t i = 0; i < kLast; ++i )
173 AliDebug(1, Form("Execution time (timer %d) : R:%7.2fs C:%7.2fs",i,
174 fTimers[i].RealTime(),fTimers[i].CpuTime()));
180 //______________________________________________________________________________
182 //AliMUONRawWriter::CheckDigits()
184 // std::map<int,std::map<int,int> > m;
186 // for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt)
188 // for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh)
190 // TClonesArray* muonDigits = fMUONData->Digits(iCh);
191 // for (Int_t idig = 0; idig < muonDigits->GetEntriesFast(); idig++)
193 // AliMUONDigit* digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
194 // Int_t busPatchId = GetBusPatch(*digit);
195 // m[busPatchId][digit->ManuId()]++;
200 // std::map<int,std::map<int,int> >::const_iterator it;
202 // Int_t nManuMax(0);
204 // for ( it = m.begin(); it != m.end(); ++it )
206 // AliDebug(1,Form("BusPatch %3d has %3d manus",it->first,it->second.size()));
207 // nManuMax = std::max((Int_t)it->second.size(),nManuMax);
208 // std::map<int,int>::const_iterator it2;
209 // for ( it2 = it->second.begin(); it2 != it->second.end(); ++it2 )
211 // AliDebug(1,Form(" BusPatch %3d Manu %4d Nch %3d",it->first,it2->first,it2->second));
214 // AliDebug(1,Form("Max manus per busPatch : %3d",nManuMax));
217 //____________________________________________________________________
218 Int_t AliMUONRawWriter::Digits2Raw()
220 /// convert digits of the current event to raw data
225 fMUONData->GetLoader()->LoadDigits("READ");
227 fMUONData->SetTreeAddress("D,GLT");
229 fMUONData->ResetDigits();
230 fMUONData->ResetTrigger();
232 // This will get both tracker and trigger digits.
233 fMUONData->GetDigits();
239 for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt) {
241 // open files for one station
242 // cos station 3, 1/4 of DE's from 2 chambers has same DDL number
244 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
245 fFile[0] = fopen(name,"w");
247 idDDL = (iSt * 4) + 1;
248 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
249 fFile[1] = fopen(name,"w");
251 idDDL = (iSt * 4) + 2;;
252 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
253 fFile[2] = fopen(name,"w");
255 idDDL = (iSt * 4) + 3;
256 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
257 fFile[3] = fopen(name,"w");
259 WriteTrackerDDL(iSt);
261 // reset and close when station has been processed
269 AliDebug(1,"Tracker written");
275 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
276 fFile[0] = fopen(name,"w");
279 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
280 fFile[1] = fopen(name,"w");
288 AliDebug(1,"Trigger written");
290 fMUONData->ResetDigits();
291 fMUONData->ResetTrigger();
292 fMUONData->GetLoader()->UnloadDigits();
294 AliDebug(1,"muondata reset");
299 //____________________________________________________________________
300 Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iSt)
302 /// writing DDL for tracker
303 /// used inverse mapping
305 fTimers[kWriteTracker].Start(kFALSE);
307 static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
310 TClonesArray* muonDigits = 0;
313 Int_t headerSize = sizeof(fHeader)/4;
315 // DDL event one per half chamber
320 UChar_t channelId = 0;
322 Int_t busPatchId = 0;
327 Int_t totalDspLength;
331 Int_t totalBlkLength;
335 Int_t totalDDLLength;
342 // buffer size (max'ed out)
343 // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch
344 // + 10 dsp words)*5 dsps + 8 block words)*2 blocks
345 static const Int_t kBufferSize = (((43*64 + 4)*5 + 10)*5 + 8)*2;
349 AliMpExMap busPatchMap(kTRUE);
351 fTimers[kDigitLoop].Start(kFALSE);
353 for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh) {
355 muonDigits = fMUONData->Digits(iCh);
357 nDigits = muonDigits->GetEntriesFast();
360 for (Int_t idig = 0; idig < nDigits; ++idig) {
362 AliMUONDigit* digit = static_cast<AliMUONDigit*>(muonDigits->UncheckedAt(idig));
364 charge = digit->ADC();
365 if ( charge > kMAXADC )
367 // This is most probably an error in the digitizer (which should insure
368 // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
369 AliError(Form("adc value %d above %x for ch %d . Setting to %x. Digit is:",iCh,
370 charge,kMAXADC,kMAXADC));
371 StdoutToAliError(digit->Print());
376 fTimers[kGetBusPatch].Start(kFALSE);
377 busPatchId = GetBusPatch(*digit);
378 fTimers[kGetBusPatch].Stop();
379 if (busPatchId<0) continue;
381 fTimers[kTest].Start(kFALSE);
382 busPatchId = GetBusPatch(*digit);
383 fTimers[kTest].Stop();
385 if ( digit->ManuId() > 0x7FF || digit->ManuId() < 0 ||
386 digit->ManuChannel() > 0x3F || digit->ManuChannel() < 0 )
388 StdoutToAliError(digit->Print(););
389 AliFatal("ManuId,ManuChannel are invalid for the digit above.");
392 manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
393 channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
397 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
398 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
399 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
403 for (Int_t i = 1; i <= 30; ++i)
404 parity ^= ((word >> i) & 0x1);
405 AliBitPacking::PackWord((UInt_t)parity,word,31,31);
407 AliMUONBusStruct* busStruct =
408 static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
412 busStruct = new AliMUONBusStruct;
413 busStruct->SetDataKey(busStruct->GetDefaultDataKey());
414 busStruct->SetBusPatchId(busPatchId);
415 busStruct->SetLength(0);
416 busPatchMap.Add(busPatchId,busStruct);
420 busStruct->AddData(word);
423 } // loop over chamber in station
425 fTimers[kDigitLoop].Stop();
427 // getting info for the number of buspatches
430 Int_t iBusPerDSP[5];//number of bus patches per DSP
431 Int_t iDspMax; //number max of DSP per block
434 AliMUONBusStruct* busStructPtr(0x0);
436 // open DDL files, 4 per station
437 for (Int_t iDDL = iSt*4; iDDL < 4 + iSt*4; ++iDDL) {
439 fBusPatchManager->ResetBusItr(iDDL);
440 fBusPatchManager->GetDspInfo(iDDL, iDspMax, iBusPerDSP);
442 Int_t buffer[kBufferSize];
450 // two blocks A and B per DDL
451 for (Int_t iBlock = 0; iBlock < 2; ++iBlock) {
454 length = fBlockHeader->GetHeaderLength();
455 memcpy(&buffer[index],fBlockHeader->GetHeader(),length*4);
459 // 5 DSP's max per block
460 for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp) {
463 length = fDspHeader->GetHeaderLength();
464 memcpy(&buffer[index],fDspHeader->GetHeader(),length*4);
468 //Â 5 buspatches max per DSP
469 for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) {
471 iBusPatch = fBusPatchManager->NextBusInDDL(iDDL);
473 // iteration over bus patch in DDL
474 if (iBusPatch == -1) {
475 AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
479 // 4 DDL's per station, condition needed for station 3
480 iFile = iDDL - iSt*4; // works only if DDL begins at zero (as it should be) !!!
482 busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
484 // check if buspatchid has digit
486 // add bus patch structure header
487 length = busStructPtr->GetHeaderLength();
488 memcpy(&buffer[index],busStructPtr->GetHeader(),length*4);
491 // add bus patch data
492 length = busStructPtr->GetLength();
493 memcpy(&buffer[index],busStructPtr->GetData(),length*4);
496 if (AliLog::GetGlobalDebugLevel() == 3) {
497 for (Int_t j = 0; j < busStructPtr->GetLength(); j++) {
498 printf("busPatchId %d, manuId %d channelId %d\n", busStructPtr->GetBusPatchId(),
499 busStructPtr->GetManuId(j), busStructPtr->GetChannelId(j));
503 // writting anyhow buspatch structure (empty ones)
504 buffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
505 buffer[index++] = busStructPtr->GetHeaderLength(); // header length
506 buffer[index++] = 0; // raw data length
507 buffer[index++] = iBusPatch; // bus patch
511 // check if totalLength even
512 // set padding word in case
513 // Add one word 0xBEEFFACE at the end of DSP structure
514 totalDspLength = index - indexDsp;
515 if ((totalDspLength % 2) == 1) {
516 buffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
517 buffer[index++] = fDspHeader->GetDefaultPaddingWord();
521 dspLength = totalDspLength - fDspHeader->GetHeaderLength();
523 buffer[indexDsp+1] = totalDspLength; // dsp total length
524 buffer[indexDsp+2] = dspLength; // data length
528 totalBlkLength = index - indexBlk;
529 blkLength = totalBlkLength - fBlockHeader->GetHeaderLength();
530 totalDDLLength += totalBlkLength;
532 buffer[indexBlk+1] = totalBlkLength; // total block length
533 buffer[indexBlk+2] = blkLength;
539 // total length in bytes
540 fHeader.fSize = (totalDDLLength + headerSize) * 4;
542 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iFile]);
543 fwrite(buffer,sizeof(int),index,fFile[iFile]);
546 fTimers[kWriteTracker].Stop();
550 //____________________________________________________________________
551 Int_t AliMUONRawWriter::GetBusPatch(Int_t detElemId, Int_t manuId) const
553 /// Determine the BusPatch this digit belongs to.
557 AliMpPlaneType plane =
558 (manuId & AliMpConstants::ManuMask(kNonBendingPlane)) ?
559 kNonBendingPlane : kBendingPlane;
561 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
563 if ( stationType == kStation1 || stationType == kStation2 )
565 if (plane == kBendingPlane)
567 ptr = &fgManuPerBusSwp1B[0];
571 ptr = &fgManuPerBusSwp1NB[0];
576 if (plane == kBendingPlane)
578 ptr = &fgManuPerBusSwp2B[0];
582 ptr = &fgManuPerBusSwp2NB[0];
586 // Getting buspatch id
587 TArrayI* vec = fBusPatchManager->GetBusfromDE(detElemId);
590 Int_t m = ( manuId & 0x3FF ); // remove bit 10
591 //FIXME : how can we remove that condition
592 // on the 10-th bit ? All the rest need not any knowledge about it,
593 // can't we find a way to get manu<->buspatch transparent to this too ?
595 if ( stationType == kStation1 || stationType == kStation2 )
597 for (pos = 11; pos >=0 ; --pos)
599 if (m >= ptr[pos]) break;
604 // offset of 100 in manuId for following bus patch
609 if (pos >(Int_t) vec->GetSize())
611 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
612 pos, (Int_t)vec->GetSize(), manuId, detElemId));
613 AliError(Form("Chamber %s Plane %s manuId %d m %d",
614 StationTypeName(stationType).Data(),
615 PlaneTypeName(plane).Data(),
621 Int_t busPatchId = vec->At(pos);
623 if ( ( stationType == kStation1 || stationType == kStation2 ) &&
624 ( plane == kNonBendingPlane ) )
632 //____________________________________________________________________
633 Int_t AliMUONRawWriter::GetBusPatch(const AliMUONDigit& digit) const
635 /// Determine the BusPatch this digit belongs to.
637 return GetBusPatch(digit.DetElemId(),digit.ManuId());
640 //____________________________________________________________________
641 Int_t AliMUONRawWriter::WriteTriggerDDL()
643 /// Write trigger DDL
645 fTimers[kWriteTrigger].Start(kFALSE);
647 // DDL event one per half chamber
649 // stored local id number
650 TArrayI isFired(256);
655 Int_t headerSize = sizeof(AliRawDataHeader)/4;
657 TClonesArray* localTrigger;
658 TClonesArray* globalTrigger;
659 AliMUONGlobalTrigger* gloTrg;
660 AliMUONLocalTrigger* locTrg = 0x0;
662 // global trigger for trigger pattern
663 globalTrigger = fMUONData->GlobalTrigger();
664 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
667 fTimers[kWriteTrigger].Stop();
671 Int_t gloTrigResp = gloTrg->GetGlobalResponse();
674 localTrigger = fMUONData->LocalTrigger();
680 Int_t iLocCard, locCard;
681 Char_t locDec, trigY, posY, posX, regOut;
686 Int_t version = 1; // software version
687 Int_t eventPhys = 1; // trigger type: 1 for physics, 0 for software
688 Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
689 Int_t globalFlag = 0; // set to 1 if global info present in DDL else set to 0
692 static const Int_t kDarcHeaderLength = fDarcHeader->GetDarcHeaderLength();
693 static const Int_t kGlobalHeaderLength = fDarcHeader->GetGlobalHeaderLength();
694 static const Int_t kDarcScalerLength = fDarcHeader->GetDarcScalerLength();
695 static const Int_t kGlobalScalerLength = fDarcHeader->GetGlobalScalerLength();
696 static const Int_t kRegHeaderLength = fRegHeader->GetHeaderLength();
697 static const Int_t kRegScalerLength = fRegHeader->GetScalerLength();
698 static const Int_t kLocHeaderLength = fLocalStruct->GetLength();
699 static const Int_t kLocScalerLength = fLocalStruct->GetScalerLength();
701 // [16(local)*6 words + 6 words]*8(reg) + 8 words = 824
702 static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) + (kRegHeaderLength+1))* 8
703 + kDarcHeaderLength + kGlobalHeaderLength + 2;
705 // [16(local)*51 words + 16 words]*8(reg) + 8 + 10 + 8 words scaler event 6682 words
706 static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength + kLocScalerLength +1) +
707 (kRegHeaderLength + kRegScalerLength +1))* 8 +
708 (kDarcHeaderLength + kDarcScalerLength +
709 kGlobalHeaderLength + kGlobalScalerLength + 2);
711 eventPhys = 0; //set to generate scaler events
713 Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
714 // stored the local card id that's fired
715 for (Int_t i = 0; i < nEntries; i++) {
716 locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
717 isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations
721 AliDebug(1, "No Trigger information available");
724 buffer = new Int_t [kScalerBufferSize];
726 buffer = new Int_t [kBufferSize];
730 // open DDL file, on per 1/2 chamber
731 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
735 if (iDDL == 0) // suppose global info in DDL one
741 // set darc status word
742 // see AliMUONDarcHeader.h for details
743 AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30);
744 AliBitPacking::PackWord((UInt_t)serialNb,word,20,23);
745 AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10);
746 AliBitPacking::PackWord((UInt_t)version,word,12,19);
747 fDarcHeader->SetWord(word);
749 memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4);
750 index += kDarcHeaderLength;
752 // no global input for the moment....
754 fDarcHeader->SetGlobalOutput(gloTrigResp);
756 fDarcHeader->SetGlobalOutput(0);
759 // 6 DARC scaler words
760 memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4);
761 index += kDarcScalerLength;
764 buffer[index++] = fDarcHeader->GetEndOfDarc();
766 // 4 words of global board input + Global board output
767 memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4);
768 index += kGlobalHeaderLength;
771 // 10 Global scaler words
772 memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4);
773 index += kGlobalScalerLength;
776 // end of global word
777 buffer[index++] = fDarcHeader->GetEndOfGlobal();
779 // 8 regional cards per DDL
780 for (Int_t iReg = 0; iReg < 8; iReg++) {
783 AliMUONTriggerCrate* crate = fCrateManager->Crate(iDDL, iReg);
786 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
788 // Regional card header
791 // set darc status word
792 fRegHeader->SetDarcWord(word);
795 regInpHpt = regInpLpt = 0;
796 // fill darc word, not darc status for the moment (empty)
797 //see AliMUONRegHeader.h for details
798 AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31);
799 AliBitPacking::PackWord((UInt_t)serialNb,word,19,24);
800 AliBitPacking::PackWord((UInt_t)version,word,16,23);
801 AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
802 AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // waiting realistic output of AliMUONGlobalTrigger (oct 06 ?)
803 fRegHeader->SetWord(word);
806 // fill header later, need local response
807 Int_t indexReg = index;
808 index += kRegHeaderLength;
810 // 11 regional scaler word
812 memcpy(&buffer[index], fRegHeader->GetScalers(), kRegScalerLength*4);
813 index += kRegScalerLength;
816 // end of regional word
817 buffer[index++] = fRegHeader->GetEndOfReg();
819 TObjArray *boards = crate->Boards();
822 // 16 local card per regional board
823 UShort_t localMask = 0x0;
825 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
827 // slot zero for Regional card
828 AliMUONLocalTriggerBoard* localBoard = (AliMUONLocalTriggerBoard*)boards->At(iLoc+1);
830 if (localBoard) { // if not empty slot
832 if ((iLocCard = localBoard->GetNumber()) != 0) {// if notified board
834 localMask |= (0x1 << iLoc); // local mask
835 if (isFired[iLocCard]) { // if card has triggered
836 locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries);
837 locCard = locTrg->LoCircuit();
838 locDec = locTrg->GetLoDecision();
840 posY = locTrg->LoStripY();
841 posX = locTrg->LoStripX();
842 devX = locTrg->LoDev();
844 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
845 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
846 } else { //no trigger (see PRR chpt 3.4)
852 // set local card id to -1
855 // calculate regional input High and low Pt
856 UInt_t tmp1 = (locDec >> 2) & 0x3;
857 UInt_t tmp2 = locDec & 0x3;
859 regInpHpt |= tmp1 << (30 - iLoc*2);
860 regInpLpt |= tmp2 << (30 - iLoc*2);
864 AliBitPacking::PackWord((UInt_t)iLoc,word,19,22); //card id number in crate
865 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
866 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
867 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
868 AliBitPacking::PackWord((UInt_t)devX,word,5,9);
869 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
871 if (locCard == iLocCard) {
872 // add local cards structure
873 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
874 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
875 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
876 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
877 buffer[index++] = (Int_t)word; // data word
878 if (iEntries < nEntries-1)
881 buffer[index++] = 0; // 4 words for x1, x2, y1, y2
885 buffer[index++] = (Int_t)word; // data word
889 // fill with 10CDEAD word for 'non-notified' slots
890 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
891 buffer[index++] = fLocalStruct->GetDisableWord();
894 // fill with 10CDEAD word for empty slots
895 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
896 buffer[index++] = fLocalStruct->GetDisableWord();
897 }// condition localBoard
899 // 45 regional scaler word
901 memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
902 index += kLocScalerLength;
905 // end of local structure words
906 buffer[index++] = fLocalStruct->GetEndOfLocal();
909 // fill regional header with local output
910 fRegHeader->SetInput(regInpLpt, 0);
911 fRegHeader->SetInput(regInpHpt, 1);
912 fRegHeader->SetMask(localMask);
913 memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);
918 // writting onto disk
920 fHeader.fSize = (index + headerSize) * 4;// total length in bytes
921 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iDDL]);
922 fwrite(buffer,sizeof(int),index,fFile[iDDL]);
927 fTimers[kWriteTrigger].Stop();
931 //____________________________________________________________________
932 void AliMUONRawWriter::SetScalersNumbers()
934 /// set numbers for scaler events for trigger headers
935 /// since this is provided by the experiment
936 /// put dummy numbers to check the monitoring
938 fDarcHeader->SetScalersNumbers();
939 fRegHeader->SetScalersNumbers();
940 fLocalStruct->SetScalersNumbers();
942 fScalerEvent = kTRUE;