Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:47:04

0001 //
0002 // test Payload I/O
0003 //
0004 // requires a few sed....
0005 
0006 #include "CondCore/DBCommon/interface/DbScopedTransaction.h"
0007 #include "CondCore/DBCommon/interface/DbConnection.h"
0008 #include "CondCore/DBCommon/interface/DbTransaction.h"
0009 #include "CondCore/DBCommon/interface/Exception.h"
0010 #include "FWCore/PluginManager/interface/PluginManager.h"
0011 #include "FWCore/PluginManager/interface/standard.h"
0012 #include "RelationalAccess/ISchema.h"
0013 #include "RelationalAccess/TableDescription.h"
0014 #include "CoralBase/AttributeSpecification.h"
0015 #include <iostream>
0016 
0017 #include <vector>
0018 
0019 #ifdef ALLCLASSES
0020 #include "CondFormats/THEPACKAGE/src/classes.h"
0021 #else
0022 #include "CondFormats/THEPACKAGE/interface/THEHEADER.h"
0023 #endif
0024 
0025 typedef THECLASS Payload;
0026 
0027 int main(int argc, char**) {
0028   try {
0029     // this is the correct container name following cms rules (container name = C++ type name)
0030     //  std::string className = cond::classNameForTypeId(typeid(THECLASS));
0031 
0032     // for this test we use the class name THECLASS as typed by the user including space, typedefs etc
0033     // this makes further mapping query easier at script level....
0034     std::string className("THECLASS");
0035 
0036     edmplugin::PluginManager::Config config;
0037     edmplugin::PluginManager::configure(edmplugin::standard::config());
0038 
0039     unsigned int nobjects = 10;
0040     std::vector<std::string> payTok;
0041 
0042     //write....
0043     {
0044       cond::DbConnection conn;
0045       conn.configure(cond::CmsDefaults);
0046       cond::DbSession session = conn.createSession();
0047       session.open("sqlite_file:test.db", false);
0048 
0049       cond::DbScopedTransaction tr(session);
0050       tr.start(false);
0051       session.createDatabase();
0052       unsigned int iw;
0053       for (iw = 0; iw < nobjects; ++iw) {
0054         std::shared_ptr<Payload> payload(new Payload);
0055         std::string pToken = session.storeObject(payload.get(), className);
0056         payTok.push_back(pToken);
0057       }
0058 
0059       tr.commit();
0060       if (payTok.size() != nobjects)
0061         throw std::string("not all object written!");
0062     }
0063 
0064     //read....
0065     {
0066       cond::DbConnection conn;
0067       conn.configure(cond::CmsDefaults);
0068       cond::DbSession session = conn.createSession();
0069       session.open("sqlite_file:test.db");
0070       cond::DbScopedTransaction tr(session);
0071       tr.start(true);
0072 
0073       unsigned int ir;
0074       for (ir = 0; ir < payTok.size(); ++ir) {
0075         std::shared_ptr<Payload> payload = session.getTypedObject<Payload>(payTok[ir]);
0076         Payload const& p = *payload;
0077       }
0078 
0079       if (ir != nobjects)
0080         throw std::string("not all object read!");
0081 
0082       tr.commit();
0083     }
0084 
0085     //read
0086 
0087   } catch (const std::exception& e) {
0088     std::cout << "ERROR: " << e.what() << std::endl;
0089     throw;
0090   } catch (const std::string& e) {
0091     std::cout << "ERROR: " << e << std::endl;
0092     throw;
0093   }
0094 
0095   return 0;
0096 }