CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes | Friends

LMFDat Class Reference

#include <LMFDat.h>

Inheritance diagram for LMFDat:
LMFUnique IUniqueDBObject IDBObject LMFColoredTable LMFCorrCoefDatComponent LMFLaserConfigDat LMFRunDat LMFTestPulseConfigDat LMFClsDat LMFLaserPulseDat LMFPnPrimDat LMFPrimDat

List of all members.

Public Member Functions

void dump () const
void dump (int n) const
virtual void dump (int n, int max) const
void fetch (const EcalLogicID &id) throw (std::runtime_error)
void fetch () throw (std::runtime_error)
void fetch (int logic_id) throw (std::runtime_error)
void fetch (int logic_id, const Tm &tm) throw (std::runtime_error)
void fetch (int logic_id, const Tm *timestamp, int dir) throw (std::runtime_error)
void fetch (const EcalLogicID &id, const Tm &tm) throw (std::runtime_error)
void fetch (const EcalLogicID &id, const Tm &tm, int dir) throw (std::runtime_error)
std::map< int, std::vector
< float > > 
fetchData () throw (std::runtime_error)
virtual std::string foreignKeyName () const
std::vector< float > getData (int id)
bool getData (const EcalLogicID &id, const std::string &key, float &ret)
std::vector< float > getData (const EcalLogicID &id)
bool getData (int id, std::vector< float > &ret)
bool getData (const EcalLogicID &id, std::vector< float > &ret)
std::map< int, std::vector
< float > > 
getData ()
bool getData (int id, const std::string &key, float &ret)
float getData (int id, unsigned int k)
float getData (const EcalLogicID &id, unsigned int k)
float getData (const EcalLogicID &id, const std::string &key)
float getData (int id, const std::string &key)
bool getData (int id, unsigned int k, float &ret)
bool getData (const EcalLogicID &id, unsigned int k, float &ret)
virtual std::string getIovIdFieldName () const
std::list< std::string > getKeyList ()
std::map< std::string,
unsigned int > 
getKeys ()
LMFRunIOV getLMFRunIOV () const
int getLMFRunIOVID ()
std::list< int > getLogicIds ()
void getNext (LMFDat *dat) throw (std::runtime_error)
void getPrevious (LMFDat *dat) throw (std::runtime_error)
std::map< unsigned int,
std::string > 
getReverseMap () const
Tm getSubrunStart () const
virtual std::string getTableName () const
virtual bool isValid ()
 LMFDat (EcalDBConnection *c)
 LMFDat ()
 LMFDat (oracle::occi::Environment *env, oracle::occi::Connection *conn)
std::vector< float > operator[] (int id)
LMFDatsetData (const EcalLogicID &logic_id, const std::string &key, float v)
LMFDatsetData (int logic_id, const std::vector< float > &data)
LMFDatsetData (const EcalLogicID &logic_id, const std::vector< float > &data)
LMFDatsetLMFRunIOV (const LMFRunIOV &iov)
LMFDatsetMaxDataToDump (int n)
int size () const
 ~LMFDat ()

Protected Member Functions

std::string buildInsertSql ()
std::string buildSelectSql (int logic_id=0, int direction=0)
bool check ()
void getKeyTypes () throw (std::runtime_error)
void getNeighbour (LMFDat *dat, int which) throw (std::runtime_error)
int writeDB () throw (std::runtime_error)

Protected Attributes

std::map< int, std::vector
< float > > 
m_data
std::string m_Error
std::map< std::string,
unsigned int > 
m_keys
int m_max
std::string m_tableName
std::vector< std::string > m_type

Friends

class EcalCondDBInterface

Detailed Description

Data Tables for LMF Runs

Definition at line 19 of file LMFDat.h.


Constructor & Destructor Documentation

LMFDat::LMFDat ( )

Definition at line 9 of file LMFDat.cc.

References m_max, and m_tableName.

               : LMFUnique() { 
  m_tableName = ""; 
  m_max = -1; 
}
LMFDat::LMFDat ( EcalDBConnection c)

Definition at line 14 of file LMFDat.cc.

References m_max, and m_tableName.

                                  : LMFUnique(c) {
  m_tableName = "";
  m_max = -1;
}
LMFDat::LMFDat ( oracle::occi::Environment *  env,
oracle::occi::Connection *  conn 
)

Definition at line 19 of file LMFDat.cc.

References m_max, and m_tableName.

                                           : LMFUnique(env, conn) {
  m_tableName = "";
  m_max = -1;
}
LMFDat::~LMFDat ( ) [inline]

Definition at line 27 of file LMFDat.h.

{ }

Member Function Documentation

std::string LMFDat::buildInsertSql ( ) [protected]

Definition at line 97 of file LMFDat.cc.

References gather_cfg::cout, getTableName(), i, LMFUnique::m_className, LMFUnique::m_debug, and m_keys.

Referenced by writeDB().

                                 {
  // create the insert statement
  std::stringstream sql;
  sql << "INSERT INTO " + getTableName() + " VALUES (";
  unsigned int nParameters = m_keys.size() + 2; 
  for (unsigned int i = 0; i < nParameters - 1; i++) {
    sql << ":" << i + 1 << ", ";
  }
  sql << ":" << nParameters << ")";
  std::string sqls = sql.str();
  if (m_debug) {
    cout << m_className << "::writeDB: " << sqls << endl;
  }
  return sqls;
}
std::string LMFDat::buildSelectSql ( int  logic_id = 0,
int  direction = 0 
) [protected]

Definition at line 117 of file LMFDat.cc.

References prof2calltree::count, gather_cfg::cout, getIovIdFieldName(), getLMFRunIOVID(), getTableName(), LMFUnique::m_className, and LMFUnique::m_debug.

                                                            {
  // create the insert statement
  // if logic_id = 0 select all channels for a given iov_id
  std::stringstream sql;
  int count = 1;
  if (getLMFRunIOVID() > 0) {
    // in this case we are looking for all data collected during the same
    // IOV. There can be many logic_ids per IOV.
    sql << "SELECT * FROM " << getTableName() << " WHERE "
        << getIovIdFieldName() << " = " << getLMFRunIOVID();
  } else {
    // in this case we are looking for a specific logic_id whose
    // data have been collected at a given time. There is only
    // one record in this case.
    std::string op = ">";
    std::string order = "ASC";
    if (direction < 0) {
      op = "<";
      order = "DESC";
    }
    sql << "SELECT * FROM (SELECT " << getTableName() << ".* FROM " 
        << getTableName() 
        << " JOIN LMF_RUN_IOV ON " 
        << "LMF_RUN_IOV.LMF_IOV_ID = " 
        << getTableName() << "." << getIovIdFieldName() << " "
        << "WHERE SUBRUN_START " << op << "= TO_DATE(:" << count;
    count++;
    sql << ", 'YYYY-MM-DD HH24:MI:SS') ORDER BY SUBRUN_START " 
        << order << ") WHERE ROWNUM <= 1";
  }
  if (logic_id > 0) {
    sql << " AND LOGIC_ID = :" << count;
  }
  std::string sqls = sql.str();
  if (m_debug) {
    cout << m_className << "::buildSelectSqlDB: " << sqls << endl;
  }
  return sqls;
}
bool LMFDat::check ( void  ) [protected]

Definition at line 508 of file LMFDat.cc.

References getKeyTypes(), getTableName(), LMFUnique::m_className, m_Error, m_keys, m_type, and runTheMatrix::ret.

Referenced by writeDB().

                   {
  // check that everything has been correctly setup
  bool ret = true;
  m_Error = "";
  // first of all we need to check that the class name has been set
  if (m_className == "LMFUnique") {
    m_Error = "class name not set ";
    ret = false;
  }
  //then check that the table name has been set
  if (getTableName() == "") {
    m_Error += "table name not set ";
    ret = false;
  }
  // fill key types if not yet done
  if (m_type.size() != m_keys.size()) {
    getKeyTypes();
    if (m_type.size() != m_keys.size()) {
      m_Error += "key size does not correspond to table definition";
      ret = false;
    }
  }
  return ret;
}
void LMFDat::dump ( void  ) const [virtual]

Reimplemented from LMFUnique.

Definition at line 62 of file LMFDat.cc.

References m_max.

Referenced by dump(), LMFCorrCoefDat::fetch(), and writeDB().

                        {
  dump(0, m_max);
}
void LMFDat::dump ( int  n,
int  max 
) const [virtual]

Definition at line 70 of file LMFDat.cc.

References trackerHits::c, gather_cfg::cout, dump(), end, getReverseMap(), j, m_data, L1TEmulatorMonitor_cff::p, submit::rm, asciidump::s, and ExpressReco_HICollisions_FallBack::x.

                                      {
  LMFUnique::dump(n);
  int s = m_data.size();
  cout << "Stored data: " << s << endl;
  if (max >= 0) {
    std::map<int, std::vector<float> >::const_iterator p = m_data.begin();
    std::map<int, std::vector<float> >::const_iterator end = m_data.end();
    int c = 0;
    std::map<unsigned int, std::string> rm = getReverseMap();
    while ((p != end) && (c < max)) {
      int id = p->first;
      std::vector<float> x = p->second;
      cout << c << " -------------------------------------------" << endl;
      cout << "   ID: " << id << endl;
      for (unsigned int j = 0; j < x.size(); j++) {
        if (j % 4 == 0) {
          cout << endl << "   ";
        }
        cout << rm[j] << ":" << x[j] << "\t";
      }
      cout << endl;
      p++;
      c++;
    }
  }
}
void LMFDat::dump ( int  n) const [virtual]

Reimplemented from LMFUnique.

Definition at line 66 of file LMFDat.cc.

References dump(), and m_max.

                             {
  dump(n, m_max);
}
void LMFDat::fetch ( ) throw (std::runtime_error)

Definition at line 206 of file LMFDat.cc.

Referenced by LMFCorrCoefDat::fetch().

{
  fetch(0);
}
void LMFDat::fetch ( int  logic_id) throw (std::runtime_error)

Definition at line 212 of file LMFDat.cc.

References NULL.

{
  fetch(logic_id, NULL, 0);
}
void LMFDat::fetch ( int  logic_id,
const Tm tm 
) throw (std::runtime_error)

Definition at line 218 of file LMFDat.cc.

{
  fetch(logic_id, &tm, 1);
}
void LMFDat::fetch ( const EcalLogicID id,
const Tm tm 
) throw (std::runtime_error)

Definition at line 193 of file LMFDat.cc.

{
  fetch(id.getLogicID(), &tm, 1);
}
void LMFDat::fetch ( const EcalLogicID id,
const Tm tm,
int  dir 
) throw (std::runtime_error)

Definition at line 199 of file LMFDat.cc.

{
  setInt(foreignKeyName(), 0); /* set the LMF_IOV_ID to undefined */
  fetch(id.getLogicID(), &tm, direction);
}
void LMFDat::fetch ( const EcalLogicID id) throw (std::runtime_error)

Definition at line 187 of file LMFDat.cc.

{
  fetch(id.getLogicID());
}
void LMFDat::fetch ( int  logic_id,
const Tm timestamp,
int  dir 
) throw (std::runtime_error)

Definition at line 224 of file LMFDat.cc.

References CastorDataFrameFilter_impl::check(), prof2calltree::count, gather_cfg::cout, ExpressReco_HICollisions_FallBack::e, i, NULL, convertSQLiteXML::ok, cond::timestamp, and ExpressReco_HICollisions_FallBack::x.

{
  bool ok = check();
  if ((timestamp == NULL) && (getLMFRunIOVID() == 0)) {
    throw(std::runtime_error(m_className + "::fetch: Cannot fetch data with "
                        "timestamp = 0 and LMFRunIOV = 0"));
  }
  if (ok && isValid()) {
    if (m_debug) {
      std::cout << "[LMFDat] This object is valid..." << std::endl;
    }
    try {
      Statement * stmt = m_conn->createStatement();
      std::string sql = buildSelectSql(logic_id, direction);
      if (m_debug) {
        std::cout << "[LMFDat] Executing query " << std::endl;
        std::cout << "         " << sql << std::endl << std::flush;
      }
      if (logic_id == 0) {
        // get data for all crystals with a given timestamp
        stmt->setPrefetchRowCount(131072);
      }
      stmt->setSQL(sql);
      int count = 1;
      if (logic_id > 0) {
        if (timestamp != NULL) {
          stmt->setString(count, timestamp->str());
          count++;
        }
        stmt->setInt(count, logic_id);
      }
      ResultSet *rset = stmt->executeQuery();
      std::vector<float> x;
      int nData = m_keys.size();
      x.reserve(nData);
      while (rset->next()) {
        for (int i = 0; i < nData; i++) {
          x.push_back(rset->getFloat(i + 3));
        }
        int id = rset->getInt(2);
        if (timestamp != NULL) {
          setInt(foreignKeyName(), rset->getInt(1));
        }
        this->setData(id, x);
        x.clear();
      }
      stmt->setPrefetchRowCount(0);
      m_conn->terminateStatement(stmt);
    }
    catch (oracle::occi::SQLException &e) {
      throw(std::runtime_error(m_className + "::fetch: " + e.getMessage()));
    }
    m_ID = m_data.size();
  }
}
std::map< int, std::vector< float > > LMFDat::fetchData ( ) throw (std::runtime_error)

Definition at line 294 of file LMFDat.cc.

References gather_cfg::cout, ExpressReco_HICollisions_FallBack::e, getIovIdFieldName(), getLMFRunIOVID(), getTableName(), i, LMFUnique::m_className, IDBObject::m_conn, m_data, LMFUnique::m_debug, and asciidump::s.

Referenced by writeDB().

{
  // see if any of the data is already in the database
  std::map<int, std::vector<float> > s = m_data;
  std::string sql = "SELECT LOGIC_ID FROM " + getTableName() + " WHERE "
    + getIovIdFieldName() + " = :1";
  if (m_debug) {
    cout << m_className << ":: candidate data items to be written = " 
         << s.size() << endl;
    cout << m_className << "   Executing " << sql;
    cout << " where " << getIovIdFieldName() << " = " 
         << getLMFRunIOVID() << endl;
  }
  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL(sql);
    stmt->setInt(1, getLMFRunIOVID());
    stmt->setPrefetchRowCount(131072);
    ResultSet* rset = stmt->executeQuery();
    std::map<int, std::vector<float> >::iterator i = s.end();
    std::map<int, std::vector<float> >::iterator e = s.end();
    while (rset->next()) {
      if (m_debug) {
        cout << m_className << ":: checking " << rset->getInt(1) << endl
             << std::flush;
      }
      i = s.find(rset->getInt(1));
      if (i != e) {
        s.erase(i);
      }
    }
    stmt->setPrefetchRowCount(0);
    m_conn->terminateStatement(stmt);
  }
  catch (oracle::occi::SQLException &e) {
    throw(std::runtime_error(m_className + "::fetchData:  "+e.getMessage()));
  }
  if (m_debug) {
    cout << m_className << ":: data items to write = " 
         << s.size() << endl;
  }
  return s;
}
std::string LMFDat::foreignKeyName ( ) const [virtual]

Reimplemented in LMFCorrCoefDatComponent.

Definition at line 25 of file LMFDat.cc.

Referenced by getLMFRunIOV(), getLMFRunIOVID(), isValid(), setLMFRunIOV(), and writeDB().

                                       {
  return "lmfRunIOV";
}
std::vector< float > LMFDat::getData ( const EcalLogicID id)

Definition at line 547 of file LMFDat.cc.

References getData().

                                                      {
  return getData(id.getLogicID());
}
bool LMFDat::getData ( int  id,
std::vector< float > &  ret 
)

Definition at line 553 of file LMFDat.cc.

References ExpressReco_HICollisions_FallBack::id, and m_data.

                                                  {
  bool retval = false;
  if (m_data.find(id) != m_data.end()) {
    ret= m_data[id];
    retval = true;
  }
  return retval;
}
bool LMFDat::getData ( const EcalLogicID id,
std::vector< float > &  ret 
)

Definition at line 562 of file LMFDat.cc.

References getData().

                                                                 {
  return getData(id.getLogicID(), ret);
}
std::map< int, std::vector< float > > LMFDat::getData ( void  )

Definition at line 568 of file LMFDat.cc.

References m_data.

Referenced by LMFPrimDat::getAlpha(), LMFPrimDat::getAPDoverAM3(), LMFPrimDat::getAPDoverAMean(), LMFPrimDat::getAPDoverARMS(), LMFPrimDat::getAPDoverBM3(), LMFPrimDat::getAPDoverBMean(), LMFPrimDat::getAPDoverBRMS(), LMFPrimDat::getAPDoverPnM3(), LMFPrimDat::getAPDoverPnMean(), LMFPrimDat::getAPDoverPnRMS(), LMFPrimDat::getBeta(), LMFTestPulseConfigDat::getDACMGPA(), getData(), LMFClsDat::getEFlag(), LMFClsDat::getENorm(), LMFRunDat::getEvents(), LMFLaserPulseDat::getFitMethod(), LMFPnPrimDat::getFlag(), LMFCorrCoefDatComponent::getFlag(), LMFClsDat::getFlag(), LMFPrimDat::getFlag(), LMFClsDat::getLMFRefRunIOVID(), LMFLaserConfigDat::getLSRAttenuator(), LMFLaserConfigDat::getLSRCURRENT(), LMFLaserConfigDat::getLSRDelay1(), LMFLaserConfigDat::getLSRDelay2(), LMFLaserConfigDat::getLSRPower(), LMFPrimDat::getM3(), LMFPnPrimDat::getM3(), LMFPrimDat::getMean(), LMFClsDat::getMean(), LMFPnPrimDat::getMean(), LMFLaserPulseDat::getMTQAmplification(), LMFLaserPulseDat::getMTQFW20(), LMFLaserPulseDat::getMTQFW80(), LMFLaserPulseDat::getMTQFWHM(), LMFLaserPulseDat::getMTQRise(), LMFLaserPulseDat::getMTQSliding(), LMFLaserPulseDat::getMTQTime(), LMFClsDat::getNevt(), LMFClsDat::getNorm(), LMFCorrCoefDatComponent::getParameterErrors(), LMFCorrCoefDatComponent::getParameters(), LMFPnPrimDat::getPNAoverBM3(), LMFPnPrimDat::getPNAoverBMean(), LMFPnPrimDat::getPNAoverBRMS(), LMFTestPulseConfigDat::getPNGain(), LMFLaserConfigDat::getPNGain(), LMFTestPulseConfigDat::getPNVinj(), LMFRunDat::getQualityFlag(), LMFPnPrimDat::getRMS(), LMFPrimDat::getRMS(), LMFClsDat::getRMS(), LMFCorrCoefDatComponent::getSeqID(), LMFCorrCoefDatComponent::getSequence(), LMFPnPrimDat::getShapeCor(), LMFPrimDat::getShapeCorr(), LMFLaserConfigDat::getVFEGain(), LMFTestPulseConfigDat::getVFEGain(), LMFColoredTable::getVmax(), LMFColoredTable::getVmin(), LMFLaserConfigDat::getWavelength(), and operator[]().

                                               {
  return m_data;
}
float LMFDat::getData ( int  id,
unsigned int  k 
)

Definition at line 574 of file LMFDat.cc.

References ExpressReco_HICollisions_FallBack::id, gen::k, and m_data.

                                            {
  return m_data[id][k];
}
float LMFDat::getData ( const EcalLogicID id,
const std::string &  key 
)

Definition at line 582 of file LMFDat.cc.

References getData(), and m_keys.

                                                                 {
  return getData(id.getLogicID(), m_keys[key]);
}
float LMFDat::getData ( const EcalLogicID id,
unsigned int  k 
)

Definition at line 578 of file LMFDat.cc.

References getData().

                                                           {
  return getData(id.getLogicID(), k);
}
std::vector< float > LMFDat::getData ( int  id)

Definition at line 535 of file LMFDat.cc.

References ExpressReco_HICollisions_FallBack::id, m_data, and runTheMatrix::ret.

Referenced by LMFCorrCoefDat::getParameters().

                                       {
  std::vector<float> ret;
  if (m_data.find(id) != m_data.end()) {
    ret = m_data[id];
  }
  return ret;
}
float LMFDat::getData ( int  id,
const std::string &  key 
)

Definition at line 586 of file LMFDat.cc.

References getData(), and m_keys.

                                                  {
  return getData(id, m_keys[key]);
}
bool LMFDat::getData ( int  id,
unsigned int  k,
float &  ret 
)

Definition at line 592 of file LMFDat.cc.

References getData(), gen::k, and v.

                                                       {
  bool retval = false;
  std::vector<float> v;
  retval = getData(id, v);
  if ((retval) && (v.size() > k)) {
    ret= v[k];
    retval = true;
  } else {
    retval = false;
  }
  return retval;
}
bool LMFDat::getData ( const EcalLogicID id,
unsigned int  k,
float &  ret 
)

Definition at line 605 of file LMFDat.cc.

References getData().

                                                                      {
  return getData(id.getLogicID(), k, ret);
}
bool LMFDat::getData ( int  id,
const std::string &  key,
float &  ret 
)

Definition at line 609 of file LMFDat.cc.

References getData(), and m_keys.

                                                             {
  bool retval = false;
  if (m_keys.find(key) != m_keys.end()) {
    retval = getData(id, m_keys[key], ret); 
  }
  return retval;
}
bool LMFDat::getData ( const EcalLogicID id,
const std::string &  key,
float &  ret 
)

Definition at line 617 of file LMFDat.cc.

References getData().

{
  return getData(id.getLogicID(), key, ret);
}
std::string LMFDat::getIovIdFieldName ( ) const [virtual]

Reimplemented in LMFCorrCoefDatComponent.

Definition at line 113 of file LMFDat.cc.

Referenced by buildSelectSql(), fetchData(), and getKeyTypes().

                                          {
  return "LMF_IOV_ID";
}
std::list<std::string> LMFDat::getKeyList ( ) [inline]

Definition at line 113 of file LMFDat.h.

References ExpressReco_HICollisions_FallBack::e, i, prof2calltree::l, and m_keys.

                                  {
    std::list<std::string> l;
    std::map<std::string, unsigned int>::const_iterator i = m_keys.begin();
    std::map<std::string, unsigned int>::const_iterator e = m_keys.end();
    while (i != e) {
      l.push_back(i->first);
      i++;
    }
    return l;
  }
std::map<std::string, unsigned int> LMFDat::getKeys ( ) [inline]

Definition at line 110 of file LMFDat.h.

References m_keys.

                                            {
    return m_keys;
  }
void LMFDat::getKeyTypes ( ) throw (std::runtime_error) [protected]

Definition at line 479 of file LMFDat.cc.

References ExpressReco_HICollisions_FallBack::e, getIovIdFieldName(), getTableName(), i, LMFUnique::m_className, IDBObject::m_conn, m_keys, m_type, AlCaRecoCosmics_cfg::name, and matplotRender::t.

Referenced by check().

{
  m_type.reserve(m_keys.size());
  for (unsigned int i = 0; i < m_keys.size(); i++) {
    m_type.push_back("");
  }
  // get the description of the table
  std::string sql = "";
  try {
    Statement *stmt = m_conn->createStatement();
    sql = "SELECT COLUMN_NAME, DATA_TYPE FROM " 
      "USER_TAB_COLS WHERE TABLE_NAME = '" + getTableName() + "' " 
      "AND COLUMN_NAME != '" + getIovIdFieldName() +  "' AND COLUMN_NAME != " 
      "'LOGIC_ID'";
    stmt->setSQL(sql);
    ResultSet *rset = stmt->executeQuery();
    while (rset->next()) {
      std::string name = rset->getString(1);
      std::string t = rset->getString(2);
      m_type[m_keys[name]] = t;
    }
    m_conn->terminateStatement(stmt);
  } catch (oracle::occi::SQLException &e) {
    throw(std::runtime_error(m_className + "::getKeyTypes: " + e.getMessage() +
                        " [" + sql + "]"));
  }
}
LMFRunIOV LMFDat::getLMFRunIOV ( ) const [inline]

Definition at line 36 of file LMFDat.h.

References foreignKeyName(), LMFUnique::getInt(), IDBObject::m_conn, IDBObject::m_env, and LMFUnique::setByID().

Referenced by getSubrunStart().

                                 {
    LMFRunIOV runiov(m_env, m_conn);
    runiov.setByID(getInt(foreignKeyName()));
    return runiov;
  }
int LMFDat::getLMFRunIOVID ( )

Definition at line 29 of file LMFDat.cc.

References LMFUnique::fetchID(), foreignKeyName(), LMFUnique::getInt(), i, ExpressReco_HICollisions_FallBack::id, o2o::iov, LMFUnique::m_foreignKeys, NULL, and LMFUnique::setInt().

Referenced by buildSelectSql(), and fetchData().

                           {
  int id = getInt(foreignKeyName());
  if (id == 0) {
    // try to get it from the list of foreign keys
    std::map<std::string, LMFUnique*>::iterator i = 
      m_foreignKeys.find(foreignKeyName());
    if (i != m_foreignKeys.end()) {
      LMFRunIOV *iov = (LMFRunIOV*)(i->second);
      if (iov != NULL) {
        id = iov->fetchID();
        setInt(foreignKeyName(), id);
      }
    }
  }
  return id;
}
std::list<int> LMFDat::getLogicIds ( ) [inline]

Definition at line 99 of file LMFDat.h.

References ExpressReco_HICollisions_FallBack::e, i, prof2calltree::l, and m_data.

                             {
    std::list<int> l;
    std::map<int, std::vector<float> >::const_iterator i = m_data.begin();
    std::map<int, std::vector<float> >::const_iterator e = m_data.end();
    while (i != e) {
      l.push_back(i->first);
      i++;
    }
    return l;
  }
void LMFDat::getNeighbour ( LMFDat dat,
int  which 
) throw (std::runtime_error) [protected]

Definition at line 169 of file LMFDat.cc.

References ExpressReco_HICollisions_FallBack::dump.

{
  // there should be just one record in this case
  if (m_data.size() == 1) {
    dat->setConnection(this->getEnv(), this->getConn());
    int logic_id = m_data.begin()->first;
    Tm lastMeasuredOn = getSubrunStart();
    lastMeasuredOn += which;
    dat->fetch(logic_id, &lastMeasuredOn, which);
    dat->setMaxDataToDump(m_max);
  } else {
    dump();
    throw(std::runtime_error(m_className + "::getPrevious: Too many LOGIC_IDs in "
                        "this object"));
  }
}
void LMFDat::getNext ( LMFDat dat) throw (std::runtime_error)

Definition at line 163 of file LMFDat.cc.

{
  getNeighbour(dat, +1);
}
void LMFDat::getPrevious ( LMFDat dat) throw (std::runtime_error)

Definition at line 157 of file LMFDat.cc.

{
  getNeighbour(dat, -1);
}
std::map< unsigned int, std::string > LMFDat::getReverseMap ( ) const

Definition at line 51 of file LMFDat.cc.

References ExpressReco_HICollisions_FallBack::e, i, m, and m_keys.

Referenced by dump().

                                                            {
  std::map<unsigned int, std::string> m;
  std::map<std::string, unsigned int>::const_iterator i = m_keys.begin();
  std::map<std::string, unsigned int>::const_iterator e = m_keys.end();
  while (i != e) {
    m[i->second] = i->first;
    i++;
  }
  return m;
}
Tm LMFDat::getSubrunStart ( ) const [inline]

Definition at line 42 of file LMFDat.h.

References getLMFRunIOV(), and LMFRunIOV::getSubRunStart().

                            {
    return getLMFRunIOV().getSubRunStart();
  }
virtual std::string LMFDat::getTableName ( ) const [inline, virtual]
bool LMFDat::isValid ( void  ) [virtual]

Reimplemented in LMFClsDat, LMFLaserPulseDat, LMFPnPrimDat, and LMFPrimDat.

Definition at line 281 of file LMFDat.cc.

References gather_cfg::cout, foreignKeyName(), LMFUnique::m_className, LMFUnique::m_debug, m_Error, LMFUnique::m_foreignKeys, and runTheMatrix::ret.

Referenced by writeDB().

                     {
  bool ret = true;
  if (m_foreignKeys.find(foreignKeyName()) == m_foreignKeys.end()) {
    ret = false;
    m_Error += " Can't find lmfRunIOV within foreign keys.";
    if (m_debug) {
      cout << m_className << ": Foreign keys map size: " << m_foreignKeys.size() 
           << endl;
    }
  }
  return ret;
}
std::vector< float > LMFDat::operator[] ( int  id)

Definition at line 543 of file LMFDat.cc.

References getData().

                                          {
  return getData(id);
}
LMFDat& LMFDat::setData ( const EcalLogicID logic_id,
const std::string &  key,
float  v 
) [inline]

Definition at line 64 of file LMFDat.h.

References EcalLogicID::getLogicID(), ExpressReco_HICollisions_FallBack::id, combine::key, m_data, m_keys, and v.

                           {
    int id = logic_id.getLogicID();
    m_data[id].resize(m_keys.size());
    m_data[id][m_keys[key]] = v;
    return *this;
  }
LMFDat& LMFDat::setData ( int  logic_id,
const std::vector< float > &  data 
) [inline]

Definition at line 55 of file LMFDat.h.

References runTheMatrix::data, and m_data.

Referenced by LMFPrimDat::setAlpha(), LMFPrimDat::setAPDoverAM3(), LMFPrimDat::setAPDoverAMean(), LMFPrimDat::setAPDoverARMS(), LMFPrimDat::setAPDoverBM3(), LMFPrimDat::setAPDoverBMean(), LMFPrimDat::setAPDoverBRMS(), LMFPrimDat::setAPDoverPnM3(), LMFPrimDat::setAPDoverPnMean(), LMFPrimDat::setAPDoverPnRMS(), LMFPrimDat::setBeta(), LMFClsDat::setEFlag(), LMFClsDat::setENorm(), LMFLaserPulseDat::setFitMethod(), LMFClsDat::setFlag(), LMFPrimDat::setFlag(), LMFCorrCoefDatComponent::setFlag(), LMFPnPrimDat::setFlag(), LMFClsDat::setLMFRefRunIOVID(), LMFPrimDat::setM3(), LMFPnPrimDat::setM3(), LMFPrimDat::setMean(), LMFClsDat::setMean(), LMFPnPrimDat::setMean(), LMFLaserPulseDat::setMTQAmplification(), LMFLaserPulseDat::setMTQFW20(), LMFLaserPulseDat::setMTQFW80(), LMFLaserPulseDat::setMTQFWHM(), LMFLaserPulseDat::setMTQRise(), LMFLaserPulseDat::setMTQSliding(), LMFLaserPulseDat::setMTQTime(), LMFClsDat::setNevt(), LMFClsDat::setNorm(), LMFCorrCoefDatComponent::setP123(), LMFCorrCoefDatComponent::setP123Errors(), LMFPnPrimDat::setPNAoverBM3(), LMFPnPrimDat::setPNAoverBMean(), LMFPnPrimDat::setPNAoverBRMS(), LMFPnPrimDat::setRMS(), LMFPrimDat::setRMS(), LMFClsDat::setRMS(), LMFCorrCoefDatComponent::setSequence(), LMFPrimDat::setShapeCorr(), LMFPnPrimDat::setShapeCorr(), LMFColoredTable::setVersions(), LMFColoredTable::setVmax(), and LMFColoredTable::setVmin().

                                                              {
    m_data[logic_id] = data;
    return *this;
  }
LMFDat& LMFDat::setData ( const EcalLogicID logic_id,
const std::vector< float > &  data 
) [inline]

Definition at line 59 of file LMFDat.h.

References runTheMatrix::data, EcalLogicID::getLogicID(), and m_data.

                                                {
    m_data[logic_id.getLogicID()] = data;
    return *this;
  }
LMFDat& LMFDat::setLMFRunIOV ( const LMFRunIOV iov) [inline]

Definition at line 31 of file LMFDat.h.

References LMFUnique::attach(), foreignKeyName(), LMFUnique::getID(), and LMFUnique::setInt().

                                             {
    setInt(foreignKeyName(), iov.getID());
    attach(foreignKeyName(), (LMFUnique*)&iov);
    return *this;
  }
LMFDat & LMFDat::setMaxDataToDump ( int  n)

Definition at line 46 of file LMFDat.cc.

References m_max, and n.

Referenced by writeDB().

                                      {
  m_max = n;
  return *this;
}
int LMFDat::size ( void  ) const [inline]

Definition at line 71 of file LMFDat.h.

References m_data.

Referenced by writeDB().

{ return m_data.size(); }
int LMFDat::writeDB ( ) throw (std::runtime_error) [protected, virtual]

Reimplemented from LMFUnique.

Reimplemented in LMFColoredTable, and LMFCorrCoefDatComponent.

Definition at line 339 of file LMFDat.cc.

References b, buildInsertSql(), trackerHits::c, check(), IDBObject::checkConnection(), gather_cfg::cout, LMFUnique::debug(), dump(), ExpressReco_HICollisions_FallBack::e, fetchData(), foreignKeyName(), LMFUnique::getID(), i, ExpressReco_HICollisions_FallBack::id, isValid(), gen::k, LMFUnique::m_className, IDBObject::m_conn, LMFUnique::m_debug, m_Error, LMFUnique::m_foreignKeys, m_keys, m_max, m_type, convertSQLiteXML::ok, runTheMatrix::ret, setMaxDataToDump(), size(), LMFUnique::writeForeignKeys(), and ExpressReco_HICollisions_FallBack::x.

{
  // first of all check if data already present
  if (m_debug) {
    cout << m_className << ": Writing foreign keys" << endl;
  }
  LMFUnique::writeForeignKeys();
  if (m_debug) {
    cout << m_className << ": Foreign keys written" << endl;
  }
  // write data on the database
  int ret = 0;
  std::map<int, std::vector<float> > data2write = fetchData();
  if (data2write.size() > 0) {
    this->checkConnection();
    bool ok = check();
    // write
    if (ok && isValid()) {
      std::list<dvoid *> bufPointers;
      int nParameters = m_keys.size(); 
      int nData = data2write.size();
      if (m_debug) {
        cout << m_className << ": # data items = " << nData << endl;
        cout << m_className << ": # parameters = " << nParameters << endl;
      }
      int * iovid_vec = new int[nData];
      int * logicid_vec = new int[nData];
      int *intArray = new int[nData];
      float *floatArray = new float[nData];
      ub2 * intSize = new ub2[nData];
      ub2 * floatSize = new ub2[nData];
      size_t intTotalSize = sizeof(int)*nData;
      size_t floatTotalSize = sizeof(float)*nData;
      try {
        Statement * stmt = m_conn->createStatement();
        std::string sql = buildInsertSql();
        stmt->setSQL(sql);
        // build the array of the size of each column
        for (int i = 0; i < nData; i++) {
          intSize[i] = sizeof(int);
          floatSize[i] = sizeof(int);
        }
        // build the data array for first column: the same run iov id
        LMFRunIOV *runiov = (LMFRunIOV*)m_foreignKeys[foreignKeyName()];
        int iov_id = runiov->getID();
        std::map<int, std::vector<float> >::const_iterator b = data2write.begin();
        std::map<int, std::vector<float> >::const_iterator e = data2write.end();
        for (int i = 0; i < nData; i++) {
          iovid_vec[i] = iov_id;
        }
        stmt->setDataBuffer(1, (dvoid*)iovid_vec, oracle::occi::OCCIINT,
                            sizeof(iovid_vec[0]), intSize);
        // build the data array for second column: the logic ids
        int c = 0;
        while (b != e) {
          int id = b->first;
          logicid_vec[c++] = id;
          b++;
        }
        stmt->setDataBuffer(2, (dvoid*)logicid_vec, oracle::occi::OCCIINT,
                            sizeof(logicid_vec[0]), intSize);
        // for each column build the data array
        oracle::occi::Type type = oracle::occi::OCCIFLOAT;
        for (int i = 0; i < nParameters; i++) {
          b = data2write.begin();
          // loop on all logic ids
          c = 0;
          while (b != e) {
            std::vector<float> x = b->second;
            if (m_type[i] == "INT") {
              intArray[c] = (int)rint(x[i]);
            } else if ((m_type[i] == "FLOAT") || (m_type[i] == "NUMBER")) {
              floatArray[c] = x[i];
            } else {
              throw(std::runtime_error("ERROR: LMFDat::writeDB: unsupported type"));
            }
            c++;
            b++;
          }
          // copy data into a "permanent" buffer
          dvoid * buffer;
          type = oracle::occi::OCCIINT;
          ub2 *sizeArray = intSize;
          int size = sizeof(intArray[0]);
          if ((m_type[i] == "FLOAT") || (m_type[i] == "NUMBER")) {
            buffer = (dvoid *)malloc(sizeof(float)*nData);
            memcpy(buffer, floatArray, floatTotalSize);
            type = oracle::occi::OCCIFLOAT;
            sizeArray = floatSize;
            size = sizeof(floatArray[0]);
          } else {
            buffer = (dvoid *)malloc(sizeof(int)*nData);
            memcpy(buffer, intArray, intTotalSize);
          }
          bufPointers.push_back(buffer);
          if (m_debug) {
            for (int k = 0; ((k < nData) && (k < m_max)); k++) {
              cout << m_className << ": === Index=== " << k << endl;
              cout << m_className << ": RUN_IOV_ID = " << iovid_vec[k] << endl;
              cout << m_className << ": LOGIC_ID = " << logicid_vec[k] << endl;
              cout << m_className << ": FIELD " << i << ": " 
                   << ((float *)(buffer))[k] << endl;
            }
          }
          stmt->setDataBuffer(i + 3, buffer, type, size, sizeArray);
        }
        stmt->executeArrayUpdate(nData);
        delete [] intArray;
        delete [] floatArray;
        delete [] intSize;
        delete [] floatSize;
        delete [] logicid_vec;
        delete [] iovid_vec;
        std::list<dvoid *>::const_iterator bi = bufPointers.begin();
        std::list<dvoid *>::const_iterator be = bufPointers.end();
        while (bi != be) {
          free(*bi);
          bi++;
        }
        m_conn->commit();
        m_conn->terminateStatement(stmt);
        ret = nData;
      } catch (oracle::occi::SQLException &e) {
        debug();
        setMaxDataToDump(nData);
        dump();
        m_conn->rollback();
        throw(std::runtime_error(m_className + "::writeDB: " + 
                                 e.getMessage()));
      }
    } else {
      cout << m_className << "::writeDB: Cannot write because " << 
        m_Error << endl;
      dump();
    }
  }
  return ret;
}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from LMFUnique.

Reimplemented in LMFCorrCoefDatComponent.

Definition at line 21 of file LMFDat.h.


Member Data Documentation

std::map<int, std::vector<float> > LMFDat::m_data [protected]

Definition at line 150 of file LMFDat.h.

Referenced by dump(), fetchData(), getData(), getLogicIds(), setData(), size(), and LMFColoredTable::writeDB().

std::string LMFDat::m_Error [protected]
std::map<std::string, unsigned int> LMFDat::m_keys [protected]
int LMFDat::m_max [protected]

Definition at line 146 of file LMFDat.h.

Referenced by dump(), LMFDat(), setMaxDataToDump(), and writeDB().

std::string LMFDat::m_tableName [protected]
std::vector<std::string> LMFDat::m_type [protected]