Source

mana-core-athenarootcomps / src / RootNtupleEventSelector.h

Full commit
///////////////////////// -*- C++ -*- /////////////////////////////
// RootNtupleEventSelector.h 
// Header file for class RootNtupleEventSelector
// Author: S.Binet<binet@cern.ch>
/////////////////////////////////////////////////////////////////// 
#ifndef ATHENAROOTCOMPS_ATHENA_ROOTNTUPLEEVENTSELECTOR_H 
#define ATHENAROOTCOMPS_ATHENA_ROOTNTUPLEEVENTSELECTOR_H 1

// STL includes
#include "CxxUtils/unordered_set.h" // move to STL when available

// framework includes
#include "AthenaBaseComps/AthService.h"
#include "GaudiKernel/IEvtSelector.h"
#include "GaudiKernel/ServiceHandle.h"
#include "GaudiKernel/Property.h"
#include "GaudiKernel/MsgStream.h"
#include "AthenaKernel/IEventSeek.h"
#include "AthenaKernel/IAddressProvider.h"

// Forward declaration
class ISvcLocator;
class StoreGateSvc;
//class ITHistSvc;
class TTree;
class IClassIDSvc;
class IDictLoaderSvc;
//class IAthenaRootCnvSvc;
//namespace Athena { class RootCnvSvc; }
//namespace Athena { class RootNtupleEventContext; }

namespace Athena {

/** @brief Class implementing the GAUDI @c IEvtSelector interface using 
 *         ROOT @c TTree as a backend
 */
class RootNtupleEventSelector : 
  virtual public IEvtSelector,
  virtual public IEventSeek,
  virtual public IAddressProvider,
  virtual public AthService
{ 

  /////////////////////////////////////////////////////////////////// 
  // Public methods: 
  /////////////////////////////////////////////////////////////////// 
 public: 

  /// Constructor with parameters: 
  RootNtupleEventSelector( const std::string& name, ISvcLocator* svcLoc );

  /// Destructor: 
  virtual ~RootNtupleEventSelector(); 

  // Athena hooks
  virtual StatusCode initialize();
  virtual StatusCode finalize();
  virtual StatusCode queryInterface( const InterfaceID& riid, 
                                     void** ppvInterface );
  
  ///@{
  /// @c IEvtSelector interface
  virtual StatusCode createContext( Context*& refpCtxt ) const;

  virtual StatusCode last( Context& refContext ) const;
  virtual StatusCode next( Context& refCtxt ) const;
  virtual StatusCode next( Context& refCtxt, int jump ) const;
  virtual StatusCode previous( Context& refCtxt ) const;
  virtual StatusCode previous( Context& refCtxt, int jump ) const;
  virtual StatusCode rewind( Context& refCtxt ) const;

  virtual StatusCode createAddress( const Context& refCtxt, 
                                    IOpaqueAddress*& ) const;
  virtual StatusCode releaseContext( Context*& refCtxt ) const;
  virtual StatusCode resetCriteria( const std::string& cr, 
                                    Context& ctx )const;
  ///@}

  ///@{
  /// @c IEventSeek interface
  /**
   * @brief Seek to a given event number.
   * @param evtnum  The event number to which to seek.
   */
  virtual StatusCode seek (int evtnum);

  /**
   * @brief return the current event number.
   * @return The current event number.
   */
  virtual int curEvent () const;
  ///@}
  
  ///@{
  /// @c IAddressProvider interface
  ///get all addresses from Provider : Called before Begin Event
  virtual 
  StatusCode preLoadAddresses(StoreID::type storeID, tadList& list);
 
   /// get all new addresses from Provider for this Event.
  virtual 
  StatusCode loadAddresses(StoreID::type storeID, tadList& list);
 
  /// update a transient Address
  virtual 
  StatusCode updateAddress(SG::TransientAddress* tad);
  ///@}

  /////////////////////////////////////////////////////////////////// 
  // Const methods: 
  ///////////////////////////////////////////////////////////////////

  /////////////////////////////////////////////////////////////////// 
  // Non-const methods: 
  /////////////////////////////////////////////////////////////////// 

  /////////////////////////////////////////////////////////////////// 
  // Private methods: 
  /////////////////////////////////////////////////////////////////// 
 private: 

  /// callback to synchronize the list of input files
  void setupInputCollection( Property& inputCollectionsName );

  /// helper method to create proxies
  StatusCode createRootBranchAddresses(StoreID::type storeID,
                                       tadList &tads);

  /// helper method to retrieve the correct tuple
  TTree* fetchNtuple(const std::string& fname) const;

  /////////////////////////////////////////////////////////////////// 
  // Private data: 
  /////////////////////////////////////////////////////////////////// 
 private: 

  typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t;
  /// Pointer to the @c StoreGateSvc event store
  StoreGateSvc_t m_storeGate;

  typedef ServiceHandle<IClassIDSvc> ICLIDSvc_t;
  /// Pointer to the @c IClassIDSvc
  ICLIDSvc_t m_clidsvc;

  typedef ServiceHandle<IDictLoaderSvc> IDictSvc_t;
  /// Pointer to the @c IDictLoaderSvc
  IDictSvc_t m_dictsvc;

  //typedef ServiceHandle<Athena::RootCnvSvc> IAthenaRootCnvSvc_t;
  /// handle to the athena RootCnvSvc
  //IAthenaRootCnvSvc_t m_cnvsvc;

  /// List of input files containing @c TTree 
  StringArrayProperty m_inputCollectionsName;

  /// Name of @c TTree to load from collection of input files
  StringProperty m_tupleName;

  /// List of branches to activate in the @c TTree 
  StringArrayProperty m_activeBranchNames;

  /// Number of events to skip at the beginning 
  long m_skipEvts;

  /// Number of Events read so far.
  mutable long m_nbrEvts;

  /// current tree being read
  mutable TTree *m_tuple;

  /** The (python) selection function to apply on the @c TChain we are reading
   */
  //PyObject* m_pySelectionFct;

  typedef SG::unordered_set<SG::TransientAddress*> Addrs_t;
  // the list of transient addresses we "manage" or know about
  // these addresses are the actual TTree's branch names
  Addrs_t m_rootAddresses;
}; 

/////////////////////////////////////////////////////////////////// 
// Inline methods: 
/////////////////////////////////////////////////////////////////// 

} //> namespace Athena

#endif //> ATHENAROOTCOMPS_ATHENA_ROOTNTUPLEEVENTSELECTOR_H