Back to home page

Project CMSSW displayed by LXR

 
 

    


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     // for runnumber
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.configuration().setAuthenticationPath(".");
0023     connection.configure();
0024     cond::DbSession session = connection.createSession();
0025     session.open("sqlite_file:test.db");
0026 
0027     cond::IOVEditor ioveditor(session);
0028     session.transaction().start(false);
0029     std::cout << "globalTill value " << globalTill << std::endl;
0030     ioveditor.create(timetype, globalTill);
0031     for (unsigned int i = 0; i < 3; ++i) {  //inserting 3 payloads
0032       std::shared_ptr<Pedestals> myped(new Pedestals);
0033       for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0034         Pedestals::Item item;
0035         item.m_mean = 1.11 * ichannel + i;
0036         item.m_variance = 1.12 * ichannel + i * 2;
0037         myped->m_pedestals.push_back(item);
0038       }
0039       std::string payloadToken = session.storeObject(myped.get(), "PedestalsRcd");
0040       ioveditor.append(cond::Time_t(2 + 2 * i), payloadToken);
0041     }
0042     //last one
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     std::string iovtoken = ioveditor.token();
0053     std::cout << "iov token " << iovtoken << std::endl;
0054     session.transaction().commit();
0055     //pooldb.disconnect();
0056     session.transaction().start(false);
0057     ioveditor.create(timetype, globalTill);
0058     std::shared_ptr<Pedestals> p(new Pedestals);
0059     for (int ichannel = 1; ichannel <= 2; ++ichannel) {
0060       Pedestals::Item item;
0061       item.m_mean = 4.11 * ichannel;
0062       item.m_variance = 5.82 * ichannel;
0063       p->m_pedestals.push_back(item);
0064     }
0065     std::string payloadToken2 = session.storeObject(p.get(), "PedestalsRcd");
0066     ioveditor.append(90001, payloadToken2);
0067     std::string pediovtoken = ioveditor.token();
0068     std::cout << "iov token " << pediovtoken << std::endl;
0069     session.transaction().commit();
0070     //
0071     ///I write different pedestals in another record
0072     //
0073     cond::IOVEditor anotherioveditor(session);
0074     session.transaction().start(false);
0075     anotherioveditor.create(timetype, globalTill);
0076     for (unsigned int i = 0; i < 2; ++i) {  //inserting 2 payloads to another Rcd
0077       std::shared_ptr<Pedestals> myped(new Pedestals);
0078       for (int ichannel = 1; ichannel <= 3; ++ichannel) {
0079         Pedestals::Item item;
0080         item.m_mean = 1.11 * ichannel + i;
0081         item.m_variance = 1.12 * ichannel + i * 2;
0082         myped->m_pedestals.push_back(item);
0083       }
0084       std::string payloadToken = session.storeObject(myped.get(), "anotherPedestalsRcd");
0085       anotherioveditor.append(cond::Time_t(2 + 2 * i), payloadToken);
0086     }
0087     std::string anotheriovtoken = anotherioveditor.token();
0088     std::cout << "anotheriovtoken " << anotheriovtoken << std::endl;
0089     session.transaction().commit();
0090 
0091     cond::MetaData metadata(session);
0092     session.transaction().start(false);
0093     metadata.addMapping("mytest", iovtoken, cond::runnumber);
0094     metadata.addMapping("pedtag", pediovtoken, cond::runnumber);
0095     metadata.addMapping("anothermytest", anotheriovtoken, cond::runnumber);
0096     session.transaction().commit();
0097   } catch (const cond::Exception& er) {
0098     std::cout << "error " << er.what() << std::endl;
0099   } catch (const std::exception& er) {
0100     std::cout << "std error " << er.what() << std::endl;
0101   }
0102 }