File indexing completed on 2024-04-06 12:01:39
0001 #include "CondCore/DBCommon/interface/DbConnection.h"
0002 #include "CondCore/DBCommon/interface/DbTransaction.h"
0003 #include "CondCore/DBCommon/interface/Time.h"
0004 #include "CondCore/DBCommon/interface/Exception.h"
0005 #include "CondCore/IOVService/interface/IOVEditor.h"
0006 #include "CondCore/MetaDataService/interface/MetaData.h"
0007 #include "CondFormats/Calibration/interface/Pedestals.h"
0008 #include "FWCore/PluginManager/interface/PluginManager.h"
0009 #include "FWCore/PluginManager/interface/standard.h"
0010 #include <iostream>
0011
0012 int main() {
0013 try {
0014
0015 cond::TimeType timetype = cond::runnumber;
0016 cond::Time_t globalTill = cond::timeTypeSpecs[timetype].endValue;
0017 edmplugin::PluginManager::Config config;
0018 edmplugin::PluginManager::configure(edmplugin::standard::config());
0019
0020 cond::DbConnection connection;
0021 connection.configuration().setMessageLevel(coral::Error);
0022 connection.configure();
0023 cond::DbSession session = connection.createSession();
0024 session.open("sqlite_file:mytest.db");
0025
0026 cond::IOVEditor ioveditor(session);
0027 session.transaction().start(false);
0028 ioveditor.create(timetype, globalTill);
0029 std::string mytestiovtoken;
0030 for (unsigned int i = 0; i < 3; ++i) {
0031 std::shared_ptr<Pedestals> myped(new Pedestals);
0032 for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0033 Pedestals::Item item;
0034 item.m_mean = 1.11 * ichannel + i;
0035 item.m_variance = 1.12 * ichannel + i * 2;
0036 myped->m_pedestals.push_back(item);
0037 }
0038
0039 std::string payloadToken = session.storeObject(myped.get(), "PedestalsRcd");
0040 ioveditor.append(cond::Time_t(2 + 2 * i), payloadToken);
0041 }
0042
0043 std::shared_ptr<Pedestals> myped(new Pedestals);
0044 for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0045 Pedestals::Item item;
0046 item.m_mean = 3.11 * ichannel;
0047 item.m_variance = 5.12 * ichannel;
0048 myped->m_pedestals.push_back(item);
0049 }
0050 std::string payloadToken = session.storeObject(myped.get(), "PedestalsRcd");
0051 ioveditor.append(9001, payloadToken);
0052 mytestiovtoken = ioveditor.token();
0053 std::cout << "mytest iov token " << mytestiovtoken << std::endl;
0054 session.transaction().commit();
0055
0056 std::string mypedestalsiovtoken;
0057 cond::IOVEditor ioveditor2(session);
0058 session.transaction().start(false);
0059 ioveditor2.create(timetype, globalTill);
0060 for (unsigned int i = 0; i < 2; ++i) {
0061 std::shared_ptr<Pedestals> myped(new Pedestals);
0062 for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0063 Pedestals::Item item;
0064 item.m_mean = 1.11 * ichannel + i;
0065 item.m_variance = 1.12 * ichannel + i * 2;
0066 myped->m_pedestals.push_back(item);
0067 }
0068 std::string payloadToken = session.storeObject(myped.get(), "PedestalsRcd");
0069 ioveditor2.append(cond::Time_t(5 + 2 * i), payloadToken);
0070 }
0071 mypedestalsiovtoken = ioveditor2.token();
0072 std::cout << "mytest iov token " << mypedestalsiovtoken << std::endl;
0073 session.transaction().commit();
0074
0075
0076
0077
0078 std::string anothermytestiovtoken;
0079 cond::IOVEditor anotherioveditor(session);
0080 session.transaction().start(false);
0081 anotherioveditor.create(timetype, globalTill);
0082 for (unsigned int i = 0; i < 2; ++i) {
0083 std::shared_ptr<Pedestals> myped(new Pedestals);
0084 for (int ichannel = 1; ichannel <= 3; ++ichannel) {
0085 Pedestals::Item item;
0086 item.m_mean = 1.11 * ichannel + i;
0087 item.m_variance = 1.12 * ichannel + i * 2;
0088 myped->m_pedestals.push_back(item);
0089 }
0090 std::string payloadToken = session.storeObject(myped.get(), "anotherPedestalsRcd");
0091 anotherioveditor.append(cond::Time_t(2 + 2 * i), payloadToken);
0092 }
0093 anothermytestiovtoken = anotherioveditor.token();
0094 session.transaction().commit();
0095 std::cout << "anothermytest iov token " << anothermytestiovtoken << std::endl;
0096
0097 cond::MetaData metadata(session);
0098 session.transaction().start(false);
0099 metadata.addMapping("mytest", mytestiovtoken);
0100 metadata.addMapping("mypedestals", mypedestalsiovtoken);
0101 metadata.addMapping("anothermytest", anothermytestiovtoken);
0102 session.transaction().commit();
0103 } catch (const cond::Exception& er) {
0104 std::cout << "error " << er.what() << std::endl;
0105 } catch (const std::exception& er) {
0106 std::cout << "std error " << er.what() << std::endl;
0107 }
0108 }