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 1 (further details could be found in Alice-note)
21 // Generates raw data for MUON tracker and finally for trigger
22 // * a simple mapping is used (see below)
23 // * the bus patch id is calculated with an absolute number 0 - 999
24 // * one DDL per 1/2 chamber is created for both cathode.
25 // For trigger there is no mapping (mapping could be found in AliMUONTriggerCircuit)
28 // Using still dummy mapping (inverse) for tracker
29 // Indranil Das (Adapted for runloader: Ch. Finck) july 05
30 ////////////////////////////////////
35 #include <TClonesArray.h>
37 #include "AliLoader.h"
38 #include "AliBitPacking.h"
39 #include "AliRawReader.h"
44 #include "AliMUONRawData.h"
45 #include "AliMUONDigit.h"
47 #include "AliMUONChamber.h"
48 #include "AliMUONConstants.h"
49 #include "AliMUONData.h"
51 #include "AliMUONSubEventTrigger.h"
52 #include "AliMUONDDLTracker.h"
53 #include "AliMUONDDLTrigger.h"
55 #include "AliMUONLocalTrigger.h"
56 #include "AliMUONGlobalTrigger.h"
58 #include "AliMUONGeometrySegmentation.h"
59 #include "AliMUONGeometryModule.h"
60 #include "AliMUONGeometryStore.h"
61 #include "AliMUONSegmentationManager.h"
62 #include "AliMpPlaneType.h"
63 #include "AliMpVSegmentation.h"
64 #include "AliMpHelper.h"
68 ClassImp(AliMUONRawData) // Class implementation in ROOT context
69 //__________________________________________________________________________
70 AliMUONRawData::AliMUONRawData(AliLoader* loader)
73 // Standard Constructor
75 // initialize loader's
78 // initialize container
79 fMUONData = new AliMUONData(fLoader,"MUON","MUON");
82 fSubEventArray = new TClonesArray("AliMUONSubEventTracker",1000);
86 fDDLTracker = new AliMUONDDLTracker();
87 fDDLTrigger = new AliMUONDDLTrigger();
93 //__________________________________________________________________________
94 AliMUONRawData::AliMUONRawData()
101 // Default Constructor
102 fFile[0] = fFile[1] = 0x0;
106 //_______________________________________________________________________
107 AliMUONRawData::AliMUONRawData (const AliMUONRawData& rhs)
110 // Protected copy constructor
112 AliFatal("Not implemented.");
115 //_______________________________________________________________________
117 AliMUONRawData::operator=(const AliMUONRawData& rhs)
119 // Protected assignement operator
121 if (this == &rhs) return *this;
123 AliFatal("Not implemented.");
128 //__________________________________________________________________________
129 AliMUONRawData::~AliMUONRawData(void)
134 fSubEventArray->Delete(); //using delete cos allocating memory in copy ctor.
141 fDetElemIdToBusPatch.Delete();
142 fBusPatchToDetElem.Delete();
146 //____________________________________________________________________
147 Int_t AliMUONRawData::Digits2Raw()
149 // convert digits of the current event to raw data
154 fLoader->LoadDigits("READ");
156 fMUONData->SetTreeAddress("D,GLT");
161 for (Int_t ich = 0; ich < AliMUONConstants::NTrackingCh(); ich++) {
164 idDDL = ich * 2 + 0x900; // official number for MUON
165 sprintf(name, "MUON_%d.ddl",idDDL);
166 fFile[0] = fopen(name,"w");
168 idDDL = (ich * 2) + 1 + 0x900;
169 sprintf(name, "MUON_%d.ddl",idDDL);
170 fFile[1] = fopen(name,"w");
172 WriteTrackerDDL(ich);
177 fMUONData->ResetDigits();
183 idDDL = 0xA00;// official number for MUTR
184 sprintf(name, "MUTR_%d.ddl",idDDL);
185 fFile[0] = fopen(name,"w");
188 sprintf(name, "MUTR_%d.ddl",idDDL);
189 fFile[1] = fopen(name,"w");
196 fMUONData->ResetTrigger();
198 fLoader->UnloadDigits();
202 //____________________________________________________________________
203 Int_t AliMUONRawData::WriteTrackerDDL(Int_t iCh)
205 // writing DDL for tracker
206 // used inverse mapping
209 TClonesArray* muonDigits = 0;
210 fSubEventArray->Clear();
220 AliRawDataHeader header = fDDLTracker->GetHeader();
221 Int_t headerSize = fDDLTracker->GetHeaderSize();
223 // DDL event one per half chamber
224 AliMUONSubEventTracker* subEvent;
229 UChar_t channelId = 0;
231 Int_t busPatchId = 0;
245 const AliMUONDigit* digit;
247 AliDebug(3, Form("WriteDDL chamber %d\n", iCh+1));
250 fMUONData->ResetDigits();
251 fMUONData->GetDigits();
252 muonDigits = fMUONData->Digits(iCh);
254 nDigits = muonDigits->GetEntriesFast();
255 AliDebug(3,Form("ndigits = %d\n",nDigits));
258 for (Int_t idig = 0; idig < nDigits; idig++) {
260 digit = (AliMUONDigit*) muonDigits->UncheckedAt(idig);
262 padX = digit->PadX();
263 padY = digit->PadY();
264 charge = digit->Signal();
266 cathode = digit->Cathode();
267 detElemId = digit->DetElemId();
270 Int_t error = GetInvMapping(digit, busPatchId, manuId, channelId);
273 AliDebug(1,Form("input IdDE %d busPatchId %d PadX %d PadY %d iCath %d \n",
274 detElemId, busPatchId, padX, padY, cathode));
276 AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", busPatchId, manuId, channelId ));
279 AliBitPacking::PackWord((UInt_t)parity,word,29,31);
280 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
281 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
282 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
285 subEvent = new AliMUONSubEventTracker();
286 subEvent->AddData(word);
287 subEvent->SetBusPatchId(busPatchId);
289 // storing the number of identical buspatches
290 nbInBus[busPatchId]++;
296 // sorting by buspatch
297 fSubEventArray->Sort();
299 // gather datas from same bus patch
300 nEntries = fSubEventArray->GetEntriesFast();
302 for (Int_t i = 0; i < nEntries; i++) {
303 AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray->At(i);
304 busPatchId = temp->GetBusPatchId();
306 // add bus patch header, length and total length managed by subevent class
307 temp->SetTriggerWord(0xdeadbeef);
308 for (Int_t j = 0; j < nbInBus[busPatchId]-1; j++) {
309 AliMUONSubEventTracker* temp1 = (AliMUONSubEventTracker*)fSubEventArray->At(++i);
310 temp->AddData(temp1->GetData(0));
311 fSubEventArray->RemoveAt(i) ;
314 fSubEventArray->Compress();
316 if (AliLog::GetGlobalDebugLevel() == 3) {
317 nEntries = fSubEventArray->GetEntriesFast();
318 for (Int_t i = 0; i < nEntries; i++) {
319 AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray->At(i);
320 printf("busPatchid back %d\n",temp->GetBusPatchId());
321 for (Int_t j = 0; j < temp->GetLength(); j++) {
322 printf("manuId back %d, ",temp->GetManuId(j));
323 printf("channelId back %d, ",temp->GetChannelId(j));
324 printf("charge back %d\n",temp->GetCharge(j));
334 // open DDL file, on per 1/2 chamber
335 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
338 nEntries = fSubEventArray->GetEntriesFast();
339 buffer = new Int_t [(2048+24)*50]; // 24 words in average for one buspatch and 2048 manu info at most
346 // two blocks A and B per DDL
347 for (Int_t iBlock = 0; iBlock < 2; iBlock++) {
350 length = fDDLTracker->GetBlkHeaderLength();
351 memcpy(&buffer[index],fDDLTracker->GetBlkHeader(),length*4);
356 for (Int_t iDsp = 0; iDsp < 5; iDsp++) {
359 length = fDDLTracker->GetDspHeaderLength();
360 memcpy(&buffer[index],fDDLTracker->GetDspHeader(),length*4);
364 //Â 5 buspatches per DSP
365 for (Int_t i = 0; i < 5; i++) {
367 // assuming busPatchId begins at 100 (to be discussed ChF)
368 iBusPatch = i + iBlock*25 + iDsp*5 + 50*(2*(iCh+1) + iDDL);
369 AliDebug(3,Form("busPatchId %d", iBusPatch));
371 AliMUONSubEventTracker* temp = (AliMUONSubEventTracker*)fSubEventArray->At(iEntries);
373 busPatchId = temp->GetBusPatchId();
374 AliDebug(3,Form("busPatchId %d", temp->GetBusPatchId()));
378 // check if buspatchid has digit
379 if (busPatchId == iBusPatch) {
380 // add bus patch structure
381 length = temp->GetHeaderLength();
382 memcpy(&buffer[index],temp->GetAddress(),length*4);
384 for (Int_t j = 0; j < temp->GetLength(); j++) {
385 buffer[index++] = temp->GetData(j);
386 AliDebug(3,Form("busPatchId %d, manuId %d channelId %d\n", temp->GetBusPatchId(),
387 temp->GetManuId(j), temp->GetChannelId(j) ));
389 if (iEntries < nEntries-1)
392 // writting anyhow buspatch structure (empty ones)
393 buffer[index++] = 4; // total length
394 buffer[index++] = 0; // raw data length
395 buffer[index++] = iBusPatch; // bus patch
396 buffer[index++] = 0xdeadbeef; // trigger word
399 buffer[indexDsp] = index - indexDsp; // dsp length
400 buffer[indexDsp+1] = index - indexDsp - fDDLTracker->GetDspHeaderLength();
401 if ((index - indexDsp) % 2 == 0)
402 buffer[indexDsp+7] = 0;
404 buffer[indexDsp+7] = 1;
406 buffer[indexBlk] = index - indexBlk; // block length
407 buffer[indexBlk+1] = index - indexBlk - fDDLTracker->GetBlkHeaderLength();
412 header.fSize = (index + headerSize) * 4;// total length in bytes
413 fwrite((char*)(&header),headerSize*4,1,fFile[iDDL]);
414 fwrite(buffer,sizeof(int),index,fFile[iDDL]);
421 //____________________________________________________________________
422 Int_t AliMUONRawData::WriteTriggerDDL()
425 // DDL event one per half chamber
426 AliMUONSubEventTrigger* subEvent = 0x0;
429 // stored local id number
430 TArrayI isFired(256);
435 AliRawDataHeader header = fDDLTrigger->GetHeader();
436 Int_t headerSize = fDDLTrigger->GetHeaderSize();
438 TClonesArray* localTrigger;
439 TClonesArray* globalTrigger;
440 AliMUONGlobalTrigger* gloTrg;
441 AliMUONLocalTrigger* locTrg = 0x0;
443 // getting information from trigger
444 fMUONData->GetTriggerD();
446 // global trigger for trigger pattern
447 globalTrigger = fMUONData->GlobalTrigger();
448 gloTrg = (AliMUONGlobalTrigger*)globalTrigger->UncheckedAt(0);
449 Int_t gloTrigPat = GetGlobalTriggerPattern(gloTrg);
452 localTrigger = fMUONData->LocalTrigger();
458 Int_t iLocCard, locCard;
459 Char_t locDec, trigY, posY, devX, posX,regOut;
460 Int_t version = 1; // software version
461 Int_t eventType = 1; // trigger type: 1 for physics ?
462 Int_t serialNb = 0xF; // serial nb of card: all bits on for the moment
463 Int_t globalFlag = 1; // set to 2 if global info present in DDL else set to 1
465 Int_t nEntries = (Int_t) (localTrigger->GetEntries());// 234 local cards
466 // stored the local card id that's fired
467 for (Int_t i = 0; i < nEntries; i++) {
468 locTrg = (AliMUONLocalTrigger*)localTrigger->At(i);
469 isFired[locTrg->LoCircuit()] = 1; // storing local boards with informations
473 AliError("No Trigger information available");
475 buffer = new Int_t [672]; // [16(local)*5 words + 3 words]*8(reg) + 8 words = 672
477 // open DDL file, on per 1/2 chamber
478 for (Int_t iDDL = 0; iDDL < 2; iDDL++) {
482 // DDL enhanced header
484 AliBitPacking::PackWord((UInt_t)iDDL+1,word,28,31); //see AliMUONDDLTrigger.h for details
485 AliBitPacking::PackWord((UInt_t)serialNb,word,24,27);
486 AliBitPacking::PackWord((UInt_t)version,word,16,23);
487 AliBitPacking::PackWord((UInt_t)eventType,word,12,15);
489 if (iDDL == 0) // suppose global info in DDL one
493 AliBitPacking::PackWord((UInt_t)globalFlag,word,8,11);
494 fDDLTrigger->SetDDLWord(word);
497 fDDLTrigger->SetGlobalOutput(gloTrigPat);// no global input for the moment....
499 fDDLTrigger->SetGlobalOutput(0);
500 length = fDDLTrigger->GetHeaderLength();
501 memcpy(&buffer[index],fDDLTrigger->GetEnhancedHeader(),length*4);
504 // 8 regional cards per DDL
505 for (Int_t iReg = 0; iReg < 8; iReg++) {
507 subEvent = new AliMUONSubEventTrigger();
509 // Regional card header
512 AliBitPacking::PackWord((UInt_t)serialNb,word,24,28); //see AliMUONSubEventTrigger.h for details
513 AliBitPacking::PackWord((UInt_t)version,word,16,23);
514 AliBitPacking::PackWord((UInt_t)iReg,word,12,15);
515 AliBitPacking::PackWord((UInt_t)regOut,word,0,7); // whenever regional output will be implemented
517 subEvent->SetRegWord(word);
518 memcpy(&buffer[index++],subEvent->GetAddress(),4);
520 buffer[index++] = 0;// 2 words of regional input
523 // 16 local card per regional board
524 for (Int_t iLoc = 0; iLoc < 16; iLoc++) {
526 iLocCard = iLoc + iReg*16 + iDDL*128;
528 if (isFired[iLocCard]) {
529 locTrg = (AliMUONLocalTrigger*)localTrigger->At(iEntries);
530 locCard = locTrg->LoCircuit();
531 locDec = locTrg->GetLoDecision();
533 posY = locTrg->LoStripY();
534 posX = locTrg->LoStripX();
535 devX = locTrg->LoDev();
536 AliDebug(4,Form("loctrg %d, posX %d, posY %d, devX %d\n",
537 locTrg->LoCircuit(),locTrg->LoStripX(),locTrg->LoStripY(),locTrg->LoDev()));
538 } else { //no trigger (see PRR chpt 3.4)
549 AliBitPacking::PackWord((UInt_t)(iLocCard % 16),word,19,22); //card id number in crate
550 AliBitPacking::PackWord((UInt_t)locDec,word,15,18);
551 AliBitPacking::PackWord((UInt_t)trigY,word,14,14);
552 AliBitPacking::PackWord((UInt_t)posY,word,10,13);
553 AliBitPacking::PackWord((UInt_t)devX,word,5,9);
554 AliBitPacking::PackWord((UInt_t)posX,word,0,4);
556 if (locCard == iLocCard) {
557 // add local cards structure
558 buffer[index++] = (locTrg->GetX1Pattern() | (locTrg->GetX2Pattern() << 16));
559 buffer[index++] = (locTrg->GetX3Pattern() | (locTrg->GetX4Pattern() << 16));
560 buffer[index++] = (locTrg->GetY1Pattern() | (locTrg->GetY2Pattern() << 16));
561 buffer[index++] = (locTrg->GetY3Pattern() | (locTrg->GetY4Pattern() << 16));
562 buffer[index++] = (Int_t)word; // data word
563 if (iEntries < nEntries-1)
566 buffer[index++] = 0; // 4 words for x1, x2, y1, y2
570 buffer[index++] = (Int_t)word; // data word
579 buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word
580 buffer[index++] = fDDLTrigger->GetEoD(); // End of DDL word for 64 bits transfer purpose
582 // writting onto disk
584 header.fSize = (index + headerSize) * 4;// total length in bytes
585 fwrite((char*)(&header),headerSize*4,1,fFile[iDDL]);
586 fwrite(buffer,sizeof(int),index,fFile[iDDL]);
594 //____________________________________________________________________
595 Int_t AliMUONRawData::GetInvMapping(const AliMUONDigit* digit,
596 Int_t &busPatchId, UShort_t &manuId, UChar_t &channelId)
599 // Inverse mapping for tracker
601 // information from digits
602 Int_t iCath = digit->Cathode();
603 Int_t idDE = digit->DetElemId();
604 Int_t padX = digit->PadX();
605 Int_t padY = digit->PadY();
607 if (idDE >= 500) { // Since in AliMpSlat pads begin at (0,0)
608 padX--; // while in AliMUONSt345Seg. they begin at (1,1)
613 AliMpPlaneType plane;
614 AliMpPlaneType plane1 = kBendingPlane;
615 AliMpPlaneType plane2 = kNonBendingPlane;
617 if (idDE < 500) { // should use GetDirection somehow (ChF)
618 if ( ((idDE % 100) % 2) != 0 ) {
619 plane1 = kNonBendingPlane;
620 plane2 = kBendingPlane;
623 // station 345 bending == cath0 for the moment
624 plane = (iCath == 0) ? plane1 : plane2;
626 AliMpVSegmentation* seg = AliMUONSegmentationManager::Segmentation(idDE, plane);
627 AliMpPad pad = seg->PadByIndices(AliMpIntPair(padX,padY),kTRUE);
630 AliWarning(Form("No elec. for idDE: %d, padx: %d pady %d, charge: %d\n",
631 idDE, digit->PadX(), digit->PadY(), digit->Signal()));
636 manuId = pad.GetLocation().GetFirst();
637 manuId &= 0x7FF; // 11 bits
639 // Getting channel id
640 channelId = pad.GetLocation().GetSecond();
641 channelId &= 0x3F; // 6 bits
643 // Getting buspatch id
644 TArrayI* vec = GetBusfromDE(idDE);
647 if (idDE < 500) { // station 1 & 2
648 // set 32 manus for one bus patch ? (ChF)
651 // offset of 100 in manuId for following bus patch
655 // if (pos >(int_t) vec.size())
656 // AliWarning("pos greater than size\n");
657 busPatchId = vec->At(pos);
659 if (plane == kNonBendingPlane) // for Non-Bending manuid+= 1000;
660 manuId += 1000; // tmp solution til one finds something better (ChF)
662 AliDebug(3,Form("idDE: %d, busPatchId %d, manuId: %d, channelId:%d\n",
663 idDE, busPatchId, manuId, channelId));
665 AliDebug(3,Form("idDE: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady: %d, charge: %d\n",
666 idDE, busPatchId, manuId, channelId, digit->PadX(), digit->PadY(), digit->Signal()));
668 return kFALSE; // no error
671 //____________________________________________________________________
672 Int_t AliMUONRawData::GetGlobalTriggerPattern(const AliMUONGlobalTrigger* gloTrg) const
674 // global trigger pattern calculation
676 Int_t gloTrigPat = 0;
678 if (gloTrg->SinglePlusLpt()) gloTrigPat|= 0x1;
679 if (gloTrg->SinglePlusHpt()) gloTrigPat|= 0x2;
680 if (gloTrg->SinglePlusApt()) gloTrigPat|= 0x4;
682 if (gloTrg->SingleMinusLpt()) gloTrigPat|= 0x8;
683 if (gloTrg->SingleMinusHpt()) gloTrigPat|= 0x10;
684 if (gloTrg->SingleMinusApt()) gloTrigPat|= 0x20;
686 if (gloTrg->SingleUndefLpt()) gloTrigPat|= 0x40;
687 if (gloTrg->SingleUndefHpt()) gloTrigPat|= 0x80;
688 if (gloTrg->SingleUndefApt()) gloTrigPat|= 0x100;
690 if (gloTrg->PairUnlikeLpt()) gloTrigPat|= 0x200;
691 if (gloTrg->PairUnlikeHpt()) gloTrigPat|= 0x400;
692 if (gloTrg->PairUnlikeApt()) gloTrigPat|= 0x800;
694 if (gloTrg->PairLikeLpt()) gloTrigPat|= 0x1000;
695 if (gloTrg->PairLikeHpt()) gloTrigPat|= 0x2000;
696 if (gloTrg->PairLikeApt()) gloTrigPat|= 0x4000;
701 //____________________________________________________________________
702 Int_t AliMUONRawData::Raw2Digits(AliRawReader* rawReader)
706 ReadTrackerDDL(rawReader);
709 ReadTriggerDDL(rawReader);
715 //____________________________________________________________________
716 Int_t AliMUONRawData::ReadTrackerDDL(AliRawReader* rawReader)
718 // reading tracker DDL
719 // filling the TClonesArray in MUONData
722 AliMUONSubEventTracker* subEventTracker = new AliMUONSubEventTracker();
723 AliMUONDigit* digit = new AliMUONDigit();
726 //Read Header Size of DDL,Block,DSP and BusPatch.
728 Int_t ddlHeaderSize = fDDLTracker->GetHeaderSize();
729 Int_t blockHeaderSize = fDDLTracker->GetBlkHeaderLength();
730 Int_t dspHeaderSize = fDDLTracker->GetDspHeaderLength();
731 Int_t buspatchHeaderSize = subEventTracker->GetHeaderLength();
733 // Each DDL is made with 2 Blocks each of which consists of 5 DSP and each of DSP has at most 5 buspatches.
734 // This information is used to calculate the size of headers (DDL,Block and DSP) which has no interesting data.
736 const Int_t kBlankDDLSize = ddlHeaderSize + 2*blockHeaderSize + 2*5*dspHeaderSize + 2*5*5*buspatchHeaderSize;
737 const Int_t kBlankBlockSize = blockHeaderSize + 5*dspHeaderSize + 5*5*buspatchHeaderSize;
738 const Int_t kBlankDspSize = dspHeaderSize + 5*buspatchHeaderSize;
740 Int_t totalDDLSize, totalBlockSize, totalDspSize , totalBusPatchSize, dataSize;
743 Int_t padX, padY,iCath;
745 for(Int_t iDDL = 0; iDDL < 20; iDDL++) { // DDL loop
746 AliDebug(3, Form("Chamber %d\n", iDDL/2 +1 ));
748 rawReader->Select(0X9, iDDL, iDDL); //Select the DDL file to be read
750 rawReader->ReadHeader();
752 totalDDLSize = (rawReader->GetDataSize()+sizeof(AliRawDataHeader))/4; // 4 is multiplied to convert byte 2 word
754 if(totalDDLSize>kBlankDDLSize){ // Compare the DDL header with an empty DDL header size to read the file
756 Int_t totalDataWord = rawReader->GetDataSize()/4 ;
757 UInt_t *buffer = new UInt_t[totalDataWord];
758 for(Int_t i = 0; i < totalDataWord; i++) {
759 UInt_t& temp = buffer[i];
760 rawReader->ReadNextInt(temp); // takes the whole result into buffer variable for future analysis
766 UShort_t manuId;//,charge;
767 Int_t idDE;//,padX, padY,iCath;
768 Int_t indexDsp, indexBusPatch, index = 0;
771 for(Int_t iBlock = 0; iBlock < 2 ;iBlock++){ // loop over 2 blocks
772 totalBlockSize = buffer[index];
774 if(totalBlockSize > kBlankBlockSize){ // compare block header
775 index += blockHeaderSize;
777 for(Int_t iDsp = 0; iDsp < 5 ;iDsp++){ //DSP loop
778 totalDspSize = buffer[index];
781 if(totalDspSize > kBlankDspSize){ // Compare DSP Header
782 index += dspHeaderSize;
784 for(Int_t iBusPatch = 0; iBusPatch < 5 ; iBusPatch++){
785 totalBusPatchSize = buffer[index];
786 indexBusPatch = index;
787 buspatchId = buffer[index+2];
789 if(totalBusPatchSize > buspatchHeaderSize){ //Check Buspatch header
790 index += buspatchHeaderSize;
791 dataSize = totalBusPatchSize - buspatchHeaderSize;
795 for(Int_t iData = 0; iData < dataSize ;iData++) {
797 subEventTracker->SetData(buffer[index++],iData); //Set to extract data
798 parity = subEventTracker->GetParity(iData);
799 manuId = subEventTracker->GetManuId(iData);
800 channelId = subEventTracker->GetChannelId(iData);
801 charge = subEventTracker->GetCharge(iData);
802 digit->SetSignal(charge); // set charge
804 Int_t error = GetMapping(buspatchId,manuId,channelId,digit); // Get Back the hits at pads
807 padX = digit->PadX();
808 padY = digit->PadY();
809 iCath = digit->Cathode();
810 idDE = digit->DetElemId();
812 AliDebug(1,Form("output IdDE %d busPatchid %d PadX %d PadY %d iCath %d \n",
813 idDE, buspatchId, padX, padY, iCath));
816 AliDebug(3,Form("idDE %d Padx %d Pady %d, Cath %d, charge %d",idDE, padX, padY, iCath, charge));
818 // fMUONData->AddDigit(iCh, *digit);
819 fMUONData->AddDigit(iDDL/2, *digit);
824 } // testing buspatch
826 index = indexBusPatch + totalBusPatchSize;
833 index = indexDsp + totalDspSize;
839 index = totalBlockSize;
844 } //loop checking the header size of DDL
850 delete subEventTracker;
856 //____________________________________________________________________
857 Int_t AliMUONRawData::GetMapping(Int_t busPatchId, UShort_t manuId,
858 UChar_t channelId, AliMUONDigit* digit )
861 // mapping for tracker
863 // getting DE from buspatch
864 Int_t idDE = GetDEfromBus(busPatchId);
865 AliDebug(3,Form("idDE: %d busPatchId %d\n", idDE, busPatchId));
872 AliMpPlaneType plane;
874 if (manuId > 1000) { // again tmp solution (ChF) (+1000 for Non-Bending plane
875 plane = kNonBendingPlane;
877 plane = kBendingPlane;
880 if (idDE < 500) { // should use GetDirection somehow (ChF)
881 if ( ((idDE % 100) % 2) != 0 ) {
887 iCath = (manuId > 1000) ? iCath2 : iCath1;
889 if (manuId > 1000) manuId -= 1000; // back to normal manuId
891 AliMpVSegmentation* seg = AliMUONSegmentationManager::Segmentation(idDE, plane);
892 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,(Int_t)channelId),kTRUE);
895 AliWarning(Form("No pad for idDE: %d, busPatchId %d, manuId: %d, channelId: %d\n",
896 idDE, busPatchId, manuId, channelId));
901 Int_t padX = pad.GetIndices().GetFirst();
904 Int_t padY = pad.GetIndices().GetSecond();
906 if (idDE >= 500) { // Since in AliMpSlat pads begin at (0,0)
907 padX++; // while in AliMUONSt345Seg. they begin at (1,1)
910 // storing into digits
911 digit->SetPadX(padX);
912 digit->SetPadY(padY);
913 digit->SetCathode(iCath);
914 digit->SetDetElemId(idDE);
916 AliDebug(3,Form("idDE: %d, busPatchId %d, manuId: %d, channelId: %d, padx: %d pady %d\n",
917 idDE, busPatchId, manuId, channelId, padX, padY));
921 //____________________________________________________________________
922 Int_t AliMUONRawData::ReadTriggerDDL(AliRawReader* rawReader)
925 // reading DDL for trigger
927 AliMUONSubEventTrigger* subEventTrigger = new AliMUONSubEventTrigger();
928 AliMUONGlobalTrigger* globalTrigger = 0x0;
929 AliMUONLocalTrigger* localTrigger = new AliMUONLocalTrigger();
932 //Int_t ddlHeaderSize = fDDLTrigger->GetHeaderSize();
933 // we dont need this, as size of ddl data is same for triger and no trigger
935 Int_t ddlEnhanceHeaderSize = fDDLTrigger->GetHeaderLength();
936 Int_t regHeaderLength = subEventTrigger->GetRegHeaderLength() ;
938 Int_t loCircuit, loStripX, loDev, loStripY, loLpt, loHpt;
941 UShort_t x1Pattern, x2Pattern, x3Pattern, x4Pattern;
942 UShort_t y1Pattern, y2Pattern, y3Pattern, y4Pattern;
945 // loop over the two ddl's
946 for(Int_t iDDL = 0; iDDL < 2; iDDL++) { //DDL loop
948 rawReader->Select(0XA,iDDL,iDDL); //Select the DDL file to be read
950 rawReader->ReadHeader();
952 Int_t totalDataWord = rawReader->GetDataSize()/4 ;
953 UInt_t *buffer = new UInt_t[totalDataWord];
954 for(Int_t i=0;i<totalDataWord;i++){
955 UInt_t& temp = buffer[i];
956 rawReader->ReadNextInt(temp); // takes the whole result into buffer variable for future analysis
959 // rawReader->ReadNext((UChar_t*)buffer, totalDataWord); // method is protected ????
963 // fill DDL header informations
964 memcpy(fDDLTrigger->GetEnhancedHeader(), &buffer[index], ddlEnhanceHeaderSize*4);
966 // fill global trigger information
967 globalTrigger = GetGlobalTriggerPattern(fDDLTrigger->GetGlobalOuput());
968 fMUONData->AddGlobalTrigger(*globalTrigger);
970 index += ddlEnhanceHeaderSize;
973 for (Int_t iReg = 0; iReg < 8; iReg++) { //loop over regeonal card
976 subEventTrigger->SetRegWord(buffer[index]); //read regional data
978 index += regHeaderLength;
980 // 16 local cards per regional board
981 for (Int_t iLoc = 0; iLoc < 16; iLoc++) { //loop over local card
983 Int_t iLocIndex = index;
985 // 5 word trigger information
986 for(Int_t iData = 0; iData < 5 ;iData++ ){
987 subEventTrigger->SetLocalData(buffer[index++],5*iLoc+iData); //read local data
990 if(buffer[iLocIndex] > 0) {
992 loCircuit = (Int_t)subEventTrigger->GetLocalId(iLoc)+ 16*iReg + 128*iDDL;
993 loStripX = (Int_t)subEventTrigger->GetXPos(iLoc);
994 loStripY = (Int_t)subEventTrigger->GetYPos(iLoc);
995 loDev = (Int_t)subEventTrigger->GetXDev(iLoc);
997 // fill local trigger
998 localTrigger->SetLoCircuit(loCircuit);
999 localTrigger->SetLoStripX(loStripX );
1000 localTrigger->SetLoStripY(loStripY);
1001 localTrigger->SetLoDev(loDev);
1003 loDecision = subEventTrigger->GetLocalDec(iLoc);
1004 loLpt = loDecision & 0x3;
1005 loHpt = (loDecision >> 2) & 0x3;
1007 // fill local trigger
1008 localTrigger->SetLoLpt(loLpt);
1009 localTrigger->SetLoHpt(loHpt);
1011 //getting pattern from subvent
1012 x1Pattern = subEventTrigger->GetX1(iLoc);
1013 x2Pattern = subEventTrigger->GetX2(iLoc);
1014 x3Pattern = subEventTrigger->GetX3(iLoc);
1015 x4Pattern = subEventTrigger->GetX4(iLoc);
1017 y1Pattern = subEventTrigger->GetY1(iLoc);
1018 y2Pattern = subEventTrigger->GetY2(iLoc);
1019 y3Pattern = subEventTrigger->GetY3(iLoc);
1020 y4Pattern = subEventTrigger->GetY4(iLoc);
1022 // fill local trigger
1023 localTrigger->SetX1Pattern(x1Pattern);
1024 localTrigger->SetX2Pattern(x2Pattern);
1025 localTrigger->SetX3Pattern(x3Pattern);
1026 localTrigger->SetX4Pattern(x4Pattern);
1028 localTrigger->SetY1Pattern(y1Pattern);
1029 localTrigger->SetY2Pattern(y2Pattern);
1030 localTrigger->SetY3Pattern(y3Pattern);
1031 localTrigger->SetY4Pattern(y4Pattern);
1032 fMUONData->AddLocalTrigger(*localTrigger);
1036 } // local card loop
1038 } // regional card loop
1043 delete subEventTrigger;
1044 delete globalTrigger;
1045 delete localTrigger;
1050 //____________________________________________________________________
1051 AliMUONGlobalTrigger* AliMUONRawData::GetGlobalTriggerPattern(Int_t gloTrigPat) const
1053 // global trigger pattern calculation
1055 Int_t globalSinglePlus[3]; // tot num of single plus
1056 Int_t globalSingleMinus[3]; // tot num of single minus
1057 Int_t globalSingleUndef[3]; // tot num of single undefined
1058 Int_t globalPairUnlike[3]; // tot num of unlike-sign pairs
1059 Int_t globalPairLike[3]; // tot num of like-sign pairs
1062 for (Int_t i = 0; i < 3; i++) {
1063 globalSinglePlus[i] = gloTrigPat & (0x1 << i);
1064 globalSingleMinus[i] = gloTrigPat & (0x1 << i+3);
1065 globalSingleUndef[i] = gloTrigPat & (0x1 << i+6);
1066 globalPairUnlike[i] = gloTrigPat & (0x1 << i+9);
1067 globalPairLike[i] = gloTrigPat & (0x1 << i+12);
1070 return (new AliMUONGlobalTrigger(globalSinglePlus, globalSingleMinus,
1071 globalSingleUndef, globalPairUnlike,
1075 //____________________________________________________________________
1076 Int_t AliMUONRawData::GetDEfromBus(Int_t busPatchId)
1078 // getting DE id from bus patch
1079 Long_t it = fBusPatchToDetElem.GetValue(busPatchId);
1087 //____________________________________________________________________
1088 TArrayI* AliMUONRawData::GetBusfromDE(Int_t idDE)
1090 // getting bus patch from DE id
1092 return (TArrayI*)fDetElemIdToBusPatch.GetValue(idDE);
1094 //____________________________________________________________________
1095 void AliMUONRawData::ReadBusPatchFile()
1098 // idDE <> buspatch map
1101 TString dirPath = gSystem->Getenv("ALICE_ROOT");
1102 dirPath += "/MUON/mapping/data/";
1104 TString infile = dirPath + "DetElemIdToBusPatch.dat";
1106 ifstream in(infile, ios::in);
1107 if (!in) AliError("DetElemIdToBusPatch.dat not found.");
1111 while ( in.getline(line,80) ) {
1113 if ( line[0] == '#' ) continue;
1115 TString tmp(AliMpHelper::Normalize(line));
1117 Int_t blankPos = tmp.First(' ');
1119 TString sDE(tmp(0, blankPos));
1121 Int_t idDE = atoi(sDE.Data());
1123 TString busPatch(tmp(blankPos + 1, tmp.Length()-blankPos));
1125 TArrayI busPatchList;
1126 // decoding range of buspatch
1127 AliMpHelper::DecodeName(busPatch,';',busPatchList);
1129 // filling buspatch -> idDE
1130 for (Int_t i = 0; i < busPatchList.GetSize(); i++)
1131 fBusPatchToDetElem.Add((Long_t)busPatchList[i],(Long_t)idDE);
1134 // filling idDE -> buspatch list (vector)
1135 fDetElemIdToBusPatch.Add((Long_t)idDE, (Long_t)(new TArrayI(busPatchList)));