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 **************************************************************************/
16 ////////////////////////////////////
18 // MUON Raw Data generator and reader in ALICE-MUON
19 // This class version 3 (further details could be found in Alice-note)
21 // Implemented non-constant buspatch numbers for tracking
22 // with correct DDL id (first guess)
23 // (Ch. Finck, dec 2005)
26 // Generates raw data for MUON tracker and finally for trigger
27 // Using real mapping (inverse) for tracker
28 // For trigger there is no mapping (mapping could be found in AliMUONTriggerCircuit)
32 // Using real mapping for tracker
33 // Indranil Das (Adapted for runloader: Ch. Finck) july 05
35 ////////////////////////////////////
40 #include <TClonesArray.h>
42 #include "AliLoader.h"
43 #include "AliBitPacking.h"
44 #include "AliRawReader.h"
49 #include "AliMUONRawData.h"
50 #include "AliMUONDigit.h"
52 #include "AliMUONConstants.h"
53 #include "AliMUONData.h"
55 #include "AliMUONSubEventTrigger.h"
56 #include "AliMUONDDLTracker.h"
57 #include "AliMUONDDLTrigger.h"
59 #include "AliMUONLocalTrigger.h"
60 #include "AliMUONGlobalTrigger.h"
62 #include "AliMUONGeometrySegmentation.h"
63 #include "AliMUONGeometryModule.h"
64 #include "AliMUONGeometryStore.h"
65 #include "AliMUONSegmentationManager.h"
66 #include "AliMpPlaneType.h"
67 #include "AliMpVSegmentation.h"
68 #include "AliMpHelper.h"
72 ClassImp(AliMUONRawData) // Class implementation in ROOT context
73 //__________________________________________________________________________
74 AliMUONRawData::AliMUONRawData(AliLoader* loader)
77 // Standard Constructor
79 // initialize loader's
82 // initialize container
83 fMUONData = new AliMUONData(fLoader,"MUON","MUON");
86 fSubEventArray = new TClonesArray("AliMUONSubEventTracker",1000);
90 fDDLTracker = new AliMUONDDLTracker();
91 fDDLTrigger = new AliMUONDDLTrigger();
93 fBusPatchManager = new AliMpBusPatch();
94 fBusPatchManager->ReadBusPatchFile();
98 //__________________________________________________________________________
99 AliMUONRawData::AliMUONRawData()
106 // Default Constructor
107 fFile[0] = fFile[1] = 0x0;
111 //_______________________________________________________________________
112 AliMUONRawData::AliMUONRawData (const AliMUONRawData& rhs)
115 // Protected copy constructor
117 AliFatal("Not implemented.");
120 //_______________________________________________________________________
122 AliMUONRawData::operator=(const AliMUONRawData& rhs)
124 // Protected assignement operator
126 if (this == &rhs) return *this;
128 AliFatal("Not implemented.");
133 //__________________________________________________________________________
134 AliMUONRawData::~AliMUONRawData(void)
139 fSubEventArray->Delete(); //using delete cos allocating memory in copy ctor.
146 fBusPatchManager->Delete();
150 //____________________________________________________________________
151 Int_t AliMUONRawData::Digits2Raw()
153 // convert digits of the current event to raw data
158 fLoader->LoadDigits("READ");
160 fMUONData->SetTreeAddress("D,GLT");
165 for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++) {
168 idDDL = ich * 2 + 0x900; // official number for MUON
169 sprintf(name, "MUON_%d.ddl",idDDL);
170 fFile[0] = fopen(name,"w");
172 idDDL = (ich * 2) + 1 + 0x900;
173 sprintf(name, "MUON_%d.ddl",idDDL);
174 fFile[1] = fopen(name,"w");
176 WriteTrackerDDL(ich);
181 fMUONData->ResetDigits();
187 idDDL = 0xA00;// official number for MUTR
188 sprintf(name, "MUTR_%d.ddl",idDDL);
189 fFile[0] = fopen(name,"w");
192 sprintf(name, "MUTR_%d.ddl",idDDL);
193 fFile[1] = fopen(name,"w");
200 fMUONData->ResetTrigger();
202 fLoader->UnloadDigits();
206 //____________________________________________________________________
207 Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
209 // writing DDL for tracker
210 // used inverse mapping
213 TClonesArray* muonDigits = 0;
214 fSubEventArray->Clear();
224 AliRawDataHeader header = fDDLTracker->GetHeader();
225 Int_t headerSize = fDDLTracker->GetHeaderSize();
227 // DDL event one per half chamber
228 AliMUONSubEventTracker* subEvent;
233 UChar_t channelId = 0;
235 Int_t busPatchId = 0;
249 const AliMUONDigit* digit;
251 AliDebug(3, Form("WriteDDL chamber %d\n", iCh+1));
254 fMUONData->ResetDigits();
255 fMUONData->GetDigits();
256 muonDigits = fMUONData->Digits(iCh);
258 nDigits = muonDigits->GetEntriesFast();
259 AliDebug(3,Form("ndigits = %d\n",nDigits));
262 for (Int_t idig = 0; idig < nDigits; idig++) {
264 digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
266 padX = digit->PadX();
267 padY = digit->PadY();
268 charge = digit->Signal();
270 cathode = digit->Cathode();
271 detElemId = digit->DetElemId();
274 Int_t error = GetInvMapping(digit, busPatchId, manuId, channelId);
277 AliDebug(3,Form("input IdDE %d busPatchId %d PadX %d PadY %d iCath %d \n",
278 detElemId, busPatchId, padX, padY, cathode));
280 AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", busPatchId, manuId, channelId ));
283 AliBitPacking::PackWord((UInt_t)parity,word,29,31);
284 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
285 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
286 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
289 subEvent = new AliMUONSubEventTracker();
290 subEvent->AddData(word);
291 subEvent->SetBusPatchId(busPatchId);
293 // storing the number of identical buspatches
294 nbInBus[busPatchId]++;
300 // sorting by buspatch
301 fSubEventArray->Sort();
303 // gather datas from same bus patch
304 nEntries = fSubEventArray->GetEntriesFast();
306 for (Int_t i = 0; i < nEntries; i++) {
307 AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray->At(i);
308 busPatchId = temp->GetBusPatchId();
310 // add bus patch header, length and total length managed by subevent class
311 temp->SetTriggerWord(0xdeadbeef);
312 for (Int_t j = 0; j < nbInBus[busPatchId]-1; j++) {
313 AliMUONSubEventTracker* temp1 = (AliMUONSubEventTracker*)fSubEventArray->At(++i);
314 temp->AddData(temp1->GetData(0));
315 fSubEventArray->RemoveAt(i) ;
318 fSubEventArray->Compress();
320 if (AliLog::GetGlobalDebugLevel() == 3) {
321 nEntries = fSubEventArray->GetEntriesFast();
322 for (Int_t i = 0; i < nEntries; i++) {
323 AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray->At(i);
324 printf("busPatchid back %d\n",temp->GetBusPatchId());
325 for (Int_t j = 0; j < temp->GetLength(); j++) {
326 printf("manuId back %d, ",temp->GetManuId(j));
327 printf("channelId back %d, ",temp->GetChannelId(j));
328 printf("charge back %d\n",temp->GetCharge(j));
334 // getting info for the number of buspatches
337 Int_t iBusPerDSP[5];//number of bus patches per DSP
338 Int_t iDspMax; //number max of DSP per block
341 fBusPatchManager->GetDspInfo(iCh, iDspMax, iBusPerDSP);
343 TArrayI* vec = fBusPatchManager->GetBusfromDE((iCh+1)*100);
345 Int_t iBus0AtCh = vec->At(0); //get first bus patch id for a given ich
347 AliDebug(3,Form("iBus0AtCh %d", iBus0AtCh));
349 iBusPatch = iBus0AtCh - 1; // starting point for each chamber
351 // nEntries = fSubEventArray->GetEntriesFast();
352 AliMUONSubEventTracker* temp = 0x0;
354 // open DDL file, on per 1/2 chamber
355 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
359 buffer = new Int_t [(2048+24)*50]; // 24 words in average for one buspatch and 2048 manu info at most
365 // two blocks A and B per DDL
366 for (Int_t iBlock = 0; iBlock < 2; iBlock++) {
369 length = fDDLTracker->GetBlkHeaderLength();
370 memcpy(&buffer[index],fDDLTracker->GetBlkHeader(),length*4);
374 // 5 DSP's max per block
375 for (Int_t iDsp = 0; iDsp < iDspMax; iDsp++) {
378 length = fDDLTracker->GetDspHeaderLength();
379 memcpy(&buffer[index],fDDLTracker->GetDspHeader(),length*4);
383 //Â 5 buspatches max per DSP
384 for (Int_t i = 0; i < iBusPerDSP[iDsp]; i++) {
387 if ((fBusPatchManager->GetDDLfromBus(iBusPatch) % 2) == 1) // comparing to DDL file
392 AliDebug(3,Form("iCh %d iDDL %d iBlock %d iDsp %d busPatchId %d", iCh, iDDL, iBlock, iDsp, iBusPatch));
394 nEntries = fSubEventArray->GetEntriesFast();
396 for (Int_t iEntries = 0; iEntries < nEntries; iEntries++) { // method "bourrique"...
397 temp = (AliMUONSubEventTracker*)fSubEventArray->At(iEntries);
398 busPatchId = temp->GetBusPatchId();
399 if (busPatchId == iBusPatch) break;
401 AliDebug(3,Form("busPatchId %d", temp->GetBusPatchId()));
404 // check if buspatchid has digit
405 if (busPatchId != -1) {
406 // add bus patch structure
407 length = temp->GetHeaderLength();
408 memcpy(&buffer[index],temp->GetAddress(),length*4);
410 for (Int_t j = 0; j < temp->GetLength(); j++) {
411 buffer[index++] = temp->GetData(j);
412 AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", temp->GetBusPatchId(),
413 temp->GetManuId(j), temp->GetChannelId(j) ));
415 // fSubEventArray->RemoveAt(iEntries);
416 // fSubEventArray->Compress();
418 // writting anyhow buspatch structure (empty ones)
419 buffer[index++] = 4; // total length
420 buffer[index++] = 0; // raw data length
421 buffer[index++] = iBusPatch; // bus patch
422 buffer[index++] = 0xdeadbeef; // trigger word
425 buffer[indexDsp] = index - indexDsp; // dsp length
426 buffer[indexDsp+1] = index - indexDsp - fDDLTracker->GetDspHeaderLength();
427 if ((index - indexDsp) % 2 == 0)
428 buffer[indexDsp+7] = 0;
430 buffer[indexDsp+7] = 1;
432 buffer[indexBlk] = index - indexBlk; // block length
433 buffer[indexBlk+1] = index - indexBlk - fDDLTracker->GetBlkHeaderLength();
438 header.fSize = (index + headerSize) * 4;// total length in bytes
439 fwrite((char*)(&header),headerSize*4,1,fFile[iFile]);
440 fwrite(buffer,sizeof(int),index,fFile[iFile]);
447 //____________________________________________________________________
448 Int_t AliMUONRawData::WriteTriggerDDL()
451 // DDL event one per half chamber
452 AliMUONSubEventTrigger* subEvent = 0x0;
455 // stored local id number
456 TArrayI isFired(256);
461 AliRawDataHeader header = fDDLTrigger->GetHeader();
462 Int_t headerSize = fDDLTrigger->GetHeaderSize();
464 TClonesArray* localTrigger;
465 TClonesArray* globalTrigger;
466 AliMUONGlobalTrigger* gloTrg;
467 AliMUONLocalTrigger* locTrg = 0x0;
469 // getting information from trigger
470 fMUONData->GetTriggerD();
472 // global trigger for trigger pattern
473 globalTrigger = fMUONData->GlobalTrigger();
474 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
475 Int_t gloTrigPat = GetGlobalTriggerPattern(gloTrg);
478 localTrigger = fMUONData->LocalTrigger();
484 Int_t iLocCard, locCard;
485 Char_t locDec, trigY, posY, posX,regOut;
487 Int_t version = 1; // software version
488 Int_t eventType = 1; // trigger type: 1 for physics ?
489 Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
490 Int_t globalFlag = 1; // set to 2 if global info present in DDL else set to 1
492 Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
493 // stored the local card id that's fired
494 for (Int_t i = 0; i < nEntries; i++) {
495 locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
496 isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations
500 AliError("No Trigger information available");
502 buffer = new Int_t [672]; // [16(local)*5 words + 3 words]*8(reg) + 8 words = 672
504 // open DDL file, on per 1/2 chamber
505 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
509 // DDL enhanced header
511 AliBitPacking::PackWord((UInt_t)iDDL+1,word,28,31); //see AliMUONDDLTrigger.h for details
512 AliBitPacking::PackWord((UInt_t)serialNb,word,24,27);
513 AliBitPacking::PackWord((UInt_t)version,word,16,23);
514 AliBitPacking::PackWord((UInt_t)eventType,word,12,15);
516 if (iDDL == 0) // suppose global info in DDL one
520 AliBitPacking::PackWord((UInt_t)globalFlag,word,8,11);
521 fDDLTrigger->SetDDLWord(word);
524 fDDLTrigger->SetGlobalOutput(gloTrigPat);// no global input for the moment....
526 fDDLTrigger->SetGlobalOutput(0);
527 length = fDDLTrigger->GetHeaderLength();
528 memcpy(&buffer[index],fDDLTrigger->GetEnhancedHeader(),length*4);
531 // 8 regional cards per DDL
532 for (Int_t iReg = 0; iReg < 8; iReg++) {
534 subEvent = new AliMUONSubEventTrigger();
536 // Regional card header
539 AliBitPacking::PackWord((UInt_t)serialNb,word,24,28); //see AliMUONSubEventTrigger.h for details
540 AliBitPacking::PackWord((UInt_t)version,word,16,23);
541 AliBitPacking::PackWord((UInt_t)iReg,word,12,15);
542 AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // whenever regional output will be implemented
544 subEvent->SetRegWord(word);
545 memcpy(&buffer[index++],subEvent->GetAddress(),4);
547 buffer[index++] = 0;// 2 words of regional input
550 // 16 local card per regional board
551 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
553 iLocCard = iLoc + iReg*16 + iDDL*128;
555 if (isFired[iLocCard]) {
556 locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries);
557 locCard = locTrg->LoCircuit();
558 locDec = locTrg->GetLoDecision();
560 posY = locTrg->LoStripY();
561 posX = locTrg->LoStripX();
562 devX = locTrg->LoDev();
563 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
564 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
565 } else { //no trigger (see PRR chpt 3.4)
576 AliBitPacking::PackWord((UInt_t)(iLocCard % 16),word,19,22); //card id number in crate
577 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
578 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
579 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
580 AliBitPacking::PackWord((UInt_t)devX,word,5,9);
581 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
583 if (locCard == iLocCard) {
584 // add local cards structure
585 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
586 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
587 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
588 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
589 buffer[index++] = (Int_t)word; // data word
590 if (iEntries < nEntries-1)
593 buffer[index++] = 0; // 4 words for x1, x2, y1, y2
597 buffer[index++] = (Int_t)word; // data word
606 buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word
607 buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word for 64 bits transfer purpose
609 // writting onto disk
611 header.fSize = (index + headerSize) * 4;// total length in bytes
612 fwrite((char*)(&header),headerSize*4,1,fFile[iDDL]);
613 fwrite(buffer,sizeof(int),index,fFile[iDDL]);
621 //____________________________________________________________________
622 Int_t AliMUONRawData::GetInvMapping(const AliMUONDigit* digit,
623 Int_t &busPatchId, UShort_t &manuId, UChar_t &channelId)
626 // Inverse mapping for tracker
628 // information from digits
629 Int_t iCath = digit->Cathode();
630 Int_t idDE = digit->DetElemId();
631 Int_t padX = digit->PadX();
632 Int_t padY = digit->PadY();
634 if (idDE >= 500) { // Since in AliMpSlat pads begin at (0,0)
635 padX--; // while in AliMUONSt345Seg. they begin at (1,1)
640 AliMpPlaneType plane;
641 AliMpPlaneType plane1 = kBendingPlane;
642 AliMpPlaneType plane2 = kNonBendingPlane;
644 if (idDE < 500) { // should use GetDirection somehow (ChF)
645 if ( ((idDE % 100) % 2) != 0 ) {
646 plane1 = kNonBendingPlane;
647 plane2 = kBendingPlane;
650 // station 345 bending == cath0 for the moment
651 plane = (iCath == 0) ? plane1 : plane2;
653 AliMpVSegmentation* seg = AliMUONSegmentationManager::Segmentation(idDE, plane);
654 AliMpPad pad = seg->PadByIndices(AliMpIntPair(padX,padY),kTRUE);
657 AliWarning(Form("No elec. for idDE: %d, padx: %d pady %d, charge: %d\n",
658 idDE, digit->PadX(), digit->PadY(), digit->Signal()));
663 manuId = pad.GetLocation().GetFirst();
664 manuId &= 0x7FF; // 11 bits
666 // Getting channel id
667 channelId = pad.GetLocation().GetSecond();
668 channelId &= 0x3F; // 6 bits
670 // Getting buspatch id
671 TArrayI* vec = fBusPatchManager->GetBusfromDE(idDE);
674 if (idDE < 500) { // station 1 & 2
675 // set 32 manus for one bus patch ? (ChF)
678 // offset of 100 in manuId for following bus patch
682 // if (pos >(int_t) vec.size())
683 // AliWarning("pos greater than size\n");
684 busPatchId = vec->At(pos);
686 if (plane == kNonBendingPlane) // for Non-Bending manuid+= 1000;
687 manuId += 1000; // tmp solution til one finds something better (ChF)
689 AliDebug(3,Form("idDE: %d, busPatchId %d, manuId: %d, channelId:%d\n",
690 idDE, busPatchId, manuId, channelId));
692 AliDebug(3,Form("idDE: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady: %d, charge: %d\n",
693 idDE, busPatchId, manuId, channelId, digit->PadX(), digit->PadY(), digit->Signal()));
695 return kFALSE; // no error
698 //____________________________________________________________________
699 Int_t AliMUONRawData::GetGlobalTriggerPattern(const AliMUONGlobalTrigger* gloTrg) const
701 // global trigger pattern calculation
703 Int_t gloTrigPat = 0;
705 if (gloTrg->SinglePlusLpt()) gloTrigPat|= 0x1;
706 if (gloTrg->SinglePlusHpt()) gloTrigPat|= 0x2;
707 if (gloTrg->SinglePlusApt()) gloTrigPat|= 0x4;
709 if (gloTrg->SingleMinusLpt()) gloTrigPat|= 0x8;
710 if (gloTrg->SingleMinusHpt()) gloTrigPat|= 0x10;
711 if (gloTrg->SingleMinusApt()) gloTrigPat|= 0x20;
713 if (gloTrg->SingleUndefLpt()) gloTrigPat|= 0x40;
714 if (gloTrg->SingleUndefHpt()) gloTrigPat|= 0x80;
715 if (gloTrg->SingleUndefApt()) gloTrigPat|= 0x100;
717 if (gloTrg->PairUnlikeLpt()) gloTrigPat|= 0x200;
718 if (gloTrg->PairUnlikeHpt()) gloTrigPat|= 0x400;
719 if (gloTrg->PairUnlikeApt()) gloTrigPat|= 0x800;
721 if (gloTrg->PairLikeLpt()) gloTrigPat|= 0x1000;
722 if (gloTrg->PairLikeHpt()) gloTrigPat|= 0x2000;
723 if (gloTrg->PairLikeApt()) gloTrigPat|= 0x4000;
728 //____________________________________________________________________
729 Int_t AliMUONRawData::Raw2Digits(AliRawReader* rawReader)
733 ReadTrackerDDL(rawReader);
736 ReadTriggerDDL(rawReader);
742 //____________________________________________________________________
743 Int_t AliMUONRawData::ReadTrackerDDL(AliRawReader* rawReader)
745 // reading tracker DDL
746 // filling the TClonesArray in MUONData
749 AliMUONSubEventTracker* subEventTracker = new AliMUONSubEventTracker();
750 AliMUONDigit* digit = new AliMUONDigit();
753 //Read Header Size of DDL,Block,DSP and BusPatch.
755 Int_t ddlHeaderSize = fDDLTracker->GetHeaderSize();
756 Int_t blockHeaderSize = fDDLTracker->GetBlkHeaderLength();
757 Int_t dspHeaderSize = fDDLTracker->GetDspHeaderLength();
758 Int_t buspatchHeaderSize = subEventTracker->GetHeaderLength();
760 Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize;
763 Int_t iBusPerDSP[5];//number of bus patches per DSP
764 Int_t iDspMax; //number max of DSP per block
766 // minimum data size (only header's)
768 Int_t blankBlockSize;
771 for(Int_t iDDL = 0; iDDL < 20; iDDL++) { // DDL loop
773 AliDebug(3, Form("Chamber %d\n", iDDL/2 +1 ));
776 fBusPatchManager->GetDspInfo(iDDL/2, iDspMax, iBusPerDSP);
778 // Each DDL is made with 2 Blocks each of which consists of 5 DSP's at most and each of DSP has at most 5 buspatches.
779 // This information is used to calculate the size of headers (DDL,Block and DSP) which has no interesting data.
780 blankDDLSize = ddlHeaderSize + 2*blockHeaderSize + 2*iDspMax*dspHeaderSize;
781 blankBlockSize = blockHeaderSize + iDspMax*dspHeaderSize;
783 for (Int_t i = 0; i < iDspMax; i++) {
784 blankDDLSize += 2*iBusPerDSP[i]*buspatchHeaderSize;
785 blankBlockSize += iBusPerDSP[i]*buspatchHeaderSize;
788 rawReader->Select(0X9, iDDL, iDDL); //Select the DDL file to be read
790 rawReader->ReadHeader();
792 totalDDLSize = (rawReader->GetDataSize() + sizeof(AliRawDataHeader))/4; // 4 is multiplied to convert byte 2 words
794 if(totalDDLSize > blankDDLSize) { // Compare the DDL header with an empty DDL header size to read the file
796 Int_t totalDataWord = rawReader->GetDataSize()/4 ;
797 UInt_t *buffer = new UInt_t[totalDataWord];
798 for(Int_t i = 0; i < totalDataWord; i++) {
799 UInt_t& temp = buffer[i];
800 rawReader->ReadNextInt(temp); // takes the whole result into buffer variable for future analysis
815 for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){ // loop over 2 blocks
816 totalBlockSize = buffer[index];
818 if(totalBlockSize > blankBlockSize) { // compare block header
819 index += blockHeaderSize;
821 for(Int_t iDsp = 0; iDsp < iDspMax ;iDsp++){ //DSP loop
823 totalDspSize = buffer[index];
826 blankDspSize = dspHeaderSize + iBusPerDSP[iDsp]*buspatchHeaderSize; // no data just header
828 if(totalDspSize > blankDspSize) { // Compare DSP Header
829 index += dspHeaderSize;
831 for(Int_t iBusPatch = 0; iBusPatch < iBusPerDSP[iDsp]; iBusPatch++) {
833 totalBusPatchSize = buffer[index];
834 buspatchId = buffer[index+2];
835 indexBusPatch = index;
837 if(totalBusPatchSize > buspatchHeaderSize) { //Check Buspatch header
839 index += buspatchHeaderSize;
840 dataSize = totalBusPatchSize - buspatchHeaderSize;
842 if(dataSize>0) { // check data present
844 for(Int_t iData = 0; iData < dataSize; iData++) {
846 subEventTracker->SetData(buffer[index++],iData); //Set to extract data
848 parity = subEventTracker->GetParity(iData); // test later for parity
849 manuId = subEventTracker->GetManuId(iData);
850 channelId = subEventTracker->GetChannelId(iData);
851 charge = subEventTracker->GetCharge(iData);
853 digit->SetSignal(charge);
855 Int_t error = GetMapping(buspatchId,manuId,channelId,digit); // Get Back the hits at pads
859 if (AliLog::GetGlobalDebugLevel() == 3) {
860 Int_t padX = digit->PadX();
861 Int_t padY = digit->PadY();
862 Int_t iCath = digit->Cathode();
863 Int_t idDE = digit->DetElemId();
865 AliDebug(1,Form("output IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n",
866 idDE, buspatchId, padX, padY, iCath));
868 AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d",idDE, padX, padY, iCath, charge));
872 fMUONData->AddDigit(iDDL/2, *digit);
876 } // testing buspatch
878 index = indexBusPatch + totalBusPatchSize;
884 index = indexDsp + totalDspSize;
890 index = totalBlockSize;
895 } //loop checking the header size of DDL
901 delete subEventTracker;
907 //____________________________________________________________________
908 Int_t AliMUONRawData::GetMapping(Int_t busPatchId, UShort_t manuId,
909 UChar_t channelId, AliMUONDigit* digit )
912 // mapping for tracker
914 // getting DE from buspatch
915 Int_t idDE = fBusPatchManager->GetDEfromBus(busPatchId);
916 AliDebug(3,Form("idDE: %d busPatchId %d\n", idDE, busPatchId));
923 AliMpPlaneType plane;
925 if (manuId > 1000) { // again tmp solution (ChF) (+1000 for Non-Bending plane
926 plane = kNonBendingPlane;
928 plane = kBendingPlane;
931 if (idDE < 500) { // should use GetDirection somehow (ChF)
932 if ( ((idDE % 100) % 2) != 0 ) {
938 iCath = (manuId > 1000) ? iCath2 : iCath1;
940 if (manuId > 1000) manuId -= 1000; // back to normal manuId
942 AliMpVSegmentation* seg = AliMUONSegmentationManager::Segmentation(idDE, plane);
943 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,(Int_t)channelId),kTRUE);
946 AliWarning(Form("No pad for idDE: %d, busPatchId %d, manuId: %d, channelId: %d\n",
947 idDE, busPatchId, manuId, channelId));
952 Int_t padX = pad.GetIndices().GetFirst();
955 Int_t padY = pad.GetIndices().GetSecond();
957 if (idDE >= 500) { // Since in AliMpSlat pads begin at (0,0)
958 padX++; // while in AliMUONSt345Seg. they begin at (1,1)
961 // storing into digits
962 digit->SetPadX(padX);
963 digit->SetPadY(padY);
964 digit->SetCathode(iCath);
965 digit->SetDetElemId(idDE);
967 AliDebug(3,Form("idDE: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
968 idDE, busPatchId, manuId, channelId, padX, padY));
972 //____________________________________________________________________
973 Int_t AliMUONRawData::ReadTriggerDDL(AliRawReader* rawReader)
976 // reading DDL for trigger
978 AliMUONSubEventTrigger* subEventTrigger = new AliMUONSubEventTrigger();
979 AliMUONGlobalTrigger* globalTrigger = 0x0;
980 AliMUONLocalTrigger* localTrigger = new AliMUONLocalTrigger();
983 //Int_t ddlHeaderSize = fDDLTrigger->GetHeaderSize();
984 // we dont need this, as size of ddl data is same for triger and no trigger
986 Int_t ddlEnhanceHeaderSize = fDDLTrigger->GetHeaderLength();
987 Int_t regHeaderLength = subEventTrigger->GetRegHeaderLength() ;
989 Int_t loCircuit, loStripX, loDev, loStripY, loLpt, loHpt;
992 UShort_t x1Pattern, x2Pattern, x3Pattern, x4Pattern;
993 UShort_t y1Pattern, y2Pattern, y3Pattern, y4Pattern;
996 // loop over the two ddl's
997 for(Int_t iDDL = 0; iDDL < 2; iDDL++) { //DDL loop
999 rawReader->Select(0XA,iDDL,iDDL); //Select the DDL file to be read
1001 rawReader->ReadHeader();
1003 Int_t totalDataWord = rawReader->GetDataSize()/4 ;
1004 UInt_t *buffer = new UInt_t[totalDataWord];
1005 for(Int_t i=0;i<totalDataWord;i++){
1006 UInt_t& temp = buffer[i];
1007 rawReader->ReadNextInt(temp); // takes the whole result into buffer variable for future analysis
1010 // rawReader->ReadNext((UChar_t*)buffer, totalDataWord); // method is protected ????
1014 // fill DDL header informations
1015 memcpy(fDDLTrigger->GetEnhancedHeader(), &buffer[index], ddlEnhanceHeaderSize*4);
1017 // fill global trigger information
1018 globalTrigger = GetGlobalTriggerPattern(fDDLTrigger->GetGlobalOuput());
1019 fMUONData->AddGlobalTrigger(*globalTrigger);
1021 index += ddlEnhanceHeaderSize;
1023 // 8 regional boards
1024 for (Int_t iReg = 0; iReg < 8; iReg++) { //loop over regeonal card
1027 subEventTrigger->SetRegWord(buffer[index]); //read regional data
1029 index += regHeaderLength;
1031 // 16 local cards per regional board
1032 for (Int_t iLoc = 0; iLoc < 16; iLoc++) { //loop over local card
1034 Int_t iLocIndex = index;
1036 // 5 word trigger information
1037 for(Int_t iData = 0; iData < 5 ;iData++ ){
1038 subEventTrigger->SetLocalData(buffer[index++],5*iLoc+iData); //read local data
1041 if(buffer[iLocIndex] > 0) {
1043 loCircuit = (Int_t)subEventTrigger->GetLocalId(iLoc)+ 16*iReg + 128*iDDL;
1044 loStripX = (Int_t)subEventTrigger->GetXPos(iLoc);
1045 loStripY = (Int_t)subEventTrigger->GetYPos(iLoc);
1046 loDev = (Int_t)subEventTrigger->GetXDev(iLoc);
1048 // fill local trigger
1049 localTrigger->SetLoCircuit(loCircuit);
1050 localTrigger->SetLoStripX(loStripX );
1051 localTrigger->SetLoStripY(loStripY);
1052 localTrigger->SetLoDev(loDev);
1054 loDecision = subEventTrigger->GetLocalDec(iLoc);
1055 loLpt = loDecision & 0x3;
1056 loHpt = (loDecision >> 2) & 0x3;
1058 // fill local trigger
1059 localTrigger->SetLoLpt(loLpt);
1060 localTrigger->SetLoHpt(loHpt);
1062 //getting pattern from subvent
1063 x1Pattern = subEventTrigger->GetX1(iLoc);
1064 x2Pattern = subEventTrigger->GetX2(iLoc);
1065 x3Pattern = subEventTrigger->GetX3(iLoc);
1066 x4Pattern = subEventTrigger->GetX4(iLoc);
1068 y1Pattern = subEventTrigger->GetY1(iLoc);
1069 y2Pattern = subEventTrigger->GetY2(iLoc);
1070 y3Pattern = subEventTrigger->GetY3(iLoc);
1071 y4Pattern = subEventTrigger->GetY4(iLoc);
1073 // fill local trigger
1074 localTrigger->SetX1Pattern(x1Pattern);
1075 localTrigger->SetX2Pattern(x2Pattern);
1076 localTrigger->SetX3Pattern(x3Pattern);
1077 localTrigger->SetX4Pattern(x4Pattern);
1079 localTrigger->SetY1Pattern(y1Pattern);
1080 localTrigger->SetY2Pattern(y2Pattern);
1081 localTrigger->SetY3Pattern(y3Pattern);
1082 localTrigger->SetY4Pattern(y4Pattern);
1083 fMUONData->AddLocalTrigger(*localTrigger);
1087 } // local card loop
1089 } // regional card loop
1094 delete subEventTrigger;
1095 delete globalTrigger;
1096 delete localTrigger;
1101 //____________________________________________________________________
1102 AliMUONGlobalTrigger* AliMUONRawData::GetGlobalTriggerPattern(Int_t gloTrigPat) const
1104 // global trigger pattern calculation
1106 Int_t globalSinglePlus[3]; // tot num of single plus
1107 Int_t globalSingleMinus[3]; // tot num of single minus
1108 Int_t globalSingleUndef[3]; // tot num of single undefined
1109 Int_t globalPairUnlike[3]; // tot num of unlike-sign pairs
1110 Int_t globalPairLike[3]; // tot num of like-sign pairs
1113 for (Int_t i = 0; i < 3; i++) {
1114 globalSinglePlus[i] = gloTrigPat & (0x1 << i);
1115 globalSingleMinus[i] = gloTrigPat & (0x1 << i+3);
1116 globalSingleUndef[i] = gloTrigPat & (0x1 << i+6);
1117 globalPairUnlike[i] = gloTrigPat & (0x1 << i+9);
1118 globalPairLike[i] = gloTrigPat & (0x1 << i+12);
1121 return (new AliMUONGlobalTrigger(globalSinglePlus, globalSingleMinus,
1122 globalSingleUndef, globalPairUnlike,