]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New interface of a MUON data store, that can be connected to a TTree (Laurent)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 17 Jun 2007 20:36:27 +0000 (20:36 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 17 Jun 2007 20:36:27 +0000 (20:36 +0000)
MUON/AliMUONVStore.cxx [new file with mode: 0644]
MUON/AliMUONVStore.h [new file with mode: 0644]

diff --git a/MUON/AliMUONVStore.cxx b/MUON/AliMUONVStore.cxx
new file mode 100644 (file)
index 0000000..c344164
--- /dev/null
@@ -0,0 +1,278 @@
+/**************************************************************************
+* 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 AliMUONVStore
+///
+/// A store is a container, which can be searched for (using FindObject methods),
+/// iterated upon (using CreateIterator() method), and into which you can 
+/// add objects (using Add)
+///
+/// In addition, a store can be connected to a TTree.
+///
+/// The general way of dealing with I/O for MUON is a two stage process :
+/// 
+/// 1) first get a TTree pointer using the AliLoader mechanism (this is AliRoot
+///    general)
+///
+/// 2) connect that TTree to a MUON (virtual) data container using
+///    the container's Connect(TTree&) method (this is MUON specific)
+///
+/// Example for reading digits for nevents
+///
+/// \code
+///
+/// AliMUONVDigitStore* digitStore(0x0);
+///
+/// AliLoader* loader = ... ( get loader from somewhere, e.g. AliRunLoader::GetDetectorLoader());
+/// loader->LoadDigits("READ"); // load digits
+///
+/// for ( Int_t i = 0; i < nevents; ++i ) 
+/// {
+///   TTree* treeD = loader->TreeD(); // get the tree
+///   if (!digitStore) digitStore = static_cast<AliMUONVDigitStore*>
+///     (AliMUONVDigitStore::CreateStore(*treeD,"Digit")); // creates a container for digits 
+///   (concrete class is given by the tree itself)
+///   digitStore->Connect(*treeD);
+///   treeD->GetEvent(0); // actual reading of the data
+///
+///   the digitStore is now filled and ready to be used
+///   ....
+///
+///   digitStore->Clear(); // reset once used
+/// }
+///
+/// \endcode
+///
+/// Please note that for reading data, you do *not* need to know the concrete
+/// container class, as it is given to you by the TTree
+///
+/// Example for writing digits
+///
+/// \code
+///
+/// get the loader and do a loader->LoadDigits("RECREATE" or "UPDATE") 
+/// (generally done by the framework itself)
+///
+/// AliMUONVDigitStore* digitStore = new AliMUONDigitStoreV1
+/// // for writing, must decide on the concrete store class to use
+///
+/// for ( Int_t i = 0; i < nevents; ++i ) 
+/// {
+///   TTree* treeD = loader->TreeD();
+///   digitStore->Connect(*treeD);
+///   
+///   ... put some digits in the digitStore
+///
+///   treeD->Fill();
+///
+///   loader->WriteDigits("OVERWRITE");
+/// }
+///
+/// delete digitStore;
+///
+/// loader->UnloadDigits();
+///
+/// \endcode
+///
+/// In the write case, one *must* specify a concrete class for the container
+///
+
+#include "AliMUONVStore.h"
+
+#include "AliMUONTreeManager.h"
+#include "AliLog.h"
+
+#include <TRegexp.h>
+#include <TClass.h>
+
+/// \cond CLASSIMP
+ClassImp(AliMUONVStore)
+/// \endcond
+
+//_____________________________________________________________________________
+AliMUONVStore::AliMUONVStore() : TObject()
+{
+  /// ctor
+}
+
+//_____________________________________________________________________________
+AliMUONVStore::~AliMUONVStore()
+{
+  /// dtor
+}
+
+//_____________________________________________________________________________
+Bool_t
+AliMUONVStore::Connect(TTree&, Bool_t) const
+{
+  /// Connect to a Ttree
+  AliError("Not implemented");
+  return kFALSE;
+}
+
+//_____________________________________________________________________________
+AliMUONVStore* 
+AliMUONVStore::Create(TTree& tree, const char* what)
+{
+  /// Create a store from a tree. Forwarded to AliMUONTreeManager::CreateStore
+  AliMUONTreeManager tman;
+
+  TObject* o = tman.CreateObject(tree,what);;
+  if (o)
+  {
+    AliMUONVStore* c = dynamic_cast<AliMUONVStore*>(o);
+    if (!c)
+    {
+      AliErrorClass(Form("Object of class %s cannot be cast to an AliMUONVStore",
+                    o->ClassName()));
+    }
+    return c;
+  }
+  return 0x0;
+}
+
+//_____________________________________________________________________________
+TObject*
+AliMUONVStore::FindObject(Int_t, Int_t) const
+{
+  /// Find an object using 2 identifiers
+  AliError("Not implemented");
+  return 0;
+}
+
+//_____________________________________________________________________________
+TObject*
+AliMUONVStore::FindObject(Int_t,Int_t, Int_t) const
+{
+  /// Find an object using 3 identifiers
+  AliError("Not implemented");
+  return 0;
+}
+
+//_____________________________________________________________________________
+TObject*
+AliMUONVStore::FindObject(Int_t, Int_t, Int_t, Int_t) const
+{
+  /// Find an object using 4 identifiers
+  AliError("Not implemented");
+  return 0;
+}
+
+//______________________________________________________________________________
+TObject*
+AliMUONVStore::FindObject(const char *name) const
+{
+  // Find an object in this collection using its name. Requires a sequential
+  // scan till the object has been found. Returns 0 if object with specified
+  // name is not found.
+  
+  TIter next(CreateIterator());
+  TObject *obj;
+  
+  while ((obj = next()))
+    if (!strcmp(name, obj->GetName())) return obj;
+  return 0;
+}
+
+//______________________________________________________________________________
+TObject*
+AliMUONVStore::FindObject(const TObject *obj) const
+{
+  // Find an object in this store using the object's IsEqual()
+  // member function. Requires a sequential scan till the object has
+  // been found. Returns 0 if object is not found.
+  // Typically this function is overridden by a more efficient version
+  // in concrete collection classes (e.g. THashTable).
+  
+  TIter next(CreateIterator());
+  TObject *ob;
+  
+  while ((ob = next()))
+    if (ob->IsEqual(obj)) return ob;
+  return 0;
+}
+
+//_____________________________________________________________________________
+TObject* 
+AliMUONVStore::FindObject(UInt_t uniqueID) const
+{
+  /// Generic find method. Should be overriden by derived class if it can
+  /// be made more efficient there.
+  
+  AliDebug(1,Form("uniqueID=%u",uniqueID));
+  
+  TIter next(CreateIterator());
+  TObject* o;
+  while ( ( o = next() ) ) 
+  {
+    if ( o->GetUniqueID() == uniqueID ) return o;
+  }
+  return 0x0;
+}
+
+//______________________________________________________________________________
+Int_t
+AliMUONVStore::GetSize(Int_t /*i*/) const
+{
+  /// Number of objects store for "i", whatever that can means
+  AliError("Not implemented");
+  return 0;
+}
+
+//______________________________________________________________________________
+void 
+AliMUONVStore::Print(Option_t *wildcard) const
+{
+  // Print all objects in this store.
+  // Wildcarding is supported, e.g. wildcard="xxx*" prints only objects
+  // with names matching xxx*.
+  
+  if (!wildcard) wildcard = "";
+  TRegexp re(wildcard, kTRUE);
+  Int_t nch = strlen(wildcard);
+  TIter next(CreateIterator());
+  TObject *object;
+  
+  while ((object = next())) {
+    TString s = object->GetName();
+    if (nch && s != wildcard && s.Index(re) == kNPOS) continue;
+    object->Print();
+  }
+}
+
+//_____________________________________________________________________________
+void 
+AliMUONVStore::Print(Option_t *wildcard, Option_t *option) const
+{
+  // Print all objects in this store, passing option to the
+  // objects Print() method.
+  // Wildcarding is supported, e.g. wildcard="xxx*" prints only objects
+  // with names matching xxx*.
+  
+  if (!wildcard) wildcard = "";
+  TRegexp re(wildcard, kTRUE);
+  Int_t nch = strlen(wildcard);
+  TIter next(CreateIterator());
+  TObject *object;
+  
+  while ((object = next())) {
+    TString s = object->GetName();
+    if (nch && s != wildcard && s.Index(re) == kNPOS) continue;
+    object->Print(option);
+  }
+}
+
diff --git a/MUON/AliMUONVStore.h b/MUON/AliMUONVStore.h
new file mode 100644 (file)
index 0000000..9fbb266
--- /dev/null
@@ -0,0 +1,85 @@
+#ifndef ALIMUONVSTORE_H
+#define ALIMUONVSTORE_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+// $Id$
+
+/// \ingroup calib
+/// \class AliMUONVStore
+/// \brief Base class for MUON data stores.
+/// 
+// Author Laurent Aphecetche, Subatech
+
+#ifndef ROOT_TObject
+#  include "TObject.h"
+#endif
+
+class TIterator;
+class TTree;
+
+class AliMUONVStore : public TObject
+{
+public:
+  AliMUONVStore();
+  virtual ~AliMUONVStore();
+  
+  /// Add an object to the store
+  virtual Bool_t Add(TObject* object) = 0;
+  
+  /// Clear ourselves (i.e. Reset)
+  virtual void Clear(Option_t* opt="") = 0;
+  
+  /// Create an empty copy of this
+  virtual AliMUONVStore* Create() const = 0;
+
+  /// Create a store from a TTree
+  static AliMUONVStore* Create(TTree& tree, const char* what);
+
+  /// Return an iterator to loop over the whole store
+  virtual TIterator* CreateIterator() const = 0;
+  
+  /// Whether the Connect(TTree&) method is implemented
+  virtual Bool_t CanConnect() const = 0;
+  
+  /// Connect us to a TTree (only valid if CanConnect()==kTRUE)
+  virtual Bool_t Connect(TTree& tree, Bool_t alone=kTRUE) const;
+
+  /// Find an object by name
+  virtual TObject* FindObject(const char* name) const;
+  
+  /// Find an object
+  virtual TObject* FindObject(const TObject* object) const;
+
+  /// Find an object using a single id
+       virtual TObject* FindObject(UInt_t uniqueID) const;
+  
+  /// Find an object using 2 ids
+  virtual TObject* FindObject(Int_t i, Int_t j) const;
+  
+  /// Find an object using 3 ids
+  virtual TObject* FindObject(Int_t i, Int_t j, Int_t k) const;
+
+  /// Find an object using 4 ids
+  virtual TObject* FindObject(Int_t i, Int_t j, Int_t k, Int_t l) const;
+  
+  /// The number of objects stored
+  virtual Int_t GetSize() const = 0;
+
+  /// The number of objects stored for firstid=i. Not implemented by default.
+  virtual Int_t GetSize(Int_t i) const;
+
+  /// Whether we are empty or not
+  virtual Bool_t IsEmpty() const { return GetSize() == 0; }
+  
+  /// Print all objects whose name matches wildcard
+  virtual void Print(Option_t* wildcard="") const;
+
+  /// Print, with option, all objects whose name matches wildcard
+  virtual void Print(Option_t* wildcard, Option_t* opt) const;
+  
+  ClassDef(AliMUONVStore,1) // Base class for a MUON data store
+};
+
+#endif