CondTools
L1Trigger
interface
WriterProxy.h
Go to the documentation of this file.
1
#ifndef CondTools_L1Trigger_WriterProxy_h
2
#define CondTools_L1Trigger_WriterProxy_h
3
4
#include "
FWCore/Framework/interface/EventSetup.h
"
5
#include "
FWCore/Framework/interface/ESHandle.h
"
6
7
#include "
FWCore/PluginManager/interface/PluginFactory.h
"
8
9
#include "
FWCore/ServiceRegistry/interface/Service.h
"
10
#include "
CondCore/DBOutputService/interface/PoolDBOutputService.h
"
11
12
#include "
CondTools/L1Trigger/interface/Exception.h
"
13
14
#include <string>
15
16
namespace
l1t
{
17
18
/* This is class that is used to save data to DB. Saving requires that we should know types at compile time.
19
* This means that I cannot create simple class that saves all records. So, I create a base class, and template
20
* version of it, that will procede with saving. This approach is the same as used in DataProxy.
21
*/
22
class
WriterProxy
{
23
public
:
24
virtual
~WriterProxy
() {}
25
26
/* Saves record and type from given event setup to pool DB. This method should not worry
27
* about such things as IOV and so on. It should return new payload token and then
28
* the framework would take care of it.
29
*
30
* This method should not care of pool transactions and connections management.
31
* In case some need other methods, like delete and update, one should add more abstract
32
* methods here.
33
*/
34
35
virtual
std::string
save
(
const
edm::EventSetup
&
setup
)
const
= 0;
36
37
protected
:
38
};
39
40
/* Concrete implementation of WriteProxy. This will do all the saving, also user of new types that should be saved
41
* should instaciate a new version of this class and register it in plugin system.
42
*/
43
template
<
class
Record,
class
Type>
44
class
WriterProxyT
:
public
WriterProxy
{
45
public
:
46
~WriterProxyT
()
override
{}
47
48
/* This method requires that Record and Type supports copy constructor */
49
std::string
save
(
const
edm::EventSetup
&
setup
)
const override
{
50
// load record and type from EventSetup and save them in db
51
edm::ESHandle<Type>
handle
;
52
53
try
{
54
setup
.get<
Record
>().
get
(
handle
);
55
}
catch
(
l1t::DataAlreadyPresentException
& ex) {
56
return
std::string
();
57
}
58
59
// If handle is invalid, then data is already in DB
60
61
edm::Service<cond::service::PoolDBOutputService>
poolDb;
62
if
(!poolDb.
isAvailable
()) {
63
throw
cond::Exception
(
"DataWriter: PoolDBOutputService not available."
);
64
}
65
poolDb->
forceInit
();
66
cond::persistency::Session
session = poolDb->
session
();
67
cond::persistency::TransactionScope
tr(session.
transaction
());
68
// if throw transaction will unroll
70
71
std::shared_ptr<Type> pointer = std::make_shared<Type>(*(
handle
.product()));
72
std::string
payloadToken = session.
storePayload
(*pointer);
74
tr.close();
75
return
payloadToken;
76
}
77
};
78
79
typedef
edmplugin::PluginFactory
<
l1t::WriterProxy
*()>
WriterFactory
;
80
81
// Defines new type, creates static instance of this class and register it for plugin
82
#define REGISTER_L1_WRITER(record, type) \
83
template class l1t::WriterProxyT<record, type>; \
84
typedef l1t::WriterProxyT<record, type> record##_##type##_Writer; \
85
DEFINE_EDM_PLUGIN(l1t::WriterFactory, record##_##type##_Writer, #record "@" #type "@Writer")
86
87
}
// namespace l1t
88
89
#endif
cond::persistency::TransactionScope
Definition:
Session.h:231
PluginFactory.h
Exception.h
ESHandle.h
patZpeak.handle
handle
Definition:
patZpeak.py:23
l1t::DataAlreadyPresentException
Definition:
Exception.h:32
edm::Service::isAvailable
bool isAvailable() const
Definition:
Service.h:40
singleTopDQM_cfi.setup
setup
Definition:
singleTopDQM_cfi.py:37
l1t::WriterProxyT
Definition:
WriterProxy.h:44
l1t::WriterProxy
Definition:
WriterProxy.h:22
PoolDBOutputService.h
cond::service::PoolDBOutputService::session
cond::persistency::Session session() const
Definition:
PoolDBOutputService.cc:94
Service.h
edm::ESHandle
Definition:
DTSurvey.h:22
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
l1t
delete x;
Definition:
CaloConfig.h:22
edmplugin::PluginFactory
Definition:
PluginFactory.h:34
cond::persistency::Session
Definition:
Session.h:63
edm::Service< cond::service::PoolDBOutputService >
cond::Exception
persistency::Exception Exception
Definition:
Exception.h:25
l1t::WriterProxy::save
virtual std::string save(const edm::EventSetup &setup) const =0
edm::EventSetup
Definition:
EventSetup.h:57
get
#define get
cond::persistency::Session::storePayload
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition:
Session.h:186
cond::persistency::Session::transaction
Transaction & transaction()
Definition:
Session.cc:52
l1t::WriterProxyT::~WriterProxyT
~WriterProxyT() override
Definition:
WriterProxy.h:46
Record
l1t::WriterProxy::~WriterProxy
virtual ~WriterProxy()
Definition:
WriterProxy.h:24
EventSetup.h
l1t::WriterProxyT::save
std::string save(const edm::EventSetup &setup) const override
Definition:
WriterProxy.h:49
cond::service::PoolDBOutputService::forceInit
void forceInit()
Definition:
PoolDBOutputService.cc:173
Generated for CMSSW Reference Manual by
1.8.16