File indexing completed on 2023-03-17 11:20:00
0001 #include "FWCore/PluginManager/interface/PluginManager.h"
0002 #include "FWCore/PluginManager/interface/standard.h"
0003 #include "RecoLuminosity/LumiProducer/interface/DataPipe.h"
0004 #include "RecoLuminosity/LumiProducer/interface/DataPipeFactory.h"
0005 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
0006 #include "RecoLuminosity/LumiProducer/interface/RevisionDML.h"
0007 #include "RecoLuminosity/LumiProducer/interface/DBConfig.h"
0008 #include "RecoLuminosity/LumiProducer/interface/Exception.h"
0009 #include "RelationalAccess/ConnectionService.h"
0010 #include "RelationalAccess/ISessionProxy.h"
0011 #include "RelationalAccess/ITransaction.h"
0012 #include "RelationalAccess/ITypeConverter.h"
0013 #include "RelationalAccess/ISchema.h"
0014 #include "CoralBase/Exception.h"
0015 #include <fstream>
0016 #include <stdexcept>
0017 #include <sstream>
0018 #include <iostream>
0019 #include <time.h>
0020 #include <unistd.h>
0021 #include <cstdio>
0022
0023 #include <boost/program_options.hpp>
0024
0025 int main(int argc, char** argv) {
0026 std::string lumipluginName("Lumi2DB");
0027 std::string trgpluginName("TRGScalers2DB");
0028 std::string wbmpluginName("TRGWBM2DB");
0029 std::string hltpluginName("HLTV32DB");
0030 std::string hltconfpluginName("HLTConf2DB");
0031 std::string runsummarypluginName("CMSRunSummary2DB");
0032 std::string defaultRuninfoConnect("oracle://cms_omds_lb/CMS_RUNINFO");
0033 std::string defaultTRGConnect("oracle://cms_omds_lb/CMS_GT_MON");
0034 std::string defaultWBMConnect("oracle://cms_omds_lb/CMS_WBM");
0035 std::string defaultHLTConfConnect("oracle://cms_omds_lb/CMS_HLT");
0036
0037 boost::program_options::options_description desc("options");
0038 boost::program_options::options_description visible("Usage: cmmdLoadLumiDB [options] \n");
0039 visible.add_options()("runnumber,r", boost::program_options::value<unsigned int>(), "runnumber(required)")(
0040 "destConnect,c", boost::program_options::value<std::string>(), "destionation connection (required)")(
0041 "lumipath,L", boost::program_options::value<std::string>(), "path to lumi data file(required)")(
0042 "authpath,P", boost::program_options::value<std::string>(), "path to authentication xml(default .)")(
0043 "runinfodb,R", boost::program_options::value<std::string>(), "connect to runinfodb")(
0044 "confdb,C", boost::program_options::value<std::string>(), "connect to hltconfdb")(
0045 "trgdb,T", boost::program_options::value<std::string>(), "connect to trgdb")(
0046 "wbmdb,W", boost::program_options::value<std::string>(), "connect to wbmdb")(
0047 "configFile,f", boost::program_options::value<std::string>(), "configuration file(optional)")(
0048 "norm,n", boost::program_options::value<float>(), "norm factor(optional)")(
0049 "patchcomment,a", boost::program_options::value<std::string>(), "patchcomment(optional)")(
0050 "without-lumi", "exclude lumi loading")("without-trg", "exclude trg loading")(
0051 "without-hlt", "exclude hlt loading")("without-runsummary", "exclude runsummary loading")(
0052 "without-hconf", "exclude hltconf loading")("use-wbm", "use wbmdb for trigger info")(
0053 "collision-only", "load collision/physics run only")("schemav2-only", "load only to schemav2")(
0054 "nocheckingstablebeam", "do not require any presence of stable beam")("novalidate", "do not validate lumi data")(
0055 "dryrun", "dryrun print parameter only")("debug", "switch on debug mode")("help,h", "help message");
0056 desc.add(visible);
0057 std::string configuration_filename;
0058 unsigned int runnumber;
0059 std::string authpath(".");
0060 std::string destconnect;
0061 std::string lumipath;
0062 std::string runinfodb = defaultRuninfoConnect;
0063 std::string trgdb = defaultTRGConnect;
0064 std::string wbmdb = defaultWBMConnect;
0065 std::string hltconfdb = defaultHLTConfConnect;
0066 std::string patchcomment("");
0067 float norm = 0.0;
0068 bool without_lumi = false;
0069 bool without_trg = false;
0070 bool without_hlt = false;
0071 bool without_runsummary = false;
0072 bool without_hltconf = false;
0073 bool use_wbm = false;
0074 bool debug = false;
0075 bool novalidate = false;
0076 bool collision_only = false;
0077 bool schemav2_only = false;
0078 bool nocheckingstablebeam = false;
0079 bool dryrun = false;
0080 boost::program_options::variables_map vm;
0081 try {
0082 boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).run(), vm);
0083 if (vm.count("help")) {
0084 std::cout << visible << std::endl;
0085 ;
0086 return 0;
0087 }
0088 if (vm.count("configFile")) {
0089 configuration_filename = vm["configFile"].as<std::string>();
0090 if (!configuration_filename.empty()) {
0091 std::fstream configuration_file;
0092 configuration_file.open(configuration_filename.c_str(), std::fstream::in);
0093 boost::program_options::store(boost::program_options::parse_config_file(configuration_file, desc), vm);
0094 configuration_file.close();
0095 }
0096 }
0097 if (!vm.count("runnumber")) {
0098 std::cerr << "[Error] runnumber[r] option given \n";
0099 std::cerr << " please do " << argv[0] << " --help \n";
0100 return 1;
0101 } else {
0102 runnumber = vm["runnumber"].as<unsigned int>();
0103 }
0104 if (!vm.count("destConnect")) {
0105 std::cerr << "[Error] no destConnect[c] option given \n";
0106 std::cerr << " please do " << argv[0] << " --help \n";
0107 return 1;
0108 } else {
0109 destconnect = vm["destConnect"].as<std::string>();
0110 }
0111 if (vm.count("lumipath")) {
0112 lumipath = vm["lumipath"].as<std::string>();
0113 }
0114 if (vm.count("authpath")) {
0115 authpath = vm["authpath"].as<std::string>();
0116 }
0117 if (vm.count("runinfodb")) {
0118 runinfodb = vm["runinfodb"].as<std::string>();
0119 }
0120 if (vm.count("confdb")) {
0121 hltconfdb = vm["confdb"].as<std::string>();
0122 }
0123 if (vm.count("trgdb")) {
0124 trgdb = vm["trgdb"].as<std::string>();
0125 }
0126 if (vm.count("wbmdb")) {
0127 wbmdb = vm["wbmdb"].as<std::string>();
0128 }
0129 if (vm.count("patchcomment")) {
0130 patchcomment = vm["patchcomment"].as<std::string>();
0131 }
0132 if (vm.count("norm")) {
0133 norm = vm["norm"].as<float>();
0134 }
0135 if (vm.count("without-lumi")) {
0136 without_lumi = true;
0137 }
0138 if (vm.count("without-trg")) {
0139 without_trg = true;
0140 }
0141 if (vm.count("without-hlt")) {
0142 without_hlt = true;
0143 }
0144 if (vm.count("without-runsummary")) {
0145 without_runsummary = true;
0146 }
0147 if (vm.count("without-hconf")) {
0148 without_hltconf = true;
0149 }
0150 if (vm.count("use-wbm")) {
0151 use_wbm = true;
0152 }
0153 if (vm.count("novalidate")) {
0154 novalidate = true;
0155 }
0156 if (vm.count("collision-only")) {
0157 collision_only = true;
0158 }
0159 if (vm.count("schemav2-only")) {
0160 schemav2_only = true;
0161 }
0162 if (vm.count("nocheckingstablebeam")) {
0163 nocheckingstablebeam = true;
0164 }
0165 if (vm.count("dryrun")) {
0166 dryrun = true;
0167 }
0168 if (vm.count("debug")) {
0169 debug = true;
0170 }
0171 if (!without_lumi && lumipath.size() == 0) {
0172 std::cerr << "[Error] lumipath[L] option is required \n";
0173 std::cerr << " please do " << argv[0] << " --help \n";
0174 return 1;
0175 }
0176 boost::program_options::notify(vm);
0177 } catch (const boost::program_options::error& er) {
0178 std::cerr << er.what() << std::endl;
0179 return 1;
0180 }
0181 if (debug) {
0182 std::cout << "runnumber " << runnumber << std::endl;
0183 std::cout << "destConnect " << destconnect << std::endl;
0184 std::cout << "authpath " << authpath << std::endl;
0185 std::cout << "lumipath " << lumipath << std::endl;
0186 std::cout << "runinfodb " << runinfodb << std::endl;
0187 std::cout << "hltconfdb " << hltconfdb << std::endl;
0188 std::cout << "trgdb " << trgdb << std::endl;
0189 std::cout << "wbmdb " << wbmdb << std::endl;
0190 std::string answer;
0191 (without_lumi) ? (answer = std::string("No")) : (answer = std::string("Yes"));
0192 std::cout << "loading lumi? " << answer << std::endl;
0193 (without_trg) ? (answer = std::string("No")) : (answer = std::string("Yes"));
0194 std::cout << "loading trg? " << answer << std::endl;
0195 (without_hlt) ? (answer = std::string("No")) : (answer = std::string("Yes"));
0196 std::cout << "loading hlt? " << answer << std::endl;
0197 (without_runsummary) ? (answer = std::string("No")) : (answer = std::string("Yes"));
0198 std::cout << "loading runsummary? " << answer << std::endl;
0199 (without_hltconf) ? (answer = std::string("No")) : (answer = std::string("Yes"));
0200 std::cout << "loading hltconf? " << answer << std::endl;
0201 (use_wbm) ? (answer = std::string("Yes")) : (answer = std::string("No"));
0202 std::cout << "using wbm as trigger source? " << answer << std::endl;
0203 (novalidate) ? (answer = std::string("No")) : (answer = std::string("Yes"));
0204 std::cout << "validate data? " << answer << std::endl;
0205 (collision_only) ? (answer = std::string("Yes")) : (answer = std::string("No"));
0206 std::cout << "collision only ? " << answer << std::endl;
0207 (schemav2_only) ? (answer = std::string("Yes")) : (answer = std::string("No"));
0208 std::cout << "schemav2 only ? " << answer << std::endl;
0209 (nocheckingstablebeam) ? (answer = std::string("No")) : (answer = std::string("Yes"));
0210 std::cout << "checking stablebeam ? " << answer << std::endl;
0211 (dryrun) ? (answer = std::string("Yes")) : (answer = std::string("No"));
0212 std::cout << "dryrun? " << answer << std::endl;
0213 }
0214 if (dryrun)
0215 return 0;
0216 clock_t startClock, endClock;
0217 double elapsedTime = 0.0;
0218 time_t t1, t2;
0219 edmplugin::PluginManager::Config config;
0220 edmplugin::PluginManager::configure(edmplugin::standard::config());
0221 std::cout << "==========" << std::endl;
0222 unsigned int lumidataid = 0;
0223 unsigned int trgdataid = 0;
0224 unsigned int hltdataid = 0;
0225 if (!without_lumi) {
0226 std::cout << "Loading lumi from " << lumipath << " to " << destconnect << " run " << runnumber << " with "
0227 << lumipluginName << std::endl;
0228 try {
0229 std::unique_ptr<lumi::DataPipe> lumiptr(lumi::DataPipeFactory::get()->create(lumipluginName, destconnect));
0230 lumiptr->setAuthPath(authpath);
0231 lumiptr->setSource(lumipath);
0232 if (novalidate) {
0233 lumiptr->setNoValidate();
0234 }
0235 if (nocheckingstablebeam) {
0236 lumiptr->setNoCheckingStableBeam();
0237 }
0238 if (norm != 0.0) {
0239 std::cout << "applying norm " << norm << std::endl;
0240 lumiptr->setNorm(norm);
0241 }
0242
0243 if (!schemav2_only) {
0244 lumiptr->setMode("loadoldschema");
0245 }
0246 startClock = clock();
0247 time(&t1);
0248 lumidataid = lumiptr->retrieveData(runnumber);
0249 time(&t2);
0250 endClock = clock();
0251 lumiptr.release();
0252 } catch (const lumi::invalidDataException& er) {
0253
0254
0255
0256
0257 std::cout << "\t [ERROR]lumi data for this run is not valid, stop loading immediately";
0258 std::cout << "\t" << er.what() << std::endl;
0259 return 1;
0260
0261 } catch (const lumi::noStableBeamException& er) {
0262 std::cout << "\t [ERROR]lumi data for this run has no stable beam, stop loading immediately";
0263 std::cout << "\t" << er.what() << std::endl;
0264 return 1;
0265 } catch (const coral::Exception& er) {
0266 std::cout << "\t Database error " << er.what() << std::endl;
0267 throw;
0268 } catch (...) {
0269 std::cout << "\tproblem in loading lumi " << runnumber << " SKIP " << std::endl;
0270 throw;
0271 }
0272 printf("\tElaspsed time %fs\n", difftime(t2, t1));
0273 elapsedTime = ((double)(endClock - startClock)) / CLOCKS_PER_SEC;
0274 std::cout << "\tCPU Time taken in seconds : " << elapsedTime << std::endl;
0275 }
0276 if (!without_runsummary) {
0277 std::cout << "Loading runsummary from " << runinfodb << " to " << destconnect << " run " << runnumber << " with "
0278 << runsummarypluginName << std::endl;
0279 try {
0280 std::unique_ptr<lumi::DataPipe> runptr(lumi::DataPipeFactory::get()->create(runsummarypluginName, destconnect));
0281 runptr->setSource(runinfodb);
0282 runptr->setAuthPath(authpath);
0283 if (!collision_only) {
0284 runptr->setNoValidate();
0285 }
0286 startClock = clock();
0287 time(&t1);
0288 runptr->retrieveData(runnumber);
0289 time(&t2);
0290 endClock = clock();
0291 runptr.release();
0292 } catch (const lumi::invalidDataException& er) {
0293 std::cout << "\t [ERROR], run is not collision run, stop loading immediately";
0294 std::cout << "\t" << er.what() << std::endl;
0295 return 1;
0296 } catch (const coral::Exception& er) {
0297 std::cout << "\t Database error " << er.what() << std::endl;
0298 throw;
0299 } catch (...) {
0300 std::cout << "\tproblem in loading runsummary " << runnumber << " SKIP " << std::endl;
0301 throw;
0302 }
0303 printf("\tElaspsed time %fs\n", difftime(t2, t1));
0304 elapsedTime = ((double)(endClock - startClock)) / CLOCKS_PER_SEC;
0305 std::cout << "\tCPU Time taken in seconds : " << elapsedTime << std::endl;
0306 }
0307 if (!without_hltconf) {
0308 try {
0309 std::cout << "Loading hlt conf from " << hltconfdb << " to " << destconnect << " run " << runnumber << " with "
0310 << hltconfpluginName << std::endl;
0311 std::unique_ptr<lumi::DataPipe> confptr(lumi::DataPipeFactory::get()->create(hltconfpluginName, destconnect));
0312 confptr->setSource(hltconfdb);
0313 confptr->setAuthPath(authpath);
0314 startClock = clock();
0315 time(&t1);
0316 confptr->retrieveData(runnumber);
0317 time(&t2);
0318 endClock = clock();
0319 confptr.release();
0320 } catch (const coral::Exception& er) {
0321 std::cout << "\t Database error " << er.what() << std::endl;
0322 throw;
0323 } catch (...) {
0324 std::cout << "\tproblem in loading hltconf " << runnumber << " SKIP " << std::endl;
0325 throw;
0326 }
0327 printf("\tElaspsed time %fs\n", difftime(t2, t1));
0328 elapsedTime = ((double)(endClock - startClock)) / CLOCKS_PER_SEC;
0329 std::cout << "\tCPU Time taken in seconds : " << elapsedTime << std::endl;
0330 }
0331 if (!without_trg) {
0332 try {
0333 if (!use_wbm) {
0334 std::cout << "Loading trg from GT " << trgdb << " to " << destconnect << " run " << runnumber << " with "
0335 << trgpluginName << std::endl;
0336 std::unique_ptr<lumi::DataPipe> trgptr(lumi::DataPipeFactory::get()->create(trgpluginName, destconnect));
0337 trgptr->setAuthPath(authpath);
0338 trgptr->setSource(trgdb);
0339 if (!schemav2_only) {
0340 trgptr->setMode("loadoldschema");
0341 }
0342 startClock = clock();
0343 time(&t1);
0344 trgdataid = trgptr->retrieveData(runnumber);
0345 time(&t2);
0346 endClock = clock();
0347 trgptr.release();
0348 } else {
0349 std::cout << "Loading trg from WBM " << wbmdb << " to " << destconnect << " run " << runnumber << " with "
0350 << wbmpluginName << std::endl;
0351 std::unique_ptr<lumi::DataPipe> trgptr(lumi::DataPipeFactory::get()->create(wbmpluginName, destconnect));
0352 trgptr->setAuthPath(authpath);
0353 trgptr->setSource(wbmdb);
0354 startClock = clock();
0355 time(&t1);
0356 trgdataid = trgptr->retrieveData(runnumber);
0357 time(&t2);
0358 endClock = clock();
0359 trgptr.release();
0360 }
0361 } catch (const coral::Exception& er) {
0362 std::cout << "\t Database error " << er.what() << std::endl;
0363 throw;
0364 } catch (...) {
0365 std::cout << "\tproblem in loading trigger " << runnumber << " SKIP " << std::endl;
0366 throw;
0367 }
0368 printf("\tElaspsed time %fs\n", difftime(t2, t1));
0369 elapsedTime = ((double)(endClock - startClock)) / CLOCKS_PER_SEC;
0370 std::cout << "\tCPU Time taken in seconds : " << elapsedTime << std::endl;
0371 }
0372 if (!without_hlt) {
0373 std::cout << "Loading hlt from Runinfo " << runinfodb << " to " << destconnect << " run " << runnumber << " with "
0374 << hltpluginName << std::endl;
0375 try {
0376 std::unique_ptr<lumi::DataPipe> hltptr(lumi::DataPipeFactory::get()->create(hltpluginName, destconnect));
0377 hltptr->setSource(runinfodb);
0378 hltptr->setAuthPath(authpath);
0379 if (!schemav2_only) {
0380 hltptr->setMode("loadoldschema");
0381 }
0382 startClock = clock();
0383 time(&t1);
0384 hltdataid = hltptr->retrieveData(runnumber);
0385 time(&t2);
0386 endClock = clock();
0387 hltptr.release();
0388 } catch (const coral::Exception& er) {
0389 std::cout << "\t Database error " << er.what() << std::endl;
0390 throw;
0391 } catch (...) {
0392 std::cout << "\tproblem in loading hlt " << runnumber << " SKIP " << std::endl;
0393 throw;
0394 }
0395 printf("\tElaspsed time %fs\n", difftime(t2, t1));
0396 std::cout << "\tCPU Time taken in seconds : " << elapsedTime << std::endl;
0397 }
0398
0399
0400
0401
0402 coral::ConnectionService* svc = new coral::ConnectionService;
0403 lumi::DBConfig dbconf(*svc);
0404 if (!authpath.empty()) {
0405 dbconf.setAuthentication(authpath);
0406 }
0407 coral::ISessionProxy* session = svc->connect(destconnect, coral::Update);
0408 coral::ITypeConverter& lumitpc = session->typeConverter();
0409 lumitpc.setCppTypeForSqlType("unsigned int", "NUMBER(7)");
0410 lumitpc.setCppTypeForSqlType("unsigned int", "NUMBER(10)");
0411 lumitpc.setCppTypeForSqlType("unsigned long long", "NUMBER(20)");
0412 coral::ITransaction& transaction = session->transaction();
0413 transaction.start(false);
0414 lumi::RevisionDML revisionDML;
0415 unsigned long long currenttagiid = 0;
0416 try {
0417 currenttagiid = revisionDML.addRunToCurrentHFDataTag(
0418 session->nominalSchema(), runnumber, lumidataid, trgdataid, hltdataid, patchcomment);
0419 } catch (const lumi::duplicateRunInDataTagException&) {
0420 std::cout << "\t[ERROR] run already registered in the current tag, create a new tag for the patches" << std::endl;
0421 transaction.rollback();
0422 delete session;
0423 return 0;
0424 } catch (const coral::Exception& er) {
0425 std::cout << "\t[ERROR] Database error " << er.what() << std::endl;
0426 throw;
0427 } catch (...) {
0428 std::cout << "\t[ERROR] problem in registering run to tag " << runnumber << " SKIP " << std::endl;
0429 throw;
0430 }
0431 transaction.commit();
0432 std::cout << "register run to current data tag id=" << currenttagiid << " run " << runnumber
0433 << " dataid: " << lumidataid << "-" << trgdataid << "-" << hltdataid << " " << patchcomment << std::endl;
0434 delete session;
0435 return 0;
0436 }