00001
00002 #ifndef ATLFAST_TESIO_H
00003 #define ATLFAST_TESIO_H
00004
00005
00006 #include <vector>
00007 #include <string>
00008
00009
00010
00011
00012
00013 #ifndef GAUDIKERNEL_BOOTSTRAP_H
00014 #include "GaudiKernel/Bootstrap.h"
00015 #define GAUDIKERNEL__BOOTSTRAP_H
00016 #endif
00017
00018 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
00019 #include "GaudiKernel/ISvcLocator.h"
00020 #define GAUDIKERNEL__ISVCLOCATOR_H
00021 #endif
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef STOREGATE_STOREGATESVC_H
00039 #include "StoreGate/StoreGateSvc.h"
00040 #define STOREGATE_STOREGATESVC_H
00041 #endif
00042
00043 #ifndef STOREGATE_DATAHANDLE_H
00044 #include "StoreGate/DataHandle.h"
00045 #define STOREGATE_DATAHANDLE_H
00046 #endif
00047
00048 #ifndef ATLFASTEVENT_MCPARTICLECOLLECTION_H
00049 #include "AtlfastEvent/MCparticleCollection.h"
00050 #endif
00051
00052 #ifndef ATLFASTEVENT_MCPARTICLECOLLECTION_H
00053 #include "AtlfastEvent/MCparticleCollection.h"
00054 #endif
00055
00056 #ifndef ATLFAST_MCWEIGHTCONTAINERCOLLECTION_H
00057 #include "AtlfastEvent/MCweightContainerCollection.h"
00058 #endif
00059
00060 namespace HepMC_helper{
00061 class IMCselector;
00062 }
00063
00064
00065 namespace Atlfast {
00066 class TesIoStat{
00067 public:
00068 TesIoStat(): m_status(StatusCode::SUCCESS),m_errMsg(""){}
00069 TesIoStat(StatusCode sc, std::string string): m_status(sc),
00070 m_errMsg(string){}
00071 TesIoStat(StatusCode s): m_status(s), m_errMsg(""){}
00072
00073 StatusCode status() const {return m_status;}
00074 std::string message() const {return m_errMsg;}
00075
00076 bool isValid() const {return m_status.isSuccess();}
00077 bool isNotValid() const {return !isValid();}
00078 bool operator !() const {return isNotValid();}
00079 operator bool() const {return isValid();}
00080 operator StatusCode() const {return m_status;}
00081 private:
00082 StatusCode m_status;
00083 std::string m_errMsg;
00084 };
00085
00086 class TesIO {
00087 public:
00088 typedef std::string String;
00089
00090 TesIO(std::string mcLocation="", bool justHardScatter=true);
00091 TesIoStat getMC (MCparticleCollection&) const;
00092 TesIoStat getMC (MCparticleCollection&,
00093 const HepMC_helper::IMCselector* ) const;
00095 TesIoStat getMCweightContainers
00096 (MCweightContainerCollection&) const;
00097
00098 template<class T> TesIoStat getDH (const T*&) const;
00099 template<class T> TesIoStat getDH (const T*&, String key) const;
00100 template<class T> TesIoStat store (T*) const;
00101 template<class T> TesIoStat store (T*, String key) const;
00102 template<class T> TesIoStat store (T*, String key, bool allowmods) const;
00103 template<class T> TesIoStat lock (T*) const;
00106
00107 template<class T,
00108 class U> TesIoStat copy (U&, String key) const;
00109 private:
00110
00111 std::string m_mcLocation;
00112 bool m_justHardScatter;
00113 StoreGateSvc* m_sgSvc;
00114 };
00115
00116
00117
00118
00119
00120 inline TesIO::TesIO(std::string mcLocation, bool justHardScatter):
00121 m_mcLocation(mcLocation), m_justHardScatter(justHardScatter), m_sgSvc(0) {
00122 ISvcLocator* svcLoc = Gaudi::svcLocator( );
00123 if( (svcLoc->service( "StoreGateSvc", m_sgSvc )).isFailure() ){
00124 throw TesIoStat(StatusCode::FAILURE, "TesIO could not find StoreGate");
00125 }
00126 }
00127
00128
00129
00130 template<class T, class U> inline
00131 TesIoStat TesIO::copy(U& localCopy, String key) const {
00132 const T* objects(0);
00133 TesIoStat stat = this->getDH(objects, key);
00134 if(!stat){
00135 return TesIoStat(StatusCode::FAILURE,
00136 "Could not copyCollection keyed collection: "+stat.message());
00137 }
00138
00139 std::copy(objects->begin(),objects->end(),std::back_inserter(localCopy));
00140 return TesIoStat(StatusCode::SUCCESS, "Copied Collection from TDS");
00141
00142 }
00143
00144
00145
00146 template<class T> inline
00147 TesIoStat TesIO::getDH(const T*& dh) const {
00148
00149 if((m_sgSvc->retrieve(dh)).isFailure() ){
00150 return TesIoStat(StatusCode::FAILURE,
00151 "Could not find a valid DataHandle");
00152 }
00153 return TesIoStat(StatusCode::SUCCESS, "Found unkeyed DH in TDS");
00154 }
00155
00156
00157
00158 template<class T> inline
00159 TesIoStat TesIO::getDH(const T*& dh, String key) const {
00160
00161 if( (m_sgSvc->retrieve(dh, key)).isFailure() ){
00162 return TesIoStat(StatusCode::FAILURE,
00163 "Could not find a valid keyed DataHandle");
00164 }
00165 return TesIoStat(StatusCode::SUCCESS, "Found keyed DH in TDS");
00166 }
00167
00168
00169
00170 template<class T> inline TesIoStat TesIO::store(T* pObject) const {
00171 return (TesIoStat(m_sgSvc->record(pObject,false)) ) ;
00172 }
00173
00174
00175
00176 template<class T> inline
00177 TesIoStat TesIO::store(T* pObject, String key) const {
00178 return (TesIoStat(m_sgSvc->record(pObject, key, false)) ) ;
00179 }
00180
00181
00182
00183
00184 template<class T> inline
00185 TesIoStat TesIO::store(T* pObject, String key, bool allowmods) const {
00186 return (TesIoStat(m_sgSvc->record(pObject, key, allowmods)) ) ;
00187 }
00188
00189
00190
00191 template<class T> inline TesIoStat TesIO::lock(T* pObject) const {
00192 return (TesIoStat(m_sgSvc->setConst(pObject)) ) ;
00193 }
00194
00195 }
00196 #endif
00197
00198
00199
00200
00201
00202
00203
00204
00205