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 AliMUONClusterStoreV1
///
/// Implementation of VClusterStore.
///
/// This one is a basic implementation, let's say "legacy" one, i.e.
/// compatible with what we stored in MUON.RecPoints.root files before
/// the switch to data stores.
///
/// \author Laurent Aphecetche, Subatech
///
//-----------------------------------------------------------------------------

#include "AliMUONClusterStoreV1.h"

#include "AliLog.h"
#include "AliMUONRawCluster.h"
#include "AliMUONTOTCAStoreIterator.h"
#include "AliMUONTreeManager.h"
#include "AliMpConstants.h"
#include "AliMpDEManager.h"
#include <TClonesArray.h>
#include <TObjArray.h>
#include <TTree.h>

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

//_____________________________________________________________________________
AliMUONClusterStoreV1::AliMUONClusterStoreV1() 
: AliMUONVClusterStore(), 
fClusters(new TObjArray(AliMpConstants::NofChambers()))
{
  /// ctor. Set correct ownerships
  fClusters->SetOwner(kTRUE);
  for ( Int_t i = 0; i < fClusters->GetSize(); ++i )
  {
    TClonesArray* tca = new TClonesArray("AliMUONRawCluster",100);
    fClusters->AddAt(tca,i);
  }
  AliDebug(1,"");
}

//_____________________________________________________________________________
AliMUONClusterStoreV1::AliMUONClusterStoreV1(const AliMUONClusterStoreV1&)
: AliMUONVClusterStore(), 
fClusters(0x0)
{
  /// copy ctor
  AliError("Please implement me");
}

//_____________________________________________________________________________
AliMUONClusterStoreV1& 
AliMUONClusterStoreV1::operator=(const AliMUONClusterStoreV1&)
{
  /// assignment operator
  AliError("Please implement me");
  return *this;
}

//_____________________________________________________________________________
AliMUONClusterStoreV1::~AliMUONClusterStoreV1()
{
  /// dtor
  AliDebug(1,"");
  delete fClusters;
}

//_____________________________________________________________________________
AliMUONVCluster* AliMUONClusterStoreV1::CreateCluster(Int_t /*chamberId*/, Int_t detElemId, Int_t /*clusterIndex*/) const
{
  /// Create a cluster
  AliMUONVCluster* vCluster = new AliMUONRawCluster();
  (static_cast<AliMUONRawCluster*> (vCluster))->SetDetElemId(detElemId);
  return vCluster;
}

//_____________________________________________________________________________
AliMUONVCluster* 
AliMUONClusterStoreV1::Add(const AliMUONVCluster& vCluster)
{
  /// Add a cluster to this store
  const AliMUONRawCluster* cluster = dynamic_cast<const AliMUONRawCluster*>(&vCluster);
  
  if (!cluster)
  {
    AliError(Form("Cluster is not of the expected type (%s vs AliMUONRawCluster)",
                  vCluster.ClassName()));
    return 0x0;
  }
  
  Int_t iChamber = AliMpDEManager::GetChamberId(cluster->GetDetElemId());
  TClonesArray* array = ChamberClusters(iChamber);
  if (!array) 
  {
    return 0x0;
  }
  
  return new((*array)[array->GetLast()+1]) AliMUONRawCluster(*cluster);
}

//_____________________________________________________________________________
AliMUONVCluster* AliMUONClusterStoreV1::Add(Int_t chamberId, Int_t detElemId, Int_t /*clusterIndex*/)
{
  /// Add a cluster to this store
  TClonesArray* array = ChamberClusters(chamberId);
  if (!array) return 0x0;
  
  AliMUONVCluster* vCluster = static_cast<AliMUONVCluster*> (new((*array)[array->GetLast()+1]) AliMUONRawCluster());
  (static_cast<AliMUONRawCluster*> (vCluster))->SetDetElemId(detElemId);
  return vCluster;
}

//_____________________________________________________________________________
TClonesArray*
AliMUONClusterStoreV1::ChamberClusters(Int_t chamberId) const
{
  /// Get the internal array of clusters for a given chamber
  TClonesArray* array = static_cast<TClonesArray*>(fClusters->At(chamberId));
  if (!array) 
  {
    AliError(Form("Cannot get Clusters for chamberId=%d",chamberId));
    return 0x0;
  }
  return array;
}

//_____________________________________________________________________________
TObject**
AliMUONClusterStoreV1::ChamberClustersPtr(Int_t chamberId) const
{
  /// Get the internal array of clusters for a given chamber
  TClonesArray* array = static_cast<TClonesArray*>(fClusters->At(chamberId));
  if (!array) 
  {
    AliError(Form("Cannot get Clusters for chamberId=%d",chamberId));
    return 0x0;
  }
  return fClusters->GetObjectRef(array);
}

//_____________________________________________________________________________
Bool_t
AliMUONClusterStoreV1::Connect(TTree& tree, Bool_t alone) const
{
  /// Connect this to the tree, i.e. make the branches or set their addresses.
  
  AliMUONTreeManager tman;
  Bool_t ok(kTRUE);
  
  TBranch* b = tree.GetBranch("MUONRawClusters1");
  
  Bool_t isMaking = (b == 0);
  
  if ( isMaking ) 
  {
    for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i ) 
    {
      TString branchName(Form("MUONRawClusters%d",i+1));
      ok = ok && tman.MakeBranch(tree,ClassName(),"TClonesArray",
                                 branchName.Data(),ChamberClustersPtr(i));
    }
    
  }
  else
  {
    if (alone) tman.UpdateBranchStatuses(tree,"MUONRawClusters");
    for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i ) 
    {
      TString branchName(Form("MUONRawClusters%d",i+1));
      ok = ok && tman.SetAddress(tree,branchName.Data(),
                                   ChamberClustersPtr(i));
    }
  }
  return ok;
}

//_____________________________________________________________________________
AliMUONVCluster*
AliMUONClusterStoreV1::Remove(AliMUONVCluster& cluster)
{
  /// Remove a cluster
  Int_t iChamber = AliMpDEManager::GetChamberId(cluster.GetDetElemId());
  TClonesArray* array = ChamberClusters(iChamber);
  TObject* o = array->Remove(&cluster);
  if (o)
  {
    array->Compress();
  }
  return static_cast<AliMUONVCluster*>(o);
}

//_____________________________________________________________________________
void
AliMUONClusterStoreV1::Clear(Option_t*)
{
  /// Reset internal arrays
  AliDebug(1,"");
  /// Reset the tclonesarray, but keep the tobjarray's size constant.
  for ( Int_t i = 0; i < fClusters->GetSize(); ++i ) 
  {
    ChamberClusters(i)->Clear("C");
  }
}

//_____________________________________________________________________________
TIterator* 
AliMUONClusterStoreV1::CreateIterator() const
{
  /// Return an iterator to loop over our clusters
  return new AliMUONTOTCAStoreIterator(fClusters,0,AliMpConstants::NofTrackingChambers()-1);
}

//_____________________________________________________________________________
TIterator* 
AliMUONClusterStoreV1::CreateChamberIterator(Int_t firstChamber, Int_t lastChamber) const
{
  /// Return an iterator to loop over our clusters
  return new AliMUONTOTCAStoreIterator(fClusters,firstChamber,lastChamber);
}

//_____________________________________________________________________________
Int_t
AliMUONClusterStoreV1::GetSize() const
{
  /// Return the number of clusters we hold
  Int_t n(0);
  for ( Int_t i = 0; i < fClusters->GetSize(); ++i ) 
  {
    n += ChamberClusters(i)->GetLast()+1;
  }
  return n;
}

 AliMUONClusterStoreV1.cxx:1
 AliMUONClusterStoreV1.cxx:2
 AliMUONClusterStoreV1.cxx:3
 AliMUONClusterStoreV1.cxx:4
 AliMUONClusterStoreV1.cxx:5
 AliMUONClusterStoreV1.cxx:6
 AliMUONClusterStoreV1.cxx:7
 AliMUONClusterStoreV1.cxx:8
 AliMUONClusterStoreV1.cxx:9
 AliMUONClusterStoreV1.cxx:10
 AliMUONClusterStoreV1.cxx:11
 AliMUONClusterStoreV1.cxx:12
 AliMUONClusterStoreV1.cxx:13
 AliMUONClusterStoreV1.cxx:14
 AliMUONClusterStoreV1.cxx:15
 AliMUONClusterStoreV1.cxx:16
 AliMUONClusterStoreV1.cxx:17
 AliMUONClusterStoreV1.cxx:18
 AliMUONClusterStoreV1.cxx:19
 AliMUONClusterStoreV1.cxx:20
 AliMUONClusterStoreV1.cxx:21
 AliMUONClusterStoreV1.cxx:22
 AliMUONClusterStoreV1.cxx:23
 AliMUONClusterStoreV1.cxx:24
 AliMUONClusterStoreV1.cxx:25
 AliMUONClusterStoreV1.cxx:26
 AliMUONClusterStoreV1.cxx:27
 AliMUONClusterStoreV1.cxx:28
 AliMUONClusterStoreV1.cxx:29
 AliMUONClusterStoreV1.cxx:30
 AliMUONClusterStoreV1.cxx:31
 AliMUONClusterStoreV1.cxx:32
 AliMUONClusterStoreV1.cxx:33
 AliMUONClusterStoreV1.cxx:34
 AliMUONClusterStoreV1.cxx:35
 AliMUONClusterStoreV1.cxx:36
 AliMUONClusterStoreV1.cxx:37
 AliMUONClusterStoreV1.cxx:38
 AliMUONClusterStoreV1.cxx:39
 AliMUONClusterStoreV1.cxx:40
 AliMUONClusterStoreV1.cxx:41
 AliMUONClusterStoreV1.cxx:42
 AliMUONClusterStoreV1.cxx:43
 AliMUONClusterStoreV1.cxx:44
 AliMUONClusterStoreV1.cxx:45
 AliMUONClusterStoreV1.cxx:46
 AliMUONClusterStoreV1.cxx:47
 AliMUONClusterStoreV1.cxx:48
 AliMUONClusterStoreV1.cxx:49
 AliMUONClusterStoreV1.cxx:50
 AliMUONClusterStoreV1.cxx:51
 AliMUONClusterStoreV1.cxx:52
 AliMUONClusterStoreV1.cxx:53
 AliMUONClusterStoreV1.cxx:54
 AliMUONClusterStoreV1.cxx:55
 AliMUONClusterStoreV1.cxx:56
 AliMUONClusterStoreV1.cxx:57
 AliMUONClusterStoreV1.cxx:58
 AliMUONClusterStoreV1.cxx:59
 AliMUONClusterStoreV1.cxx:60
 AliMUONClusterStoreV1.cxx:61
 AliMUONClusterStoreV1.cxx:62
 AliMUONClusterStoreV1.cxx:63
 AliMUONClusterStoreV1.cxx:64
 AliMUONClusterStoreV1.cxx:65
 AliMUONClusterStoreV1.cxx:66
 AliMUONClusterStoreV1.cxx:67
 AliMUONClusterStoreV1.cxx:68
 AliMUONClusterStoreV1.cxx:69
 AliMUONClusterStoreV1.cxx:70
 AliMUONClusterStoreV1.cxx:71
 AliMUONClusterStoreV1.cxx:72
 AliMUONClusterStoreV1.cxx:73
 AliMUONClusterStoreV1.cxx:74
 AliMUONClusterStoreV1.cxx:75
 AliMUONClusterStoreV1.cxx:76
 AliMUONClusterStoreV1.cxx:77
 AliMUONClusterStoreV1.cxx:78
 AliMUONClusterStoreV1.cxx:79
 AliMUONClusterStoreV1.cxx:80
 AliMUONClusterStoreV1.cxx:81
 AliMUONClusterStoreV1.cxx:82
 AliMUONClusterStoreV1.cxx:83
 AliMUONClusterStoreV1.cxx:84
 AliMUONClusterStoreV1.cxx:85
 AliMUONClusterStoreV1.cxx:86
 AliMUONClusterStoreV1.cxx:87
 AliMUONClusterStoreV1.cxx:88
 AliMUONClusterStoreV1.cxx:89
 AliMUONClusterStoreV1.cxx:90
 AliMUONClusterStoreV1.cxx:91
 AliMUONClusterStoreV1.cxx:92
 AliMUONClusterStoreV1.cxx:93
 AliMUONClusterStoreV1.cxx:94
 AliMUONClusterStoreV1.cxx:95
 AliMUONClusterStoreV1.cxx:96
 AliMUONClusterStoreV1.cxx:97
 AliMUONClusterStoreV1.cxx:98
 AliMUONClusterStoreV1.cxx:99
 AliMUONClusterStoreV1.cxx:100
 AliMUONClusterStoreV1.cxx:101
 AliMUONClusterStoreV1.cxx:102
 AliMUONClusterStoreV1.cxx:103
 AliMUONClusterStoreV1.cxx:104
 AliMUONClusterStoreV1.cxx:105
 AliMUONClusterStoreV1.cxx:106
 AliMUONClusterStoreV1.cxx:107
 AliMUONClusterStoreV1.cxx:108
 AliMUONClusterStoreV1.cxx:109
 AliMUONClusterStoreV1.cxx:110
 AliMUONClusterStoreV1.cxx:111
 AliMUONClusterStoreV1.cxx:112
 AliMUONClusterStoreV1.cxx:113
 AliMUONClusterStoreV1.cxx:114
 AliMUONClusterStoreV1.cxx:115
 AliMUONClusterStoreV1.cxx:116
 AliMUONClusterStoreV1.cxx:117
 AliMUONClusterStoreV1.cxx:118
 AliMUONClusterStoreV1.cxx:119
 AliMUONClusterStoreV1.cxx:120
 AliMUONClusterStoreV1.cxx:121
 AliMUONClusterStoreV1.cxx:122
 AliMUONClusterStoreV1.cxx:123
 AliMUONClusterStoreV1.cxx:124
 AliMUONClusterStoreV1.cxx:125
 AliMUONClusterStoreV1.cxx:126
 AliMUONClusterStoreV1.cxx:127
 AliMUONClusterStoreV1.cxx:128
 AliMUONClusterStoreV1.cxx:129
 AliMUONClusterStoreV1.cxx:130
 AliMUONClusterStoreV1.cxx:131
 AliMUONClusterStoreV1.cxx:132
 AliMUONClusterStoreV1.cxx:133
 AliMUONClusterStoreV1.cxx:134
 AliMUONClusterStoreV1.cxx:135
 AliMUONClusterStoreV1.cxx:136
 AliMUONClusterStoreV1.cxx:137
 AliMUONClusterStoreV1.cxx:138
 AliMUONClusterStoreV1.cxx:139
 AliMUONClusterStoreV1.cxx:140
 AliMUONClusterStoreV1.cxx:141
 AliMUONClusterStoreV1.cxx:142
 AliMUONClusterStoreV1.cxx:143
 AliMUONClusterStoreV1.cxx:144
 AliMUONClusterStoreV1.cxx:145
 AliMUONClusterStoreV1.cxx:146
 AliMUONClusterStoreV1.cxx:147
 AliMUONClusterStoreV1.cxx:148
 AliMUONClusterStoreV1.cxx:149
 AliMUONClusterStoreV1.cxx:150
 AliMUONClusterStoreV1.cxx:151
 AliMUONClusterStoreV1.cxx:152
 AliMUONClusterStoreV1.cxx:153
 AliMUONClusterStoreV1.cxx:154
 AliMUONClusterStoreV1.cxx:155
 AliMUONClusterStoreV1.cxx:156
 AliMUONClusterStoreV1.cxx:157
 AliMUONClusterStoreV1.cxx:158
 AliMUONClusterStoreV1.cxx:159
 AliMUONClusterStoreV1.cxx:160
 AliMUONClusterStoreV1.cxx:161
 AliMUONClusterStoreV1.cxx:162
 AliMUONClusterStoreV1.cxx:163
 AliMUONClusterStoreV1.cxx:164
 AliMUONClusterStoreV1.cxx:165
 AliMUONClusterStoreV1.cxx:166
 AliMUONClusterStoreV1.cxx:167
 AliMUONClusterStoreV1.cxx:168
 AliMUONClusterStoreV1.cxx:169
 AliMUONClusterStoreV1.cxx:170
 AliMUONClusterStoreV1.cxx:171
 AliMUONClusterStoreV1.cxx:172
 AliMUONClusterStoreV1.cxx:173
 AliMUONClusterStoreV1.cxx:174
 AliMUONClusterStoreV1.cxx:175
 AliMUONClusterStoreV1.cxx:176
 AliMUONClusterStoreV1.cxx:177
 AliMUONClusterStoreV1.cxx:178
 AliMUONClusterStoreV1.cxx:179
 AliMUONClusterStoreV1.cxx:180
 AliMUONClusterStoreV1.cxx:181
 AliMUONClusterStoreV1.cxx:182
 AliMUONClusterStoreV1.cxx:183
 AliMUONClusterStoreV1.cxx:184
 AliMUONClusterStoreV1.cxx:185
 AliMUONClusterStoreV1.cxx:186
 AliMUONClusterStoreV1.cxx:187
 AliMUONClusterStoreV1.cxx:188
 AliMUONClusterStoreV1.cxx:189
 AliMUONClusterStoreV1.cxx:190
 AliMUONClusterStoreV1.cxx:191
 AliMUONClusterStoreV1.cxx:192
 AliMUONClusterStoreV1.cxx:193
 AliMUONClusterStoreV1.cxx:194
 AliMUONClusterStoreV1.cxx:195
 AliMUONClusterStoreV1.cxx:196
 AliMUONClusterStoreV1.cxx:197
 AliMUONClusterStoreV1.cxx:198
 AliMUONClusterStoreV1.cxx:199
 AliMUONClusterStoreV1.cxx:200
 AliMUONClusterStoreV1.cxx:201
 AliMUONClusterStoreV1.cxx:202
 AliMUONClusterStoreV1.cxx:203
 AliMUONClusterStoreV1.cxx:204
 AliMUONClusterStoreV1.cxx:205
 AliMUONClusterStoreV1.cxx:206
 AliMUONClusterStoreV1.cxx:207
 AliMUONClusterStoreV1.cxx:208
 AliMUONClusterStoreV1.cxx:209
 AliMUONClusterStoreV1.cxx:210
 AliMUONClusterStoreV1.cxx:211
 AliMUONClusterStoreV1.cxx:212
 AliMUONClusterStoreV1.cxx:213
 AliMUONClusterStoreV1.cxx:214
 AliMUONClusterStoreV1.cxx:215
 AliMUONClusterStoreV1.cxx:216
 AliMUONClusterStoreV1.cxx:217
 AliMUONClusterStoreV1.cxx:218
 AliMUONClusterStoreV1.cxx:219
 AliMUONClusterStoreV1.cxx:220
 AliMUONClusterStoreV1.cxx:221
 AliMUONClusterStoreV1.cxx:222
 AliMUONClusterStoreV1.cxx:223
 AliMUONClusterStoreV1.cxx:224
 AliMUONClusterStoreV1.cxx:225
 AliMUONClusterStoreV1.cxx:226
 AliMUONClusterStoreV1.cxx:227
 AliMUONClusterStoreV1.cxx:228
 AliMUONClusterStoreV1.cxx:229
 AliMUONClusterStoreV1.cxx:230
 AliMUONClusterStoreV1.cxx:231
 AliMUONClusterStoreV1.cxx:232
 AliMUONClusterStoreV1.cxx:233
 AliMUONClusterStoreV1.cxx:234
 AliMUONClusterStoreV1.cxx:235
 AliMUONClusterStoreV1.cxx:236
 AliMUONClusterStoreV1.cxx:237
 AliMUONClusterStoreV1.cxx:238
 AliMUONClusterStoreV1.cxx:239
 AliMUONClusterStoreV1.cxx:240
 AliMUONClusterStoreV1.cxx:241
 AliMUONClusterStoreV1.cxx:242
 AliMUONClusterStoreV1.cxx:243
 AliMUONClusterStoreV1.cxx:244
 AliMUONClusterStoreV1.cxx:245
 AliMUONClusterStoreV1.cxx:246
 AliMUONClusterStoreV1.cxx:247
 AliMUONClusterStoreV1.cxx:248
 AliMUONClusterStoreV1.cxx:249
 AliMUONClusterStoreV1.cxx:250
 AliMUONClusterStoreV1.cxx:251
 AliMUONClusterStoreV1.cxx:252
 AliMUONClusterStoreV1.cxx:253