]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Implementation of TIterator for TObjArray of TClonesArrays (Laurent)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 17 Jun 2007 20:32:45 +0000 (20:32 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 17 Jun 2007 20:32:45 +0000 (20:32 +0000)
MUON/AliMUONTOTCAStoreIterator.cxx [new file with mode: 0644]
MUON/AliMUONTOTCAStoreIterator.h [new file with mode: 0644]

diff --git a/MUON/AliMUONTOTCAStoreIterator.cxx b/MUON/AliMUONTOTCAStoreIterator.cxx
new file mode 100644 (file)
index 0000000..6120216
--- /dev/null
@@ -0,0 +1,161 @@
+/**************************************************************************
+* 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 AliMUONTOTCAStoreIterator
+///
+/// An iterator to access TObject stored in a TObjArray of TClonesArray
+///
+///
+/// \author Laurent Aphecetche, Subatech
+///
+
+#include "AliMUONTOTCAStoreIterator.h"
+
+#include <TClonesArray.h>
+#include <TObjArray.h>
+
+/// \cond CLASSIMP
+ClassImp(AliMUONTOTCAStoreIterator)
+/// \endcond
+
+//_____________________________________________________________________________
+AliMUONTOTCAStoreIterator::AliMUONTOTCAStoreIterator(const TObjArray* data,
+                                                     Int_t firstChamberId, 
+                                                     Int_t lastChamberId)
+: 
+TIterator(),
+fData(data),
+fFirstChamberId(firstChamberId),
+fLastChamberId(lastChamberId),
+fCurrentTCA(0x0),
+fCurrentTCAIndex(-1),
+fCurrentChamberId(-1)
+{
+  /// Standard constructor
+  Reset();
+}
+
+//_____________________________________________________________________________
+TIterator& 
+AliMUONTOTCAStoreIterator::operator=(const TIterator& rhs)
+{
+  /// Overriden operator= (imposed by Root's declaration of TIterator ?)
+  if ( this != &rhs && rhs.IsA() == AliMUONTOTCAStoreIterator::Class() )
+  {
+    const AliMUONTOTCAStoreIterator& rhs1 = 
+    static_cast<const AliMUONTOTCAStoreIterator&>(rhs);
+    
+    rhs1.CopyTo(*this);
+  }
+  return *this;
+}
+
+//_____________________________________________________________________________
+AliMUONTOTCAStoreIterator::AliMUONTOTCAStoreIterator(const AliMUONTOTCAStoreIterator& rhs)
+: 
+TIterator(rhs),
+fData(0x0),
+fFirstChamberId(-1),
+fLastChamberId(-1),
+fCurrentTCA(0x0),
+fCurrentTCAIndex(-1),
+fCurrentChamberId(-1)
+{
+  /// Copy constructor
+
+  rhs.CopyTo(*this);
+}
+
+//_____________________________________________________________________________
+AliMUONTOTCAStoreIterator::~AliMUONTOTCAStoreIterator()
+{
+  /// Destructor
+}
+
+//_____________________________________________________________________________
+AliMUONTOTCAStoreIterator&
+AliMUONTOTCAStoreIterator::operator=(const AliMUONTOTCAStoreIterator& rhs)
+{
+  /// Assignment operator
+
+  rhs.CopyTo(*this);
+  return *this;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTOTCAStoreIterator::CopyTo(AliMUONTOTCAStoreIterator& destination) const
+{
+  /// Copy *this to destination
+  destination.fData=fData;
+  destination.fFirstChamberId=fFirstChamberId;
+  destination.fLastChamberId=fLastChamberId;
+  destination.fCurrentTCAIndex=fCurrentTCAIndex;
+  destination.fCurrentChamberId=fCurrentChamberId;
+  destination.fCurrentTCA=fCurrentTCA;
+}
+
+//_____________________________________________________________________________
+const TCollection*
+AliMUONTOTCAStoreIterator::GetCollection() const
+{
+  /// The top level collection we're iterating upon, i.e. a TObjArray
+  return fData;
+}
+
+//_____________________________________________________________________________
+TObject*
+AliMUONTOTCAStoreIterator::Next()
+{
+  /// Find and return next element in the store
+  
+  if ( fCurrentTCA && fCurrentTCAIndex < fCurrentTCA->GetLast() ) 
+  {
+    ++fCurrentTCAIndex;
+  }
+  else
+  {
+    fCurrentTCAIndex = 0;
+    fCurrentTCA = 0;
+    
+    while ( ( !fCurrentTCA || fCurrentTCA->GetLast()==-1 ) && 
+            fCurrentChamberId < fLastChamberId ) 
+    {
+      ++fCurrentChamberId;
+      fCurrentTCA = static_cast<TClonesArray*>(fData->At(fCurrentChamberId));
+    }
+  }
+  
+  if ( fCurrentTCA ) 
+  {
+    // get the pointer to be returned
+    return fCurrentTCA->At(fCurrentTCAIndex);
+  }
+  
+  return 0x0;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTOTCAStoreIterator::Reset()
+{
+  /// Reset the iterator
+  fCurrentTCAIndex = -1;
+  fCurrentChamberId = fFirstChamberId-1;
+  fCurrentTCA = 0x0;
+}
diff --git a/MUON/AliMUONTOTCAStoreIterator.h b/MUON/AliMUONTOTCAStoreIterator.h
new file mode 100644 (file)
index 0000000..a2ac524
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef ALIMUONTOTCASTOREITERATOR_H
+#define ALIMUONTOTCASTOREITERATOR_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+// $Id$
+
+/// \ingroup base
+/// \class AliMUONTOTCAStoreIteratorV1
+/// \brief Iterator on a store composed of a TObjArray of TClonesArrays
+/// 
+//  Author: Laurent Aphecetche
+
+#include "TIterator.h"
+
+class TClonesArray;
+class TObjArray;
+
+class AliMUONTOTCAStoreIterator : public TIterator
+{
+public:
+  AliMUONTOTCAStoreIterator(const TObjArray* a, Int_t firstChamberId, Int_t lastChamberId);
+  AliMUONTOTCAStoreIterator(const AliMUONTOTCAStoreIterator& rhs);
+  TIterator& operator=(const TIterator& rhs);
+  AliMUONTOTCAStoreIterator& operator=(const AliMUONTOTCAStoreIterator& rhs);
+  virtual ~AliMUONTOTCAStoreIterator();
+    
+  virtual const TCollection* GetCollection() const;
+  
+  virtual TObject* Next();
+  
+  virtual void Reset(); 
+  
+private:
+    void CopyTo(AliMUONTOTCAStoreIterator& destination) const;
+  
+private:
+  const TObjArray* fData; //!< Pointer to data accessor
+  Int_t fFirstChamberId;      //!< First chamber to iterate on
+  Int_t fLastChamberId;       //!< Last chamber to iterate on      
+  TClonesArray* fCurrentTCA;    //!< TClonesArray of the current chamber
+  Int_t fCurrentTCAIndex;      //!< Current position within fCurrentTCA array
+  Int_t fCurrentChamberId; //!< current chamber id
+  
+  ClassDef(AliMUONTOTCAStoreIterator,0) // Iterator on digits
+};      
+
+#endif