Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:50

0001 #ifndef LMFDAT_H
0002 #define LMFDAT_H
0003 
0004 /*
0005  Last updated by  Giovanni.Organtini@roma1.infn.it 2010
0006  */
0007 
0008 #include "OnlineDB/EcalCondDB/interface/LMFUnique.h"
0009 #include "OnlineDB/EcalCondDB/interface/LMFRunIOV.h"
0010 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
0011 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
0012 
0013 #include <map>
0014 
0015 /**
0016  *   Data Tables for LMF Runs
0017  */
0018 class LMFDat : public LMFUnique {
0019 public:
0020   friend class EcalCondDBInterface;
0021 
0022   LMFDat();
0023   LMFDat(EcalDBConnection *c);
0024   LMFDat(oracle::occi::Environment *env, oracle::occi::Connection *conn);
0025   ~LMFDat() override {}
0026 
0027   virtual std::string foreignKeyName() const;
0028 
0029   LMFDat &setLMFRunIOV(const LMFRunIOV &iov) {
0030     setInt(foreignKeyName(), iov.getID());
0031     attach(foreignKeyName(), (LMFUnique *)&iov);
0032     return *this;
0033   }
0034   LMFRunIOV getLMFRunIOV() const {
0035     LMFRunIOV runiov(m_env, m_conn);
0036     runiov.setByID(getInt(foreignKeyName()));
0037     return runiov;
0038   }
0039 
0040   Tm getSubrunStart() const { return getLMFRunIOV().getSubRunStart(); }
0041 
0042   void getPrevious(LMFDat *dat) noexcept(false);
0043   void getNext(LMFDat *dat) noexcept(false);
0044 
0045   virtual std::string getTableName() const { return m_tableName; }
0046   virtual std::string getIovIdFieldName() const;
0047   int getLMFRunIOVID();
0048 
0049   LMFDat &setData(int logic_id, const std::vector<float> &data) {
0050     m_data[logic_id] = data;
0051     return *this;
0052   }
0053   LMFDat &setData(const EcalLogicID &logic_id, const std::vector<float> &data) {
0054     m_data[logic_id.getLogicID()] = data;
0055     return *this;
0056   }
0057   LMFDat &setData(const EcalLogicID &logic_id, const std::string &key, float v) {
0058     int id = logic_id.getLogicID();
0059     m_data[id].resize(m_keys.size());
0060     m_data[id][m_keys[key]] = v;
0061     return *this;
0062   }
0063   int size() const { return m_data.size(); }
0064 
0065   std::map<unsigned int, std::string> getReverseMap() const;
0066 
0067   /* UNSAFE methods returning data for a given logic_id */
0068   std::vector<float> getData(int id);
0069   std::vector<float> operator[](int id);
0070   std::vector<float> getData(const EcalLogicID &id);
0071 
0072   /* SAFE methods returning data for a given logic_id */
0073   bool getData(int id, std::vector<float> &ret);
0074   bool getData(const EcalLogicID &id, std::vector<float> &ret);
0075 
0076   /* methods returning the whole map between logic_id and data */
0077   std::map<int, std::vector<float> > getData();
0078 
0079   /* UNSAFE methods returning a field of a given logic_id */
0080   float getData(int id, unsigned int k);
0081   float getData(const EcalLogicID &id, unsigned int k);
0082   float getData(const EcalLogicID &id, const std::string &key);
0083   float getData(int id, const std::string &key);
0084 
0085   /* SAFE methods returning a field of a given logic_id */
0086   bool getData(int id, unsigned int k, float &ret);
0087   bool getData(const EcalLogicID &id, unsigned int k, float &ret);
0088   bool getData(int id, const std::string &key, float &ret);
0089   bool getData(const EcalLogicID &id, const std::string &key, float &ret);
0090 
0091   std::list<int> getLogicIds() {
0092     std::list<int> l;
0093     std::map<int, std::vector<float> >::const_iterator i = m_data.begin();
0094     std::map<int, std::vector<float> >::const_iterator e = m_data.end();
0095     while (i != e) {
0096       l.push_back(i->first);
0097       i++;
0098     }
0099     return l;
0100   }
0101 
0102   std::map<std::string, unsigned int> getKeys() { return m_keys; }
0103   std::list<std::string> getKeyList() {
0104     std::list<std::string> l;
0105     std::map<std::string, unsigned int>::const_iterator i = m_keys.begin();
0106     std::map<std::string, unsigned int>::const_iterator e = m_keys.end();
0107     while (i != e) {
0108       l.push_back(i->first);
0109       i++;
0110     }
0111     return l;
0112   }
0113   LMFDat &setMaxDataToDump(int n);
0114   void dump() const override;
0115   void dump(int n) const override;
0116   virtual void dump(int n, int max) const;
0117   std::map<int, std::vector<float> > fetchData() noexcept(false);
0118   void fetch() noexcept(false);
0119   void fetch(int logic_id) noexcept(false);
0120   void fetch(int logic_id, const Tm &tm) noexcept(false);
0121   void fetch(int logic_id, const Tm *timestamp, int dir) noexcept(false);
0122   void fetch(const EcalLogicID &id, const Tm &tm) noexcept(false);
0123   void fetch(const EcalLogicID &id, const Tm &tm, int dir) noexcept(false);
0124   void fetch(const EcalLogicID &id) noexcept(false);
0125 
0126   bool isValid() override;
0127   void setWhereClause(std::string w);
0128   void setWhereClause(std::string w, const std::vector<std::string> &p);
0129 
0130 protected:
0131   void getNeighbour(LMFDat *dat, int which) noexcept(false);
0132   int writeDB() noexcept(false) override;
0133   bool check();
0134   void adjustParameters(int n, std::string &sql, Statement *stmt);
0135   std::string buildInsertSql();
0136   std::string buildSelectSql(int logic_id = 0, int direction = 0);
0137   void getKeyTypes() noexcept(false);
0138 
0139   int m_max;
0140   std::vector<std::string> m_type;
0141   // m_data contains objects like (key, value) where key is the logic_id
0142   // of a channel and value is a vector of values associated to that logic_id
0143   std::map<int, std::vector<float> > m_data;
0144   // m_keys contains the keys to the components of the vector of data
0145   std::map<std::string, unsigned int> m_keys;
0146   std::string m_tableName;
0147   std::string m_Error;
0148   // experts only
0149   std::string _where;
0150   std::vector<std::string> _wherePars;
0151 };
0152 
0153 #endif