LCOV - code coverage report
Current view: top level - MUON/MUONmapping - AliMpSlatMotifMap.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 67 62.7 %
Date: 2016-06-14 17:26:59 Functions: 11 12 91.7 %

          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             : 
      17             : //-----------------------------------------------------------------------------
      18             : /// \class AliMpSlatMotifMap
      19             : //
      20             : /// Basically this class provide a garbage collection of AliMpMotif and
      21             : /// AliMpMotifType objects.
      22             : ///
      23             : ///
      24             : /// \author Laurent Aphecetche
      25             : //-----------------------------------------------------------------------------
      26             : 
      27             : 
      28             : // $Id$
      29             : 
      30             : #include "AliMpSlatMotifMap.h"
      31             : 
      32             : #include "AliMpVMotif.h"
      33             : #include "AliMpMotifType.h"
      34             : #include "AliLog.h"
      35             : #include "TList.h"
      36             : #include "TObjString.h"
      37             : #include "TString.h"
      38             : #include "Riostream.h"
      39             : 
      40             : using std::cout;
      41             : using std::endl;
      42             : /// \cond CLASSIMP
      43          18 : ClassImp(AliMpSlatMotifMap)
      44             : /// \endcond
      45             : 
      46             : //_____________________________________________________________________________
      47             : AliMpSlatMotifMap::AliMpSlatMotifMap()
      48           3 : : TObject(),
      49           3 : fMotifs(),
      50           3 : fMotifTypes()
      51          15 : {
      52             :   /// ctor
      53           3 :   fMotifs.SetOwner(kTRUE);
      54           3 :   fMotifTypes.SetOwner(kTRUE);
      55           6 : }
      56             : 
      57             : //_____________________________________________________________________________
      58             : AliMpSlatMotifMap::~AliMpSlatMotifMap()
      59          12 : {
      60             :   /// dtor
      61           2 :   Reset();
      62           6 : }
      63             : 
      64             : //_____________________________________________________________________________
      65             : void
      66             : AliMpSlatMotifMap::Reset()
      67             : {
      68             :   /// Clear
      69           4 :   fMotifs.DeleteAll();
      70           2 :   fMotifTypes.DeleteAll();
      71           2 : }
      72             : 
      73             : //_____________________________________________________________________________
      74             : Bool_t 
      75             : AliMpSlatMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
      76             : {
      77             :   /// Add a motif to the map
      78        1386 :   AliDebug(1,Form("Adding motif %s",motif->GetID().Data()));
      79             :   
      80         924 :   AliMpVMotif* found = FindMotif(motif->GetID());
      81         462 :   if (found) {    
      82           0 :     if (warn && found == motif) 
      83             :     {
      84           0 :       AliWarning(Form("The motif %s is already in map",motif->GetID().Data()));
      85           0 :     }
      86           0 :     if (warn && found != motif) 
      87             :     {
      88           0 :       AliError(Form("Another motif with the same ID=%s is already in map",
      89             :                     motif->GetID().Data()));
      90           0 :     }        
      91           0 :     return false;
      92             :   }  
      93             :   
      94        2310 :   fMotifs.Add(new TObjString(motif->GetID()),motif);
      95         462 :   return true;
      96         462 : }
      97             : 
      98             : //_____________________________________________________________________________
      99             : Bool_t 
     100             : AliMpSlatMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
     101             : {
     102             :   /// Add a motif to the map
     103             : 
     104         963 :   AliDebug(1,Form("Adding motifType %s",motifType->GetID().Data()));
     105             : 
     106         642 :   AliMpMotifType* found = FindMotifType(motifType->GetID());
     107         321 :   if (found) {    
     108           0 :     if (warn && found == motifType) 
     109             :     {
     110           0 :       AliWarning(Form("The motifType %s is already in map",
     111             :                       motifType->GetID().Data()));
     112           0 :     }
     113           0 :     if (warn && found != motifType)   
     114             :     {
     115           0 :       AliError(Form("Another motifType with the same ID=%s is already in map",
     116             :                     motifType->GetID().Data()));
     117           0 :     }        
     118           0 :     return false;
     119             :   }  
     120             :   
     121        1605 :   fMotifTypes.Add(new TObjString(motifType->GetID()),motifType);
     122         321 :   return true;
     123             :   
     124         321 : }
     125             : 
     126             : //_____________________________________________________________________________
     127             : AliMpVMotif* 
     128             : AliMpSlatMotifMap::FindMotif(const TString& id) const
     129             : {
     130             :   /// Search a given motif in the map and returns it if it's there.
     131             :   
     132       40764 :   AliDebug(1,Form("Looking for motif %s",id.Data()));
     133             :   
     134       10191 :   TObject* object = fMotifs.GetValue(id.Data());
     135             :   
     136       10191 :   if (object)
     137             :   {
     138        9267 :     AliMpVMotif* motif = static_cast<AliMpVMotif*>(object);
     139       27801 :     AliDebug(1,Form("Found : %p id=%s",motif,motif->GetID().Data()));
     140             :     return motif;
     141             :   }
     142        2772 :   AliDebug(1,"Not found");
     143         924 :   return 0x0;
     144       10191 : }
     145             : 
     146             : //_____________________________________________________________________________
     147             : AliMpMotifType* 
     148             : AliMpSlatMotifMap::FindMotifType(const TString& id) const
     149             : {
     150             :   /// Search a given motifType in the map and returns it if it's there.
     151       39384 :   AliDebug(1,Form("Looking for motifType %s",id.Data()));
     152             :   
     153        9846 :   TObject* object = fMotifTypes.GetValue(id.Data());
     154             :   
     155        9846 :   if (object)
     156             :   {
     157        9204 :     AliMpMotifType* motifType = static_cast<AliMpMotifType*>(object);
     158       27612 :     AliDebug(1,Form("Found : %p id=%s",motifType,motifType->GetID().Data()));
     159             :     return motifType;
     160             :   }
     161        1926 :   AliDebug(1,"Not found");
     162         642 :   return 0x0;
     163             :   
     164        9846 : }
     165             : 
     166             : //_____________________________________________________________________________
     167             : void
     168             : AliMpSlatMotifMap::Print(Option_t*) const
     169             : {
     170             :   /// printout
     171           0 :   cout << "Motifs=" << endl;
     172             :   TObject* key;
     173           0 :   TIter next(&fMotifs);
     174           0 :   while ( ( key = next() ) ) 
     175             :   {
     176           0 :     AliMpVMotif* motif = dynamic_cast<AliMpVMotif*>(fMotifs.GetValue(key));
     177           0 :     if (motif) cout << motif->GetID() << endl;
     178             :   }
     179             : 
     180           0 :   cout << "MotifTypes=" << endl;
     181           0 :   TIter tnext(&fMotifTypes);
     182           0 :   while ( ( key = tnext() ) ) 
     183             :   {
     184           0 :     AliMpMotifType* motifType = dynamic_cast<AliMpMotifType*>(fMotifTypes.GetValue(key));
     185           0 :     if (motifType) cout << motifType->GetID() << endl;
     186             :   }
     187             :   
     188           0 : }

Generated by: LCOV version 1.11