Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:37:37

0001 /****************************************************************************
0002 *
0003 * Offline analyzer for writing TOTEM DAQ Mapping sqlite file 
0004 *
0005 ****************************************************************************/
0006 
0007 #include "CondCore/CondDB/interface/Time.h"
0008 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0009 #include "CondFormats/DataRecord/interface/TotemAnalysisMaskRcd.h"
0010 #include "CondFormats/DataRecord/interface/TotemReadoutRcd.h"
0011 #include "CondFormats/PPSObjects/interface/TotemAnalysisMask.h"
0012 #include "CondFormats/PPSObjects/interface/TotemDAQMapping.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/ServiceRegistry/interface/Service.h"
0022 #include "FWCore/Utilities/interface/ESInputTag.h"
0023 #include <cstdint>
0024 
0025 //----------------------------------------------------------------------------------------------------
0026 
0027 /**
0028  *\brief Prints and writes to SQLite the DAQ mapping loaded by TotemDAQMappingESSourceXML.
0029  **/
0030 class WriteCTPPSTotemDAQMappingMask : public edm::one::EDAnalyzer<> {
0031 public:
0032   WriteCTPPSTotemDAQMappingMask(const edm::ParameterSet &ps);
0033   ~WriteCTPPSTotemDAQMappingMask() override = default;
0034 
0035 private:
0036   const cond::Time_t daqMappingIov_;
0037   const std::string recordMap_;
0038   const std::string recordMask_;
0039   const std::string label_;
0040   const edm::ESGetToken<TotemDAQMapping, TotemReadoutRcd> tokenMapping_;
0041   const edm::ESGetToken<TotemAnalysisMask, TotemReadoutRcd> tokenAnalysisMask_;
0042 
0043   void analyze(const edm::Event &e, const edm::EventSetup &es) override;
0044 };
0045 
0046 //----------------------------------------------------------------------------------------------------
0047 
0048 WriteCTPPSTotemDAQMappingMask::WriteCTPPSTotemDAQMappingMask(const edm::ParameterSet &ps)
0049     : daqMappingIov_(ps.getParameter<unsigned long long>("daqMappingIov")),
0050       recordMap_(ps.getParameter<std::string>("recordMap")),
0051       recordMask_(ps.getParameter<std::string>("recordMask")),
0052       label_(ps.getParameter<std::string>("label")),
0053       tokenMapping_(esConsumes<TotemDAQMapping, TotemReadoutRcd>(edm::ESInputTag("", label_))),
0054       tokenAnalysisMask_(esConsumes<TotemAnalysisMask, TotemReadoutRcd>(edm::ESInputTag("", label_))) {}
0055 
0056 void WriteCTPPSTotemDAQMappingMask::analyze(const edm::Event &, edm::EventSetup const &es) {
0057   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0058 
0059   auto mappingHandle = es.getHandle(tokenMapping_);
0060   if (!recordMap_.empty() && mappingHandle.isValid() && !mappingHandle.failedToGet()) {
0061     const auto &mapping = es.getData(tokenMapping_);
0062     std::stringstream output;
0063     mapping.print(output, label_);
0064     edm::LogInfo("WriteCTPPSTotemDAQMappingMask mapping") << output.str();
0065 
0066     if (poolDbService.isAvailable()) {
0067       poolDbService->writeOneIOV(mapping, daqMappingIov_, recordMap_);
0068     } else {
0069       edm::LogError("WriteCTPPSTotemDAQMappingMask mapping")
0070           << "WriteCTPPSTotemDAQMappingMask: PoolDBService not availible. Data not written.";
0071     }
0072 
0073   } else {
0074     edm::LogWarning("WriteCTPPSTotemDAQMappingMask mapping") << "WriteCTPPSTotemDAQMappingMask: No mapping found";
0075   }
0076 
0077   auto maskHandle = es.getHandle(tokenAnalysisMask_);
0078   if (!recordMask_.empty() && maskHandle.isValid() && !maskHandle.failedToGet()) {
0079     const auto &analysisMask = es.getData(tokenAnalysisMask_);
0080     edm::LogInfo("WriteCTPPSTotemDAQMappingMask mask") << analysisMask;
0081 
0082     if (poolDbService.isAvailable()) {
0083       poolDbService->writeOneIOV(analysisMask, daqMappingIov_, recordMask_);
0084     } else {
0085       edm::LogError("WriteCTPPSTotemDAQMappingMask mask")
0086           << "WriteCTPPSTotemDAQMappingMask: PoolDBService not availible. Data not written.";
0087     }
0088   } else {
0089     edm::LogWarning("WriteCTPPSTotemDAQMappingMask mask") << "WriteCTPPSTotemDAQMappingMask: No analysis mask found";
0090   }
0091 }
0092 
0093 //----------------------------------------------------------------------------------------------------
0094 
0095 DEFINE_FWK_MODULE(WriteCTPPSTotemDAQMappingMask);