Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

TesIO.h

Go to the documentation of this file.
00001 //
00002 #ifndef ATLFAST_TESIO_H
00003 #define ATLFAST_TESIO_H
00004 
00005 // STL
00006 #include <vector>
00007 #include <string>
00008 
00009 #include "AtlfastEvent/MCparticleCollection.h"
00010 
00011 //Generator includes
00012 #include "GeneratorObjects/McEventCollection.h"
00013 
00014 #include "GaudiKernel/Bootstrap.h"
00015 #include "GaudiKernel/ISvcLocator.h"
00016 #include "GaudiKernel/DataObject.h"
00017 #include "GaudiKernel/ObjectVector.h"
00018 // StoreGate
00019 #include "StoreGate/StoreGateSvc.h"
00020 #include "StoreGate/DataHandle.h"
00021 
00022 namespace HepMC_helper{
00023   class IMCselector;
00024 }
00025 
00026 namespace Atlfast {
00027   class TesIoStat{
00028   public:
00029     TesIoStat(): m_status(StatusCode::SUCCESS),m_errMsg(""){}
00030     TesIoStat(StatusCode sc, std::string string): m_status(sc),
00031       m_errMsg(string){}
00032     TesIoStat(StatusCode s): m_status(s), m_errMsg(""){}
00033     
00034     StatusCode status()   const {return m_status;}
00035     std::string message() const {return m_errMsg;}
00036 
00037     bool isValid()        const {return m_status.isSuccess();}
00038     bool isNotValid()     const {return !isValid();}
00039     bool operator !()     const {return isNotValid();}
00040     operator bool()       const {return isValid();}
00041     operator StatusCode() const {return m_status;}
00042   private:
00043     StatusCode m_status;
00044     std::string m_errMsg;
00045   };
00046   
00047   class TesIO {
00048   public:
00049     typedef std::string String;
00050     //
00051     TesIO();
00052     TesIoStat getMC   (MCparticleCollection&)                            const;
00053     TesIoStat getMC   (MCparticleCollection&, 
00054                        const HepMC_helper::IMCselector* )                const;
00055     //
00056     template<class T> TesIoStat copy  (std::vector<T*>&)                 const;
00057     template<class T> TesIoStat copy  (std::vector<T*>&,     String key) const;
00058     template<class T> TesIoStat getDH (const DataHandle<T>&)             const;
00059     template<class T> TesIoStat getDH (const DataHandle<T>&, String key) const;
00060     template<class T> TesIoStat store (T*)                               const;
00061     template<class T> TesIoStat store (T*,                   String key) const;
00062     
00063   private:
00064     //    IDataProviderSvc* m_dataSvc;
00065     StoreGateSvc* m_sgSvc;
00066   };
00067 
00068 
00069   //**************************************************************************
00070   // TesIO()                                                                 *
00071   //**************************************************************************
00072   inline TesIO::TesIO():m_sgSvc(0){
00073     ISvcLocator* svcLoc = Gaudi::svcLocator( );
00074     if( (svcLoc->service( "StoreGateSvc", m_sgSvc )).isFailure() ){
00075       throw TesIoStat(StatusCode::FAILURE, "TesIO could not find StoreGate");
00076     }
00077   }    
00078   //**************************************************************************
00079   // TesIoStat TesIO::copy(std::vector<T*>& localCopy) const                 *
00080   //**************************************************************************
00081   template<class T> inline 
00082     TesIoStat TesIO::copy(std::vector<T*>& localCopy) const {
00083     DataHandle<ObjectVector<T> > objects;
00084     TesIoStat stat = this->getDH(objects);
00085     if(!stat) {
00086       return TesIoStat(StatusCode::FAILURE,
00087                        "Could not copy collection: "+stat.message());
00088     }
00089     
00090     std::copy(objects->begin(),objects->end(),back_inserter(localCopy));
00091     return TesIoStat(StatusCode::SUCCESS, "Copied Collection from TDS");
00092     
00093   }
00094   //**************************************************************************
00095   //TesIoStat TesIO::copy(std::vector<T*>& localCopy, String key) const      *
00096   //**************************************************************************
00097   template<class T> inline 
00098     TesIoStat TesIO::copy(std::vector<T*>& localCopy, String key) const {
00099     DataHandle<ObjectVector<T> > objects;
00100     TesIoStat stat = this->getDH(objects, key);
00101     if(!stat){
00102       return TesIoStat(StatusCode::FAILURE,
00103                        "Could not copy keyed collection: "+stat.message());
00104     }
00105 
00106     std::copy(objects->begin(),objects->end(),back_inserter(localCopy));
00107     return TesIoStat(StatusCode::SUCCESS, "Copied Collection from TDS");
00108     
00109   }
00110   //**************************************************************************
00111   //*TesIoStat TesIO::getDH(const DataHandle<T>& dh) const                   *
00112   //**************************************************************************
00113   template<class T> inline 
00114     TesIoStat TesIO::getDH(const DataHandle<T>& dh) const {
00115     if((m_sgSvc->retrieve(dh)).isFailure() ){
00116       return TesIoStat(StatusCode::FAILURE,
00117                        "Could not find a valid DataHandle");
00118     }
00119     return TesIoStat(StatusCode::SUCCESS, "Found unkeyed DH in TDS");
00120   }
00121   //**************************************************************************
00122   //*TesIoStat TesIO::getDH(const DataHandle<T>& dh, String key) const       *
00123   //**************************************************************************
00124   template<class T> inline 
00125     TesIoStat TesIO::getDH(const DataHandle<T>& dh, String key) const {
00126     if( (m_sgSvc->retrieve(dh, key)).isFailure() ){
00127       return TesIoStat(StatusCode::FAILURE,
00128                        "Could not find a valid keyed DataHandle");
00129     }
00130     return TesIoStat(StatusCode::SUCCESS, "Found keyed DH in TDS");
00131   }
00132   //**************************************************************************
00133   //template<class T> inline TesIoStat TesIO::store(T* pObject) const        *
00134   //**************************************************************************
00135   template<class T> inline TesIoStat TesIO::store(T* pObject) const { 
00136     return (TesIoStat(m_sgSvc->record(pObject)) ) ;
00137   }
00138   //**************************************************************************
00139   //TesIoStat TesIO::store(T* storee, String key) const                      *
00140   //**************************************************************************
00141   template<class T> inline 
00142     TesIoStat TesIO::store(T* storee, String key) const { 
00143     return (TesIoStat(m_sgSvc->record(storee, key)) ) ;
00144   }
00145   
00146 }
00147 #endif
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 

Generated on Wed Jan 15 11:00:30 2003 for AtlfastUtils by doxygen1.3-rc1