LCOV - code coverage report
Current view: top level - MUON/MUONcore - AliMUON2DMap.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 50 74 67.6 %
Date: 2016-06-14 17:26:59 Functions: 15 21 71.4 %

          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 "AliMUON2DMap.h"
      19             : 
      20             : #include "AliLog.h"
      21             : #include "AliMUON2DMapIterator.h"
      22             : #include "AliMUON2DMapIteratorByI.h"
      23             : #include "AliMpExMap.h"
      24             : #include "AliMpExMapIterator.h"
      25             : 
      26             : //-----------------------------------------------------------------------------
      27             : /// \class AliMUON2DMap
      28             : /// Basic implementation of AliMUONVStore container using
      29             : /// AliMpExMap internally.
      30             : /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
      31             : ///
      32             : /// \author Laurent Aphecetche
      33             : //-----------------------------------------------------------------------------
      34             : 
      35             : /// \cond CLASSIMP
      36          18 : ClassImp(AliMUON2DMap)
      37             : /// \endcond
      38             : 
      39             : const Int_t AliMUON2DMap::fgkOptimalSizeForDEManu = 228;
      40             : 
      41             : //_____________________________________________________________________________
      42             : AliMUON2DMap::AliMUON2DMap(TRootIOCtor*)
      43          13 : : AliMUONVStore(), 
      44          13 : fMap(0x0),
      45          13 : fOptimizeForDEManu(kFALSE)
      46          65 : {
      47             :   /// Root I/O constructor.
      48          26 : }
      49             : 
      50             : //_____________________________________________________________________________
      51             : AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu) 
      52          31 : : AliMUONVStore(), 
      53          93 :   fMap(new AliMpExMap),
      54          31 :   fOptimizeForDEManu(optimizeForDEManu)
      55          93 : {
      56             :   /// Default constructor.
      57             :   // hard-coded constant in order not to depend on mapping
      58             :   // if this number ever change, it will not break the code, simply the
      59             :   // automatic resizing will give a warning...
      60             :     
      61          60 :   if ( fOptimizeForDEManu ) fMap->SetSize(fgkOptimalSizeForDEManu); 
      62          62 : }
      63             : 
      64             : //_____________________________________________________________________________
      65             : AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
      66           0 : : AliMUONVStore(),
      67           0 :   fMap(new AliMpExMap(*other.fMap)),
      68           0 :   fOptimizeForDEManu(other.fOptimizeForDEManu)
      69           0 : {
      70             :  /// Copy constructor.
      71           0 : }
      72             : 
      73             : //_____________________________________________________________________________
      74             : AliMUON2DMap&
      75             : AliMUON2DMap::operator=(const AliMUON2DMap& other)
      76             : {
      77             : /// Assignment operator
      78           0 :   if ( this != &other )
      79             :   {
      80           0 :     *fMap = *other.fMap;
      81           0 :     fOptimizeForDEManu = other.fOptimizeForDEManu;
      82           0 :   }
      83           0 :   return *this;
      84             : }
      85             : 
      86             : //_____________________________________________________________________________
      87             : AliMUON2DMap::~AliMUON2DMap()
      88         186 : {
      89             : /// Destructor. 
      90             : /// We delete the map, which will delete the objects, as we're owner.
      91          62 :   delete fMap;
      92          93 : }
      93             : 
      94             : //_____________________________________________________________________________
      95             : AliMUONVStore*
      96             : AliMUON2DMap::Create() const
      97             : {
      98             :   /// Create a void copy of *this. 
      99           0 :   return new AliMUON2DMap(fOptimizeForDEManu);
     100           0 : }
     101             : 
     102             : //_____________________________________________________________________________
     103             : Bool_t
     104             : AliMUON2DMap::Add(TObject* object)
     105             : {
     106             :   /// Add object, using the decoding of uniqueID into two ints as the key
     107      169768 :   if (!object) return kFALSE;
     108       84884 :   UInt_t uniqueID = object->GetUniqueID();
     109       84884 :   Int_t j = ( uniqueID & 0xFFFF0000 ) >> 16;
     110       84884 :   Int_t i = ( uniqueID & 0xFFFF);
     111       84884 :   return Set(i,j,object,kFALSE);
     112       84884 : }
     113             : 
     114             : //_____________________________________________________________________________
     115             : TObject* 
     116             : AliMUON2DMap::FindObject(UInt_t uid) const
     117             : {
     118             :   /// Return the value at position uid
     119             :   
     120           0 :   Int_t j = ( uid & 0xFFFF0000 ) >> 16;
     121           0 :   Int_t i = ( uid & 0xFFFF);
     122           0 :   return FindObject(i,j);
     123             : }
     124             : 
     125             : //_____________________________________________________________________________
     126             : TObject* 
     127             : AliMUON2DMap::FindObject(Int_t i, Int_t j) const
     128             : {
     129             :   /// Return the value at position (i,j).
     130     9938646 :   AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
     131    12770105 :   return m ? m->GetValue(j) : 0x0;
     132             : }
     133             : 
     134             : //_____________________________________________________________________________
     135             : TIterator*
     136             : AliMUON2DMap::CreateIterator() const
     137             : {
     138             :   // Create and return an iterator on this map
     139             :   // Returned iterator must be deleted by user.
     140          12 :   return new AliMUON2DMapIterator(*fMap);
     141           0 : }
     142             : 
     143             : //_____________________________________________________________________________
     144             : TIterator*
     145             : AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
     146             : {
     147             :   // Create and return an iterator on this map
     148             :   // Returned iterator must be deleted by user.
     149        2883 :   return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
     150           0 : }
     151             : 
     152             : //_____________________________________________________________________________
     153             : void 
     154             : AliMUON2DMap::Clear(Option_t*)
     155             : {
     156             :   /// Clear memory
     157        2884 :   fMap->Clear();
     158        1442 : }  
     159             : 
     160             : //_____________________________________________________________________________
     161             : Int_t 
     162             : AliMUON2DMap::GetSize() const
     163             : {
     164             :   /// Return the number of objects we hold
     165           4 :   TIter next(fMap->CreateIterator());
     166             :   Int_t theSize(0);
     167             :   AliMpExMap* m;
     168             :   
     169         942 :   while ( ( m = static_cast<AliMpExMap*>(next()) ) )
     170             :   {
     171         624 :     TIter next2(m->CreateIterator());
     172      101592 :     while ( next2() ) 
     173             :     {
     174       33656 :       ++theSize;
     175             :     }
     176         312 :   }
     177             :   return theSize;
     178           2 : }
     179             : 
     180             : //_____________________________________________________________________________
     181             : Int_t 
     182             : AliMUON2DMap::GetSize(Int_t i) const
     183             : {
     184             :   /// Return the number of objects we hold
     185           0 :   AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
     186           0 :   return m ? m->GetSize() : 0;
     187             : }
     188             : 
     189             : //_____________________________________________________________________________
     190             : Bool_t 
     191             : AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
     192             : {
     193             : /// Set the object at position (i,j).
     194             : /// If replace==kTRUE, we don't care if there's an object there already,
     195             : /// otherwise we might refuse to set if the (i,j) location is already
     196             : /// filled (in which case we return kFALSE).
     197             :   
     198       84884 :   TObject* o = fMap->GetValue(i);
     199       84884 :   if ( !o )
     200             :   {
     201        4880 :     AliMpExMap* m = new AliMpExMap;
     202        4880 :     if ( fOptimizeForDEManu ) 
     203             :     {
     204        4600 :       m->SetSize(451); // same remark as for the SetSize in ctor...
     205        4600 :     }
     206        4880 :     fMap->Add(i,m);
     207        4880 :     o = fMap->GetValue(i);
     208        4880 :   }
     209       84884 :   AliMpExMap* m = static_cast<AliMpExMap*>(o);
     210             :  
     211       84884 :   o = m->GetValue(j);
     212             :   
     213       84884 :   if ( !o )
     214             :   {
     215       84884 :     m->Add(j,object);
     216       84884 :   }
     217             :   else 
     218             :   {
     219           0 :     if ( replace ) 
     220             :     {
     221           0 :       delete o;
     222           0 :       m->Add(j,object);
     223             :     }
     224             :     else
     225             :     {
     226           0 :       AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
     227           0 :       return kFALSE;
     228             :     }
     229             :   }
     230             : 
     231       84884 :   return kTRUE;
     232       84884 : }
     233             : 

Generated by: LCOV version 1.11