LCOV - code coverage report
Current view: top level - MUON/MUONcore - AliMUON1DArray.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 61 47.5 %
Date: 2016-06-14 17:26:59 Functions: 9 17 52.9 %

          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 "AliMUON1DArray.h"
      19             : 
      20             : #include "AliLog.h"
      21             : #include <TClass.h>
      22             : #include <TObjArray.h>
      23             : #include <Riostream.h>
      24             : 
      25             : //-----------------------------------------------------------------------------
      26             : /// \class AliMUON1DArray
      27             : /// This class is simply a wrapper to a TObjArray, offering in addition a
      28             : /// control over the replacement policy when you add
      29             : /// something to it.
      30             : ///
      31             : /// \author Laurent Aphecetche
      32             : //-----------------------------------------------------------------------------
      33             : 
      34             : /// \cond CLASSIMP
      35          18 : ClassImp(AliMUON1DArray)
      36             : /// \endcond
      37             : 
      38             : //_____________________________________________________________________________
      39             : AliMUON1DArray::AliMUON1DArray(Int_t theSize)
      40           7 : : AliMUONVStore(),
      41           7 :   fArray(0x0)
      42          35 : {
      43             :     /// Default ctor
      44             : 
      45          14 :   if (theSize<=0) theSize=16;
      46             :         
      47          21 :   fArray = new TObjArray(theSize);
      48           7 :   fArray->SetOwner(kTRUE);
      49          14 : }
      50             : 
      51             : //_____________________________________________________________________________
      52             : AliMUON1DArray::AliMUON1DArray(const AliMUON1DArray& other)
      53           0 : : AliMUONVStore(),
      54           0 :   fArray(0x0)
      55           0 : {
      56             : /// Copy constructor
      57             : 
      58           0 :     AliDebug(1,Form("this=%p copy ctor",this));
      59           0 :   other.CopyTo(*this);
      60           0 : }
      61             : 
      62             : //_____________________________________________________________________________
      63             : AliMUON1DArray&
      64             : AliMUON1DArray::operator=(const AliMUON1DArray& other)
      65             : {
      66             : /// Assignment operator
      67             : 
      68           0 :   other.CopyTo(*this);
      69           0 :   return *this;
      70             : }
      71             : 
      72             : //_____________________________________________________________________________
      73             : AliMUON1DArray::~AliMUON1DArray()
      74          12 : {
      75             :   /// dtor, we're the owner of our internal array.
      76             : 
      77          10 :   AliDebug(1,Form("this=%p",this));
      78           4 :   delete fArray;
      79           6 : }
      80             : 
      81             : //_____________________________________________________________________________
      82             : Bool_t
      83             : AliMUON1DArray::Add(TObject* object)
      84             : {
      85             :   /// Add an object to this, if its uniqueID is below maxsize
      86          40 :   if (!object) return kFALSE;
      87             :   
      88          20 :   Int_t i = (Int_t)object->GetUniqueID();
      89          20 :   if ( i >= fArray->GetSize() ) 
      90             :   {
      91           0 :     AliError(Form("Index out of bounds %u (max is %u)",i,fArray->GetSize()));
      92           0 :     return kFALSE;
      93             :   }
      94             : 
      95          20 :   Set(object->GetUniqueID(),object,kFALSE);
      96          20 :   return kTRUE;
      97          20 : }
      98             : 
      99             : //_____________________________________________________________________________
     100             : void
     101             : AliMUON1DArray::Clear(Option_t* opt)
     102             : {
     103             :   /// Reset
     104           0 :   fArray->Clear(opt);
     105           0 : }
     106             : 
     107             : //_____________________________________________________________________________
     108             : void
     109             : AliMUON1DArray::CopyTo(AliMUON1DArray& dest) const
     110             : {
     111             : /// Make a deep copy
     112             : 
     113           0 :   delete dest.fArray;
     114           0 :   dest.fArray = 0;
     115           0 :   dest.fArray = new TObjArray(fArray->GetSize());
     116           0 :   dest.fArray->SetOwner(kTRUE);
     117           0 :   for ( Int_t i = 0; i < fArray->GetLast(); ++i )
     118             :   {
     119           0 :     dest.fArray->AddAt(fArray->At(i)->Clone(),i);
     120             :   }
     121           0 : }
     122             : 
     123             : //_____________________________________________________________________________
     124             : AliMUON1DArray* 
     125             : AliMUON1DArray::Create() const 
     126             : {
     127             :   /// Create an empty clone of this
     128           0 :   return new AliMUON1DArray(fArray->GetSize());
     129           0 : }
     130             : 
     131             : //_____________________________________________________________________________
     132             : TObject* 
     133             : AliMUON1DArray::FindObject(UInt_t i) const
     134             : {
     135             :   /// Get the object located at index i, if it exists, and if i is correct.
     136             : 
     137       70256 :   if ( (Int_t)(i) < fArray->GetSize() )
     138             :   {
     139       35128 :     return fArray->At(i);
     140             :   }
     141           0 :   AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
     142           0 :   return 0x0;
     143       35128 : }
     144             : 
     145             : //_____________________________________________________________________________
     146             : TIterator* 
     147             : AliMUON1DArray::CreateIterator() const
     148             : {
     149             :   /// Return an iterator on this
     150           0 :   return fArray->MakeIterator();
     151             : }
     152             : 
     153             : //_____________________________________________________________________________
     154             : Bool_t 
     155             : AliMUON1DArray::Set(Int_t i, TObject* object, Bool_t replace)
     156             : {
     157             : /// Set the object located at i
     158             : /// If replace=kFALSE and there's already an object at location i,
     159             : /// this method fails and returns kFALSE, otherwise it returns kTRUE
     160             : 
     161          40 :   if ( i >= 0 && i < fArray->GetSize() )
     162             :   {
     163          20 :     if (((Int_t)(object->GetUniqueID()))!=i)
     164             :     {
     165           0 :       AliError(Form("object's UniqueID is %d, which is different from the expected %d",
     166             :                     object->GetUniqueID(),i));
     167           0 :       return kFALSE;
     168             :     }
     169             :     
     170          20 :     TObject* o = FindObject(i);
     171          20 :     if ( o && !replace )
     172             :     {
     173           0 :       AliError(Form("Object %p is already there for i=%d",o,i));
     174           0 :       return kFALSE;
     175             :     }
     176          20 :     if ( o && replace ) 
     177             :     {
     178           0 :       delete o;
     179             :     }
     180          20 :     fArray->AddAt(object,i);
     181          20 :     return kTRUE;
     182             :   }
     183           0 :   AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
     184           0 :   return kFALSE;
     185          20 : }
     186             : 
     187             : //_____________________________________________________________________________
     188             : Int_t 
     189             : AliMUON1DArray::GetSize() const
     190             : {
     191             :   /// Return the number of object we hold
     192           0 :   return fArray->GetEntries();
     193             : }

Generated by: LCOV version 1.11