Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:55

0001 #include "OnCalDBodbc.h"
0002 
0003 #include <odbc++/connection.h>
0004 #include <odbc++/drivermanager.h>
0005 #include <odbc++/statement.h>  // for Statement
0006 #include <odbc++/types.h>      // for SQLException
0007 
0008 #pragma GCC diagnostic push
0009 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
0010 #include <odbc++/resultset.h>
0011 #pragma GCC diagnostic pop
0012 
0013 #include <iostream>  // for operator<<, basic_ostream, endl, cout
0014 #include <sstream>
0015 
0016 //#define VERBOSE
0017 
0018 void OnCalDBodbc::identify() const
0019 {
0020   std::cout << "DB Name: " << dbname << std::endl;
0021   std::cout << "DB Owner: " << dbowner << std::endl;
0022   std::cout << "DB Pwd: " << dbpasswd << std::endl;
0023   return;
0024 }
0025 
0026 int OnCalDBodbc::GetLastCalibratedRun(const int runno) const
0027 {
0028   odbc::Connection* con = nullptr;
0029   odbc::Statement* query = nullptr;
0030   std::ostringstream cmd;
0031   int closestgoodrun = 329640;
0032   try
0033   {
0034     con = odbc::DriverManager::getConnection(dbname.c_str(), dbowner.c_str(), dbpasswd.c_str());
0035   }
0036   catch (odbc::SQLException& e)
0037   {
0038     std::cout << __PRETTY_FUNCTION__
0039               << " Exception caught during DriverManager::getConnection" << std::endl;
0040     std::cout << "Message: " << e.getMessage() << std::endl;
0041     return closestgoodrun;
0042   }
0043 
0044   query = con->createStatement();
0045   cmd << "SELECT runnumber FROM OnCal_status WHERE RUNNUMBER <= " << runno
0046       << " and dchcal > 0 and padcal > 0 and pbscgainscal > 0 and pbglqa>0 and pbglcal > 0"
0047       << " order by runnumber desc limit 1";
0048   if (verbosity > 0)
0049   {
0050     std::cout << "command: " << cmd.str() << std::endl;
0051   }
0052   odbc::ResultSet* rs = nullptr;
0053   try
0054   {
0055     rs = query->executeQuery(cmd.str());
0056   }
0057   catch (odbc::SQLException& e)
0058   {
0059     std::cout << "Exception caught" << std::endl;
0060     std::cout << "Message: " << e.getMessage() << std::endl;
0061   }
0062   if (rs && rs->next())
0063   {
0064     closestgoodrun = rs->getInt("runnumber");
0065   }
0066   delete con;
0067   return closestgoodrun;
0068 }