1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include "CondCore/DBCommon/interface/DbConnection.h"
#include "CondCore/DBCommon/interface/DbTransaction.h"
#include "CondCore/DBCommon/interface/Time.h"
#include "CondCore/DBCommon/interface/Exception.h"
#include "CondCore/IOVService/interface/IOVEditor.h"
#include "CondCore/MetaDataService/interface/MetaData.h"
#include "CondFormats/Calibration/interface/Pedestals.h"
#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/PluginManager/interface/standard.h"
#include <iostream>
int main() {
try {
// for runnumber
cond::TimeType timetype = cond::runnumber;
cond::Time_t globalTill = cond::timeTypeSpecs[timetype].endValue;
edmplugin::PluginManager::Config config;
edmplugin::PluginManager::configure(edmplugin::standard::config());
cond::DbConnection connection;
connection.configuration().setMessageLevel(coral::Error);
connection.configuration().setAuthenticationPath(".");
connection.configure();
cond::DbSession session = connection.createSession();
session.open("sqlite_file:test.db");
cond::IOVEditor ioveditor(session);
session.transaction().start(false);
std::cout << "globalTill value " << globalTill << std::endl;
ioveditor.create(timetype, globalTill);
for (unsigned int i = 0; i < 3; ++i) { //inserting 3 payloads
std::shared_ptr<Pedestals> myped(new Pedestals);
for (int ichannel = 1; ichannel <= 5; ++ichannel) {
Pedestals::Item item;
item.m_mean = 1.11 * ichannel + i;
item.m_variance = 1.12 * ichannel + i * 2;
myped->m_pedestals.push_back(item);
}
std::string payloadToken = session.storeObject(myped.get(), "PedestalsRcd");
ioveditor.append(cond::Time_t(2 + 2 * i), payloadToken);
}
//last one
std::shared_ptr<Pedestals> myped(new Pedestals);
for (int ichannel = 1; ichannel <= 5; ++ichannel) {
Pedestals::Item item;
item.m_mean = 3.11 * ichannel;
item.m_variance = 5.12 * ichannel;
myped->m_pedestals.push_back(item);
}
std::string payloadToken = session.storeObject(myped.get(), "PedestalsRcd");
ioveditor.append(9001, payloadToken);
std::string iovtoken = ioveditor.token();
std::cout << "iov token " << iovtoken << std::endl;
session.transaction().commit();
//pooldb.disconnect();
session.transaction().start(false);
ioveditor.create(timetype, globalTill);
std::shared_ptr<Pedestals> p(new Pedestals);
for (int ichannel = 1; ichannel <= 2; ++ichannel) {
Pedestals::Item item;
item.m_mean = 4.11 * ichannel;
item.m_variance = 5.82 * ichannel;
p->m_pedestals.push_back(item);
}
std::string payloadToken2 = session.storeObject(p.get(), "PedestalsRcd");
ioveditor.append(90001, payloadToken2);
std::string pediovtoken = ioveditor.token();
std::cout << "iov token " << pediovtoken << std::endl;
session.transaction().commit();
//
///I write different pedestals in another record
//
cond::IOVEditor anotherioveditor(session);
session.transaction().start(false);
anotherioveditor.create(timetype, globalTill);
for (unsigned int i = 0; i < 2; ++i) { //inserting 2 payloads to another Rcd
std::shared_ptr<Pedestals> myped(new Pedestals);
for (int ichannel = 1; ichannel <= 3; ++ichannel) {
Pedestals::Item item;
item.m_mean = 1.11 * ichannel + i;
item.m_variance = 1.12 * ichannel + i * 2;
myped->m_pedestals.push_back(item);
}
std::string payloadToken = session.storeObject(myped.get(), "anotherPedestalsRcd");
anotherioveditor.append(cond::Time_t(2 + 2 * i), payloadToken);
}
std::string anotheriovtoken = anotherioveditor.token();
std::cout << "anotheriovtoken " << anotheriovtoken << std::endl;
session.transaction().commit();
cond::MetaData metadata(session);
session.transaction().start(false);
metadata.addMapping("mytest", iovtoken, cond::runnumber);
metadata.addMapping("pedtag", pediovtoken, cond::runnumber);
metadata.addMapping("anothermytest", anotheriovtoken, cond::runnumber);
session.transaction().commit();
} catch (const cond::Exception& er) {
std::cout << "error " << er.what() << std::endl;
} catch (const std::exception& er) {
std::cout << "std error " << er.what() << std::endl;
}
}
|