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 ////////////////////////////////////
20 // MUON Raw Data generaton in ALICE-MUON
21 // This class version 3 (further details could be found in Alice-note)
23 // Implemented non-constant buspatch numbers for tracking
24 // with correct DDL id (first guess)
25 // (Ch. Finck, dec 2005)
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)
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
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.
42 ////////////////////////////////////
44 #include "AliMUONRawWriter.h"
46 #include "AliBitPacking.h"
50 #include "AliMUONBlockHeader.h"
51 #include "AliMUONBusStruct.h"
52 #include "AliMUONConstants.h"
53 #include "AliMUONDarcHeader.h"
54 #include "AliMUONData.h"
55 #include "AliMUONDigit.h"
56 #include "AliMUONDspHeader.h"
57 #include "AliMUONGlobalTrigger.h"
58 #include "AliMUONLocalStruct.h"
59 #include "AliMUONLocalTrigger.h"
60 #include "AliMUONLocalTriggerBoard.h"
61 #include "AliMUONRegHeader.h"
62 #include "AliMUONTriggerCrate.h"
63 #include "AliMUONTriggerCrateStore.h"
64 #include "AliMpBusPatch.h"
65 #include "AliMpDEManager.h"
66 #include "AliMpExMap.h"
67 #include "AliMpIntPair.h"
68 #include "AliMpConstants.h"
71 #include "AliMpPlaneType.h"
72 #include "AliMpSegFactory.h"
73 #include "AliMpStationType.h"
74 #include "AliMpVSegmentation.h"
75 #include "AliRawReader.h"
76 #include "TObjArray.h"
77 #include "TStopwatch.h"
79 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]),
106 fSegFactory(new AliMpSegFactory())
110 // Standard Constructor
112 AliDebug(1,"Standard ctor");
113 fFile[0] = fFile[1] = 0x0;
114 fFile[2] = fFile[3] = 0x0;
116 // setting data key to default value (only for writting)
117 fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
118 fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
120 // bus patch managers
121 fBusPatchManager->ReadBusPatchFile();
124 fCrateManager->ReadFromFile();
127 for ( Int_t i = 0; i < kLast; ++i )
129 fTimers[i].Start(kTRUE);
135 //__________________________________________________________________________
136 AliMUONRawWriter::AliMUONRawWriter()
146 fScalerEvent(kFALSE),
152 // Default Constructor
154 AliDebug(1,"Default ctor");
155 fFile[0] = fFile[1] = 0x0;
156 fFile[2] = fFile[3] = 0x0;
160 //__________________________________________________________________________
161 AliMUONRawWriter::~AliMUONRawWriter(void)
174 delete fBusPatchManager;
175 delete fCrateManager;
179 for ( Int_t i = 0; i < kLast; ++i )
181 AliInfo(Form("Execution time (timer %d) : R:%7.2fs C:%7.2fs",i,
182 fTimers[i].RealTime(),fTimers[i].CpuTime()));
188 //______________________________________________________________________________
190 //AliMUONRawWriter::CheckDigits()
192 // std::map<int,std::map<int,int> > m;
194 // for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt)
196 // for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh)
198 // TClonesArray* muonDigits = fMUONData->Digits(iCh);
199 // for (Int_t idig = 0; idig < muonDigits->GetEntriesFast(); idig++)
201 // AliMUONDigit* digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
202 // Int_t busPatchId = GetBusPatch(*digit);
203 // m[busPatchId][digit->ManuId()]++;
208 // std::map<int,std::map<int,int> >::const_iterator it;
210 // Int_t nManuMax(0);
212 // for ( it = m.begin(); it != m.end(); ++it )
214 // AliDebug(1,Form("BusPatch %3d has %3d manus",it->first,it->second.size()));
215 // nManuMax = std::max((Int_t)it->second.size(),nManuMax);
216 // std::map<int,int>::const_iterator it2;
217 // for ( it2 = it->second.begin(); it2 != it->second.end(); ++it2 )
219 // AliDebug(1,Form(" BusPatch %3d Manu %4d Nch %3d",it->first,it2->first,it2->second));
222 // AliDebug(1,Form("Max manus per busPatch : %3d",nManuMax));
225 //____________________________________________________________________
226 Int_t AliMUONRawWriter::Digits2Raw()
229 // convert digits of the current event to raw data
234 fMUONData->GetLoader()->LoadDigits("READ");
236 fMUONData->SetTreeAddress("D,GLT");
238 fMUONData->ResetDigits();
239 fMUONData->ResetTrigger();
241 // This will get both tracker and trigger digits.
242 fMUONData->GetDigits();
248 for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt) {
250 // open files for one station
251 // cos station 3, 1/4 of DE's from 2 chambers has same DDL number
253 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
254 fFile[0] = fopen(name,"w");
256 idDDL = (iSt * 4) + 1;
257 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
258 fFile[1] = fopen(name,"w");
260 idDDL = (iSt * 4) + 2;;
261 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
262 fFile[2] = fopen(name,"w");
264 idDDL = (iSt * 4) + 3;
265 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
266 fFile[3] = fopen(name,"w");
268 WriteTrackerDDL(iSt);
270 // reset and close when station has been processed
278 AliDebug(1,"Tracker written");
284 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
285 fFile[0] = fopen(name,"w");
288 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
289 fFile[1] = fopen(name,"w");
297 AliDebug(1,"Trigger written");
299 fMUONData->ResetDigits();
300 fMUONData->ResetTrigger();
301 fMUONData->GetLoader()->UnloadDigits();
303 AliDebug(1,"muondata reset");
308 //____________________________________________________________________
309 Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iSt)
311 // writing DDL for tracker
312 // used inverse mapping
314 fTimers[kWriteTracker].Start(kFALSE);
316 static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
319 TClonesArray* muonDigits = 0;
322 Int_t headerSize = sizeof(fHeader)/4;
324 // DDL event one per half chamber
329 UChar_t channelId = 0;
331 Int_t busPatchId = 0;
336 Int_t totalDspLength;
340 Int_t totalBlkLength;
344 Int_t totalDDLLength;
351 // buffer size (max'ed out)
352 // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch
353 // + 10 dsp words)*5 dsps + 8 block words)*2 blocks
354 static const Int_t kBufferSize = (((43*64 + 4)*5 + 10)*5 + 8)*2;
358 AliMpExMap busPatchMap(kTRUE);
360 fTimers[kDigitLoop].Start(kFALSE);
362 for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh) {
364 muonDigits = fMUONData->Digits(iCh);
366 nDigits = muonDigits->GetEntriesFast();
369 for (Int_t idig = 0; idig < nDigits; ++idig) {
371 AliMUONDigit* digit = static_cast<AliMUONDigit*>(muonDigits->UncheckedAt(idig));
373 charge = digit->ADC();
374 if ( charge > kMAXADC )
376 // This is most probably an error in the digitizer (which should insure
377 // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
378 AliError(Form("adc value %d above %x for ch %d . Setting to %x. Digit is:",iCh,
379 charge,kMAXADC,kMAXADC));
380 StdoutToAliError(digit->Print());
385 fTimers[kGetBusPatch].Start(kFALSE);
386 busPatchId = GetBusPatch(*digit);
387 fTimers[kGetBusPatch].Stop();
388 if (busPatchId<0) continue;
390 fTimers[kTest].Start(kFALSE);
391 busPatchId = GetBusPatch(*digit);
392 fTimers[kTest].Stop();
394 if ( digit->ManuId() > 0x7FF || digit->ManuId() < 0 ||
395 digit->ManuChannel() > 0x3F || digit->ManuChannel() < 0 )
397 StdoutToAliError(digit->Print(););
398 AliFatal("ManuId,ManuChannel are invalid for the digit above.");
401 manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
402 channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
406 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
407 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
408 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
412 for (Int_t i = 1; i <= 30; ++i)
413 parity ^= ((word >> i) & 0x1);
414 AliBitPacking::PackWord((UInt_t)parity,word,31,31);
416 AliMUONBusStruct* busStruct =
417 static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
421 busStruct = new AliMUONBusStruct;
422 busStruct->SetDataKey(busStruct->GetDefaultDataKey());
423 busStruct->SetBusPatchId(busPatchId);
424 busStruct->SetLength(0);
425 busPatchMap.Add(busPatchId,busStruct);
429 busStruct->AddData(word);
432 } // loop over chamber in station
434 fTimers[kDigitLoop].Stop();
436 // getting info for the number of buspatches
439 Int_t iBusPerDSP[5];//number of bus patches per DSP
440 Int_t iDspMax; //number max of DSP per block
443 AliMUONBusStruct* busStructPtr(0x0);
445 // open DDL files, 4 per station
446 for (Int_t iDDL = iSt*4; iDDL < 4 + iSt*4; ++iDDL) {
448 fBusPatchManager->ResetBusItr(iDDL);
449 fBusPatchManager->GetDspInfo(iDDL, iDspMax, iBusPerDSP);
451 Int_t buffer[kBufferSize];
459 // two blocks A and B per DDL
460 for (Int_t iBlock = 0; iBlock < 2; ++iBlock) {
463 length = fBlockHeader->GetHeaderLength();
464 memcpy(&buffer[index],fBlockHeader->GetHeader(),length*4);
468 // 5 DSP's max per block
469 for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp) {
472 length = fDspHeader->GetHeaderLength();
473 memcpy(&buffer[index],fDspHeader->GetHeader(),length*4);
477 //Â 5 buspatches max per DSP
478 for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) {
480 iBusPatch = fBusPatchManager->NextBusInDDL(iDDL);
482 // iteration over bus patch in DDL
483 if (iBusPatch == -1) {
484 AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
488 // 4 DDL's per station, condition needed for station 3
489 iFile = iDDL - iSt*4; // works only if DDL begins at zero (as it should be) !!!
491 busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
493 // check if buspatchid has digit
495 // add bus patch structure header
496 length = busStructPtr->GetHeaderLength();
497 memcpy(&buffer[index],busStructPtr->GetHeader(),length*4);
500 // add bus patch data
501 length = busStructPtr->GetLength();
502 memcpy(&buffer[index],busStructPtr->GetData(),length*4);
505 if (AliLog::GetGlobalDebugLevel() == 3) {
506 for (Int_t j = 0; j < busStructPtr->GetLength(); j++) {
507 printf("busPatchId %d, manuId %d channelId %d\n", busStructPtr->GetBusPatchId(),
508 busStructPtr->GetManuId(j), busStructPtr->GetChannelId(j));
512 // writting anyhow buspatch structure (empty ones)
513 buffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
514 buffer[index++] = busStructPtr->GetHeaderLength(); // header length
515 buffer[index++] = 0; // raw data length
516 buffer[index++] = iBusPatch; // bus patch
520 // check if totalLength even
521 // set padding word in case
522 // Add one word 0xBEEFFACE at the end of DSP structure
523 totalDspLength = index - indexDsp;
524 if ((totalDspLength % 2) == 1) {
525 buffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
526 buffer[index++] = fDspHeader->GetDefaultPaddingWord();
530 dspLength = totalDspLength - fDspHeader->GetHeaderLength();
532 buffer[indexDsp+1] = totalDspLength; // dsp total length
533 buffer[indexDsp+2] = dspLength; // data length
537 totalBlkLength = index - indexBlk;
538 blkLength = totalBlkLength - fBlockHeader->GetHeaderLength();
539 totalDDLLength += totalBlkLength;
541 buffer[indexBlk+1] = totalBlkLength; // total block length
542 buffer[indexBlk+2] = blkLength;
548 // total length in bytes
549 fHeader.fSize = (totalDDLLength + headerSize) * 4;
551 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iFile]);
552 fwrite(buffer,sizeof(int),index,fFile[iFile]);
555 fTimers[kWriteTracker].Stop();
559 //____________________________________________________________________
560 Int_t AliMUONRawWriter::GetBusPatch(Int_t detElemId, Int_t manuId) const
563 // Determine the BusPatch this digit belongs to.
568 AliMpPlaneType plane =
569 (manuId & AliMpConstants::ManuMask(kNonBendingPlane)) ?
570 kNonBendingPlane : kBendingPlane;
572 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
574 if ( stationType == kStation1 || stationType == kStation2 )
576 if (plane == kBendingPlane)
578 ptr = &fgManuPerBusSwp1B[0];
582 ptr = &fgManuPerBusSwp1NB[0];
587 if (plane == kBendingPlane)
589 ptr = &fgManuPerBusSwp2B[0];
593 ptr = &fgManuPerBusSwp2NB[0];
597 // Getting buspatch id
598 TArrayI* vec = fBusPatchManager->GetBusfromDE(detElemId);
601 Int_t m = ( manuId & 0x3FF ); // remove bit 10
602 //FIXME : how can we remove that condition
603 // on the 10-th bit ? All the rest need not any knowledge about it,
604 // can't we find a way to get manu<->buspatch transparent to this too ?
606 if ( stationType == kStation1 || stationType == kStation2 )
608 for (pos = 11; pos >=0 ; --pos)
610 if (m >= ptr[pos]) break;
615 // offset of 100 in manuId for following bus patch
620 if (pos >(Int_t) vec->GetSize())
622 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
623 pos, (Int_t)vec->GetSize(), manuId, detElemId));
624 AliError(Form("Chamber %s Plane %s manuId %d m %d",
625 StationTypeName(stationType).Data(),
626 PlaneTypeName(plane).Data(),
632 Int_t busPatchId = vec->At(pos);
634 if ( ( stationType == kStation1 || stationType == kStation2 ) &&
635 ( plane == kNonBendingPlane ) )
643 //____________________________________________________________________
644 Int_t AliMUONRawWriter::GetBusPatch(const AliMUONDigit& digit) const
647 // Determine the BusPatch this digit belongs to.
649 return GetBusPatch(digit.DetElemId(),digit.ManuId());
652 //____________________________________________________________________
653 Int_t AliMUONRawWriter::WriteTriggerDDL()
658 fTimers[kWriteTrigger].Start(kFALSE);
660 // DDL event one per half chamber
662 // stored local id number
663 TArrayI isFired(256);
668 Int_t headerSize = sizeof(AliRawDataHeader)/4;
670 TClonesArray* localTrigger;
671 TClonesArray* globalTrigger;
672 AliMUONGlobalTrigger* gloTrg;
673 AliMUONLocalTrigger* locTrg = 0x0;
675 // global trigger for trigger pattern
676 globalTrigger = fMUONData->GlobalTrigger();
677 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
680 fTimers[kWriteTrigger].Stop();
684 Int_t gloTrigResp = gloTrg->GetGlobalResponse();
687 localTrigger = fMUONData->LocalTrigger();
693 Int_t iLocCard, locCard;
694 Char_t locDec, trigY, posY, posX, regOut;
699 Int_t version = 1; // software version
700 Int_t eventPhys = 1; // trigger type: 1 for physics, 0 for software
701 Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
702 Int_t globalFlag = 0; // set to 1 if global info present in DDL else set to 0
705 static const Int_t kDarcHeaderLength = fDarcHeader->GetDarcHeaderLength();
706 static const Int_t kGlobalHeaderLength = fDarcHeader->GetGlobalHeaderLength();
707 static const Int_t kDarcScalerLength = fDarcHeader->GetDarcScalerLength();
708 static const Int_t kGlobalScalerLength = fDarcHeader->GetGlobalScalerLength();
709 static const Int_t kRegHeaderLength = fRegHeader->GetHeaderLength();
710 static const Int_t kRegScalerLength = fRegHeader->GetScalerLength();
711 static const Int_t kLocHeaderLength = fLocalStruct->GetLength();
712 static const Int_t kLocScalerLength = fLocalStruct->GetScalerLength();
714 // [16(local)*6 words + 6 words]*8(reg) + 8 words = 824
715 static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) + (kRegHeaderLength+1))* 8
716 + kDarcHeaderLength + kGlobalHeaderLength + 2;
718 // [16(local)*51 words + 16 words]*8(reg) + 8 + 10 + 8 words scaler event 6682 words
719 static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength + kLocScalerLength +1) +
720 (kRegHeaderLength + kRegScalerLength +1))* 8 +
721 (kDarcHeaderLength + kDarcScalerLength +
722 kGlobalHeaderLength + kGlobalScalerLength + 2);
724 eventPhys = 0; //set to generate scaler events
726 Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
727 // stored the local card id that's fired
728 for (Int_t i = 0; i < nEntries; i++) {
729 locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
730 isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations
734 AliInfo("No Trigger information available");
737 buffer = new Int_t [kScalerBufferSize];
739 buffer = new Int_t [kBufferSize];
743 // open DDL file, on per 1/2 chamber
744 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
748 if (iDDL == 0) // suppose global info in DDL one
754 // set darc status word
755 // see AliMUONDarcHeader.h for details
756 AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30);
757 AliBitPacking::PackWord((UInt_t)serialNb,word,20,23);
758 AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10);
759 AliBitPacking::PackWord((UInt_t)version,word,12,19);
760 fDarcHeader->SetWord(word);
762 memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4);
763 index += kDarcHeaderLength;
765 // no global input for the moment....
767 fDarcHeader->SetGlobalOutput(gloTrigResp);
769 fDarcHeader->SetGlobalOutput(0);
772 // 6 DARC scaler words
773 memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4);
774 index += kDarcScalerLength;
777 buffer[index++] = fDarcHeader->GetEndOfDarc();
779 // 4 words of global board input + Global board output
780 memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4);
781 index += kGlobalHeaderLength;
784 // 10 Global scaler words
785 memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4);
786 index += kGlobalScalerLength;
789 // end of global word
790 buffer[index++] = fDarcHeader->GetEndOfGlobal();
792 // 8 regional cards per DDL
793 for (Int_t iReg = 0; iReg < 8; iReg++) {
796 AliMUONTriggerCrate* crate = fCrateManager->Crate(iDDL, iReg);
799 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
801 // Regional card header
804 // set darc status word
805 fRegHeader->SetDarcWord(word);
808 regInpHpt = regInpLpt = 0;
809 // fill darc word, not darc status for the moment (empty)
810 //see AliMUONRegHeader.h for details
811 AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31);
812 AliBitPacking::PackWord((UInt_t)serialNb,word,19,24);
813 AliBitPacking::PackWord((UInt_t)version,word,16,23);
814 AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
815 AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // waiting realistic output of AliMUONGlobalTrigger (oct 06 ?)
816 fRegHeader->SetWord(word);
819 // fill header later, need local response
820 Int_t indexReg = index;
821 index += kRegHeaderLength;
823 // 11 regional scaler word
825 memcpy(&buffer[index], fRegHeader->GetScalers(), kRegScalerLength*4);
826 index += kRegScalerLength;
829 // end of regional word
830 buffer[index++] = fRegHeader->GetEndOfReg();
832 TObjArray *boards = crate->Boards();
835 // 16 local card per regional board
836 UShort_t localMask = 0x0;
838 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
840 // slot zero for Regional card
841 AliMUONLocalTriggerBoard* localBoard = (AliMUONLocalTriggerBoard*)boards->At(iLoc+1);
843 if (localBoard) { // if not empty slot
845 if ((iLocCard = localBoard->GetNumber()) != 0) {// if notified board
847 localMask |= (0x1 << iLoc); // local mask
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
868 // calculate regional input High and low Pt
869 UInt_t tmp1 = (locDec >> 2) & 0x3;
870 UInt_t tmp2 = locDec & 0x3;
872 regInpHpt |= tmp1 << (30 - iLoc*2);
873 regInpLpt |= tmp2 << (30 - iLoc*2);
877 AliBitPacking::PackWord((UInt_t)iLoc,word,19,22); //card id number in crate
878 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
879 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
880 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
881 AliBitPacking::PackWord((UInt_t)devX,word,5,9);
882 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
884 if (locCard == iLocCard) {
885 // add local cards structure
886 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
887 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
888 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
889 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
890 buffer[index++] = (Int_t)word; // data word
891 if (iEntries < nEntries-1)
894 buffer[index++] = 0; // 4 words for x1, x2, y1, y2
898 buffer[index++] = (Int_t)word; // data word
902 // fill with 10CDEAD word for 'non-notified' slots
903 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
904 buffer[index++] = fLocalStruct->GetDisableWord();
907 // fill with 10CDEAD word for empty slots
908 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
909 buffer[index++] = fLocalStruct->GetDisableWord();
910 }// condition localBoard
912 // 45 regional scaler word
914 memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
915 index += kLocScalerLength;
918 // end of local structure words
919 buffer[index++] = fLocalStruct->GetEndOfLocal();
922 // fill regional header with local output
923 fRegHeader->SetInput(regInpLpt, 0);
924 fRegHeader->SetInput(regInpHpt, 1);
925 fRegHeader->SetMask(localMask);
926 memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);
931 // writting onto disk
933 fHeader.fSize = (index + headerSize) * 4;// total length in bytes
934 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iDDL]);
935 fwrite(buffer,sizeof(int),index,fFile[iDDL]);
940 fTimers[kWriteTrigger].Stop();
944 //____________________________________________________________________
945 void AliMUONRawWriter::SetScalersNumbers()
947 // set numbers for scaler events for trigger headers
948 // since this is provided by the experiment
949 // put dummy numbers to check the monitoring
951 fDarcHeader->SetScalersNumbers();
952 fRegHeader->SetScalersNumbers();
953 fLocalStruct->SetScalersNumbers();
955 fScalerEvent = kTRUE;