ROOT logo
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
*                                                                        *
* Author: The ALICE Off-line Project.                                    *
* Contributors are mentioned in the code where appropriate.              *
*                                                                        *
* Permission to use, copy, modify and distribute this software and its   *
* documentation strictly for non-commercial purposes is hereby granted   *
* without fee, provided that the above copyright notice appears in all   *
* copies and that both the copyright notice and this permission notice   *
* appear in the supporting documentation. The authors make no claims     *
* about the suitability of this software for any purpose. It is          *
* provided "as is" without express or implied warranty.                  *
**************************************************************************/

// $Id$

//-----------------------------------------------------------------------------
/// \class AliMUONVDigitStore
///
/// Interface for a digit (or sdigit) container
///
/// It offers methods to Add, Find and Remove single elements, and
/// can create iterators to loop over (part of) the elements.
///
/// \author Laurent Aphecetche, Subatech
//-----------------------------------------------------------------------------

#include "AliMUONVDigitStore.h"

#include "AliLog.h"
#include "AliMUONVDigit.h"
#include <TClass.h>
#include <TString.h>
#include <TTree.h>

/// \cond CLASSIMP
ClassImp(AliMUONVDigitStore)
/// \endcond

//_____________________________________________________________________________
AliMUONVDigitStore::AliMUONVDigitStore()
{
  /// ctor
}

//_____________________________________________________________________________
AliMUONVDigitStore::~AliMUONVDigitStore()
{
  /// dtor
}

//_____________________________________________________________________________
Bool_t 
AliMUONVDigitStore::Add(TObject* object)
{
  /// Add an object, if it is of type AliMUONVDigit
  if (object)
  {
    AliMUONVDigit* digit = dynamic_cast<AliMUONVDigit*>(object);
    if (digit)
    {
      AliMUONVDigit* added = Add(*digit,AliMUONVDigitStore::kIgnore);
      if (!added)
      {
        AliError("Could not add digit through Add(TObject*) method");
      }
      else
      {
        return kTRUE;
      }
    }
  }
  return kFALSE;
}

//_____________________________________________________________________________
AliMUONVDigit* 
AliMUONVDigitStore::Add(Int_t detElemId, 
                       Int_t manuId,
                       Int_t manuChannel,
                       Int_t cathode,
                       EReplacePolicy replace)
{
  /// Add a digit and return it
  AliMUONVDigit* digit = CreateDigit(detElemId,manuId,manuChannel,cathode);
  if (digit)
  {
    AliMUONVDigit* d = Add(*digit,replace);
    delete digit;
    return d;
  }
  return 0x0;
}

//____________________________________________________________________________
AliMUONVDigitStore* 
AliMUONVDigitStore::Create(const char* digitstoreclassname)
{
  /// Create a concrete digitStore, given its classname
  
  TClass* classPtr = TClass::GetClass(digitstoreclassname);
  if (!classPtr || !classPtr->InheritsFrom("AliMUONVDigitStore"))
  {
    return 0x0;
  }
  
  AliMUONVDigitStore* digitStore = 
    reinterpret_cast<AliMUONVDigitStore*>(classPtr->New());
  
  return digitStore;
}

//_____________________________________________________________________________
AliMUONVDigitStore*
AliMUONVDigitStore::Create(TTree& tree)
{
  /// Create store from the given tree (if possible).
  TString dataType = ( strcmp(tree.GetName(),"TreeD") == 0 ? "Digit" : 
                       (strcmp(tree.GetName(),"TreeS")== 9 ? "SDigit" : "")
                       );
  return static_cast<AliMUONVDigitStore*>(AliMUONVStore::Create(tree,dataType.Data()));
}

//_____________________________________________________________________________
AliMUONVDigit* 
AliMUONVDigitStore::FindObject(const TObject* object) const
{
  /// Find an object, if of AliMUONVDigit type.
  const AliMUONVDigit* digit = dynamic_cast<const AliMUONVDigit*>(object);
  if (digit)
  {
    return FindObject(digit->GetUniqueID());
  }
  return 0x0;
}

//_____________________________________________________________________________
AliMUONVDigit* 
AliMUONVDigitStore::FindObject(UInt_t uniqueID) const
{
  /// Find digit by its uniqueID
  
  return FindObject(AliMUONVDigit::DetElemId(uniqueID),
                    AliMUONVDigit::ManuId(uniqueID),
                    AliMUONVDigit::ManuChannel(uniqueID),
                    AliMUONVDigit::Cathode(uniqueID));
}

//_____________________________________________________________________________
Int_t 
AliMUONVDigitStore::GetSize(Int_t detElemId, Int_t cathode) const
{
  /// Return the number of digits we have for a given detection element
  TIter next(CreateIterator(detElemId,detElemId,cathode));
  Int_t n(0);
  while ( ( next() ) )
  {
    ++n;
  }
  return n;
}

 AliMUONVDigitStore.cxx:1
 AliMUONVDigitStore.cxx:2
 AliMUONVDigitStore.cxx:3
 AliMUONVDigitStore.cxx:4
 AliMUONVDigitStore.cxx:5
 AliMUONVDigitStore.cxx:6
 AliMUONVDigitStore.cxx:7
 AliMUONVDigitStore.cxx:8
 AliMUONVDigitStore.cxx:9
 AliMUONVDigitStore.cxx:10
 AliMUONVDigitStore.cxx:11
 AliMUONVDigitStore.cxx:12
 AliMUONVDigitStore.cxx:13
 AliMUONVDigitStore.cxx:14
 AliMUONVDigitStore.cxx:15
 AliMUONVDigitStore.cxx:16
 AliMUONVDigitStore.cxx:17
 AliMUONVDigitStore.cxx:18
 AliMUONVDigitStore.cxx:19
 AliMUONVDigitStore.cxx:20
 AliMUONVDigitStore.cxx:21
 AliMUONVDigitStore.cxx:22
 AliMUONVDigitStore.cxx:23
 AliMUONVDigitStore.cxx:24
 AliMUONVDigitStore.cxx:25
 AliMUONVDigitStore.cxx:26
 AliMUONVDigitStore.cxx:27
 AliMUONVDigitStore.cxx:28
 AliMUONVDigitStore.cxx:29
 AliMUONVDigitStore.cxx:30
 AliMUONVDigitStore.cxx:31
 AliMUONVDigitStore.cxx:32
 AliMUONVDigitStore.cxx:33
 AliMUONVDigitStore.cxx:34
 AliMUONVDigitStore.cxx:35
 AliMUONVDigitStore.cxx:36
 AliMUONVDigitStore.cxx:37
 AliMUONVDigitStore.cxx:38
 AliMUONVDigitStore.cxx:39
 AliMUONVDigitStore.cxx:40
 AliMUONVDigitStore.cxx:41
 AliMUONVDigitStore.cxx:42
 AliMUONVDigitStore.cxx:43
 AliMUONVDigitStore.cxx:44
 AliMUONVDigitStore.cxx:45
 AliMUONVDigitStore.cxx:46
 AliMUONVDigitStore.cxx:47
 AliMUONVDigitStore.cxx:48
 AliMUONVDigitStore.cxx:49
 AliMUONVDigitStore.cxx:50
 AliMUONVDigitStore.cxx:51
 AliMUONVDigitStore.cxx:52
 AliMUONVDigitStore.cxx:53
 AliMUONVDigitStore.cxx:54
 AliMUONVDigitStore.cxx:55
 AliMUONVDigitStore.cxx:56
 AliMUONVDigitStore.cxx:57
 AliMUONVDigitStore.cxx:58
 AliMUONVDigitStore.cxx:59
 AliMUONVDigitStore.cxx:60
 AliMUONVDigitStore.cxx:61
 AliMUONVDigitStore.cxx:62
 AliMUONVDigitStore.cxx:63
 AliMUONVDigitStore.cxx:64
 AliMUONVDigitStore.cxx:65
 AliMUONVDigitStore.cxx:66
 AliMUONVDigitStore.cxx:67
 AliMUONVDigitStore.cxx:68
 AliMUONVDigitStore.cxx:69
 AliMUONVDigitStore.cxx:70
 AliMUONVDigitStore.cxx:71
 AliMUONVDigitStore.cxx:72
 AliMUONVDigitStore.cxx:73
 AliMUONVDigitStore.cxx:74
 AliMUONVDigitStore.cxx:75
 AliMUONVDigitStore.cxx:76
 AliMUONVDigitStore.cxx:77
 AliMUONVDigitStore.cxx:78
 AliMUONVDigitStore.cxx:79
 AliMUONVDigitStore.cxx:80
 AliMUONVDigitStore.cxx:81
 AliMUONVDigitStore.cxx:82
 AliMUONVDigitStore.cxx:83
 AliMUONVDigitStore.cxx:84
 AliMUONVDigitStore.cxx:85
 AliMUONVDigitStore.cxx:86
 AliMUONVDigitStore.cxx:87
 AliMUONVDigitStore.cxx:88
 AliMUONVDigitStore.cxx:89
 AliMUONVDigitStore.cxx:90
 AliMUONVDigitStore.cxx:91
 AliMUONVDigitStore.cxx:92
 AliMUONVDigitStore.cxx:93
 AliMUONVDigitStore.cxx:94
 AliMUONVDigitStore.cxx:95
 AliMUONVDigitStore.cxx:96
 AliMUONVDigitStore.cxx:97
 AliMUONVDigitStore.cxx:98
 AliMUONVDigitStore.cxx:99
 AliMUONVDigitStore.cxx:100
 AliMUONVDigitStore.cxx:101
 AliMUONVDigitStore.cxx:102
 AliMUONVDigitStore.cxx:103
 AliMUONVDigitStore.cxx:104
 AliMUONVDigitStore.cxx:105
 AliMUONVDigitStore.cxx:106
 AliMUONVDigitStore.cxx:107
 AliMUONVDigitStore.cxx:108
 AliMUONVDigitStore.cxx:109
 AliMUONVDigitStore.cxx:110
 AliMUONVDigitStore.cxx:111
 AliMUONVDigitStore.cxx:112
 AliMUONVDigitStore.cxx:113
 AliMUONVDigitStore.cxx:114
 AliMUONVDigitStore.cxx:115
 AliMUONVDigitStore.cxx:116
 AliMUONVDigitStore.cxx:117
 AliMUONVDigitStore.cxx:118
 AliMUONVDigitStore.cxx:119
 AliMUONVDigitStore.cxx:120
 AliMUONVDigitStore.cxx:121
 AliMUONVDigitStore.cxx:122
 AliMUONVDigitStore.cxx:123
 AliMUONVDigitStore.cxx:124
 AliMUONVDigitStore.cxx:125
 AliMUONVDigitStore.cxx:126
 AliMUONVDigitStore.cxx:127
 AliMUONVDigitStore.cxx:128
 AliMUONVDigitStore.cxx:129
 AliMUONVDigitStore.cxx:130
 AliMUONVDigitStore.cxx:131
 AliMUONVDigitStore.cxx:132
 AliMUONVDigitStore.cxx:133
 AliMUONVDigitStore.cxx:134
 AliMUONVDigitStore.cxx:135
 AliMUONVDigitStore.cxx:136
 AliMUONVDigitStore.cxx:137
 AliMUONVDigitStore.cxx:138
 AliMUONVDigitStore.cxx:139
 AliMUONVDigitStore.cxx:140
 AliMUONVDigitStore.cxx:141
 AliMUONVDigitStore.cxx:142
 AliMUONVDigitStore.cxx:143
 AliMUONVDigitStore.cxx:144
 AliMUONVDigitStore.cxx:145
 AliMUONVDigitStore.cxx:146
 AliMUONVDigitStore.cxx:147
 AliMUONVDigitStore.cxx:148
 AliMUONVDigitStore.cxx:149
 AliMUONVDigitStore.cxx:150
 AliMUONVDigitStore.cxx:151
 AliMUONVDigitStore.cxx:152
 AliMUONVDigitStore.cxx:153
 AliMUONVDigitStore.cxx:154
 AliMUONVDigitStore.cxx:155
 AliMUONVDigitStore.cxx:156
 AliMUONVDigitStore.cxx:157
 AliMUONVDigitStore.cxx:158
 AliMUONVDigitStore.cxx:159
 AliMUONVDigitStore.cxx:160
 AliMUONVDigitStore.cxx:161
 AliMUONVDigitStore.cxx:162
 AliMUONVDigitStore.cxx:163