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"
44 #include "AliMUONBlockHeader.h"
45 #include "AliMUONBusStruct.h"
46 #include "AliMUONConstants.h"
47 #include "AliMUONDarcHeader.h"
48 #include "AliMUONData.h"
49 #include "AliMUONDigit.h"
50 #include "AliMUONDspHeader.h"
51 #include "AliMUONGlobalTrigger.h"
52 #include "AliMUONLocalStruct.h"
53 #include "AliMUONLocalTrigger.h"
54 #include "AliMUONLocalTriggerBoard.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 "AliMpIntPair.h"
63 #include "AliMpConstants.h"
65 #include "AliMpPlaneType.h"
66 #include "AliMpSegmentation.h"
67 #include "AliMpStationType.h"
68 #include "AliMpVSegmentation.h"
70 #include "AliRawReader.h"
71 #include "AliBitPacking.h"
76 #include "TObjArray.h"
77 #include "TStopwatch.h"
80 ClassImp(AliMUONRawWriter) // Class implementation in ROOT context
83 Int_t AliMUONRawWriter::fgManuPerBusSwp1B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 224, 232};
84 Int_t AliMUONRawWriter::fgManuPerBusSwp1NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 225, 233};
86 Int_t AliMUONRawWriter::fgManuPerBusSwp2B[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 226, 246};
87 Int_t AliMUONRawWriter::fgManuPerBusSwp2NB[12] = {1, 27, 53, 79, 105, 131, 157, 183, 201, 214, 227, 245};
91 enum ETimer { kWriteTracker, kWriteTrigger, kDigitLoop, kGetBusPatch, kTest, kLast };
94 //__________________________________________________________________________
95 AliMUONRawWriter::AliMUONRawWriter(AliMUONData* data)
98 fBlockHeader(new AliMUONBlockHeader()),
99 fDspHeader(new AliMUONDspHeader()),
100 fDarcHeader(new AliMUONDarcHeader()),
101 fRegHeader(new AliMUONRegHeader()),
102 fLocalStruct(new AliMUONLocalStruct()),
103 fBusPatchManager(new AliMpBusPatch()),
104 fCrateManager(new AliMUONTriggerCrateStore()),
105 fScalerEvent(kFALSE),
107 fTimers(new TStopwatch[kLast])
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),
150 /// Default Constructor
152 AliDebug(1,"Default ctor");
153 fFile[0] = fFile[1] = 0x0;
154 fFile[2] = fFile[3] = 0x0;
158 //__________________________________________________________________________
159 AliMUONRawWriter::~AliMUONRawWriter(void)
171 delete fBusPatchManager;
172 delete fCrateManager;
174 for ( Int_t i = 0; i < kLast; ++i )
176 AliDebug(1, Form("Execution time (timer %d) : R:%7.2fs C:%7.2fs",i,
177 fTimers[i].RealTime(),fTimers[i].CpuTime()));
183 //______________________________________________________________________________
185 //AliMUONRawWriter::CheckDigits()
187 // std::map<int,std::map<int,int> > m;
189 // for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt)
191 // for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh)
193 // TClonesArray* muonDigits = fMUONData->Digits(iCh);
194 // for (Int_t idig = 0; idig < muonDigits->GetEntriesFast(); idig++)
196 // AliMUONDigit* digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
197 // Int_t busPatchId = GetBusPatch(*digit);
198 // m[busPatchId][digit->ManuId()]++;
203 // std::map<int,std::map<int,int> >::const_iterator it;
205 // Int_t nManuMax(0);
207 // for ( it = m.begin(); it != m.end(); ++it )
209 // AliDebug(1,Form("BusPatch %3d has %3d manus",it->first,it->second.size()));
210 // nManuMax = std::max((Int_t)it->second.size(),nManuMax);
211 // std::map<int,int>::const_iterator it2;
212 // for ( it2 = it->second.begin(); it2 != it->second.end(); ++it2 )
214 // AliDebug(1,Form(" BusPatch %3d Manu %4d Nch %3d",it->first,it2->first,it2->second));
217 // AliDebug(1,Form("Max manus per busPatch : %3d",nManuMax));
220 //____________________________________________________________________
221 Int_t AliMUONRawWriter::Digits2Raw()
223 /// convert digits of the current event to raw data
228 fMUONData->GetLoader()->LoadDigits("READ");
230 fMUONData->SetTreeAddress("D,GLT");
232 fMUONData->ResetDigits();
233 fMUONData->ResetTrigger();
235 // This will get both tracker and trigger digits.
236 fMUONData->GetDigits();
242 for (Int_t iSt = 0; iSt < AliMUONConstants::NTrackingCh()/2; ++iSt) {
244 // open files for one station
245 // cos station 3, 1/4 of DE's from 2 chambers has same DDL number
247 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
248 fFile[0] = fopen(name,"w");
250 idDDL = (iSt * 4) + 1;
251 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
252 fFile[1] = fopen(name,"w");
254 idDDL = (iSt * 4) + 2;;
255 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
256 fFile[2] = fopen(name,"w");
258 idDDL = (iSt * 4) + 3;
259 strcpy(name,AliDAQ::DdlFileName("MUONTRK",idDDL));
260 fFile[3] = fopen(name,"w");
262 WriteTrackerDDL(iSt);
264 // reset and close when station has been processed
272 AliDebug(1,"Tracker written");
278 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
279 fFile[0] = fopen(name,"w");
282 strcpy(name,AliDAQ::DdlFileName("MUONTRG",idDDL));
283 fFile[1] = fopen(name,"w");
291 AliDebug(1,"Trigger written");
293 fMUONData->ResetDigits();
294 fMUONData->ResetTrigger();
295 fMUONData->GetLoader()->UnloadDigits();
297 AliDebug(1,"muondata reset");
302 //____________________________________________________________________
303 Int_t AliMUONRawWriter::WriteTrackerDDL(Int_t iSt)
305 /// writing DDL for tracker
306 /// used inverse mapping
308 fTimers[kWriteTracker].Start(kFALSE);
310 static const Int_t kMAXADC = (1<<12)-1; // We code the charge on a 12 bits ADC.
313 TClonesArray* muonDigits = 0;
316 Int_t headerSize = sizeof(fHeader)/4;
318 // DDL event one per half chamber
323 UChar_t channelId = 0;
325 Int_t busPatchId = 0;
330 Int_t totalDspLength;
334 Int_t totalBlkLength;
338 Int_t totalDDLLength;
345 // buffer size (max'ed out)
346 // (((43 manus max per bus patch *64 channels + 4 bus patch words) * 5 bus patch
347 // + 10 dsp words)*5 dsps + 8 block words)*2 blocks
348 static const Int_t kBufferSize = (((43*64 + 4)*5 + 10)*5 + 8)*2;
352 AliMpExMap busPatchMap(kTRUE);
354 fTimers[kDigitLoop].Start(kFALSE);
356 for (Int_t iCh = iSt*2; iCh <= iSt*2 + 1; ++iCh) {
358 muonDigits = fMUONData->Digits(iCh);
360 nDigits = muonDigits->GetEntriesFast();
363 for (Int_t idig = 0; idig < nDigits; ++idig) {
365 AliMUONDigit* digit = static_cast<AliMUONDigit*>(muonDigits->UncheckedAt(idig));
367 charge = digit->ADC();
368 if ( charge > kMAXADC )
370 // This is most probably an error in the digitizer (which should insure
371 // the adc is below kMAXADC), so make it a (non-fatal) error indeed.
372 AliError(Form("adc value %d above %x for ch %d . Setting to %x. Digit is:",iCh,
373 charge,kMAXADC,kMAXADC));
374 StdoutToAliError(digit->Print());
379 fTimers[kGetBusPatch].Start(kFALSE);
380 busPatchId = GetBusPatch(*digit);
381 fTimers[kGetBusPatch].Stop();
382 if (busPatchId<0) continue;
384 fTimers[kTest].Start(kFALSE);
385 busPatchId = GetBusPatch(*digit);
386 fTimers[kTest].Stop();
388 if ( digit->ManuId() > 0x7FF || digit->ManuId() < 0 ||
389 digit->ManuChannel() > 0x3F || digit->ManuChannel() < 0 )
391 StdoutToAliError(digit->Print(););
392 AliFatal("ManuId,ManuChannel are invalid for the digit above.");
395 manuId = ( digit->ManuId() & 0x7FF ); // 11 bits
396 channelId = ( digit->ManuChannel() & 0x3F ); // 6 bits
400 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
401 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
402 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
406 for (Int_t i = 1; i <= 30; ++i)
407 parity ^= ((word >> i) & 0x1);
408 AliBitPacking::PackWord((UInt_t)parity,word,31,31);
410 AliMUONBusStruct* busStruct =
411 static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(busPatchId));
415 busStruct = new AliMUONBusStruct;
416 busStruct->SetDataKey(busStruct->GetDefaultDataKey());
417 busStruct->SetBusPatchId(busPatchId);
418 busStruct->SetLength(0);
419 busPatchMap.Add(busPatchId,busStruct);
423 busStruct->AddData(word);
426 } // loop over chamber in station
428 fTimers[kDigitLoop].Stop();
430 // getting info for the number of buspatches
433 Int_t iBusPerDSP[5];//number of bus patches per DSP
434 Int_t iDspMax; //number max of DSP per block
437 AliMUONBusStruct* busStructPtr(0x0);
439 // open DDL files, 4 per station
440 for (Int_t iDDL = iSt*4; iDDL < 4 + iSt*4; ++iDDL) {
442 fBusPatchManager->ResetBusItr(iDDL);
443 fBusPatchManager->GetDspInfo(iDDL, iDspMax, iBusPerDSP);
445 Int_t buffer[kBufferSize];
453 // two blocks A and B per DDL
454 for (Int_t iBlock = 0; iBlock < 2; ++iBlock) {
457 length = fBlockHeader->GetHeaderLength();
458 memcpy(&buffer[index],fBlockHeader->GetHeader(),length*4);
462 // 5 DSP's max per block
463 for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp) {
466 length = fDspHeader->GetHeaderLength();
467 memcpy(&buffer[index],fDspHeader->GetHeader(),length*4);
471 //Â 5 buspatches max per DSP
472 for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) {
474 iBusPatch = fBusPatchManager->NextBusInDDL(iDDL);
476 // iteration over bus patch in DDL
477 if (iBusPatch == -1) {
478 AliWarning(Form("Error in bus itr in DDL %d\n", iDDL));
482 // 4 DDL's per station, condition needed for station 3
483 iFile = iDDL - iSt*4; // works only if DDL begins at zero (as it should be) !!!
485 busStructPtr = static_cast<AliMUONBusStruct*>(busPatchMap.GetValue(iBusPatch));
487 // check if buspatchid has digit
489 // add bus patch structure header
490 length = busStructPtr->GetHeaderLength();
491 memcpy(&buffer[index],busStructPtr->GetHeader(),length*4);
494 // add bus patch data
495 length = busStructPtr->GetLength();
496 memcpy(&buffer[index],busStructPtr->GetData(),length*4);
499 if (AliLog::GetGlobalDebugLevel() == 3) {
500 for (Int_t j = 0; j < busStructPtr->GetLength(); j++) {
501 printf("busPatchId %d, manuId %d channelId %d\n", busStructPtr->GetBusPatchId(),
502 busStructPtr->GetManuId(j), busStructPtr->GetChannelId(j));
506 // writting anyhow buspatch structure (empty ones)
507 buffer[index++] = busStructPtr->GetDefaultDataKey(); // fill it also for empty data size
508 buffer[index++] = busStructPtr->GetHeaderLength(); // header length
509 buffer[index++] = 0; // raw data length
510 buffer[index++] = iBusPatch; // bus patch
514 // check if totalLength even
515 // set padding word in case
516 // Add one word 0xBEEFFACE at the end of DSP structure
517 totalDspLength = index - indexDsp;
518 if ((totalDspLength % 2) == 1) {
519 buffer[indexDsp + fDspHeader->GetHeaderLength() - 2] = 1;
520 buffer[index++] = fDspHeader->GetDefaultPaddingWord();
524 dspLength = totalDspLength - fDspHeader->GetHeaderLength();
526 buffer[indexDsp+1] = totalDspLength; // dsp total length
527 buffer[indexDsp+2] = dspLength; // data length
531 totalBlkLength = index - indexBlk;
532 blkLength = totalBlkLength - fBlockHeader->GetHeaderLength();
533 totalDDLLength += totalBlkLength;
535 buffer[indexBlk+1] = totalBlkLength; // total block length
536 buffer[indexBlk+2] = blkLength;
542 // total length in bytes
543 fHeader.fSize = (totalDDLLength + headerSize) * 4;
545 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iFile]);
546 fwrite(buffer,sizeof(int),index,fFile[iFile]);
549 fTimers[kWriteTracker].Stop();
553 //____________________________________________________________________
554 Int_t AliMUONRawWriter::GetBusPatch(Int_t detElemId, Int_t manuId) const
556 /// Determine the BusPatch this digit belongs to.
560 AliMpPlaneType plane =
561 (manuId & AliMpConstants::ManuMask(kNonBendingPlane)) ?
562 kNonBendingPlane : kBendingPlane;
564 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
566 if ( stationType == kStation1 || stationType == kStation2 )
568 if (plane == kBendingPlane)
570 ptr = &fgManuPerBusSwp1B[0];
574 ptr = &fgManuPerBusSwp1NB[0];
579 if (plane == kBendingPlane)
581 ptr = &fgManuPerBusSwp2B[0];
585 ptr = &fgManuPerBusSwp2NB[0];
589 // Getting buspatch id
590 TArrayI* vec = fBusPatchManager->GetBusfromDE(detElemId);
593 Int_t m = ( manuId & 0x3FF ); // remove bit 10
594 //FIXME : how can we remove that condition
595 // on the 10-th bit ? All the rest need not any knowledge about it,
596 // can't we find a way to get manu<->buspatch transparent to this too ?
598 if ( stationType == kStation1 || stationType == kStation2 )
600 for (pos = 11; pos >=0 ; --pos)
602 if (m >= ptr[pos]) break;
607 // offset of 100 in manuId for following bus patch
612 if (pos >(Int_t) vec->GetSize())
614 AliError(Form("pos greater %d than size %d manuId %d detElemId %d \n",
615 pos, (Int_t)vec->GetSize(), manuId, detElemId));
616 AliError(Form("Chamber %s Plane %s manuId %d m %d",
617 StationTypeName(stationType).Data(),
618 PlaneTypeName(plane).Data(),
624 Int_t busPatchId = vec->At(pos);
626 if ( ( stationType == kStation1 || stationType == kStation2 ) &&
627 ( plane == kNonBendingPlane ) )
635 //____________________________________________________________________
636 Int_t AliMUONRawWriter::GetBusPatch(const AliMUONDigit& digit) const
638 /// Determine the BusPatch this digit belongs to.
640 return GetBusPatch(digit.DetElemId(),digit.ManuId());
643 //____________________________________________________________________
644 Int_t AliMUONRawWriter::WriteTriggerDDL()
646 /// Write trigger DDL
648 fTimers[kWriteTrigger].Start(kFALSE);
650 // DDL event one per half chamber
652 // stored local id number
653 TArrayI isFired(256);
658 Int_t headerSize = sizeof(AliRawDataHeader)/4;
660 TClonesArray* localTrigger;
661 TClonesArray* globalTrigger;
662 AliMUONGlobalTrigger* gloTrg;
663 AliMUONLocalTrigger* locTrg = 0x0;
665 // global trigger for trigger pattern
666 globalTrigger = fMUONData->GlobalTrigger();
667 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
670 fTimers[kWriteTrigger].Stop();
674 Int_t gloTrigResp = gloTrg->GetGlobalResponse();
677 localTrigger = fMUONData->LocalTrigger();
683 Int_t iLocCard, locCard;
684 Char_t locDec, trigY, posY, posX, regOut;
689 Int_t version = 1; // software version
690 Int_t eventPhys = 1; // trigger type: 1 for physics, 0 for software
691 Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
692 Int_t globalFlag = 0; // set to 1 if global info present in DDL else set to 0
695 static const Int_t kDarcHeaderLength = fDarcHeader->GetDarcHeaderLength();
696 static const Int_t kGlobalHeaderLength = fDarcHeader->GetGlobalHeaderLength();
697 static const Int_t kDarcScalerLength = fDarcHeader->GetDarcScalerLength();
698 static const Int_t kGlobalScalerLength = fDarcHeader->GetGlobalScalerLength();
699 static const Int_t kRegHeaderLength = fRegHeader->GetHeaderLength();
700 static const Int_t kRegScalerLength = fRegHeader->GetScalerLength();
701 static const Int_t kLocHeaderLength = fLocalStruct->GetLength();
702 static const Int_t kLocScalerLength = fLocalStruct->GetScalerLength();
704 // [16(local)*6 words + 6 words]*8(reg) + 8 words = 824
705 static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) + (kRegHeaderLength+1))* 8
706 + kDarcHeaderLength + kGlobalHeaderLength + 2;
708 // [16(local)*51 words + 16 words]*8(reg) + 8 + 10 + 8 words scaler event 6682 words
709 static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength + kLocScalerLength +1) +
710 (kRegHeaderLength + kRegScalerLength +1))* 8 +
711 (kDarcHeaderLength + kDarcScalerLength +
712 kGlobalHeaderLength + kGlobalScalerLength + 2);
714 eventPhys = 0; //set to generate scaler events
716 Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
717 // stored the local card id that's fired
718 for (Int_t i = 0; i < nEntries; i++) {
719 locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
720 isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations
724 AliDebug(1, "No Trigger information available");
727 buffer = new Int_t [kScalerBufferSize];
729 buffer = new Int_t [kBufferSize];
733 // open DDL file, on per 1/2 chamber
734 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
738 if (iDDL == 0) // suppose global info in DDL one
744 // set darc status word
745 // see AliMUONDarcHeader.h for details
746 AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30);
747 AliBitPacking::PackWord((UInt_t)serialNb,word,20,23);
748 AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10);
749 AliBitPacking::PackWord((UInt_t)version,word,12,19);
750 fDarcHeader->SetWord(word);
752 memcpy(&buffer[index], fDarcHeader->GetHeader(), (kDarcHeaderLength)*4);
753 index += kDarcHeaderLength;
755 // no global input for the moment....
757 fDarcHeader->SetGlobalOutput(gloTrigResp);
759 fDarcHeader->SetGlobalOutput(0);
762 // 6 DARC scaler words
763 memcpy(&buffer[index], fDarcHeader->GetDarcScalers(),kDarcScalerLength*4);
764 index += kDarcScalerLength;
767 buffer[index++] = fDarcHeader->GetEndOfDarc();
769 // 4 words of global board input + Global board output
770 memcpy(&buffer[index], fDarcHeader->GetGlobalInput(), (kGlobalHeaderLength)*4);
771 index += kGlobalHeaderLength;
774 // 10 Global scaler words
775 memcpy(fDarcHeader->GetGlobalScalers(), &buffer[index], kGlobalScalerLength*4);
776 index += kGlobalScalerLength;
779 // end of global word
780 buffer[index++] = fDarcHeader->GetEndOfGlobal();
782 // 8 regional cards per DDL
783 for (Int_t iReg = 0; iReg < 8; iReg++) {
786 AliMUONTriggerCrate* crate = fCrateManager->Crate(iDDL, iReg);
789 AliWarning(Form("Missing crate number %d in DDL %d\n", iReg, iDDL));
791 // Regional card header
794 // set darc status word
795 fRegHeader->SetDarcWord(word);
798 regInpHpt = regInpLpt = 0;
799 // fill darc word, not darc status for the moment (empty)
800 //see AliMUONRegHeader.h for details
801 AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31);
802 AliBitPacking::PackWord((UInt_t)serialNb,word,19,24);
803 AliBitPacking::PackWord((UInt_t)version,word,16,23);
804 AliBitPacking::PackWord((UInt_t)iReg,word,15,18);
805 AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // waiting realistic output of AliMUONGlobalTrigger (oct 06 ?)
806 fRegHeader->SetWord(word);
809 // fill header later, need local response
810 Int_t indexReg = index;
811 index += kRegHeaderLength;
813 // 11 regional scaler word
815 memcpy(&buffer[index], fRegHeader->GetScalers(), kRegScalerLength*4);
816 index += kRegScalerLength;
819 // end of regional word
820 buffer[index++] = fRegHeader->GetEndOfReg();
822 TObjArray *boards = crate->Boards();
825 // 16 local card per regional board
826 UShort_t localMask = 0x0;
828 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
830 // slot zero for Regional card
831 AliMUONLocalTriggerBoard* localBoard = (AliMUONLocalTriggerBoard*)boards->At(iLoc+1);
833 if (localBoard) { // if not empty slot
835 if ((iLocCard = localBoard->GetNumber()) != 0) {// if notified board
837 localMask |= (0x1 << iLoc); // local mask
838 if (isFired[iLocCard]) { // if card has triggered
839 locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries);
840 locCard = locTrg->LoCircuit();
841 locDec = locTrg->GetLoDecision();
843 posY = locTrg->LoStripY();
844 posX = locTrg->LoStripX();
845 devX = locTrg->LoDev();
847 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
848 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
849 } else { //no trigger (see PRR chpt 3.4)
855 // set local card id to -1
858 // calculate regional input High and low Pt
859 UInt_t tmp1 = (locDec >> 2) & 0x3;
860 UInt_t tmp2 = locDec & 0x3;
862 regInpHpt |= tmp1 << (30 - iLoc*2);
863 regInpLpt |= tmp2 << (30 - iLoc*2);
867 AliBitPacking::PackWord((UInt_t)iLoc,word,19,22); //card id number in crate
868 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
869 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
870 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
871 AliBitPacking::PackWord((UInt_t)devX,word,5,9);
872 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
874 if (locCard == iLocCard) {
875 // add local cards structure
876 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
877 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
878 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
879 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
880 buffer[index++] = (Int_t)word; // data word
881 if (iEntries < nEntries-1)
884 buffer[index++] = 0; // 4 words for x1, x2, y1, y2
888 buffer[index++] = (Int_t)word; // data word
892 // fill with 10CDEAD word for 'non-notified' slots
893 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
894 buffer[index++] = fLocalStruct->GetDisableWord();
897 // fill with 10CDEAD word for empty slots
898 for (Int_t i = 0; i < fLocalStruct->GetLength(); i++)
899 buffer[index++] = fLocalStruct->GetDisableWord();
900 }// condition localBoard
902 // 45 regional scaler word
904 memcpy(&buffer[index], fLocalStruct->GetScalers(), kLocScalerLength*4);
905 index += kLocScalerLength;
908 // end of local structure words
909 buffer[index++] = fLocalStruct->GetEndOfLocal();
912 // fill regional header with local output
913 fRegHeader->SetInput(regInpLpt, 0);
914 fRegHeader->SetInput(regInpHpt, 1);
915 fRegHeader->SetMask(localMask);
916 memcpy(&buffer[indexReg],fRegHeader->GetHeader(),kRegHeaderLength*4);
921 // writting onto disk
923 fHeader.fSize = (index + headerSize) * 4;// total length in bytes
924 fwrite((char*)(&fHeader),headerSize*4,1,fFile[iDDL]);
925 fwrite(buffer,sizeof(int),index,fFile[iDDL]);
930 fTimers[kWriteTrigger].Stop();
934 //____________________________________________________________________
935 void AliMUONRawWriter::SetScalersNumbers()
937 /// set numbers for scaler events for trigger headers
938 /// since this is provided by the experiment
939 /// put dummy numbers to check the monitoring
941 fDarcHeader->SetScalersNumbers();
942 fRegHeader->SetScalersNumbers();
943 fLocalStruct->SetScalersNumbers();
945 fScalerEvent = kTRUE;