Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-23 22:52:55

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "DataFormats/OnlineMetaData/interface/DCSRecord.h"
0003 #include "DataFormats/Scalers/interface/DcsStatus.h"
0004 #include "FWCore/Framework/interface/stream/EDFilter.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 
0011 class DetStatus : public edm::stream::EDFilter<> {
0012 public:
0013   DetStatus(const edm::ParameterSet&);
0014   ~DetStatus() override;
0015 
0016   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0017 
0018 private:
0019   bool filter(edm::Event&, edm::EventSetup const&) override;
0020 
0021   bool verbose_;
0022   bool applyfilter_;
0023   bool AndOr_;
0024   std::vector<std::string> DetNames_;
0025   std::bitset<DcsStatus::nPartitions> requestedPartitions_;
0026   unsigned int DetMap_;
0027   edm::EDGetTokenT<DcsStatusCollection> scalersToken_;
0028   edm::EDGetTokenT<DCSRecord> dcsRecordToken_;
0029 
0030   bool checkForDCSStatus(const DcsStatusCollection& dcsStatus);
0031   bool checkForDCSRecord(const DCSRecord& dcsRecod);
0032 };
0033 
0034 using namespace std;
0035 
0036 //
0037 // -- Constructor
0038 //
0039 DetStatus::DetStatus(const edm::ParameterSet& pset) {
0040   verbose_ = pset.getUntrackedParameter<bool>("DebugOn", false);
0041   AndOr_ = pset.getParameter<bool>("AndOr");
0042   applyfilter_ = pset.getParameter<bool>("ApplyFilter");
0043   DetNames_ = pset.getParameter<std::vector<std::string>>("DetectorType");
0044 
0045   // build a map
0046   DetMap_ = 0;
0047 
0048   for (unsigned int detreq = 0; detreq < DetNames_.size(); detreq++) {
0049     for (unsigned int detlist = 0; detlist < DcsStatus::nPartitions; detlist++) {
0050       if (DetNames_[detreq] == DcsStatus::partitionName[detlist]) {
0051         //edm::LogPrint("DetStatus") << __PRETTY_FUNCTION__ << " requested:" << DetNames_[detreq] << std::endl;
0052 
0053         // set for DCSRecord
0054         requestedPartitions_.set(detlist, true);
0055 
0056         // set for DCSStatus
0057         DetMap_ |= (1 << DcsStatus::partitionList[detlist]);
0058 
0059         if (verbose_) {
0060           edm::LogInfo("DetStatus") << "DCSStatus filter: asked partition " << DcsStatus::partitionName[detlist]
0061                                     << " bit " << DcsStatus::partitionList[detlist] << std::endl;
0062         }
0063       }
0064     }
0065   }
0066   scalersToken_ = consumes<DcsStatusCollection>(edm::InputTag("scalersRawToDigi"));
0067   dcsRecordToken_ = consumes<DCSRecord>(edm::InputTag("onlineMetaDataDigis"));
0068 }
0069 
0070 //
0071 // -- Destructor
0072 //
0073 DetStatus::~DetStatus() = default;
0074 
0075 //*********************************************************************//
0076 bool DetStatus::checkForDCSStatus(const DcsStatusCollection& dcsStatus)
0077 //*********************************************************************//
0078 {
0079   if (verbose_) {
0080     edm::LogInfo("DetStatus") << "Using FED#735 for reading DCS bits" << std::endl;
0081   }
0082 
0083   bool accepted = false;
0084   unsigned int curr_dcs = (dcsStatus)[0].ready();
0085   if (verbose_) {
0086     edm::LogVerbatim("DetStatus") << "curr_dcs = " << curr_dcs << std::endl;
0087   }
0088 
0089   if (AndOr_)
0090     accepted = ((DetMap_ & curr_dcs) == DetMap_);
0091   else
0092     accepted = ((DetMap_ & curr_dcs) != 0);
0093 
0094   if (verbose_) {
0095     edm::LogInfo("DetStatus") << "DCSStatus filter: requested map: " << DetMap_ << " dcs in event: " << curr_dcs
0096                               << " filter: " << accepted << "( AndOr: " << AndOr_ << ")" << std::endl;
0097     edm::LogVerbatim("DetStatus") << "Partitions ON: ";
0098     for (unsigned int detlist = 0; detlist < DcsStatus::nPartitions; detlist++) {
0099       if ((dcsStatus)[0].ready(DcsStatus::partitionList[detlist])) {
0100         edm::LogVerbatim("DetStatus") << " " << DcsStatus::partitionName[detlist];
0101       }
0102     }
0103     edm::LogVerbatim("DetStatus") << std::endl;
0104   }
0105   return accepted;
0106 }
0107 
0108 //*********************************************************************//
0109 bool DetStatus::checkForDCSRecord(const DCSRecord& dcsRecord)
0110 //*********************************************************************//
0111 {
0112   bool accepted = false;
0113 
0114   if (verbose_) {
0115     edm::LogInfo("DetStatus") << "Using softFED#1022 for reading DCS bits" << std::endl;
0116   }
0117 
0118   for (unsigned int detlist = 0; detlist < DcsStatus::nPartitions; detlist++) {
0119     if (verbose_)
0120       edm::LogInfo("DetStatus") << "testing " << DcsStatus::partitionName[detlist];
0121     if (requestedPartitions_.test(detlist)) {
0122       if (verbose_)
0123         edm::LogInfo("DetStatus") << " " << DcsStatus::partitionName[detlist] << "in the requested list" << std::endl;
0124       if (AndOr_) {
0125         accepted = dcsRecord.highVoltageReady(detlist);
0126         if (!accepted)
0127           break;
0128       } else {
0129         accepted = (accepted || dcsRecord.highVoltageReady(detlist));
0130       }
0131     }
0132   }
0133 
0134   if (verbose_) {
0135     edm::LogInfo("DetStatus") << "DCSStatus filter: " << accepted << " ( AndOr: " << AndOr_ << ")" << std::endl;
0136     edm::LogVerbatim("DetStatus") << "Partitions ON: ";
0137     for (unsigned int detlist = 0; detlist < DcsStatus::nPartitions; detlist++) {
0138       if ((dcsRecord.highVoltageReady(detlist))) {
0139         edm::LogVerbatim("DetStatus") << " " << DcsStatus::partitionName[detlist];
0140       }
0141     }
0142     edm::LogVerbatim("DetStatus") << std::endl;
0143   }
0144 
0145   return accepted;
0146 }
0147 
0148 //*********************************************************************//
0149 bool DetStatus::filter(edm::Event& evt, edm::EventSetup const& es)
0150 //*********************************************************************//
0151 {
0152   bool accepted = false;
0153 
0154   // If FED#735 is available use it to extract DcsStatusCollection.
0155   // If not, use softFED#1022 to extract DCSRecord.
0156   // Populate DCS Bits array with received information.
0157 
0158   edm::Handle<DcsStatusCollection> dcsStatus;
0159   evt.getByToken(scalersToken_, dcsStatus);
0160   edm::Handle<DCSRecord> dcsRecord;
0161   evt.getByToken(dcsRecordToken_, dcsRecord);
0162 
0163   // if the old style DCS status is valid (Run1 + Run2)
0164   if (dcsStatus.isValid() && !dcsStatus->empty()) {
0165     accepted = checkForDCSStatus(*dcsStatus);
0166   } else if (dcsRecord.isValid()) {
0167     if (evt.eventAuxiliary().isRealData()) {
0168       // in case of real data check for DCSRecord content (Run >=3)
0169       accepted = checkForDCSRecord(*dcsRecord);
0170     } else {
0171       // in case of MC accept in any case
0172       accepted = true;
0173     }
0174   } else {
0175     edm::LogError("DetStatus")
0176         << "Error! can't get the product, neither DCSRecord, nor scalersRawToDigi: accept in any case!";
0177     accepted = true;
0178   }
0179 
0180   if (!applyfilter_) {
0181     accepted = true;
0182   }
0183 
0184   return accepted;
0185 }
0186 
0187 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0188 void DetStatus::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0189   edm::ParameterSetDescription desc;
0190   desc.addUntracked<bool>("DebugOn", false);
0191   desc.add<bool>("AndOr", true);
0192   desc.add<bool>("ApplyFilter", true);
0193   desc.add<std::vector<std::string>>("DetectorType", {});
0194   descriptions.add("detStatus", desc);
0195 }
0196 
0197 #include "FWCore/Framework/interface/MakerMacros.h"
0198 DEFINE_FWK_MODULE(DetStatus);