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 "AliMUONRegionalTrigger.h"
55 #include "AliMUONRegHeader.h"
56 #include "AliMUONTriggerCrate.h"
57 #include "AliMUONTriggerCrateStore.h"
59 #include "AliMpBusPatch.h"
60 #include "AliMpDEManager.h"
61 #include "AliMpExMap.h"
62 #include "AliMpConstants.h"
63 #include "AliMpPlaneType.h"
64 #include "AliMpSegmentation.h"
65 #include "AliMpStationType.h"
66 #include "AliMpVSegmentation.h"
68 #include "AliRawReader.h"
69 #include "AliBitPacking.h"
74 #include "TObjArray.h"
75 #include "TStopwatch.h"
78 ClassImp(AliMUONRawWriter) // Class implementation in ROOT context
81 Int_t AliMUONRawWriter::fgManuPerBusSwp1B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 224, 232};
82 Int_t AliMUONRawWriter::fgManuPerBusSwp1NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 225, 233};
84 Int_t AliMUONRawWriter::fgManuPerBusSwp2B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 226, 246};
85 Int_t AliMUONRawWriter::fgManuPerBusSwp2NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 227, 245};
89 enum ETimer { kWriteTracker, kWriteTrigger, kDigitLoop, kGetBusPatch, kTest, kLast };
92 //__________________________________________________________________________
93 AliMUONRawWriter::AliMUONRawWriter(AliMUONData* data)
96 fBlockHeader(new AliMUONBlockHeader()),
97 fDspHeader(new AliMUONDspHeader()),
98 fDarcHeader(new AliMUONDarcHeader()),
99 fRegHeader(new AliMUONRegHeader()),
100 fLocalStruct(new AliMUONLocalStruct()),
101 fBusPatchManager(new AliMpBusPatch()),
102 fCrateManager(new AliMUONTriggerCrateStore()),
103 fScalerEvent(kFALSE),
105 fTimers(new TStopwatch[kLast])
108 /// Standard Constructor
110 AliDebug(1,"Standard ctor");
111 fFile[0] = fFile[1] = 0x0;
112 fFile[2] = fFile[3] = 0x0;
114 // setting data key to default value (only for writting)
115 fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
116 fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
118 // bus patch managers
119 fBusPatchManager->ReadBusPatchFile();
122 fCrateManager->ReadFromFile();
125 for ( Int_t i = 0; i < kLast; ++i )
127 fTimers[i].Start(kTRUE);
133 //__________________________________________________________________________
134 AliMUONRawWriter::AliMUONRawWriter()
144 fScalerEvent(kFALSE),
148 /// Default Constructor
150 AliDebug(1,"Default ctor");
151 fFile[0] = fFile[1] = 0x0;
152 fFile[2] = fFile[3] = 0x0;
156 //__________________________________________________________________________
157 AliMUONRawWriter::~AliMUONRawWriter(void)
169 delete fBusPatchManager;
170 delete fCrateManager;
172 for ( Int_t i = 0; i < kLast; ++i )
174 AliDebug(1, Form("Execution time (timer %d) : R:%7.2fs C:%7.2fs",i,
175 fTimers[i].RealTime(),fTimers[i].CpuTime()));
181 //______________________________________________________________________________
183 //AliMUONRawWriter::CheckDigits()
185 // std::map<int,std::map<int,int> > m;
187 // for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt)
189 // for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh)
191 // TClonesArray* muonDigits = fMUONData->Digits(iCh);
192 // for (Int_t idig = 0; idig < muonDigits->GetEntriesFast(); idig++)
194 // AliMUONDigit* digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
195 // Int_t busPatchId = GetBusPatch(*digit);
196 // m[busPatchId][digit->ManuId()]++;
201 // std::map<int,std::map<int,int> >::const_iterator it;
203 // Int_t nManuMax(0);
205 // for ( it = m.begin(); it != m.end(); ++it )
207 // AliDebug(1,Form("BusPatch %3d has %3d manus",it->first,it->second.size()));
208 // nManuMax = std::max((Int_t)it->second.size(),nManuMax);
209 // std::map<int,int>::const_iterator it2;
210 // for ( it2 = it->second.begin(); it2 != it->second.end(); ++it2 )
212 // AliDebug(1,Form(" BusPatch %3d Manu %4d Nch %3d",it->first,it2->first,it2->second));
215 // AliDebug(1,Form("Max manus per busPatch : %3d",nManuMax));
218 //____________________________________________________________________
219 Int_t AliMUONRawWriter::Digits2Raw()
221 /// convert digits of the current event to raw data
226 fMUONData->GetLoader()->LoadDigits("READ");
228 fMUONData->SetTreeAddress("D,GLT");
230 fMUONData->ResetDigits();
231 fMUONData->ResetTrigger();
233 // This will get both tracker and trigger digits.
234 fMUONData->GetDigits();
240 for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt) {
242 // open files for one station
243 // cos station 3, 1/4 of DE's from 2 chambers has same DDL number
245 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
246 fFile[0] = fopen(name,"w");
248 idDDL = (iSt * 4) + 1;
249 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
250 fFile[1] = fopen(name,"w");
252 idDDL = (iSt * 4) + 2;;
253 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
254 fFile[2] = fopen(name,"w");
256 idDDL = (iSt * 4) + 3;
257 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
258 fFile[3] = fopen(name,"w");
260 WriteTrackerDDL(iSt);
262 // reset and close when station has been processed
270 AliDebug(1,"Tracker written");
276 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
277 fFile[0] = fopen(name,"w");
280 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
281 fFile[1] = fopen(name,"w");
289 AliDebug(1,"Trigger written");
291 fMUONData->ResetDigits();
292 fMUONData->ResetTrigger();
293 fMUONData->GetLoader()->UnloadDigits();
295 AliDebug(1,"muondata reset");
300 //____________________________________________________________________
301 Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iSt)
303 /// writing DDL for tracker
304 /// used inverse mapping
306 fTimers[kWriteTracker].Start(kFALSE);
308 static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
311 TClonesArray* muonDigits = 0;
314 Int_t headerSize = sizeof(fHeader)/4;
316 // DDL event one per half chamber
321 UChar_t channelId = 0;
323 Int_t busPatchId = 0;
328 Int_t totalDspLength;
332 Int_t totalBlkLength;
336 Int_t totalDDLLength;
343 // buffer size (max'ed out)
344 // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch
345 // + 10 dsp words)*5 dsps + 8 block words)*2 blocks
346 static const Int_t kBufferSize = (((43*64 + 4)*5 + 10)*5 + 8)*2;
350 AliMpExMap busPatchMap(kTRUE);
352 fTimers[kDigitLoop].Start(kFALSE);
354 for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh) {
356 muonDigits = fMUONData->Digits(iCh);
358 nDigits = muonDigits->GetEntriesFast();
361 for (Int_t idig = 0; idig < nDigits; ++idig) {
363 AliMUONDigit* digit = static_cast<AliMUONDigit*>(muonDigits->UncheckedAt(idig));
365 charge = digit->ADC();
366 if ( charge > kMAXADC )
368 // This is most probably an error in the digitizer (which should insure
369 // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
370 AliError(Form("adc value %d above %x for ch %d . Setting to %x. Digit is:",iCh,
371 charge,kMAXADC,kMAXADC));
372 StdoutToAliError(digit->Print());
377 fTimers[kGetBusPatch].Start(kFALSE);
378 busPatchId = GetBusPatch(*digit);
379 fTimers[kGetBusPatch].Stop();
380 if (busPatchId<0) continue;
382 if ( digit->ManuId() > 0x7FF || digit->ManuId() < 0 ||
383 digit->ManuChannel() > 0x3F || digit->ManuChannel() < 0 )
385 StdoutToAliError(digit->Print(););
386 AliFatal("ManuId,ManuChannel are invalid for the digit above.");
389 manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
390 channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
394 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
395 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
396 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
400 for (Int_t i = 1; i <= 30; ++i)
401 parity ^= ((word >> i) & 0x1);
402 AliBitPacking::PackWord((UInt_t)parity,word,31,31);
404 AliMUONBusStruct* busStruct =
405 static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
409 busStruct = new AliMUONBusStruct;
410 busStruct->SetDataKey(busStruct->GetDefaultDataKey());
411 busStruct->SetBusPatchId(busPatchId);
412 busStruct->SetLength(0);
413 busPatchMap.Add(busPatchId,busStruct);
417 busStruct->AddData(word);
420 } // loop over chamber in station
422 fTimers[kDigitLoop].Stop();
424 // getting info for the number of buspatches
427 Int_t iBusPerDSP[5];//number of bus patches per DSP
428 Int_t iDspMax; //number max of DSP per block
431 AliMUONBusStruct* busStructPtr(0x0);
433 // open DDL files, 4 per station
434 for (Int_t iDDL = iSt*4; iDDL < 4 + iSt*4; ++iDDL) {
436 fBusPatchManager->ResetBusItr(iDDL);
437 fBusPatchManager->GetDspInfo(iDDL, iDspMax, iBusPerDSP);
439 Int_t buffer[kBufferSize];
447 // two blocks A and B per DDL
448 for (Int_t iBlock = 0; iBlock < 2; ++iBlock) {
451 length = fBlockHeader->GetHeaderLength();
452 memcpy(&buffer[index],fBlockHeader->GetHeader(),length*4);
456 // 5 DSP's max per block
457 for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp) {
460 length = fDspHeader->GetHeaderLength();
461 memcpy(&buffer[index],fDspHeader->GetHeader(),length*4);
465 //Â 5 buspatches max per DSP
466 for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) {
468 iBusPatch = fBusPatchManager->NextBusInDDL(iDDL);
470 // iteration over bus patch in DDL
471 if (iBusPatch == -1) {
472 AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
476 // 4 DDL's per station, condition needed for station 3
477 iFile = iDDL - iSt*4; // works only if DDL begins at zero (as it should be) !!!
479 busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
481 // check if buspatchid has digit
483 // add bus patch structure header
484 length = busStructPtr->GetHeaderLength();
485 memcpy(&buffer[index],busStructPtr->GetHeader(),length*4);
488 // add bus patch data
489 length = busStructPtr->GetLength();
490 memcpy(&buffer[index],busStructPtr->GetData(),length*4);
493 if (AliLog::GetGlobalDebugLevel() == 3) {
494 for (Int_t j = 0; j < busStructPtr->GetLength(); j++) {
495 printf("busPatchId %d, manuId %d channelId %d\n", busStructPtr->GetBusPatchId(),
496 busStructPtr->GetManuId(j), busStructPtr->GetChannelId(j));
500 // writting anyhow buspatch structure (empty ones)
501 buffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
502 buffer[index++] = busStructPtr->GetHeaderLength(); // header length
503 buffer[index++] = 0; // raw data length
504 buffer[index++] = iBusPatch; // bus patch
508 // check if totalLength even
509 // set padding word in case
510 // Add one word 0xBEEFFACE at the end of DSP structure
511 totalDspLength = index - indexDsp;
512 if ((totalDspLength % 2) == 1) {
513 buffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
514 buffer[index++] = fDspHeader->GetDefaultPaddingWord();
518 dspLength = totalDspLength - fDspHeader->GetHeaderLength();
520 buffer[indexDsp+1] = totalDspLength; // dsp total length
521 buffer[indexDsp+2] = dspLength; // data length
525 totalBlkLength = index - indexBlk;
526 blkLength = totalBlkLength - fBlockHeader->GetHeaderLength();
527 totalDDLLength += totalBlkLength;
529 buffer[indexBlk+1] = totalBlkLength; // total block length
530 buffer[indexBlk+2] = blkLength;
536 // total length in bytes
537 fHeader.fSize = (totalDDLLength + headerSize) * 4;
539 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iFile]);
540 fwrite(buffer,sizeof(int),index,fFile[iFile]);
543 fTimers[kWriteTracker].Stop();
547 //____________________________________________________________________
548 Int_t AliMUONRawWriter::GetBusPatch(Int_t detElemId, Int_t manuId) const
550 /// Determine the BusPatch this digit belongs to.
554 AliMpPlaneType plane =
555 (manuId & AliMpConstants::ManuMask(kNonBendingPlane)) ?
556 kNonBendingPlane : kBendingPlane;
558 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
560 if ( stationType == kStation1)
562 if (plane == kBendingPlane)
564 ptr = &fgManuPerBusSwp1B[0];
568 ptr = &fgManuPerBusSwp1NB[0];
571 else if ( stationType == kStation2)
573 if (plane == kBendingPlane)
575 ptr = &fgManuPerBusSwp2B[0];
579 ptr = &fgManuPerBusSwp2NB[0];
583 // Getting buspatch id
584 TArrayI* vec = fBusPatchManager->GetBusfromDE(detElemId);
587 Int_t m = ( manuId & 0x3FF ); // remove bit 10
588 //FIXME : how can we remove that condition
589 // on the 10-th bit ? All the rest need not any knowledge about it,
590 // can't we find a way to get manu<->buspatch transparent to this too ?
592 if ( stationType == kStation1 || stationType == kStation2 )
594 for (pos = 11; pos >=0 ; --pos)
596 if (m >= ptr[pos]) break;
601 // offset of 100 in manuId for following bus patch
606 if (pos >(Int_t) vec->GetSize())
608 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
609 pos, (Int_t)vec->GetSize(), manuId, detElemId));
610 AliError(Form("Chamber %s Plane %s manuId %d m %d",
611 StationTypeName(stationType).Data(),
612 PlaneTypeName(plane).Data(),
618 Int_t busPatchId = vec->At(pos);
620 if ( ( stationType == kStation1 || stationType == kStation2 ) &&
621 ( plane == kNonBendingPlane ) )
629 //____________________________________________________________________
630 Int_t AliMUONRawWriter::GetBusPatch(const AliMUONDigit& digit) const
632 /// Determine the BusPatch this digit belongs to.
634 return GetBusPatch(digit.DetElemId(),digit.ManuId());
637 //____________________________________________________________________
638 Int_t AliMUONRawWriter::WriteTriggerDDL()
640 /// Write trigger DDL
642 fTimers[kWriteTrigger].Start(kFALSE);
644 // DDL event one per half chamber
646 // stored local id number
647 TArrayI isFired(256);
652 Int_t headerSize = sizeof(AliRawDataHeader)/4;
654 TClonesArray* localTrigger;
655 TClonesArray* globalTrigger;
656 TClonesArray* regionalTrigger;
658 AliMUONGlobalTrigger* gloTrg;
659 AliMUONLocalTrigger* locTrg = 0x0;
660 AliMUONRegionalTrigger* regTrg = 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();
678 regionalTrigger = fMUONData->RegionalTrigger();
685 Int_t iLocCard, locCard;
686 Char_t locDec, trigY, posY, posX, regOut;
691 Int_t version = 1; // software version
692 Int_t eventPhys = 1; // trigger type: 1 for physics, 0 for software
693 Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
694 Int_t globalFlag = 0; // set to 1 if global info present in DDL else set to 0
697 static const Int_t kDarcHeaderLength = fDarcHeader->GetDarcHeaderLength();
698 static const Int_t kGlobalHeaderLength = fDarcHeader->GetGlobalHeaderLength();
699 static const Int_t kDarcScalerLength = fDarcHeader->GetDarcScalerLength();
700 static const Int_t kGlobalScalerLength = fDarcHeader->GetGlobalScalerLength();
701 static const Int_t kRegHeaderLength = fRegHeader->GetHeaderLength();
702 static const Int_t kRegScalerLength = fRegHeader->GetScalerLength();
703 static const Int_t kLocHeaderLength = fLocalStruct->GetLength();
704 static const Int_t kLocScalerLength = fLocalStruct->GetScalerLength();
706 // [16(local)*6 words + 6 words]*8(reg) + 8 words = 824
707 static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) + (kRegHeaderLength+1))* 8
708 + kDarcHeaderLength + kGlobalHeaderLength + 2;
710 // [16(local)*51 words + 16 words]*8(reg) + 8 + 10 + 8 words scaler event 6682 words
711 static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength + kLocScalerLength +1) +
712 (kRegHeaderLength + kRegScalerLength +1))* 8 +
713 (kDarcHeaderLength + kDarcScalerLength +
714 kGlobalHeaderLength + kGlobalScalerLength + 2);
716 eventPhys = 0; //set to generate scaler events
718 Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
719 // stored the local card id that's fired
720 for (Int_t i = 0; i < nEntries; i++) {
721 locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
722 isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations
726 AliDebug(1, "No Trigger information available");
729 buffer = new Int_t [kScalerBufferSize];
731 buffer = new Int_t [kBufferSize];
735 // open DDL file, on per 1/2 chamber
736 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
740 if (iDDL == 0) // suppose global info in DDL one
746 // set darc status word
747 // see AliMUONDarcHeader.h for details
748 AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30);
749 AliBitPacking::PackWord((UInt_t)serialNb,word,20,23);
750 AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10);
751 AliBitPacking::PackWord((UInt_t)version,word,12,19);
752 fDarcHeader->SetWord(word);
754 memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4);
755 index += kDarcHeaderLength;
757 // no global input for the moment....
759 fDarcHeader->SetGlobalOutput(gloTrigResp);
761 fDarcHeader->SetGlobalOutput(0);
764 // 6 DARC scaler words
765 memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4);
766 index += kDarcScalerLength;
769 buffer[index++] = fDarcHeader->GetEndOfDarc();
771 // 4 words of global board input + Global board output
772 memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4);
773 index += kGlobalHeaderLength;
776 // 10 Global scaler words
777 memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4);
778 index += kGlobalScalerLength;
781 // end of global word
782 buffer[index++] = fDarcHeader->GetEndOfGlobal();
784 // 8 regional cards per DDL
785 for (Int_t iReg = 0; iReg < 8; iReg++) {
788 AliMUONTriggerCrate* crate = fCrateManager->Crate(iDDL, iReg);
791 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
793 // regional info tree, make sure that no reg card missing
794 for (Int_t i = 0; i < 16; ++i) {
795 regTrg = (AliMUONRegionalTrigger*)regionalTrigger->At(i);
797 if (regTrg->GetId() == (iReg + iDDL*8)) break;
800 // Regional card header
803 // set darc status word
804 fRegHeader->SetDarcWord(word);
806 regOut = regTrg->GetOutput();
807 regInpHpt = regTrg->GetLocalOutput(0);
808 regInpLpt = regTrg->GetLocalOutput(1);
810 // fill darc word, not darc status for the moment (empty)
811 //see AliMUONRegHeader.h for details
812 AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31);
813 AliBitPacking::PackWord((UInt_t)serialNb,word,19,24);
814 AliBitPacking::PackWord((UInt_t)version,word,16,23);
815 AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
816 AliBitPacking::PackWord((UInt_t)regOut,word,0,7);
817 fRegHeader->SetWord(word);
820 // fill header later, need local response
821 Int_t indexReg = index;
822 index += kRegHeaderLength;
824 // 11 regional scaler word
826 memcpy(&buffer[index], fRegHeader->GetScalers(), kRegScalerLength*4);
827 index += kRegScalerLength;
830 // end of regional word
831 buffer[index++] = fRegHeader->GetEndOfReg();
833 TObjArray *boards = crate->Boards();
836 // 16 local card per regional board
837 // UShort_t localMask = 0x0;
839 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
841 // slot zero for Regional card
842 AliMUONLocalTriggerBoard* localBoard = (AliMUONLocalTriggerBoard*)boards->At(iLoc+1);
844 if (localBoard) { // if not empty slot
846 if ((iLocCard = localBoard->GetNumber()) != 0) {// if notified board
848 if (isFired[iLocCard]) { // if card has triggered
849 locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries++);
850 locCard = locTrg->LoCircuit();
851 locDec = locTrg->GetLoDecision();
853 posY = locTrg->LoStripY();
854 posX = locTrg->LoStripX();
855 devX = locTrg->LoDev();
857 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
858 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
859 } else { //no trigger (see PRR chpt 3.4)
865 // set local card id to -1
871 AliBitPacking::PackWord((UInt_t)iLoc,word,19,22); //card id number in crate
872 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
873 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
874 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
875 AliBitPacking::PackWord((UInt_t)devX,word,5,9);
876 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
878 if (locCard == iLocCard) {
879 // add local cards structure
880 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
881 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
882 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
883 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
884 buffer[index++] = (Int_t)word; // data word
887 buffer[index++] = 0; // 4 words for x1, x2, y1, y2
891 buffer[index++] = (Int_t)word; // data word
895 // fill with 10CDEAD word for 'non-notified' slots
896 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
897 buffer[index++] = fLocalStruct->GetDisableWord();
900 // fill with 10CDEAD word for empty slots
901 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
902 buffer[index++] = fLocalStruct->GetDisableWord();
903 }// condition localBoard
905 // 45 regional scaler word
907 memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
908 index += kLocScalerLength;
911 // end of local structure words
912 buffer[index++] = fLocalStruct->GetEndOfLocal();
915 // fill regional header with local output
916 fRegHeader->SetInput(regInpHpt, 0);
917 fRegHeader->SetInput(regInpHpt, 1);
918 memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);
923 // writting onto disk
925 fHeader.fSize = (index + headerSize) * 4;// total length in bytes
926 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iDDL]);
927 fwrite(buffer,sizeof(int),index,fFile[iDDL]);
932 fTimers[kWriteTrigger].Stop();
936 //____________________________________________________________________
937 void AliMUONRawWriter::SetScalersNumbers()
939 /// set numbers for scaler events for trigger headers
940 /// since this is provided by the experiment
941 /// put dummy numbers to check the monitoring
943 fDarcHeader->SetScalersNumbers();
944 fRegHeader->SetScalersNumbers();
945 fLocalStruct->SetScalersNumbers();
947 fScalerEvent = kTRUE;