Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-04 06:48:47

0001 #ifndef CONDCORE_POPCON_ONLINEPOPCON_H
0002 #define CONDCORE_POPCON_ONLINEPOPCON_H
0003 
0004 //
0005 // Authors:
0006 //  - Francesco Brivio (Milano-Bicocca)
0007 //  - Jan Chyczynski   (AGH University of Krakow)
0008 //
0009 
0010 #include "CondCore/DBOutputService/interface/OnlineDBOutputService.h"
0011 #include "CondCore/PopCon/interface/Exception.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014 
0015 #include <algorithm>
0016 #include <functional>
0017 #include <iostream>
0018 #include <string>
0019 #include <vector>
0020 
0021 namespace popcon {
0022 
0023   //  Populator of the Condition DB.
0024   //  Specific implementation for online lumi-based conditions (OnlineDBOutputService)
0025 
0026   class OnlinePopCon {
0027   public:
0028     typedef cond::Time_t Time_t;
0029 
0030     OnlinePopCon(const edm::ParameterSet& pset);
0031 
0032     virtual ~OnlinePopCon();
0033 
0034     template <typename Source>
0035     void write(Source const& source);
0036 
0037   private:
0038     cond::persistency::Session initialize();
0039     cond::persistency::Session preparePopCon();
0040     void finalize();
0041 
0042   private:
0043     // DB service
0044     edm::Service<cond::service::OnlineDBOutputService> m_dbService;
0045 
0046     // PopCon infrastructure
0047     cond::persistency::Session m_targetSession;
0048     std::string m_targetConnectionString;
0049     std::string m_authPath;
0050     int m_authSys;
0051     std::string m_recordName;
0052     cond::TagInfo_t m_tagInfo;
0053     cond::LogDBEntry_t m_logDBEntry;
0054 
0055     // OnlinePopCon specific
0056     int m_dbLoggerReturn_;  // DB logger return value
0057     bool m_useLockRecors;   // whether to lock the records or not
0058 
0059     // Version
0060     static constexpr const char* const s_version = "1.0";
0061   };
0062 
0063   template <typename Source>
0064   void OnlinePopCon::write(Source const& source) {
0065     // Get data to be uploaded
0066     typedef typename Source::Container Container;
0067     std::pair<Container const*, std::string const> ret = source(initialize(), m_tagInfo, m_logDBEntry);
0068     Container const& iovs = *ret.first;
0069 
0070     // Check that only 1 iov/payload is provided
0071     if (iovs.size() > 1) {
0072       throw Exception("OnlinePopCon", "[write] More than one iov/payload provided!");
0073     }
0074 
0075     // If zero payloads to transfer, finalize and return
0076     if (iovs.empty()) {
0077       m_dbService->logger().logInfo() << "OnlinePopCon::write - Nothing to transfer";
0078       finalize();
0079       return;
0080     }
0081 
0082     // Upload
0083     // Check if DB service is available
0084     if (!m_dbService.isAvailable()) {
0085       throw Exception("OnlinePopCon", "[write] DBService not available");
0086     }
0087 
0088     // Get the only payload to transfer
0089     auto [originalSince, payload] = *iovs.begin();
0090 
0091     // Log the original since
0092     m_dbService->logger().logInfo() << "OnlinePopCon::write - original since: " << originalSince;
0093 
0094     // Upload the payload
0095     try {
0096       auto targetSince = m_dbService->writeIOVForNextLumisection(*payload, m_recordName);
0097       m_dbService->logger().logInfo() << "OnlinePopCon::write - writeForNextLumisection successful!";
0098       m_dbService->logger().logInfo() << "OnlinePopCon::write - uploaded with since: " << targetSince;
0099     } catch (const std::exception& e) {
0100       m_dbService->logger().logError() << "OnlinePopCon::write - Error writing record: " << m_recordName;
0101       m_dbService->logger().logError() << "Error is: " << e.what();
0102       m_dbLoggerReturn_ = 2;
0103     }
0104 
0105     // Finalize
0106     finalize();
0107   }
0108 
0109 }  // namespace popcon
0110 
0111 #endif  // CONDCORE_POPCON_ONLINEPOPCON_H