Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:57:27

0001 #include "OnlineDB/EcalCondDB/interface/LMFColoredTable.h"
0002 
0003 LMFColoredTable::LMFColoredTable() : LMFDat() {
0004   m_className = "LMFColoredTable";
0005   m_system = 0;
0006   m_color = 0;
0007   COLOR[0] = "BLUE";
0008   COLOR[1] = "GREEN";
0009   COLOR[2] = "ORANGE";
0010   COLOR[3] = "IR";
0011   SYSTEM[0] = "LASER";
0012   SYSTEM[1] = "LED";
0013 }
0014 
0015 LMFColoredTable::LMFColoredTable(EcalDBConnection* c) : LMFDat(c) {
0016   m_className = "LMFColoredTable";
0017   m_system = 0;
0018   m_color = 0;
0019   COLOR[0] = "BLUE";
0020   COLOR[1] = "GREEN";
0021   COLOR[2] = "ORANGE";
0022   COLOR[3] = "IR";
0023   SYSTEM[0] = "LASER";
0024   SYSTEM[1] = "LED";
0025 }
0026 
0027 LMFColoredTable::LMFColoredTable(oracle::occi::Environment* env, oracle::occi::Connection* conn) : LMFDat(env, conn) {
0028   m_className = "LMFColoredTable";
0029   m_system = 0;
0030   m_color = 0;
0031   COLOR[0] = "BLUE";
0032   COLOR[1] = "GREEN";
0033   COLOR[2] = "ORANGE";
0034   COLOR[3] = "IR";
0035   SYSTEM[0] = "LASER";
0036   SYSTEM[1] = "LED";
0037 }
0038 
0039 std::string LMFColoredTable::getColor() const {
0040   std::string ret = "";
0041   std::map<int, std::string>::const_iterator i = COLOR.find(m_color);
0042   if (i != COLOR.end()) {
0043     ret = i->second;
0044   }
0045   return ret;
0046 }
0047 
0048 std::string LMFColoredTable::getSystem() const {
0049   std::string ret = "";
0050   std::map<int, std::string>::const_iterator i = SYSTEM.find(m_system);
0051   if (i != SYSTEM.end()) {
0052     ret = i->second;
0053   }
0054   return ret;
0055 }
0056 
0057 LMFColoredTable& LMFColoredTable::setColor(std::string color) {
0058   std::transform(color.begin(), color.end(), color.begin(), toupper);
0059   std::map<int, std::string>::const_iterator i = COLOR.begin();
0060   std::map<int, std::string>::const_iterator e = COLOR.end();
0061   bool loop = true;
0062   while ((loop) && (i != e)) {
0063     if (i->second == color) {
0064       loop = false;
0065       setColor(i->first);
0066     }
0067     i++;
0068   }
0069   return *this;
0070 }
0071 
0072 LMFColoredTable& LMFColoredTable::setSystem(std::string system) {
0073   std::transform(system.begin(), system.end(), system.begin(), toupper);
0074   std::map<int, std::string>::const_iterator i = SYSTEM.begin();
0075   std::map<int, std::string>::const_iterator e = SYSTEM.end();
0076   bool loop = true;
0077   while ((loop) && (i != e)) {
0078     if (i->second == system) {
0079       loop = false;
0080       setSystem(i->first);
0081     }
0082     i++;
0083   }
0084   return *this;
0085 }
0086 
0087 int LMFColoredTable::writeDB() noexcept(false) {
0088   // check if the VMIN version has been properly set, otherwise
0089   // change it to the default value
0090   std::map<int, std::vector<float> >::iterator i = m_data.begin();
0091   std::map<int, std::vector<float> >::iterator e = m_data.end();
0092   std::list<int> versions;  // the list of different versions
0093   while (i != e) {
0094     int s = i->second.size();
0095     if (i->second[s - 2] == 0) {  // VMIN cannot be NULL
0096       i->second[s - 2] = 1;
0097     }
0098     versions.push_back(i->second[s - 1]);
0099     versions.push_back(i->second[s - 2]);
0100     versions.unique();
0101     i++;
0102   }
0103   //  checkVesrions(versions); // not yet used, in fact...
0104   int ret = 0;
0105   try {
0106     ret = LMFDat::writeDB();
0107   } catch (std::runtime_error& e) {
0108     m_conn->rollback();
0109     throw(e);
0110   }
0111   return ret;
0112 }