LCOV - code coverage report
Current view: top level - MUON/MUONcalib - AliMUONCalibParamNI.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 48 124 38.7 %
Date: 2016-06-14 17:26:59 Functions: 16 26 61.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             : // $Id$
      17             : 
      18             : #include "AliMUONCalibParamNI.h"
      19             : 
      20             : #include "AliLog.h"
      21             : 
      22             : #include "Riostream.h"
      23             : #include "TMath.h"
      24             : #include "TString.h"
      25             : 
      26             : //-----------------------------------------------------------------------------
      27             : /// \class AliMUONCalibParamNI
      28             : ///
      29             : /// Handle the case of N integer parameters per channel.
      30             : ///
      31             : /// Almost the same class as AliMUONCalibParamNF, but for ints.
      32             : /// We could have played with NF to store both int and float (using casts),
      33             : /// but for the sake of simplicity (e.g. the Print method must know whether
      34             : /// it should print floats or ints), we decided to "duplicate" the class
      35             : /// and use the correct type.
      36             : ///
      37             : /// \author Laurent Aphecetche
      38             : //-----------------------------------------------------------------------------
      39             : 
      40             : using std::cout;
      41             : using std::endl;
      42             : /// \cond CLASSIMP
      43          18 : ClassImp(AliMUONCalibParamNI)
      44             : /// \endcond
      45             : 
      46             : //_____________________________________________________________________________
      47             : AliMUONCalibParamNI::AliMUONCalibParamNI() 
      48       34416 : : AliMUONVCalibParam(),
      49       34416 :   fDimension(0),
      50       34416 :   fSize(0),
      51       34416 :   fN(0),
      52       34416 :   fPackingFactor(0),
      53       34416 :   fValues(0x0)
      54      172080 : {
      55             : /// Default constructor.
      56      172080 :     AliDebug(1,Form("this=%p default ctor",this));
      57       68832 : }
      58             : 
      59             : //_____________________________________________________________________________
      60             : AliMUONCalibParamNI::AliMUONCalibParamNI(Int_t dimension, Int_t theSize,
      61             :                                          Int_t id0, Int_t id1,
      62             :                                          Int_t fillWithValue, Int_t packingFactor) 
      63       50028 : : AliMUONVCalibParam(id0,id1),
      64       50028 :   fDimension(dimension),
      65       50028 :   fSize(theSize),
      66       50028 :   fN(fSize*fDimension),
      67       50028 :   fPackingFactor(packingFactor),
      68       50028 :   fValues(0x0)
      69      250140 : {
      70             : /// Normal constructor, where theSize specifies the number of channels handled
      71             : /// by this object, and fillWithValue the default value assigned to each
      72             : /// channel.
      73             : 
      74             : //    AliDebug(1,Form("this=%p dimension=%d theSize=%d fillWithValue=%d packingFactor=%d",
      75             : //                    this,dimension,theSize,fillWithValue,packingFactor));
      76             : 
      77       50028 :   if ( fN > 0 )
      78             :   {
      79      100056 :     fValues = new Int_t[fN];
      80     6503640 :     for ( Int_t i = 0; i < fN; ++i )
      81             :     {
      82     3201792 :       fValues[i] = fillWithValue;
      83             :     }
      84       50028 :   }
      85      100056 : }
      86             : 
      87             : 
      88             : //_____________________________________________________________________________
      89             : AliMUONCalibParamNI::AliMUONCalibParamNI(const AliMUONCalibParamNI& other) 
      90           0 : : AliMUONVCalibParam(),
      91           0 : fDimension(0),
      92           0 : fSize(0),
      93           0 : fN(0),
      94           0 : fPackingFactor(0),
      95           0 : fValues(0x0)
      96           0 : {
      97             : /// Copy constructor.
      98             : 
      99           0 :   AliDebug(1,Form("this=%p copy ctor",this));
     100           0 :   other.CopyTo(*this);
     101           0 : }
     102             : 
     103             : //_____________________________________________________________________________
     104             : AliMUONCalibParamNI&
     105             : AliMUONCalibParamNI::operator=(const AliMUONCalibParamNI& other) 
     106             : {
     107             : /// Assignment operator
     108             : 
     109           0 :   other.CopyTo(*this);
     110           0 :   return *this;
     111             : }
     112             : 
     113             : //_____________________________________________________________________________
     114             : AliMUONCalibParamNI::~AliMUONCalibParamNI()
     115      300168 : {
     116             : /// Destructor
     117             : 
     118      250140 :   AliDebug(1,Form("this=%p",this));
     119      100056 :   delete[] fValues;
     120      150084 : }
     121             : 
     122             : //_____________________________________________________________________________
     123             : void
     124             : AliMUONCalibParamNI::CopyTo(AliMUONCalibParamNI& destination) const
     125             : {
     126             : /// Copy *this to destination
     127             : 
     128           0 :   const TObject& o = static_cast<const TObject&>(*this);
     129           0 :   o.Copy(destination);
     130             :   
     131           0 :   delete[] destination.fValues;
     132           0 :   destination.fN = fN;
     133           0 :   destination.fSize = fSize;
     134           0 :   destination.fDimension = fDimension;
     135           0 :   destination.fPackingFactor = fPackingFactor;
     136             :   
     137           0 :   if ( fN > 0 )
     138             :   {
     139           0 :     destination.fValues = new Int_t[fN];
     140           0 :     for ( Int_t i = 0; i < fN; ++i )
     141             :     {
     142           0 :       destination.fValues[i] = fValues[i];
     143             :     }
     144           0 :   }
     145           0 : }
     146             : 
     147             : //_____________________________________________________________________________
     148             : Int_t
     149             : AliMUONCalibParamNI::Index(Int_t i, Int_t j) const
     150             : {
     151             : /// Compute the 1D index of the internal storage from the pair (i,j)
     152             : /// Returns -1 if the (i,j) pair is invalid
     153             : 
     154    13859480 :   if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
     155             :   {
     156     3464870 :     return IndexFast(i,j);
     157             :   }
     158           0 :   return -1;
     159     3464870 : }
     160             : 
     161             : //_____________________________________________________________________________
     162             : Int_t
     163             : AliMUONCalibParamNI::IndexFast(Int_t i, Int_t j) const
     164             : {
     165             :   /// Compute the 1D index of the internal storage from the pair (i,j)
     166             :   
     167    12412176 :   return i + Size()*j;
     168             : }
     169             : 
     170             : //_____________________________________________________________________________
     171             : void
     172             : AliMUONCalibParamNI::Print(Option_t* opt) const
     173             : {
     174             : /// Output this object to stdout.
     175             : /// If opt=="full" then all channels are printed, 
     176             : /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
     177             : /// otherwise only the general characteristics are printed.
     178             : 
     179           0 :   TString sopt(opt);
     180           0 :   sopt.ToUpper();
     181           0 :   cout << "AliMUONCalibParamNI - Size=" << Size()
     182           0 :     << " Dimension=" << Dimension()
     183           0 :     << " Id=(" << ID0() << "," << ID1() << ")";
     184             :   
     185           0 :   if ( IsPacked() ) 
     186             :   {
     187           0 :     cout << " Packing Factor=" << fPackingFactor;
     188             :   }
     189           0 :   cout << endl;
     190             :   
     191           0 :   if ( sopt.Contains("FULL") )
     192             :   {
     193           0 :     for ( Int_t i = 0; i < Size(); ++i )
     194             :     {
     195           0 :       cout << Form("CH %3d",i);
     196           0 :       for ( Int_t j = 0; j < Dimension(); ++j )
     197             :       {
     198           0 :         Int_t v = ValueAsInt(i,j);
     199           0 :         if ( IsPacked() )
     200             :         {
     201           0 :           Int_t m,c;
     202           0 :           UnpackValue(v,m,c);
     203           0 :           cout << Form(" (%d,%d) (0x%x,0x%x)",m,c,m,c);
     204           0 :         }
     205             :         else
     206             :         {
     207           0 :           cout << Form(" %d (0x%x)",v,v);
     208             :         }
     209             :       }
     210           0 :       cout << endl;
     211             :     }
     212           0 :   }  
     213           0 :   if ( sopt.Contains("MEAN") )
     214             :   {
     215           0 :     Int_t j(0);
     216           0 :     sscanf(sopt.Data(),"MEAN%d",&j);
     217             :     
     218             :     Float_t mean(0);
     219             :     Float_t v2(0);
     220             :     
     221           0 :     Int_t n = Size();
     222             :     
     223           0 :     for ( Int_t i = 0; i < Size(); ++i )
     224             :     {
     225           0 :       Float_t v = ValueAsFloat(i,j);
     226           0 :       mean += v;
     227           0 :       v2 += v*v;
     228             :     }
     229           0 :     mean /= n;
     230             :     float sigma = 0;
     231           0 :     if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
     232           0 :     cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
     233           0 :   }
     234             :   
     235           0 : }
     236             : 
     237             : //_____________________________________________________________________________
     238             : void
     239             : AliMUONCalibParamNI::SetValueAsInt(Int_t i, Int_t j, Int_t value)
     240             : {
     241             : /// Set one value as a float, after checking that the indices are correct.
     242             : 
     243      422852 :   Int_t ix = Index(i,j);
     244             :   
     245      211426 :   if ( ix < 0 )
     246             :   {
     247           0 :     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
     248             :                   i,j,Size()-1,Dimension()-1));
     249           0 :   }
     250             :   else
     251             :   {
     252      211426 :     fValues[ix]=value;
     253             :   }
     254      211426 : }
     255             : 
     256             : //_____________________________________________________________________________
     257             : void
     258             : AliMUONCalibParamNI::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
     259             : {
     260             :   /// Set one value as a float, w/o checking that the indices are correct.
     261             :   
     262     4361920 :   fValues[IndexFast(i,j)] = value;
     263     2180960 : }
     264             : 
     265             : //_____________________________________________________________________________
     266             : void
     267             : AliMUONCalibParamNI::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
     268             : {
     269             :   /// Set one value as an int.
     270             : 
     271           0 :   AliWarning("Float will be rounded to be stored...");
     272           0 :   SetValueAsInt(i,j,TMath::Nint(value));
     273           0 : }
     274             : 
     275             : //_____________________________________________________________________________
     276             : void
     277             : AliMUONCalibParamNI::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
     278             : {
     279             :   /// Set one value as an int.
     280             :   
     281           0 :   AliWarning("Float will be rounded to be stored...");
     282           0 :   SetValueAsIntFast(i,j,TMath::Nint(value));
     283           0 : }
     284             : 
     285             : 
     286             : //_____________________________________________________________________________
     287             : Int_t
     288             : AliMUONCalibParamNI::ValueAsInt(Int_t i, Int_t j) const
     289             : {
     290             : /// Return the value as an int (which it is), after checking indices.
     291             : 
     292     6506888 :   Int_t ix = Index(i,j);
     293             :   
     294     3253444 :   if ( ix < 0 )
     295             :   {
     296           0 :     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
     297             :                   i,j,Size()-1,Dimension()-1));
     298           0 :     return 0;
     299             :   }
     300             :   else
     301             :   {
     302     3253444 :     return fValues[ix];
     303             :   }
     304     3253444 : }
     305             : 
     306             : //_____________________________________________________________________________
     307             : Int_t
     308             : AliMUONCalibParamNI::ValueAsIntFast(Int_t i, Int_t j) const
     309             : {
     310             :   /// Return the value as an int (which it is), w/o checking indices.
     311             :   
     312     1120516 :   return fValues[IndexFast(i,j)];
     313             : }
     314             : 
     315             : //_____________________________________________________________________________
     316             : Float_t
     317             : AliMUONCalibParamNI::ValueAsFloat(Int_t i, Int_t j) const
     318             : {
     319             :   /// Return the value as a float
     320           0 :   return static_cast<Float_t>(ValueAsInt(i,j));
     321             : }
     322             : 
     323             : //_____________________________________________________________________________
     324             : Float_t
     325             : AliMUONCalibParamNI::ValueAsFloatFast(Int_t i, Int_t j) const
     326             : {
     327             :   /// Return the value as a float
     328           0 :   return static_cast<Float_t>(ValueAsIntFast(i,j));
     329             : }
     330             : 
     331             : //_____________________________________________________________________________
     332             : Bool_t 
     333             : AliMUONCalibParamNI::UnpackValue(Int_t value, Int_t& a, Int_t& b) const
     334             : {
     335             :   /// Unpack single value into a couple (a,b), using packingFactor
     336             :   /// Returns false if IsPacked()==false
     337             :   
     338      593472 :   if ( !IsPacked() ) return kFALSE;
     339      296736 :   a = value / fPackingFactor;
     340      296736 :   b = value % fPackingFactor;
     341      296736 :   return kTRUE;
     342      296736 : }
     343             : 
     344             : //_____________________________________________________________________________
     345             : Bool_t 
     346             : AliMUONCalibParamNI::PackValues(Int_t a, Int_t b, Int_t& packedValue) const
     347             : {
     348             :   /// Pack a couple (a,b) into a single value, using packingFactor
     349             :   /// Returns false if IsPacked()==false
     350             : 
     351           0 :   if ( !IsPacked() ) return kFALSE;
     352           0 :   packedValue = a*fPackingFactor + b;
     353           0 :   return kTRUE;
     354           0 : }
     355             : 
     356             : //_____________________________________________________________________________
     357             : Bool_t 
     358             : AliMUONCalibParamNI::IsPacked() const
     359             : {
     360             :   /// Whether the values we store are packed or not.
     361             :   /// If false, Pack and Unpack methods will always return false and do nothing
     362      593472 :   return (fPackingFactor != 0);
     363             : }
     364             : 

Generated by: LCOV version 1.11