LCOV - code coverage report
Current view: top level - PMD/PMDsim - AliPMDDDLRawData.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 312 368 84.8 %
Date: 2016-06-14 17:26:59 Functions: 13 17 76.5 %

          Line data    Source code
       1             : /***************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       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             :  **************************************************************************/
      15             : 
      16             : #include <Riostream.h>
      17             : #include <TClonesArray.h>
      18             : #include <TTree.h>
      19             : #include <TBranch.h>
      20             : #include <TMath.h>
      21             : #include <TString.h>
      22             : #include <TSystem.h>
      23             : 
      24             : #include "AliLog.h"
      25             : #include "AliRawDataHeaderSim.h"
      26             : #include "AliBitPacking.h"
      27             : #include "AliPMDdigit.h"
      28             : #include "AliPMDBlockHeader.h"
      29             : #include "AliPMDDspHeader.h"
      30             : #include "AliPMDPatchBusHeader.h"
      31             : #include "AliPMDRawStream.h"
      32             : #include "AliPMDddlinfoData.h"
      33             : #include "AliPMDMappingData.h"
      34             : #include "AliPMDDDLRawData.h"
      35             : #include "AliDAQ.h"
      36             : #include "AliFstream.h"
      37             : #include "AliCDBManager.h"
      38             : #include "AliCDBStorage.h"
      39             : #include "AliCDBEntry.h"
      40             : 
      41          12 : ClassImp(AliPMDDDLRawData)
      42             : 
      43           4 : AliPMDDDLRawData::AliPMDDDLRawData():
      44           8 :   fDdlinfo(GetDdlinfoData()),
      45           8 :   fMapData(GetMappingData()),
      46          12 :   fDigits(new TClonesArray("AliPMDdigit", 1000))
      47          20 : {
      48             :   // Default Constructor
      49             :   //
      50             : 
      51           8 : }
      52             : //____________________________________________________________________________
      53             : AliPMDDDLRawData::AliPMDDDLRawData(const AliPMDDDLRawData& ddlraw):
      54           0 :   TObject(ddlraw),
      55           0 :   fDdlinfo(ddlraw.fDdlinfo),
      56           0 :   fMapData(ddlraw.fMapData),
      57           0 :   fDigits(ddlraw.fDigits)
      58           0 : {
      59             :   //Copy Constructor 
      60           0 : }
      61             : //____________________________________________________________________________
      62             : AliPMDDDLRawData & AliPMDDDLRawData::operator=(const AliPMDDDLRawData& ddlraw)
      63             : {
      64             :   //Assignment operator 
      65           0 :   if(this != &ddlraw)
      66             :     {
      67           0 :       fDdlinfo = ddlraw.fDdlinfo;
      68           0 :       fMapData = ddlraw.fMapData;
      69           0 :       fDigits  = ddlraw.fDigits;
      70           0 :     }
      71           0 :   return *this;
      72             : }
      73             : //____________________________________________________________________________
      74             : 
      75             : AliPMDDDLRawData::~AliPMDDDLRawData()
      76           8 : {
      77             :   // Default Destructor
      78             :   //
      79             : 
      80          12 : }
      81             : 
      82             : //____________________________________________________________________________
      83             : void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
      84             : {
      85             :   // write digits into raw data format
      86             : 
      87             :   AliFstream *outfile;
      88             : 
      89           8 :   TBranch *branch = treeD->GetBranch("PMDDigit");
      90           4 :   if (!branch)
      91             :     {
      92           0 :       AliError("PMD Digit branch not found");
      93           0 :       return;
      94             :     }
      95           4 :   branch->SetAddress(&fDigits);  
      96             :   
      97           4 :   Int_t   nmodules = (Int_t) treeD->GetEntries();
      98          12 :   AliDebug(1,Form("Number of modules inside treeD = %d",nmodules));
      99             : 
     100           4 :   const Int_t kDDL          = AliDAQ::NumberOfDdls("PMD");
     101             : 
     102             : 
     103           4 :   AliRawDataHeaderSim header;
     104             :  // UInt_t sizeRawData = 0;  //coverity (8443) fix satya (1/9/2014) 
     105             :   
     106             :   const Int_t kbusSize = 51;
     107             :   const Int_t kSize = 1536;
     108           4 :   UInt_t buffer[kSize];
     109             : 
     110           4 :   UInt_t busPatch[kbusSize][1536];
     111             : 
     112           4 :   Int_t contentsBus[kbusSize];
     113             : 
     114           4 :   Char_t filename[80];
     115             : 
     116             :   Int_t modulePerDDL        = 0;
     117             :   Int_t mmodule = 0;
     118             :   Int_t ddlno;
     119           4 :   Int_t modulenoddl[12] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
     120             : 
     121          56 :   for(Int_t iddl = 0; iddl < kDDL; iddl++)
     122             :     {
     123             :       ddlno = iddl;
     124          24 :       modulePerDDL = fDdlinfo->GetNoOfModulePerDdl(iddl);
     125          24 :       if (modulePerDDL == 0) continue;
     126         416 :       for (Int_t im = 0; im < 12; im++)
     127             :         {
     128         192 :           modulenoddl[im] = fDdlinfo->GetModulesPerDdl(iddl,im);;
     129             :         }
     130             : 
     131          16 :       strncpy(filename,AliDAQ::DdlFileName("PMD",iddl),79);
     132             :       
     133          16 :       outfile = new AliFstream(filename);
     134             :       
     135             :       // Write the Dummy Data Header into the file
     136          16 :       Int_t bHPosition = outfile->Tellp();
     137          16 :       outfile->WriteBuffer((char*)(&header),sizeof(header));
     138             : 
     139        1664 :       for (Int_t ibus = 0; ibus < kbusSize; ibus++)
     140             :         {
     141         816 :           contentsBus[ibus] = 0;
     142     2508384 :           for (Int_t ich = 0; ich < kSize; ich++)
     143             :             {
     144     1253376 :               busPatch[ibus][ich] = 0;
     145             :             }
     146             :         }
     147             : 
     148         416 :       for(Int_t ium = 0; ium < 12; ium++)
     149             :         {
     150             :           // Extract energy deposition per cell and pack it
     151             :           // in a 32-bit word and returns all the total words
     152             :           // per one unit-module
     153             :           
     154         192 :           mmodule = modulenoddl[ium];
     155         192 :           if(mmodule == -1) continue;
     156         192 :           GetUMDigitsData(treeD, mmodule, iddl, contentsBus, busPatch);
     157         192 :         }
     158             : 
     159             :       Int_t ij = 0;
     160          16 :       Int_t dsp[10];
     161          16 :       Int_t dspBus[10];
     162         352 :       for (Int_t i = 0; i < 10; i++)
     163             :         {
     164         160 :           dsp[i] = 0;
     165         160 :           dspBus[i] = 0;
     166        1920 :           for (Int_t ibus=0; ibus < 5; ibus++)
     167             :             {
     168         800 :               ij++;
     169         800 :               if (contentsBus[ij] > 0)
     170             :                 {
     171          71 :                   dsp[i] += contentsBus[ij];
     172          71 :                 }
     173         800 :               dspBus[i]++;
     174             :             }
     175             :           // Add the patch Bus header to the DSP contents
     176         160 :           dsp[i] += 4*dspBus[i];
     177             :         }
     178             : 
     179             :       Int_t dspBlockARDL    = 0;
     180             :       Int_t dspBlockBRDL    = 0;
     181             :       Int_t remainder       = 0;
     182             : 
     183             : 
     184         192 :       for (Int_t i = 0; i < 5; i++)
     185             :         {
     186          80 :           Int_t ieven = 2*i;
     187          80 :           Int_t iodd  = 2*i + 1;
     188          80 :           if (dsp[ieven] > 0)
     189             :             {
     190          80 :               dspBlockARDL += dsp[ieven];
     191          80 :               remainder = dsp[ieven]%2;
     192          80 :               if (remainder == 1)
     193             :                 {
     194          15 :                   dspBlockARDL++;
     195          15 :                 }
     196             :             }
     197          80 :           if (dsp[iodd] > 0)
     198             :             {
     199          80 :               dspBlockBRDL += dsp[iodd];
     200          80 :               remainder = dsp[iodd]%2;
     201          80 :               if (remainder == 1)
     202             :                 {
     203          13 :                   dspBlockBRDL++;
     204          13 :                 }
     205             :             }
     206             :         }
     207             : 
     208          16 :       dspBlockARDL += 50;
     209          16 :       dspBlockBRDL += 50;
     210             : 
     211             :       // Start writing the DDL file
     212             : 
     213          16 :       AliPMDBlockHeader blHeader;
     214          16 :       AliPMDDspHeader   dspHeader;
     215          16 :       AliPMDPatchBusHeader pbusHeader;
     216             : 
     217          16 :       const Int_t kblHLen   = blHeader.GetHeaderLength();
     218          16 :       const Int_t kdspHLen  = dspHeader.GetHeaderLength();
     219          16 :       const Int_t kpbusHLen = pbusHeader.GetHeaderLength();
     220             : 
     221             :       UInt_t dspRDL = 0;
     222          16 :       UInt_t dspBlockHeaderWord[8];
     223          16 :       UInt_t dspHeaderWord[10];
     224          16 :       UInt_t patchBusHeaderWord[4];
     225          16 :       Int_t  iskip[5];
     226          16 :       UInt_t ddlEndWord[2] = {0xDEADFACE, 0xDEADFACE};
     227             : 
     228          96 :       for (Int_t iblock = 0; iblock < 2; iblock++)
     229             :         {
     230             :           // DSP Block Header
     231             :           
     232         576 :           for (Int_t i=0; i<kblHLen; i++)
     233             :             {
     234         256 :               dspBlockHeaderWord[i] = 0;
     235             :             }
     236          32 :           if (iblock == 0)
     237             :             {
     238          16 :               dspBlockHeaderWord[1] = (UInt_t) (dspBlockARDL + kblHLen);
     239          16 :               dspBlockHeaderWord[2] = (UInt_t) dspBlockARDL;
     240          16 :             }
     241          16 :           else if (iblock == 1)
     242             :             {
     243          16 :               dspBlockHeaderWord[1] = (UInt_t) (dspBlockBRDL + kblHLen);
     244          16 :               dspBlockHeaderWord[2] = (UInt_t) dspBlockBRDL;
     245          16 :             }
     246             : 
     247          32 :           outfile->WriteBuffer((char*)dspBlockHeaderWord,kblHLen*sizeof(UInt_t));
     248             : 
     249          32 :           if (iblock == 0)
     250             :             {
     251          16 :               iskip[0] = 0;
     252          16 :               iskip[1] = 10;
     253          16 :               iskip[2] = 20;
     254          16 :               iskip[3] = 30;
     255          16 :               iskip[4] = 40;
     256          16 :             }
     257          16 :           else if (iblock == 1)
     258             :             {
     259          16 :               iskip[0] = 5;
     260          16 :               iskip[1] = 15;
     261          16 :               iskip[2] = 25;
     262          16 :               iskip[3] = 35;
     263          16 :               iskip[4] = 45;
     264          16 :             }
     265             : 
     266         384 :           for (Int_t idsp = 0; idsp < 5; idsp++)
     267             :             {
     268             :               // DSP Header
     269             :               Int_t dspno = 0;
     270         160 :               if (iblock == 0)
     271             :                 {
     272          80 :                   dspno = 2*idsp;
     273          80 :                   dspRDL = (UInt_t) dsp[dspno];
     274          80 :                 }
     275          80 :               else if (iblock == 1)
     276             :                 {
     277          80 :                   dspno = 2*idsp + 1;
     278          80 :                   dspRDL = (UInt_t) dsp[dspno];
     279          80 :                 }
     280             : 
     281        3520 :               for (Int_t i=0; i<kdspHLen; i++)
     282             :                 {
     283        1600 :                   dspHeaderWord[i] = 0;
     284             :                 }
     285         160 :               remainder = dspRDL%2;
     286         188 :               if (remainder == 1) dspRDL++;
     287             : 
     288         160 :               dspHeaderWord[1] = dspRDL + kdspHLen;
     289         160 :               dspHeaderWord[2] = dspRDL;
     290         160 :               dspHeaderWord[3] = dspno;
     291         188 :               if (remainder == 1) dspHeaderWord[8] = 1; // setting the padding word
     292             : 
     293             : 
     294         160 :               outfile->WriteBuffer((char*)dspHeaderWord,kdspHLen*sizeof(UInt_t));
     295             : 
     296        1920 :               for (Int_t ibus = 0; ibus < 5; ibus++)
     297             :                 {
     298             :                   // Patch Bus Header
     299             : 
     300         800 :                   Int_t busno = iskip[idsp] + ibus + 1;
     301         800 :                   Int_t patchbusRDL = contentsBus[busno];
     302             : 
     303         800 :                   if (patchbusRDL > 0)
     304             :                     {
     305          71 :                       patchBusHeaderWord[0] = 0;
     306          71 :                       patchBusHeaderWord[1] = (UInt_t) (patchbusRDL + kpbusHLen);
     307          71 :                       patchBusHeaderWord[2] = (UInt_t) patchbusRDL;
     308          71 :                       patchBusHeaderWord[3] = (UInt_t) busno;
     309          71 :                     }
     310         729 :                   else if (patchbusRDL == 0)
     311             :                     {
     312         729 :                       patchBusHeaderWord[0] = 0;
     313         729 :                       patchBusHeaderWord[1] = (UInt_t) kpbusHLen;
     314         729 :                       patchBusHeaderWord[2] = (UInt_t) 0;
     315         729 :                       patchBusHeaderWord[3] = (UInt_t) busno;
     316         729 :                     }
     317             : 
     318             : 
     319         800 :                   outfile->WriteBuffer((char*)patchBusHeaderWord,4*sizeof(UInt_t));
     320             : 
     321        1960 :                   for (Int_t iword = 0; iword < patchbusRDL; iword++)
     322             :                     {
     323         180 :                       buffer[iword] = busPatch[busno][iword];
     324             :                     }
     325             :                   
     326         800 :                   outfile->WriteBuffer((char*)buffer,patchbusRDL*sizeof(UInt_t));
     327             : 
     328             :                 } // End of patch bus loop
     329             : 
     330             : 
     331             :               // Adding a padding word if the total words odd
     332         160 :               if (remainder == 1)
     333             :                 {
     334          28 :                   UInt_t paddingWord = dspHeader.GetDefaultPaddingWord();
     335          28 :                   outfile->WriteBuffer((char*)(&paddingWord),sizeof(UInt_t));
     336          28 :                 }
     337             :             }
     338             :         }
     339             : 
     340             :       // Write two extra word at the end of each DDL file
     341          16 :       outfile->WriteBuffer((char*)ddlEndWord,2*sizeof(UInt_t));
     342             : 
     343             :       // Write real data header
     344             :       // take the pointer to the beginning of the data header
     345             :       // write the total number of words per ddl and bring the
     346             :       // pointer to the current file position and close it
     347          16 :       UInt_t cFPosition = outfile->Tellp();
     348             :       //sizeRawData = cFPosition - bHPosition - sizeof(header); // coverity (8443) fix satya (1/9/2014) 
     349             : 
     350          16 :       header.fSize = cFPosition - bHPosition;
     351          16 :       header.SetAttribute(0);  // valid data
     352          16 :       outfile->Seekp(bHPosition);
     353          16 :       outfile->WriteBuffer((char*)(&header),sizeof(header));
     354          16 :       outfile->Seekp(cFPosition);
     355             : 
     356          32 :       delete outfile;
     357          16 :     } // DDL Loop over
     358             : 
     359           8 : }
     360             : //____________________________________________________________________________
     361             : 
     362             : void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
     363             :                                        Int_t ddlno,  Int_t *contentsBus,
     364             :                                        UInt_t busPatch[][1536])
     365             : {
     366             :   // Retrieves digits data UnitModule by UnitModule
     367             : 
     368             :   const Int_t kMaxBus = 51;
     369             : 
     370         384 :   UInt_t baseword = 0;
     371         192 :   UInt_t mcmno = 0, chno = 0;
     372             :   UInt_t adc = 0;
     373         192 :   Int_t  det = 0, smn = 0, irow = 0, icol = 0;
     374             :   UInt_t  parity = 0;
     375             :   
     376         192 :   Int_t busno = 0;
     377         192 :   Int_t patchBusNo[kMaxBus], mcmperBus[kMaxBus];
     378         192 :   Int_t startRowBus[kMaxBus], startColBus[kMaxBus];
     379         192 :   Int_t endRowBus[kMaxBus], endColBus[kMaxBus];
     380             : 
     381         192 :   Int_t beginPatchBus = -1;
     382         192 :   Int_t endPatchBus   = -1;
     383       19968 :   for(Int_t i = 0; i < kMaxBus; i++)
     384             :     {
     385        9792 :       patchBusNo[i]  = -1;
     386        9792 :       mcmperBus[i]   = -1;
     387        9792 :       startRowBus[i] = -1;
     388        9792 :       startColBus[i] = -1;
     389        9792 :       endRowBus[i]   = -1;
     390        9792 :       endColBus[i]   = -1;
     391             :     }
     392             : 
     393             :   // Fetch the DDL mapping info from the mapping database
     394             : 
     395         192 :   DdlMapping(ddlno, imodule, beginPatchBus, endPatchBus,
     396         192 :              patchBusNo, mcmperBus, startRowBus, endRowBus,
     397         192 :              startColBus, endColBus);
     398             : 
     399             :   // Read if some chains are off from the ddlinfo database
     400             : 
     401         192 :   Int_t srowoff1[2][24], erowoff1[2][24];
     402         192 :   Int_t scoloff1[2][24], ecoloff1[2][24];
     403         192 :   Int_t srowoff2[2][24], erowoff2[2][24];
     404         192 :   Int_t scoloff2[2][24], ecoloff2[2][24];
     405             : 
     406        1152 :   for (Int_t idet = 0; idet < 2; idet++)
     407             :     {
     408       19200 :       for (Int_t im = 0; im < 24; im++)
     409             :         {
     410        9216 :           srowoff1[idet][im] = fDdlinfo->GetStartRowA(idet,im);
     411        9216 :           erowoff1[idet][im] = fDdlinfo->GetEndRowA(idet,im);
     412        9216 :           scoloff1[idet][im] = fDdlinfo->GetStartColA(idet,im);
     413        9216 :           ecoloff1[idet][im] = fDdlinfo->GetEndColA(idet,im);
     414        9216 :           srowoff2[idet][im] = fDdlinfo->GetStartRowB(idet,im);
     415        9216 :           erowoff2[idet][im] = fDdlinfo->GetEndRowB(idet,im);
     416        9216 :           scoloff2[idet][im] = fDdlinfo->GetStartColB(idet,im);
     417        9216 :           ecoloff2[idet][im] = fDdlinfo->GetEndColB(idet,im);
     418             :         }
     419             :     }
     420             : 
     421         192 :   treeD->GetEntry(imodule); 
     422         192 :   Int_t nentries = fDigits->GetLast();
     423         192 :   Int_t totword = nentries+1;
     424             : 
     425             :   AliPMDdigit *pmddigit = 0x0;
     426             : 
     427         744 :   for (Int_t ient = 0; ient < totword; ient++)
     428             :     {
     429         180 :       pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
     430             :       
     431         180 :       det    = pmddigit->GetDetector();
     432         180 :       smn    = pmddigit->GetSMNumber();
     433         180 :       irow   = pmddigit->GetRow();
     434         180 :       icol   = pmddigit->GetColumn();
     435         180 :       Float_t aadc = pmddigit->GetADC();
     436         180 :       if (aadc < 0.) aadc = 0.;
     437         180 :       adc    = (UInt_t) aadc;
     438             : 
     439         180 :       TransformS2H(smn,irow,icol);
     440             :       
     441             :       // remove the non-existence channels
     442             : 
     443             :       //printf("%d %d %d %d\n",det,smn,irow,icol);
     444             :       //printf("--- %d   %d   %d   %d\n",srowoff[det][smn],erowoff[det][smn],
     445             :       //     scoloff[det][smn],ecoloff[det][smn]);
     446             : 
     447         204 :       if (irow >= srowoff1[det][smn] && irow <= erowoff1[det][smn])
     448             :         {
     449           1 :           if (icol >= scoloff1[det][smn] && icol <= ecoloff1[det][smn])
     450             :             {
     451           0 :               continue;
     452             :             }
     453             :         }
     454         204 :       if (irow >= srowoff2[det][smn] && irow <= erowoff2[det][smn])
     455             :         {
     456           3 :           if (icol >= scoloff2[det][smn] && icol <= ecoloff2[det][smn])
     457             :             {
     458           0 :               continue;
     459             :             }
     460             :         }
     461             : 
     462             : 
     463         180 :       GetMCMCh(imodule, irow, icol, beginPatchBus, endPatchBus,
     464             :                mcmperBus, startRowBus, startColBus,
     465             :                endRowBus, endColBus, busno, mcmno, chno);
     466             : 
     467         180 :       baseword = 0;
     468         180 :       AliBitPacking::PackWord(adc,baseword,0,11);
     469         180 :       AliBitPacking::PackWord(chno,baseword,12,17);
     470         180 :       AliBitPacking::PackWord(mcmno,baseword,18,28);
     471         180 :       AliBitPacking::PackWord(0,baseword,29,30);
     472         180 :       parity = ComputeParity(baseword);      // generate the parity bit
     473         180 :       AliBitPacking::PackWord(parity,baseword,31,31);
     474             : 
     475         180 :       if (busno>-1) {
     476         180 :         Int_t jj = contentsBus[busno];
     477         180 :         busPatch[busno][jj] = baseword;
     478             :         
     479         180 :         contentsBus[busno]++;
     480         180 :       }
     481         180 :     }
     482             : 
     483         192 : }
     484             : 
     485             : //____________________________________________________________________________
     486             : void AliPMDDDLRawData::TransformS2H(Int_t smn, Int_t &irow, Int_t &icol)
     487             : {
     488             :   // Does the Software to Hardware coordinate transformation
     489             :   //
     490             : 
     491             :   Int_t  irownew = 0;
     492             :   Int_t  icolnew = 0;
     493             : 
     494             :   // First in digits we have all dimension 48x96
     495             :   // Transform into the realistic one, i.e, For SM 0&1 96(row)x48(col)
     496             :   // and for SM 2&3 48(row)x96(col)
     497             :   // 
     498         360 :   if(smn < 12)
     499             :     {
     500         139 :       irownew = icol;
     501         139 :       icolnew = irow;
     502         139 :     }
     503          41 :   else if( smn >= 12 && smn < 24)
     504             :     {
     505          41 :       irownew = irow;
     506          41 :       icolnew = icol;
     507          41 :     }
     508             : 
     509         180 :   irow = irownew;
     510         180 :   icol = icolnew;
     511             : 
     512         180 : }
     513             : 
     514             : 
     515             : //____________________________________________________________________________
     516             : 
     517             : void AliPMDDDLRawData::GetMCMCh(Int_t imodule, Int_t row, Int_t col,
     518             :                                 Int_t beginPatchBus, Int_t endPatchBus,
     519             :                                 Int_t *mcmperBus,
     520             :                                 Int_t *startRowBus, Int_t *startColBus,
     521             :                                 Int_t *endRowBus, Int_t *endColBus,
     522             :                                 Int_t & busno, UInt_t &mcmno, UInt_t &chno)
     523             : {
     524             :   // This converts row col to hardware channel number
     525             :   // This is the final version of mapping supplied by Mriganka
     526             : 
     527         360 :     UInt_t iCh[16][4];
     528             : 
     529             :     static const UInt_t kChDdl01[16][4] = { {6, 4, 5, 7},
     530             :                                            {10, 2, 1, 9},
     531             :                                            {12, 0, 3, 11},
     532             :                                            {14, 8, 13, 15},
     533             :                                            {16, 18, 23, 17},
     534             :                                            {20, 28, 31, 19},
     535             :                                            {22, 30, 29, 21},
     536             :                                            {24, 26, 27, 25},
     537             :                                            {38, 36, 37, 39},
     538             :                                            {42, 34, 33, 41},
     539             :                                            {44, 32, 35, 43},
     540             :                                            {46, 40, 45, 47},
     541             :                                            {48, 50, 55, 49},
     542             :                                            {52, 60, 63, 51},
     543             :                                            {54, 62, 61, 53},
     544             :                                            {56, 58, 59, 57} };
     545             : 
     546             : 
     547             :     static const UInt_t kChDdl23[16][4] = { {57, 59, 58, 56},
     548             :                                             {53, 61, 62, 54},
     549             :                                             {51, 63, 60, 52},
     550             :                                             {49, 55, 50, 48},
     551             :                                             {47, 45, 40, 46},
     552             :                                             {43, 35, 32, 44},
     553             :                                             {41, 33, 34, 42},
     554             :                                             {39, 37, 36, 38},
     555             :                                             {25, 27, 26, 24},
     556             :                                             {21, 29, 30, 22},
     557             :                                             {19, 31, 28, 20},
     558             :                                             {17, 23, 18, 16},
     559             :                                             {15, 13, 8, 14},
     560             :                                             {11, 3, 0, 12},
     561             :                                             {9, 1, 2, 10},
     562             :                                             {7, 5, 4, 6} };
     563             :     
     564             :     
     565             :     static const UInt_t kChDdl41[16][4] = { {56, 58, 59, 57},
     566             :                                            {54, 62, 61, 53},
     567             :                                            {52, 60, 63, 51},
     568             :                                            {48, 50, 55, 49},
     569             :                                            {46, 40, 45, 47},
     570             :                                            {44, 32, 35, 43},
     571             :                                            {42, 34, 33, 41},
     572             :                                            {38, 36, 37, 39},
     573             :                                            {24, 26, 27, 25},
     574             :                                            {22, 30, 29, 21},
     575             :                                            {20, 28, 31, 19},
     576             :                                            {16, 18, 23, 17},
     577             :                                            {14, 8, 13, 15},
     578             :                                            {12, 0, 3, 11},
     579             :                                            {10, 2, 1, 9},
     580             :                                            {6, 4, 5, 7} };
     581             : 
     582             : 
     583             :     static const UInt_t kChDdl42[16][4] = { {7, 5, 4, 6},
     584             :                                             {9, 1, 2, 10},
     585             :                                             {11, 3, 0, 12},
     586             :                                             {15, 13, 8, 14},
     587             :                                             {17, 23, 18, 16},
     588             :                                             {19, 31, 28, 20},
     589             :                                             {21, 29, 30, 22},
     590             :                                             {25, 27, 26, 24},
     591             :                                             {39, 37, 36, 38},
     592             :                                             {41, 33, 34, 42},
     593             :                                             {43, 35, 32, 44},
     594             :                                             {47, 45, 40, 46},
     595             :                                             {49, 55, 50, 48},
     596             :                                             {51, 63, 60, 52},
     597             :                                             {53, 61, 62, 54},
     598             :                                             {57, 59, 58, 56} };
     599             : 
     600             : 
     601             :     static const UInt_t kChDdl51[16][4] = { {7, 5, 4, 6},
     602             :                                             {9, 1, 2, 10},
     603             :                                             {11, 3, 0, 12},
     604             :                                             {15, 13, 8, 14},
     605             :                                             {17, 23, 18, 16},
     606             :                                             {19, 31, 28, 20},
     607             :                                             {21, 29, 30, 22},
     608             :                                             {25, 27, 26, 24},
     609             :                                             {39, 37, 36, 38},
     610             :                                             {41, 33, 34, 42},
     611             :                                             {43, 35, 32, 44},
     612             :                                             {47, 45, 40, 46},
     613             :                                             {49, 55, 50, 48},
     614             :                                             {51, 63, 60, 52},
     615             :                                             {53, 61, 62, 54},
     616             :                                             {57, 59, 58, 56} };
     617             :     
     618             : 
     619             : 
     620             :     static const UInt_t kChDdl52[16][4] = { {56, 58, 59, 57},
     621             :                                             {54, 62, 61, 53},
     622             :                                             {52, 60, 63, 51},
     623             :                                             {48, 50, 55, 49},
     624             :                                             {46, 40, 45, 47},
     625             :                                             {44, 32, 35, 43},
     626             :                                             {42, 34, 33, 41},
     627             :                                             {38, 36, 37, 39},
     628             :                                             {24, 26, 27, 25},
     629             :                                             {22, 30, 29, 21},
     630             :                                             {20, 28, 31, 19},
     631             :                                             {16, 18, 23, 17},
     632             :                                             {14, 8, 13, 15},
     633             :                                             {12, 0, 3, 11},
     634             :                                             {10, 2, 1, 9},
     635             :                                             {6, 4, 5, 7} };
     636             :     
     637             :     
     638        6120 :     for (Int_t i = 0; i < 16; i++)
     639             :       {
     640       28800 :         for (Int_t j = 0; j < 4; j++)
     641             :           {
     642             :             
     643       16896 :             if(imodule < 6)                    iCh[i][j] = kChDdl01[i][j];
     644       12096 :             if(imodule >= 6 && imodule <= 11)  iCh[i][j] = kChDdl01[i][j];
     645       11840 :             if(imodule >= 12 && imodule <= 17) iCh[i][j] = kChDdl23[i][j];
     646       12928 :             if(imodule >= 18 && imodule <= 23) iCh[i][j] = kChDdl23[i][j];
     647             : 
     648       13696 :             if(imodule >= 24 && imodule <= 29) iCh[i][j] = kChDdl41[i][j];
     649       11520 :             if(imodule >= 42 && imodule <= 47) iCh[i][j] = kChDdl42[i][j];
     650       12416 :             if(imodule >= 36 && imodule <= 41) iCh[i][j] = kChDdl51[i][j];
     651       12288 :             if(imodule >= 30 && imodule <= 35) iCh[i][j] = kChDdl52[i][j];
     652             :             
     653             :           }
     654             :       }
     655             : 
     656             : 
     657         180 :   Int_t irownew = row%16;
     658         180 :   Int_t icolnew = col%4;
     659             :   
     660         180 :   chno  = iCh[irownew][icolnew];
     661             :   
     662             :   
     663        2406 :   for (Int_t ibus = beginPatchBus; ibus <= endPatchBus; ibus++)
     664             :     {
     665        1023 :       Int_t srow = startRowBus[ibus];
     666        1023 :       Int_t erow = endRowBus[ibus];
     667        1023 :       Int_t scol = startColBus[ibus];
     668        1023 :       Int_t ecol = endColBus[ibus];
     669        1023 :       Int_t tmcm = mcmperBus[ibus];
     670             : 
     671        2103 :       if ((row >= srow && row <= erow) && (col >= scol && col <= ecol))
     672             :         {
     673         180 :           busno = ibus;
     674             :           
     675             :           // Find out the MCM Number
     676             :           //
     677             : 
     678         264 :           if (imodule < 6)                  mcmno = (col-scol)/4 + 1;
     679         189 :           if (imodule >= 6 && imodule < 12) mcmno = (col-scol)/4 + 1;
     680             : 
     681         180 :           if (imodule >= 12 && imodule < 18)
     682             :             {
     683           5 :               icolnew = (col - scol)/4;
     684           5 :               mcmno = tmcm - icolnew;
     685           5 :             }         
     686         180 :           if (imodule >= 18 && imodule < 24)
     687             :             {
     688          22 :               icolnew = (col - scol)/4;
     689          22 :               mcmno = tmcm - icolnew;
     690          22 :             }         
     691             : 
     692             :           // DDL = 4
     693         180 :           if (imodule >= 24 && imodule < 30)
     694             :             {
     695             : 
     696             :               //if (tmcm == 24)
     697          34 :               Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
     698          34 :               if(rowdiff > 16)
     699             :                 {
     700           0 :                   Int_t midrow = srow + 16;
     701           0 :                   if(row >= srow && row < midrow)
     702             :                     {
     703           0 :                       mcmno = 12 + (col-scol)/4 + 1;
     704           0 :                     }
     705           0 :                   else if(row >= midrow && row <= erow)
     706             :                     
     707             :                     {
     708           0 :                       mcmno = (col-scol)/4 + 1;
     709           0 :                     }
     710           0 :                 }
     711          34 :               else if (rowdiff < 16)
     712             :                 {
     713          34 :                   mcmno = (col-scol)/4 + 1;
     714          34 :                 }
     715             :             
     716          34 :             }         
     717         180 :           if (imodule >= 42 && imodule < 48)
     718             :             {
     719           0 :               Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
     720           0 :               if(rowdiff > 16)
     721             :                 {
     722           0 :                   Int_t midrow = srow + 16;
     723           0 :                   if (row >= midrow && row <= erow)
     724             :                     {
     725           0 :                       mcmno = 12 + (ecol -col)/4 + 1;
     726           0 :                     }
     727           0 :                   else if (row >= srow && row < midrow)
     728             :                     {
     729           0 :                       mcmno = (ecol - col)/4 + 1;
     730           0 :                     }
     731           0 :                 }
     732           0 :               else if (rowdiff < 16)
     733             :                 {
     734           0 :                   mcmno = (ecol - col)/4 + 1;
     735           0 :                 }
     736           0 :             }         
     737             : 
     738             :           // DDL = 5
     739         180 :           if (imodule >= 30 && imodule < 36)
     740             :             {
     741             :               // CPV plane,  SU Mod = 1, 2 : ddl = 5
     742             :               
     743             :               //if(tmcm == 24)
     744          12 :               Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
     745          12 :               if(rowdiff > 16)
     746             :                 {
     747           0 :                   Int_t midrow = srow + 16;
     748           0 :                   if(row >= srow && row < midrow)
     749             :                     {
     750           0 :                       mcmno = 12 + (col-scol)/4 + 1;
     751           0 :                     }
     752           0 :                   else if(row >= midrow && row <= erow)
     753             :                     {
     754           0 :                       mcmno = (col-scol)/4 + 1;
     755           0 :                     }
     756           0 :                 }
     757          12 :               else if(rowdiff < 16)
     758             :                 {
     759          12 :                   mcmno = (col-scol)/4 + 1;
     760          12 :                 }
     761             :               
     762          12 :             }
     763         180 :           if (imodule >= 36 && imodule < 42)
     764             :             {
     765          14 :               Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
     766          14 :               if(rowdiff > 16)
     767             :                 {
     768           0 :                   Int_t midrow = srow + 16;
     769           0 :                   if (row >= midrow && row <= erow)
     770             :                     {
     771           0 :                       mcmno = 12 + (ecol - col)/4 + 1;
     772           0 :                     }
     773           0 :                   else if (row >= srow && row < midrow)
     774             :                     {
     775           0 :                       mcmno = (ecol - col)/4 + 1;
     776           0 :                     }
     777           0 :                 }
     778          14 :               else if (rowdiff < 16)
     779             :                 {
     780          14 :                   mcmno = (ecol - col)/4 + 1;
     781          14 :                 }
     782          14 :             }
     783             : 
     784             :         }
     785             :     }
     786         180 : } 
     787             : 
     788             : //____________________________________________________________________________
     789             : 
     790             : UInt_t AliPMDDDLRawData::ComputeParity(UInt_t baseword)
     791             : {
     792             :   // Generate the parity bit
     793             : 
     794             :   UInt_t count = 0;
     795       10980 :   for(Int_t j=0; j<29; j++)
     796             :     {
     797        6833 :       if (baseword & 0x01 ) count++;
     798        5220 :       baseword >>= 1;
     799             :     }
     800         180 :   UInt_t parity = count%2;
     801         180 :   return parity;
     802             : }
     803             : //____________________________________________________________________________
     804             : void AliPMDDDLRawData::DdlMapping(Int_t iddl, Int_t imodule,
     805             :                                   Int_t &beginPatchBus, Int_t &endPatchBus,
     806             :                                   Int_t patchBusNo[], Int_t mcmperBus[],
     807             :                                   Int_t startRowBus[], Int_t endRowBus[],
     808             :                                   Int_t startColBus[], Int_t endColBus[])
     809             : {
     810             :   // DDL Mapping fetching from mapping database
     811             : 
     812         384 :   beginPatchBus = fMapData->GetBeginPatchBus(iddl,imodule);
     813         192 :   endPatchBus   = fMapData->GetEndPatchBus(iddl,imodule);
     814             : 
     815        2048 :   for(Int_t ibus = beginPatchBus; ibus < endPatchBus+1; ibus++)
     816             :     {
     817         832 :       patchBusNo[ibus]   = ibus;
     818         832 :       mcmperBus[ibus]    = fMapData->GetMcmperBus(iddl,ibus);
     819         832 :       startRowBus[ibus]  = fMapData->GetStartRowBus(iddl,ibus);
     820         832 :       startColBus[ibus]  = fMapData->GetStartColBus(iddl,ibus);
     821         832 :       endRowBus[ibus]    = fMapData->GetEndRowBus(iddl,ibus);
     822         832 :       endColBus[ibus]    = fMapData->GetEndColBus(iddl,ibus);
     823             :     }
     824             : 
     825         192 : }
     826             : //____________________________________________________________________________
     827             : 
     828             : AliPMDddlinfoData* AliPMDDDLRawData::GetDdlinfoData() const
     829             : {
     830             :   // The run number will be centralized in AliCDBManager,
     831             :   // you don't need to set it here!
     832          12 :   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ddlinfo");
     833             :   
     834           4 :   if(!entry) AliFatal("ddlinfo object retrieval failed!");
     835             :   
     836             :   AliPMDddlinfoData *ddlinfo = 0;
     837           8 :   if (entry) ddlinfo = (AliPMDddlinfoData*) entry->GetObject();
     838             :   
     839           4 :   if (!ddlinfo)  AliFatal("No ddl info data from  database !");
     840             :   
     841           4 :   return ddlinfo;
     842           0 : }
     843             : //____________________________________________________________________________
     844             : AliPMDMappingData* AliPMDDDLRawData::GetMappingData() const
     845             : {
     846             :   // The run number will be centralized in AliCDBManager,
     847             :   // you don't need to set it here!
     848          12 :   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Mapping");
     849             :   
     850           4 :   if(!entry) AliFatal("Mapping object retrieval failed!");
     851             :   
     852             :   AliPMDMappingData *mapda = 0;
     853           8 :   if (entry) mapda = (AliPMDMappingData*) entry->GetObject();
     854             :   
     855           4 :   if (!mapda)  AliFatal("No mapping data from  database !");
     856             :   
     857           4 :   return mapda;
     858           0 : }
     859             : //____________________________________________________________________________

Generated by: LCOV version 1.11