Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:37

0001 #include "CondFormats/DataRecord/interface/TotemAnalysisMaskRcd.h"
0002 #include "CondFormats/DataRecord/interface/TotemReadoutRcd.h"
0003 #include "CondFormats/PPSObjects/interface/TotemAnalysisMask.h"
0004 #include "CondFormats/PPSObjects/interface/TotemDAQMapping.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include <fstream>
0012 #include <iostream>
0013 
0014 //----------------------------------------------------------------------------------------------------
0015 
0016 /**
0017  *\brief Writes to file the DAQ mapping loaded by TotemDAQMappingESSourceXML.
0018  **/
0019 class WriteTotemDAQMapping : public edm::one::EDAnalyzer<> {
0020 public:
0021   WriteTotemDAQMapping(const edm::ParameterSet &ps);
0022   ~WriteTotemDAQMapping() override = default;
0023 
0024 private:
0025   /// label of the CTPPS sub-system
0026   const std::string subSystemName_;
0027   std::ofstream outStream_;
0028   const bool readMap_;
0029   const bool readMask_;
0030   edm::ESGetToken<TotemDAQMapping, TotemReadoutRcd> mappingToken_;
0031   edm::ESGetToken<TotemAnalysisMask, TotemAnalysisMaskRcd> maskToken_;
0032   void analyze(const edm::Event &e, const edm::EventSetup &es) override;
0033 };
0034 
0035 WriteTotemDAQMapping::WriteTotemDAQMapping(const edm::ParameterSet &ps)
0036     : subSystemName_(ps.getUntrackedParameter<std::string>("subSystem")),
0037       outStream_(ps.getUntrackedParameter<std::string>("fileName"), std::ios_base::app),
0038       readMap_(ps.getUntrackedParameter<bool>("readMap")),
0039       readMask_(ps.getUntrackedParameter<bool>("readMask")) {
0040   if (readMap_ == true) {
0041     mappingToken_ = esConsumes(edm::ESInputTag("", subSystemName_));
0042   }
0043   if (readMask_ == true) {
0044     maskToken_ = esConsumes(edm::ESInputTag("", subSystemName_));
0045   }
0046 }
0047 
0048 //----------------------------------------------------------------------------------------------------
0049 
0050 void WriteTotemDAQMapping::analyze(const edm::Event &, edm::EventSetup const &es) {
0051   // get mapping
0052   if (readMap_ == true) {
0053     auto mappingHandle = es.getHandle(mappingToken_);
0054     if (mappingHandle.isValid() && !mappingHandle.failedToGet()) {
0055       auto const &mapping = *mappingHandle;
0056       mapping.print(outStream_, subSystemName_);
0057     } else {
0058       edm::LogError("WriteTotemDAQMapping mapping") << "WriteTotemDAQMapping: No mapping found";
0059     }
0060   }
0061 
0062   // get analysis mask to mask channels
0063   if (readMask_ == true) {
0064     auto analysisMaskHandle = es.getHandle(maskToken_);
0065     if (analysisMaskHandle.isValid() && !analysisMaskHandle.failedToGet()) {
0066       auto const &analysisMask = *analysisMaskHandle;
0067       outStream_ << analysisMask;
0068     } else {
0069       edm::LogError("WriteTotemDAQMapping mask") << "WriteTotemDAQMapping: No analysis mask found";
0070     }
0071   }
0072 
0073   outStream_.close();
0074 }
0075 
0076 //----------------------------------------------------------------------------------------------------
0077 
0078 DEFINE_FWK_MODULE(WriteTotemDAQMapping);