00001 #include "OnlineDB/CSCCondDB/interface/CSCMap.h"
00002 #include <cstdlib>
00003
00007 cscmap::cscmap () throw (oracle::occi::SQLException)
00008 {
00009 std::string db_user;
00010 std::string db_pass;
00011 env = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::DEFAULT);
00012 char* c_user = ::getenv("CSCMAP_AUTH_USER");
00013 char* c_pass = ::getenv("CSCMAP_AUTH_PASSWORD");
00014 db_user=std::string(c_user);
00015 db_pass=std::string(c_pass);
00016 con = env->createConnection (db_user,db_pass,"devdb");
00017 std::cout << "Connection to mapping DB is done." << std::endl;
00018 }
00022 cscmap::~cscmap () throw (oracle::occi::SQLException)
00023 {
00024 env->terminateConnection (con);
00025 oracle::occi::Environment::terminateEnvironment (env);
00026 }
00027
00028 void cscmap::crate0_chamber (int crate0, int dmb, std::string *chamber_id,
00029 int *chamber_num, int *sector, int *first_strip_index,
00030 int *strips_per_layer, int *chamber_index)
00031 {
00032 oracle::occi::Statement *stmt = con->createStatement();
00033 stmt->setSQL("begin cscmap.chamber0(:1, :2, :3, :4, :5, :6, :7, :8); end;");
00034
00035 stmt->setInt (1, crate0);
00036 stmt->setInt (2, dmb);
00037 stmt->registerOutParam(3, oracle::occi::OCCISTRING, 10);
00038 stmt->registerOutParam (4, oracle::occi::OCCIINT);
00039 stmt->registerOutParam (5, oracle::occi::OCCIINT);
00040 stmt->registerOutParam (6, oracle::occi::OCCIINT);
00041 stmt->registerOutParam (7, oracle::occi::OCCIINT);
00042 stmt->registerOutParam (8, oracle::occi::OCCIINT);
00043
00044 stmt->execute();
00045
00046 *chamber_id = stmt->getString(3);
00047 *chamber_num = stmt->getInt(4);
00048 *chamber_index = stmt->getInt(5);
00049 *first_strip_index = stmt->getInt(6);
00050 *strips_per_layer = stmt->getInt(7);
00051 *sector = stmt->getInt(8);
00052
00053 con->terminateStatement (stmt);
00054 }
00055
00056 void cscmap::crate_chamber (int crate, int dmb, std::string *chamber_id,
00057 int *chamber_num, int *sector, int *first_strip_index,
00058 int *strips_per_layer, int *chamber_index)
00059 {
00060 oracle::occi::Statement *stmt = con->createStatement();
00061 stmt->setSQL("begin cscmap.chamber(:1, :2, :3, :4, :5, :6, :7, :8); end;");
00062
00063 stmt->setInt (1, crate);
00064 stmt->setInt (2, dmb);
00065 stmt->registerOutParam(3, oracle::occi::OCCISTRING, 10);
00066 stmt->registerOutParam (4, oracle::occi::OCCIINT);
00067 stmt->registerOutParam (5, oracle::occi::OCCIINT);
00068 stmt->registerOutParam (6, oracle::occi::OCCIINT);
00069 stmt->registerOutParam (7, oracle::occi::OCCIINT);
00070 stmt->registerOutParam (8, oracle::occi::OCCIINT);
00071
00072 stmt->execute();
00073
00074 *chamber_id = stmt->getString(3);
00075 *chamber_num = stmt->getInt(4);
00076 *chamber_index = stmt->getInt(5);
00077 *first_strip_index = stmt->getInt(6);
00078 *strips_per_layer = stmt->getInt(7);
00079 *sector = stmt->getInt(8);
00080
00081 con->terminateStatement (stmt);
00082 }
00083
00084 void cscmap::chamber_crate (std::string chamber_id, int *crate, int *dmb,
00085 int *sector, int *chamber_num, int *crate0,
00086 int *first_strip_index, int *strips_per_layer,
00087 int *chamber_index)
00088 {
00089 oracle::occi::Statement *stmt = con->createStatement();
00090 stmt->setSQL("begin cscmap.crate0_proc(:1, :2, :3, :4, :5, :6, :7, :8, :9); end;");
00091
00092 stmt->setString (1, chamber_id);
00093 stmt->registerOutParam (2, oracle::occi::OCCIINT);
00094 stmt->registerOutParam (3, oracle::occi::OCCIINT);
00095 stmt->registerOutParam (4, oracle::occi::OCCIINT);
00096 stmt->registerOutParam (5, oracle::occi::OCCIINT);
00097 stmt->registerOutParam (6, oracle::occi::OCCIINT);
00098 stmt->registerOutParam (7, oracle::occi::OCCIINT);
00099 stmt->registerOutParam (8, oracle::occi::OCCIINT);
00100 stmt->registerOutParam (9, oracle::occi::OCCIINT);
00101
00102 stmt->execute();
00103
00104 *crate0 = stmt->getInt(2);
00105 *crate = stmt->getInt(3);
00106 *dmb = stmt->getInt(4);
00107 *sector = stmt->getInt(5);
00108 *chamber_num = stmt->getInt(6);
00109 *chamber_index = stmt->getInt(7);
00110 *first_strip_index = stmt->getInt(8);
00111 *strips_per_layer = stmt->getInt(9);
00112
00113 con->terminateStatement (stmt);
00114 }