Go to the documentation of this file.00001 #ifndef CondTools_L1Trigger_WriterProxy_h
00002 #define CondTools_L1Trigger_WriterProxy_h
00003
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006
00007 #include "FWCore/PluginManager/interface/PluginFactory.h"
00008
00009 #include "FWCore/ServiceRegistry/interface/Service.h"
00010 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00011 #include "CondCore/DBCommon/interface/DbSession.h"
00012 #include "CondCore/DBCommon/interface/DbScopedTransaction.h"
00013
00014 #include "CondTools/L1Trigger/interface/Exception.h"
00015
00016 #include <string>
00017
00018 namespace l1t
00019 {
00020
00021
00022
00023
00024
00025 class WriterProxy
00026 {
00027 public:
00028 virtual ~WriterProxy() {}
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 virtual std::string save (const edm::EventSetup & setup) const = 0;
00040
00041 protected:
00042 };
00043
00044
00045
00046
00047 template<class Record, class Type>
00048 class WriterProxyT : public WriterProxy
00049 {
00050 public:
00051 virtual ~WriterProxyT() {}
00052
00053
00054 virtual std::string save (const edm::EventSetup & setup) const
00055 {
00056
00057 edm::ESHandle<Type> handle;
00058
00059 try
00060 {
00061 setup.get<Record> ().get (handle);
00062 }
00063 catch( l1t::DataAlreadyPresentException& ex )
00064 {
00065 return std::string() ;
00066 }
00067
00068
00069
00070 edm::Service<cond::service::PoolDBOutputService> poolDb;
00071 if (!poolDb.isAvailable())
00072 {
00073 throw cond::Exception( "DataWriter: PoolDBOutputService not available."
00074 ) ;
00075 }
00076 cond::DbSession session = poolDb->session();
00077 cond::DbScopedTransaction tr(session);
00078
00079 tr.start(false);
00080
00081 boost::shared_ptr<Type> pointer(new Type (*(handle.product ())));
00082 std::string payloadToken = session.storeObject( pointer.get(),
00083 cond::classNameForTypeId(typeid(Type))
00084 );
00085 tr.commit();
00086 return payloadToken ;
00087 }
00088 };
00089
00090 typedef edmplugin::PluginFactory<l1t::WriterProxy * ()> WriterFactory;
00091
00092
00093 #define REGISTER_L1_WRITER(record,type) \
00094 template class l1t::WriterProxyT<record, type>; \
00095 typedef l1t::WriterProxyT<record, type> record ## _ ## type ## _Writer; \
00096 DEFINE_EDM_PLUGIN(l1t::WriterFactory, record ## _ ## type ## _Writer, #record "@" #type "@Writer")
00097
00098 }
00099
00100 #endif