Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:23

0001 #include "CondCore/CondDB/interface/GTProxy.h"
0002 #include "SessionImpl.h"
0003 
0004 namespace cond {
0005 
0006   namespace persistency {
0007 
0008     std::string fullyQualifiedTag(const std::string& tag, const std::string& connectionString) {
0009       if (connectionString.empty())
0010         return tag;
0011       return tag + "@[" + connectionString + "]";
0012     }
0013 
0014     std::pair<std::string, std::string> parseTag(const std::string& tag) {
0015       std::string pfn("");
0016       std::string t(tag);
0017       size_t pos = tag.rfind('[');
0018       if (pos != std::string::npos && tag.size() >= pos + 2) {
0019         if (tag[pos - 1] == '@' && tag[tag.size() - 1] == ']') {
0020           pfn = tag.substr(pos + 1, tag.size() - pos - 2);
0021           t = tag.substr(0, pos - 1);
0022         }
0023       }
0024       return std::make_pair(t, pfn);
0025     }
0026 
0027     // implementation details...
0028     // only hosting data in this case
0029     class GTProxyData {
0030     public:
0031       GTProxyData() : name(""), preFix(""), postFix(""), tagList() {}
0032 
0033       std::string name;
0034       // will become useless after the transition...
0035       std::string preFix;
0036       std::string postFix;
0037       cond::Time_t validity;
0038       boost::posix_time::ptime snapshotTime;
0039       // tag list
0040       GTProxy::GTContainer tagList;
0041     };
0042 
0043     GTProxy::Iterator::Iterator() : m_current() {}
0044 
0045     GTProxy::Iterator::Iterator(GTContainer::const_iterator current) : m_current(current) {}
0046 
0047     GTProxy::Iterator::Iterator(const Iterator& rhs) : m_current(rhs.m_current) {}
0048 
0049     GTProxy::Iterator& GTProxy::Iterator::operator=(const Iterator& rhs) {
0050       if (this != &rhs) {
0051         m_current = rhs.m_current;
0052       }
0053       return *this;
0054     }
0055 
0056     cond::GTEntry_t GTProxy::Iterator::operator*() { return cond::GTEntry_t(*m_current); }
0057 
0058     GTProxy::Iterator& GTProxy::Iterator::operator++() {
0059       m_current++;
0060       return *this;
0061     }
0062 
0063     GTProxy::Iterator GTProxy::Iterator::operator++(int) {
0064       Iterator tmp(*this);
0065       operator++();
0066       return tmp;
0067     }
0068 
0069     bool GTProxy::Iterator::operator==(const Iterator& rhs) const {
0070       if (m_current != rhs.m_current)
0071         return false;
0072       return true;
0073     }
0074 
0075     bool GTProxy::Iterator::operator!=(const Iterator& rhs) const { return !operator==(rhs); }
0076 
0077     GTProxy::GTProxy() : m_data(), m_session() {}
0078 
0079     GTProxy::GTProxy(const std::shared_ptr<SessionImpl>& session) : m_data(new GTProxyData), m_session(session) {}
0080 
0081     GTProxy::GTProxy(const GTProxy& rhs) : m_data(rhs.m_data), m_session(rhs.m_session) {}
0082 
0083     GTProxy& GTProxy::operator=(const GTProxy& rhs) {
0084       m_data = rhs.m_data;
0085       m_session = rhs.m_session;
0086       return *this;
0087     }
0088 
0089     /** this will be the final function 
0090     void GTProxy::load( const std::string& gtName ){
0091       // clear
0092       reset();
0093       
0094       checkSession( "GTProxy::load" );
0095       
0096       if(!m_session->gtSchema().gtTable().select( gtName, m_data->validity, m_data->snapshotTime ) ){
0097     throwException( "Global Tag \""+gtName+"\" has not been found in the database.","GTProxy::load");
0098       }
0099       m_data->name = gtName;
0100       
0101       m_session->gtSchema().gtMapTable().select( m_data->name, m_data->tagList );
0102       
0103     }
0104     **/
0105 
0106     // overloading for pre- and post-fix. Used in the ORA implementation
0107     void GTProxy::load(const std::string& gtName, const std::string& pref, const std::string& postf) {
0108       // clear
0109       reset();
0110 
0111       checkTransaction("GTProxy::load");
0112 
0113       if (!m_session->gtSchema().gtTable().select(gtName, m_data->validity, m_data->snapshotTime)) {
0114         throwException("Global Tag \"" + gtName + "\" has not been found in the database.", "GTProxy::load");
0115       }
0116       m_data->name = gtName;
0117       m_data->preFix = pref;
0118       m_data->postFix = postf;
0119 
0120       m_session->gtSchema().gtMapTable().select(m_data->name, pref, postf, m_data->tagList);
0121     }
0122 
0123     void GTProxy::reload() { load(m_data->name); }
0124 
0125     void GTProxy::reset() {
0126       if (m_data.get()) {
0127         m_data->tagList.clear();
0128       }
0129     }
0130 
0131     std::string GTProxy::name() const { return m_data.get() ? m_data->name : std::string(""); }
0132 
0133     cond::Time_t GTProxy::validity() const { return m_data.get() ? m_data->validity : cond::time::MIN_VAL; }
0134 
0135     boost::posix_time::ptime GTProxy::snapshotTime() const {
0136       return m_data.get() ? m_data->snapshotTime : boost::posix_time::ptime();
0137     }
0138 
0139     void GTProxy::checkTransaction(const std::string& ctx) {
0140       if (!m_session.get())
0141         throwException("The session is not active.", ctx);
0142       if (!m_session->isTransactionActive(false))
0143         throwException("The transaction is not active.", ctx);
0144     }
0145 
0146     GTProxy::Iterator GTProxy::begin() const {
0147       if (m_data.get()) {
0148         return Iterator(m_data->tagList.begin());
0149       }
0150       return Iterator();
0151     }
0152 
0153     GTProxy::Iterator GTProxy::end() const {
0154       if (m_data.get()) {
0155         return Iterator(m_data->tagList.end());
0156       }
0157       return Iterator();
0158     }
0159 
0160     int GTProxy::size() const { return m_data.get() ? m_data->tagList.size() : 0; }
0161 
0162   }  // namespace persistency
0163 }  // namespace cond