LCOV - code coverage report
Current view: top level - TRD/TRDbase - AliTRDfeeParam.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 65 136 47.8 %
Date: 2016-06-14 17:26:59 Functions: 10 28 35.7 %

          Line data    Source code
       1             : 
       2             : /**************************************************************************
       3             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       4             :  *                                                                        *
       5             :  * Author: The ALICE Off-line Project.                                    *
       6             :  * Contributors are mentioned in the code where appropriate.              *
       7             :  *                                                                        *
       8             :  * Permission to use, copy, modify and distribute this software and its   *
       9             :  * documentation strictly for non-commercial purposes is hereby granted   *
      10             :  * without fee, provided that the above copyright notice appears in all   *
      11             :  * copies and that both the copyright notice and this permission notice   *
      12             :  * appear in the supporting documentation. The authors make no claims     *
      13             :  * about the suitability of this software for any purpose. It is          *
      14             :  * provided "as is" without express or implied warranty.                  *
      15             :  **************************************************************************/
      16             : 
      17             : /* $Id$ */
      18             : 
      19             : ////////////////////////////////////////////////////////////////////////////
      20             : //                                                                        //
      21             : //  TRD front end electronics parameters class                            //
      22             : //  Contains all FEE (MCM, TRAP, PASA) related                            //
      23             : //  parameters, constants, and mapping.                                   //
      24             : //                                                                        //
      25             : //  New release on 2007/08/17:                                            //
      26             : //   The default raw data version (now fRAWversion ) is set to 3          //
      27             : //   in the constructor because version 3 raw data read and write         //
      28             : //   are fully debugged.                                                  //
      29             : //                                                                        //
      30             : //  Author:                                                               //
      31             : //    Ken Oyama (oyama@physi.uni-heidelberg.de)                           //
      32             : //                                                                        //
      33             : //  many things now configured by AliTRDtrapConfig reflecting             //
      34             : //  the real memory structure of the TRAP (Jochen)                        //
      35             : //                                                                        //
      36             : ////////////////////////////////////////////////////////////////////////////
      37             : 
      38             : //#include <TMath.h>
      39             : 
      40             : #include "AliLog.h"
      41             : 
      42             : #include "AliTRDfeeParam.h"
      43             : //#include "AliTRDgeometry.h"
      44             : #include "AliTRDCommonParam.h"
      45             : 
      46          48 : ClassImp(AliTRDfeeParam)
      47             : 
      48             : AliTRDfeeParam *AliTRDfeeParam::fgInstance   = 0;
      49             : Bool_t          AliTRDfeeParam::fgTerminated = kFALSE;
      50             : Bool_t          AliTRDfeeParam::fgTracklet = kTRUE;
      51             : Bool_t          AliTRDfeeParam::fgRejectMultipleTracklets = kFALSE;
      52             : Bool_t          AliTRDfeeParam::fgUseMisalignCorr = kFALSE;
      53             : Bool_t          AliTRDfeeParam::fgUseTimeOffset = kFALSE;
      54             : 
      55             : //_____________________________________________________________________________
      56             : AliTRDfeeParam* AliTRDfeeParam::Instance()
      57             : {
      58             :   //
      59             :   // Instance constructor
      60             :   //
      61             : 
      62        8678 :   if (fgTerminated != kFALSE) {
      63           0 :     return 0;
      64             :   }
      65             : 
      66        4339 :   if (fgInstance == 0) {
      67           6 :     fgInstance = new AliTRDfeeParam();
      68           3 :   }  
      69             : 
      70        4339 :   return fgInstance;
      71             : 
      72        4339 : }
      73             : 
      74             : //_____________________________________________________________________________
      75             : void AliTRDfeeParam::Terminate()
      76             : {
      77             :   //
      78             :   // Terminate the class and release memory
      79             :   //
      80             :   
      81           0 :   fgTerminated = kTRUE;
      82             : 
      83           0 :   if (fgInstance != 0) {
      84           0 :     delete fgInstance;
      85           0 :     fgInstance = 0;
      86           0 :   }
      87             : 
      88           0 : }
      89             : 
      90             : //_____________________________________________________________________________
      91             : AliTRDfeeParam::AliTRDfeeParam()
      92           3 :   :TObject()
      93           3 :   ,fCP(0)
      94           3 :   ,fRAWversion(3)
      95          15 : {
      96             :   //
      97             :   // Default constructor
      98             :   //
      99             :   
     100           6 :   fCP  = AliTRDCommonParam::Instance();
     101           6 : }
     102             : 
     103             : //_____________________________________________________________________________
     104             : AliTRDfeeParam::AliTRDfeeParam(TRootIoCtor *)
     105           0 :   :TObject()
     106           0 :   ,fCP(0)
     107           0 :   ,fRAWversion(0)
     108           0 : {
     109             :   //
     110             :   // IO constructor
     111             :   //
     112             : 
     113           0 : }
     114             : 
     115             : //_____________________________________________________________________________
     116             : AliTRDfeeParam::AliTRDfeeParam(const AliTRDfeeParam &p)
     117           0 :   :TObject(p)
     118           0 :   ,fCP(p.fCP)
     119           0 :   ,fRAWversion(p.fRAWversion)
     120           0 : {
     121             :   //
     122             :   // AliTRDfeeParam copy constructor
     123             :   //
     124             : 
     125           0 : }
     126             : 
     127             : //_____________________________________________________________________________
     128             : AliTRDfeeParam::~AliTRDfeeParam()
     129           0 : {
     130             :   //
     131             :   // AliTRDfeeParam destructor
     132             :   //
     133             : 
     134           0 : }
     135             : 
     136             : //_____________________________________________________________________________
     137             : AliTRDfeeParam &AliTRDfeeParam::operator=(const AliTRDfeeParam &p)
     138             : {
     139             :   //
     140             :   // Assignment operator
     141             :   //
     142             : 
     143           0 :   if (this != &p) {
     144           0 :     ((AliTRDfeeParam &) p).Copy(*this);
     145           0 :   }
     146             : 
     147           0 :   return *this;
     148             : 
     149             : }
     150             : 
     151             : //_____________________________________________________________________________
     152             : void AliTRDfeeParam::Copy(TObject &p) const
     153             : {
     154             :   //
     155             :   // Copy function
     156             :   //
     157             : 
     158           0 :   ((AliTRDfeeParam &) p).fCP          = fCP;
     159           0 :   ((AliTRDfeeParam &) p).fRAWversion  = fRAWversion;
     160             :   
     161           0 :   TObject::Copy(p);
     162             : 
     163           0 : }
     164             : 
     165             : //_____________________________________________________________________________
     166             : Int_t AliTRDfeeParam::GetPadRowFromMCM(Int_t irob, Int_t imcm) const
     167             : {
     168             :   //
     169             :   // Return on which pad row this mcm sits
     170             :   //
     171             :   
     172       99816 :   return fgkNmcmRobInRow*(irob/2) + imcm/fgkNmcmRobInCol;
     173             : 
     174             : }
     175             : 
     176             : //_____________________________________________________________________________
     177             : Int_t AliTRDfeeParam::GetPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
     178             : {
     179             :   //
     180             :   // Return which pad is connected to this adc channel.
     181             :   //
     182             :   // Return virtual pad number even if ADC is outside chamber
     183             :   // to keep compatibility of data processing at the edge MCM.
     184             :   // User has to check that this is in the chamber if it is essential.
     185             :   // Return -100 if iadc is invalid.
     186             :   //
     187             :   // Caution: ADC ordering in the online data is opposite to the pad column ordering.
     188             :   // And it is not one-by-one correspondence. Precise drawing can be found in:
     189             :   // http://wiki.kip.uni-heidelberg.de/ti/TRD/index.php/Image:ROB_MCM_numbering.pdf
     190             :   //
     191             : 
     192       49848 :   if (iadc < 0 || iadc > fgkNadcMcm ) return -100;
     193       24924 :   Int_t mcmcol = imcm%fgkNmcmRobInCol + GetRobSide(irob)*fgkNmcmRobInCol;  // MCM column number on ROC [0..7]
     194       24924 :   Int_t padcol = mcmcol*fgkNcolMcm + fgkNcolMcm + 1 - iadc;
     195       24940 :   if( padcol < 0 || padcol >= fgkNcol ) return -1;   // this is commented because of reason above OK
     196             : 
     197       24908 :   return padcol;
     198             : 
     199       24924 : }
     200             : 
     201             : //_____________________________________________________________________________
     202             : Int_t AliTRDfeeParam::GetExtendedPadColFromADC(Int_t irob, Int_t imcm, Int_t iadc) const
     203             : {     
     204             :   //
     205             :   // Return which pad coresponds to the extended digit container pad numbering
     206             :   // Extended digit container is designed to store all pad data including shared pad, 
     207             :   // so we have to introduce new virtual pad numbering scheme for this purpose. 
     208             :   //
     209             :     
     210           0 :   if (iadc < 0 || iadc > fgkNadcMcm ) return -100;
     211           0 :   Int_t mcmcol = imcm%fgkNmcmRobInCol + GetRobSide(irob)*fgkNmcmRobInCol;  // MCM column number on ROC [0..7]
     212           0 :   Int_t padcol = mcmcol*fgkNadcMcm + fgkNcolMcm + 2 - iadc;
     213             : 
     214             :   return padcol;
     215             : 
     216           0 : }
     217             : 
     218             : //_____________________________________________________________________________
     219             : Int_t AliTRDfeeParam::GetMCMfromPad(Int_t irow, Int_t icol) const
     220             : {
     221             :   //
     222             :   // Return on which MCM this pad is directry connected.
     223             :   // Return -1 for error.
     224             :   //
     225             : 
     226           0 :   if ( irow < 0 || icol < 0 || irow > fgkNrowC1 || icol > fgkNcol ) return -1;
     227             : 
     228           0 :   return (icol%(fgkNcol/2))/fgkNcolMcm + fgkNmcmRobInCol*(irow%fgkNmcmRobInRow);
     229             : 
     230           0 : }
     231             : 
     232             : //_____________________________________________________________________________
     233             : Int_t AliTRDfeeParam::GetMCMfromSharedPad(Int_t irow, Int_t icol) const
     234             : {
     235             :   //
     236             :   // Return on which MCM this pad is directry connected.
     237             :   // Return -1 for error.
     238             :   //
     239             :   
     240           0 :   if ( irow < 0 || icol < 0 || irow > fgkNrowC1 || icol > fgkNcol+8*3 ) return -1;
     241             : 
     242           0 :   Int_t adc = 20 - (icol%18) -1;
     243           0 :   switch(adc) {
     244           0 :     case 2:  icol += 5; break;
     245           0 :     case 18: icol -= 5; break;
     246           0 :     case 19: icol -= 5; break;
     247           0 :     default: icol += 0; break;
     248             :   }
     249             : 
     250           0 :   return (icol%(fgkNcol/2))/fgkNcolMcm + fgkNmcmRobInCol*(irow%fgkNmcmRobInRow);
     251             : 
     252           0 : }
     253             : 
     254             : //_____________________________________________________________________________
     255             : Int_t AliTRDfeeParam::GetROBfromPad(Int_t irow, Int_t icol) const
     256             : {
     257             :   //
     258             :   // Return on which rob this pad is
     259             :   //
     260             : 
     261           0 :   return (irow/fgkNmcmRobInRow)*2 + GetColSide(icol);
     262             : 
     263             : }
     264             : 
     265             : //_____________________________________________________________________________
     266             : Int_t AliTRDfeeParam::GetROBfromSharedPad(Int_t irow, Int_t icol) const
     267             : {
     268             :   //
     269             :   // Return on which rob this pad is for shared pads
     270             :   //
     271             : 
     272           0 :   if(icol<72) return (irow/fgkNmcmRobInRow)*2 + GetColSide(icol+5);
     273           0 :   else return (irow/fgkNmcmRobInRow)*2 + GetColSide(icol-5);
     274             : 
     275           0 : }
     276             : 
     277             : //_____________________________________________________________________________
     278             : Int_t AliTRDfeeParam::GetRobSide(Int_t irob) const
     279             : {
     280             :   //
     281             :   // Return on which side this rob sits (A side = 0, B side = 1)
     282             :   //
     283             : 
     284       49848 :   if ( irob < 0 || irob >= fgkNrobC1 ) return -1;
     285             : 
     286       24924 :   return irob%2;
     287             : 
     288       24924 : }
     289             : 
     290             : //_____________________________________________________________________________
     291             : Int_t AliTRDfeeParam::GetColSide(Int_t icol) const
     292             : {
     293             :   //
     294             :   // Return on which side this column sits (A side = 0, B side = 1)
     295             :   //
     296             : 
     297           0 :   if ( icol < 0 || icol >= fgkNcol ) return -1;
     298             : 
     299           0 :   return icol/(fgkNcol/2);
     300             : 
     301           0 : }
     302             : 
     303             : 
     304             : 
     305             : UInt_t AliTRDfeeParam::AliToExtAli(Int_t rob, Int_t aliid)
     306             : {
     307           0 :    if(aliid!= 127)
     308           0 :       return ( (1 << 10) | (rob << 7) | aliid);
     309             : 
     310           0 :    return 127;
     311           0 : }
     312             : 
     313             : 
     314             : Int_t AliTRDfeeParam::ExtAliToAli(UInt_t dest, UShort_t linkpair, UShort_t rocType, Int_t *mcmList, Int_t listSize)
     315             : {
     316             :    // Converts an extended ALICE ID which identifies a single MCM or a group of MCMs to
     317             :    // the corresponding list of MCMs. Only broadcasts (127) are encoded as 127 
     318             :    // The return value is the number of MCMs in the list
     319             : 
     320    20491488 :   mcmList[0]=-1;
     321             : 
     322             :   Short_t nmcm = 0;
     323             :   UInt_t mcm, rob, robAB;
     324             :   UInt_t cmA = 0, cmB = 0;  // Chipmask for each A and B side
     325             :   
     326             :   // Default chipmask for 4 linkpairs (each bit correponds each alice-mcm)
     327             :   static const UInt_t gkChipmaskDefLp[4] = { 0x1FFFF, 0x1FFFF, 0x3FFFF, 0x1FFFF };
     328             :   
     329    10245744 :   rob = dest >> 7;                              // Extract ROB pattern from dest.
     330    10245744 :   mcm = dest & 0x07F;                           // Extract MCM pattern from dest.
     331    10245744 :   robAB = GetRobAB( rob, linkpair ); // Get which ROB sides are selected.
     332             :   
     333             :   // Abort if no ROB is selected
     334    10245744 :   if( robAB == 0 ) {
     335     7682688 :     return 0;
     336             :   }
     337             :   
     338             :   // Special case
     339     2563056 :   if( mcm == 127 ) {
     340        2160 :     if( robAB == 3 ) {      // This is very special 127 can stay only if two ROBs are selected
     341        2160 :       mcmList[0]=127;      // broadcase to ALL
     342        2160 :       mcmList[1]=-1;
     343        2160 :       return 1;
     344             :     }
     345             :     cmA = cmB = 0x3FFFF;
     346     2560896 :   } else if( (mcm & 0x40) != 0 ) { // If top bit is 1 but not 127, this is chip group.
     347           0 :     if( (mcm & 0x01) != 0 )                  { cmA |= 0x04444; cmB |= 0x04444; } // chip_cmrg
     348           0 :     if( (mcm & 0x02) != 0 )                  { cmA |= 0x10000; cmB |= 0x10000; } // chip_bmrg
     349           0 :     if( (mcm & 0x04) != 0 && rocType == 0 ) { cmA |= 0x20000; cmB |= 0x20000; } // chip_hm3
     350           0 :     if( (mcm & 0x08) != 0 && rocType == 1 ) { cmA |= 0x20000; cmB |= 0x20000; } // chip_hm4
     351           0 :     if( (mcm & 0x10) != 0 )                  { cmA |= 0x01111; cmB |= 0x08888; } // chip_edge
     352           0 :     if( (mcm & 0x20) != 0 )                  { cmA |= 0x0aaaa; cmB |= 0x03333; } // chip_norm
     353             :   } else { // Otherwise, this is normal chip ID, turn on only one chip.
     354     2560896 :     cmA = 1 << mcm;
     355             :     cmB = 1 << mcm;
     356             :   }
     357             :   
     358             :   // Mask non-existing MCMs
     359     2560896 :   cmA &= gkChipmaskDefLp[linkpair];
     360     2560896 :   cmB &= gkChipmaskDefLp[linkpair];
     361             :   // Remove if only one side is selected
     362     2560896 :   if( robAB == 1 ) 
     363             :     cmB = 0;
     364     2560896 :   if( robAB == 2 ) 
     365     1280448 :     cmA = 0;
     366     2560896 :   if( robAB == 4 && linkpair != 2 ) 
     367           0 :     cmA = cmB = 0; // Restrict to only T3A and T3B
     368             :   
     369             :   // Finally convert chipmask to list of slaves
     370     2560896 :   nmcm = ChipmaskToMCMlist( cmA, cmB, linkpair, mcmList, listSize);
     371             :   
     372     2560896 :   return nmcm;
     373    10245744 : }
     374             : 
     375             : 
     376             : Short_t AliTRDfeeParam::GetRobAB( UShort_t robsel, UShort_t linkpair )
     377             : {
     378             :   // Converts the ROB part of the extended ALICE ID to robs
     379             : 
     380    20491488 :   if( (robsel & 0x8) != 0 ) { // 1000 .. direct ROB selection. Only one of the 8 ROBs are used.
     381    10243584 :     robsel = robsel & 7;
     382    15365376 :     if( (robsel % 2) == 0 && (robsel / 2) == linkpair ) 
     383     1280448 :       return 1;  // Even means A side (position 0,2,4,6)
     384    14084928 :     if( (robsel % 2) == 1 && (robsel / 2) == linkpair ) 
     385     1280448 :       return 2;  // Odd  means B side (position 1,3,5,7)
     386     7682688 :     return 0;
     387             :   }
     388             :   
     389             :   // ROB group
     390        4320 :   if( robsel == 0 ) { return 3; } // Both   ROB
     391           0 :   if( robsel == 1 ) { return 1; } // A-side ROB
     392           0 :   if( robsel == 2 ) { return 2; } // B-side ROB
     393           0 :   if( robsel == 3 ) { return 3; } // Both   ROB
     394           0 :   if( robsel == 4 ) { return 4; } // Only T3A and T3B
     395             :   // Other number 5 to 7 are ignored (not defined) 
     396             :   
     397           0 :   return 0;
     398    10245744 : }
     399             : 
     400             : 
     401             : Short_t AliTRDfeeParam::ChipmaskToMCMlist( UInt_t cmA, UInt_t cmB, UShort_t linkpair, Int_t *mcmList, Int_t listSize )
     402             : {
     403             :   // Converts the chipmask to a list of MCMs 
     404             :   
     405             :   Short_t nmcm = 0;
     406             :   Short_t i;
     407    99874944 :   for( i = 0 ; i < 18 ; i++ ) {  // 18: number of MCMs on a ROB
     408    47376576 :      if( (cmA & (1 << i)) != 0 && nmcm<listSize) {
     409     1280448 :         mcmList[nmcm] = ((linkpair*2) << 7) | i;
     410     1280448 :         ++nmcm;
     411     1280448 :     }
     412    47376576 :     if( (cmB & (1 << i)) != 0  && nmcm<listSize) {
     413     1280448 :        mcmList[nmcm] = ((linkpair*2+1) << 7) | i;
     414     1280448 :        ++nmcm;
     415     1280448 :     }
     416             :   }
     417             : 
     418     2560896 :   mcmList[nmcm]=-1;
     419     2560896 :   return nmcm;
     420             : }
     421             : 
     422             : 
     423             : //_____________________________________________________________________________
     424             : void AliTRDfeeParam::SetRAWversion( Int_t rawver )
     425             : {
     426             :   //
     427             :   // Set raw data version (major number only)
     428             :   // Maximum available number is preset in fgkMaxRAWversion
     429             :   //
     430             : 
     431           0 :   if( rawver >= 0 && rawver <= fgkMaxRAWversion ) {
     432           0 :     fRAWversion = rawver;
     433           0 :   } 
     434             :   else {
     435           0 :     AliError(Form("Raw version is out of range: %d",rawver));
     436             :   }
     437             : 
     438           0 : }

Generated by: LCOV version 1.11