LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpPad.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 109 160 68.1 %
Date: 2016-06-14 17:26:59 Functions: 25 29 86.2 %

          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             : // $MpId: AliMpPad.cxx,v 1.9 2006/05/24 13:58:29 ivana Exp $
      18             : // Category: basic
      19             : 
      20             : //-----------------------------------------------------------------------------
      21             : // Class AliMpPad
      22             : // ---------------
      23             : // Class which encapsuate all informations about a pad
      24             : // Included in AliRoot: 2003/05/02
      25             : // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
      26             : // root [0] .x testSectorAreaIterator.C
      27             : // Real time 0:00:56, CP time 36.270
      28             : //-----------------------------------------------------------------------------
      29             : 
      30             : #include "AliMpPad.h"
      31             : #include "AliMpEncodePair.h"
      32             : #include "AliLog.h"
      33             : 
      34             : #include <TClonesArray.h>
      35             : #include <Riostream.h>
      36             : 
      37             : using std::cout;
      38             : using std::endl;
      39             : /// \cond CLASSIMP
      40          18 : ClassImp(AliMpPad)
      41             : /// \endcond
      42             : 
      43             : const Int_t  AliMpPad::fgkMaxNofLocations = 6;
      44             : 
      45             : //_____________________________________________________________________________
      46             : AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
      47             :                    Int_t ix, Int_t iy,
      48             :                    Double_t x,  Double_t y, 
      49             :                    Double_t dx,  Double_t dy, 
      50             :                    Bool_t validity)
      51     1706117 :  : TObject(),
      52     1706117 :    fNofLocations(0),
      53     1706117 :    fLLocations(0),
      54     3412234 :    fLLocation(AliMp::Pair(manuId, channel)),
      55     3412234 :    fLIndices(AliMp::Pair(ix, iy)),
      56     1706117 :    fPositionX(x),
      57     1706117 :    fPositionY(y),
      58     1706117 :    fDimensionX(dx),
      59     1706117 :    fDimensionY(dy),
      60     1706117 :    fValidity(validity)
      61     5118351 : {
      62             : /// Standard constructor                                                   \n
      63             : /// Be carefull : this constructor doesn't check the validity of
      64             : /// the correspondance between location and indices.
      65             : /// By default, validity is set true.
      66             : /// It is aimed to be used by MSegmentation methods, and never from outside....
      67     3412234 : }
      68             : 
      69             : //_____________________________________________________________________________
      70             : AliMpPad::AliMpPad(Int_t manuId, Int_t channel,
      71             :                    MpPair_t indices,
      72             :                    Double_t x,  Double_t y, 
      73             :                    Double_t dx,  Double_t dy, 
      74             :                    Bool_t validity)
      75     5315850 :  : TObject(),
      76     5315850 :    fNofLocations(0),
      77     5315850 :    fLLocations(0),
      78    10631700 :    fLLocation(AliMp::Pair(manuId, channel)),
      79     5315850 :    fLIndices(indices),
      80     5315850 :    fPositionX(x),
      81     5315850 :    fPositionY(y),
      82     5315850 :    fDimensionX(dx),
      83     5315850 :    fDimensionY(dy),
      84     5315850 :    fValidity(validity)
      85    15947550 : {
      86             : /// Standard constructor                                                   \n
      87             : /// Be carefull : this constructor doesn't check the validity of
      88             : /// the correspondance between location and indices.
      89             : /// By default, validity is set true.
      90             : /// It is aimed to be used by MSegmentation methods, and never from outside....
      91    10631700 : }
      92             : 
      93             : //_____________________________________________________________________________
      94             : AliMpPad::AliMpPad()
      95     1175912 :   : TObject(),
      96     1175912 :     fNofLocations(0),
      97     1175912 :     fLLocations(0),
      98     1175912 :     fLLocation(0),
      99     1175912 :     fLIndices(0),
     100     1175912 :     fPositionX(-1.),
     101     1175912 :     fPositionY(-1.),
     102     1175912 :     fDimensionX(-1.),
     103     1175912 :     fDimensionY(-1.),
     104     1175912 :     fValidity(false) 
     105     5879560 : {
     106             : /// Default constructor - creates pad in invalid state
     107     2351824 : }
     108             : 
     109             : //_____________________________________________________________________________
     110             : AliMpPad::AliMpPad(const AliMpPad& rhs)
     111      196523 :   : TObject(),
     112      196523 :     fNofLocations(0),
     113      196523 :     fLLocations(0),
     114      196523 :     fLLocation(0),
     115      196523 :     fLIndices(0),
     116      196523 :     fPositionX(-1.),
     117      196523 :     fPositionY(-1.),
     118      196523 :     fDimensionX(-1.),
     119      196523 :     fDimensionY(-1.),
     120      196523 :     fValidity(false) 
     121      982615 : {
     122             : /// Copy constructor
     123             : 
     124      196523 :  *this = rhs;
     125      393046 : }
     126             : 
     127             : //_____________________________________________________________________________
     128             : AliMpPad::~AliMpPad() 
     129    33578674 : {
     130             : /// Destructor
     131             : 
     132     8936069 :   delete [] fLLocations;
     133    16789337 : }
     134             : 
     135             : //_____________________________________________________________________________
     136             : AliMpPad& AliMpPad::operator = (const AliMpPad& rhs) 
     137             : {
     138             : /// Assignment operator
     139             :  
     140             :   // check assignment to self
     141     1837006 :   if (this == &rhs) return *this;
     142             : 
     143             :   // base class assignment
     144      918503 :   TObject::operator=(rhs);
     145             : 
     146             :   // assignment operator
     147      918503 :   fLLocation   = rhs.fLLocation;
     148      918503 :   fLIndices    = rhs.fLIndices;
     149      918503 :   fPositionX   = rhs.fPositionX;
     150      918503 :   fPositionY   = rhs.fPositionY;
     151      918503 :   fDimensionX  = rhs.fDimensionX;
     152      918503 :   fDimensionY  = rhs.fDimensionY;
     153      918503 :   fValidity = rhs.fValidity;
     154             :   
     155      918503 :   delete [] fLLocations;
     156      918503 :   fLLocations = 0;
     157      918503 :   fNofLocations = rhs.fNofLocations;
     158      918503 :   if ( rhs.GetNofLocations() ) {
     159           0 :     fLLocations = new MpPair_t[fgkMaxNofLocations];
     160           0 :     for ( UInt_t i=0; i<rhs.fNofLocations; i++ )
     161           0 :       fLLocations[i] = rhs.fLLocations[i];
     162           0 :   }                     
     163             : 
     164      918503 :   return *this;
     165      918503 : }
     166             : 
     167             : //_____________________________________________________________________________
     168             : Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
     169             : {
     170             : /// Equality operator
     171             : 
     172             :   // are this and rhs equals?
     173             : 
     174             :   // one valid, one invalid
     175      219576 :   if (fValidity != rhs.fValidity) return false;
     176             :   
     177             :   // both invalid
     178       27996 :   if (!fValidity) return true;
     179             :   
     180             :   // both valid
     181             :   Bool_t sameLocations = true;
     182             :   
     183        2652 :   if (rhs.GetNofLocations()) {
     184           0 :     for (Int_t i=0; i<rhs.GetNofLocations(); i++) 
     185           0 :       if ( GetLocation(i) != rhs.GetLocation(i) )
     186           0 :         sameLocations = false;
     187           0 :   }
     188             :   
     189        2652 :   return    ( fLLocation  == rhs.fLLocation ) 
     190        4033 :          && ( fLIndices   == rhs.fLIndices )
     191        2762 :          && ( fPositionX  == rhs.fPositionX ) 
     192        2762 :          && ( fPositionY  == rhs.fPositionY ) 
     193        2762 :          && ( fDimensionX == rhs.fDimensionX )
     194        2762 :          && sameLocations;
     195       78300 : }
     196             : //_____________________________________________________________________________
     197             : Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
     198             : {
     199             : /// Non-equality operator
     200             : 
     201             :   // are this and rhs equals?
     202      151296 :   return !(*this==rhs);
     203             : }
     204             : 
     205             : //_____________________________________________________________________________
     206             : Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
     207             : {
     208             : /// Less operator
     209             : 
     210           0 :   if ( left.GetIx() < right.GetIx() ) return kTRUE;
     211           0 :   if ( left.GetIx() > right.GetIx() ) return kFALSE;
     212           0 :   if ( left.GetIy() < right.GetIy() ) return kTRUE;
     213           0 :   return kFALSE;
     214           0 : }
     215             : 
     216             : //_____________________________________________________________________________
     217             : Bool_t AliMpPad::AddLocation(Int_t localBoardId, Int_t localBoardChannel, 
     218             :                              Bool_t warn)
     219             : {
     220             : /// Add location to the collection if not yet present and
     221             : /// if collection is not yet full                                           \n
     222             : /// Return false and optionally give a warning if location is not 
     223             : /// added. 
     224             : 
     225             :   // Check maximum number limit
     226      797204 :   if ( GetNofLocations() == fgkMaxNofLocations ) {
     227           0 :     if (warn) {
     228           0 :       AliWarningStream() << "Cannot add location: ("
     229           0 :                          << localBoardId << "," << localBoardChannel << ")."
     230           0 :                          << "  Maximum number has been reached." << endl;
     231           0 :     }
     232           0 :     return false;
     233             :   }                      
     234             : 
     235             :   // Check if location is present
     236      797204 :   if ( HasLocation(localBoardId, localBoardChannel) ) {
     237           0 :     if (warn) {
     238           0 :       AliWarningStream() << "Cannot add location: "
     239           0 :                          << localBoardId << "," << localBoardChannel << ")."
     240           0 :                          << "  Location is already present." << endl;
     241           0 :     }
     242           0 :     return false;
     243             :   } 
     244             :   
     245             :   // Add location
     246      797204 :   if ( ! fLLocations)
     247      541138 :     fLLocations = new MpPair_t[fgkMaxNofLocations];
     248             :   
     249      797204 :   fLLocations[fNofLocations++] 
     250     1594408 :     = AliMp::Pair(localBoardId, localBoardChannel);
     251             : 
     252      797204 :   return true;
     253      797204 : }
     254             : 
     255             : //_____________________________________________________________________________
     256             : Int_t  AliMpPad::GetManuId() const
     257             : {
     258             : /// Return pad manu Id 
     259             : 
     260     1936090 :   return AliMp::PairFirst(fLLocation);
     261             : }  
     262             : 
     263             : //_____________________________________________________________________________
     264             : Int_t  AliMpPad::GetManuChannel() const
     265             : {
     266             : /// Return pad manu channel
     267             : 
     268     1930726 :   return AliMp::PairSecond(fLLocation);
     269             : }  
     270             : 
     271             : //_____________________________________________________________________________
     272             : Int_t  AliMpPad::GetIx() const
     273             : {
     274             : /// Return pad index ix
     275             : 
     276     1762962 :   return AliMp::PairFirst(fLIndices);
     277             : }  
     278             : 
     279             : //_____________________________________________________________________________
     280             : Int_t  AliMpPad::GetIy() const
     281             : {
     282             : /// Return pad index iy
     283             : 
     284     1762962 :   return AliMp::PairSecond(fLIndices);
     285             : }  
     286             : 
     287             : //_____________________________________________________________________________
     288             : void AliMpPad::PrintOn(ostream& out) const
     289             : {
     290             : /// Prints all pad data.
     291             : 
     292           0 :   if ( !fValidity ) {
     293           0 :     out << "Pad::Invalid";
     294           0 :     return;
     295             :   }  
     296             : 
     297           0 :   out << "Pad: Location ";
     298           0 :   AliMp::PairPut(out, fLLocation)
     299           0 :       << "  Indices ";     
     300           0 :   AliMp::PairPut(out,fLIndices)
     301           0 :       << "  Position "
     302           0 :       << "(" << fPositionX << "," << fPositionY << ")"
     303           0 :       << "  Dimensions "
     304           0 :       << "(" << fDimensionX << "," << fDimensionY << ")";
     305             : 
     306           0 :   if ( GetNofLocations() ) {
     307           0 :     out << endl;
     308           0 :     out << "     Other locations: ";
     309             : 
     310           0 :     for (Int_t i=0; i<GetNofLocations(); i++) 
     311           0 :         AliMp::PairPut(out,GetLocation(i)) << "  ";
     312           0 :   }
     313           0 : }
     314             : 
     315             : //_____________________________________________________________________________
     316             : void AliMpPad::Print(const char* /*option*/) const
     317             : {
     318             : /// Prints all pad data.
     319             : 
     320           0 :   PrintOn(cout);
     321           0 :   cout << endl;
     322           0 : }
     323             : 
     324             : //_____________________________________________________________________________
     325             : Int_t  AliMpPad::GetNofLocations() const
     326             : {
     327             : /// Return number of other locations associated with this pad
     328             : 
     329    11821365 :   if (!fLLocations) return 0;
     330             :   
     331     2905536 :   return fNofLocations;
     332     4908967 : }  
     333             :   
     334             : 
     335             : //_____________________________________________________________________________
     336             : MpPair_t AliMpPad::GetLocation(Int_t i) const
     337             : {
     338             : /// Return i-th other location associated with this pad
     339             : 
     340     1179930 :   if ( !fLLocations || i<0 || i>=GetNofLocations() ) 
     341           0 :     return 0;
     342             : 
     343      393310 :   return fLLocations[i];
     344      393310 : }  
     345             : 
     346             : //_____________________________________________________________________________
     347             : Int_t AliMpPad::GetLocalBoardId(Int_t i) const
     348             : {
     349             : /// Return i-th other local board Id associated with this pad
     350             : 
     351     1786497 :   if ( !fLLocations || i<0 || i>=GetNofLocations() ) 
     352           0 :     return 0;
     353             : 
     354      595499 :   return AliMp::PairFirst(fLLocations[i]);
     355      595499 : }  
     356             : 
     357             : //_____________________________________________________________________________
     358             : Int_t AliMpPad::GetLocalBoardChannel(Int_t i) const
     359             : {
     360             : /// Return i-th other local board channel associated with this pad
     361             : 
     362     1356153 :   if ( !fLLocations || i<0 || i>=GetNofLocations() ) 
     363           0 :     return 0;
     364             : 
     365      452051 :   return AliMp::PairSecond(fLLocations[i]);
     366      452051 : }  
     367             : 
     368             : //_____________________________________________________________________________
     369             : Bool_t AliMpPad::HasLocation(Int_t localBoardId, Int_t localBoardChannel) const
     370             : {
     371             : /// Return true if given location is present either as fLLocation
     372             : /// or in the collectio
     373             : 
     374     1594408 :   MpPair_t location = AliMp::Pair(localBoardId, localBoardChannel);
     375             : 
     376      797204 :   if (fLLocation == location) return true;
     377             : 
     378     3178232 :   for ( Int_t i=0; i<GetNofLocations(); i++ ) {
     379      393310 :     if ( GetLocation(i) == location ) return true;
     380             :   }
     381             :     
     382      797204 :   return false;
     383      797204 : }      
     384             : 
     385             : //_____________________________________________________________________________
     386             : ostream& operator<< (ostream &out, const AliMpPad& pad)
     387             : {
     388             : /// Output streaming
     389             : 
     390           0 :   pad.PrintOn(out);
     391             : 
     392           0 :   return out;
     393             : }
     394             : 

Generated by: LCOV version 1.11