Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:51

0001 #include "FWCore/PluginManager/interface/PluginManager.h"
0002 #include "FWCore/PluginManager/interface/standard.h"
0003 //
0004 #include "CondCore/CondDB/interface/ConnectionPool.h"
0005 #include "CondFormats/Common/interface/BasicPayload.h"
0006 //
0007 #include <fstream>
0008 #include <iomanip>
0009 #include <cstdlib>
0010 #include <iostream>
0011 #include <random>
0012 
0013 using namespace cond::persistency;
0014 
0015 int run(const std::string& connectionString, bool generate) {
0016   try {
0017     //*************
0018     std::cout << "> Connecting with db in " << connectionString << std::endl;
0019     ConnectionPool connPool;
0020     connPool.setMessageVerbosity(coral::Debug);
0021     Session session = connPool.createSession(connectionString, true);
0022     session.transaction().start(false);
0023     IOVEditor editor;
0024     if (!session.existsDatabase() || !session.existsIov("BasicPayload_v0")) {
0025       editor = session.createIov<cond::BasicPayload>("BasicPayload_v0", cond::runnumber);
0026       editor.setDescription("Test for timestamp selection");
0027     }
0028     for (int i = 0; i < 10; i++) {
0029       cond::BasicPayload p;
0030       if (!generate) {
0031         cond::BasicPayload p0(i * 10.1, i + 1., 100);
0032         for (size_t j = 0; j < 100; j++)
0033           p0.m_vec[j] = 1;
0034         for (size_t j = 3; j < 7; j++)
0035           for (size_t i = 3; i < 7; i++)
0036             p0.m_vec[j * 10 + i] = 0;
0037         p = p0;
0038       } else {
0039         cond::BasicPayload p1(i * 10.1, i + 1., 10000);
0040         std::random_device rd;
0041         std::mt19937 mt(rd());
0042         std::uniform_real_distribution<float> dist(0., 1.);
0043         for (int i = 0; i < 10000; ++i)
0044           p1.m_vec[i] = dist(mt);
0045         p = p1;
0046       }
0047       auto pid = session.storePayload(p);
0048       editor.insert(i * 100 + 1, pid);
0049       p.print();
0050     }
0051     std::cout << "flushing..." << std::endl;
0052     editor.flush();
0053     std::cout << "> iov changes flushed..." << std::endl;
0054     session.transaction().commit();
0055   } catch (const std::exception& e) {
0056     std::cout << "ERROR: " << e.what() << std::endl;
0057     return -1;
0058   } catch (...) {
0059     std::cout << "UNEXPECTED FAILURE." << std::endl;
0060     return -1;
0061   }
0062   std::cout << "## Run successfully completed." << std::endl;
0063   return 0;
0064 }
0065 
0066 int main(int argc, char** argv) {
0067   bool generate = false;
0068   if (argc > 1) {
0069     std::string option = std::string(argv[1]);
0070     generate = (option == "generate");
0071   }
0072 
0073   int ret = 0;
0074   edmplugin::PluginManager::Config config;
0075   edmplugin::PluginManager::configure(edmplugin::standard::config());
0076   std::string connectionString0("sqlite_file:BasicPayload_v0.db");
0077   ret = run(connectionString0, generate);
0078   return ret;
0079 }