00001 #ifndef CondTools_L1Trigger_WriterProxy_h
00002 #define CondTools_L1Trigger_WriterProxy_h
00003
00004 #include "FWCore/Framework/interface/HCTypeTagTemplate.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007
00008 #include "FWCore/PluginManager/interface/PluginFactory.h"
00009
00010
00011
00012 #include "CondCore/DBCommon/interface/PoolTransaction.h"
00013 #include "CondCore/DBCommon/interface/TypedRef.h"
00014
00015 #include "CondTools/L1Trigger/interface/Exception.h"
00016
00017 #include <string>
00018
00019 namespace l1t
00020 {
00021
00022
00023
00024
00025
00026 class WriterProxy
00027 {
00028 public:
00029 virtual ~WriterProxy() {}
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 virtual std::string save (const edm::EventSetup & setup, cond::PoolTransaction & pool) 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, cond::PoolTransaction & pool) const
00055 {
00056
00057 std::string recordName =
00058 edm::eventsetup::heterocontainer::HCTypeTagTemplate<Record, edm::eventsetup::EventSetupRecordKey>::className ();
00059
00060
00061 edm::ESHandle<Type> handle;
00062
00063 try
00064 {
00065 setup.get<Record> ().get (handle);
00066 }
00067 catch( l1t::DataAlreadyPresentException& ex )
00068 {
00069 return std::string() ;
00070 }
00071
00072
00073 cond::TypedRef<Type> ref (pool,
00074 new Type (*(handle.product ())));
00075 ref.markWrite (recordName);
00076
00077 return ref.token ();
00078 }
00079 };
00080
00081 typedef edmplugin::PluginFactory<l1t::WriterProxy * ()> WriterFactory;
00082
00083
00084
00085 #define REGISTER_L1_WRITER(record,type) \
00086 template class l1t::WriterProxyT<record, type>; \
00087 static edm::eventsetup::heterocontainer::HCTypeTagTemplate<type, edm::eventsetup::DataKey> dummy ## _ ## record ## _ ## type ; \
00088 typedef l1t::WriterProxyT<record, type> record ## _ ## type ## _Writer; \
00089 DEFINE_EDM_PLUGIN(l1t::WriterFactory, record ## _ ## type ## _Writer, #record "@" #type "@Writer")
00090
00091 }
00092
00093 #endif