CMS 3D CMS Logo

DetStatus.cc
Go to the documentation of this file.
10 
11 class DetStatus : public edm::stream::EDFilter<> {
12 public:
14  ~DetStatus() override;
15 
16  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
17 
18 private:
19  bool filter(edm::Event&, edm::EventSetup const&) override;
20 
21  bool verbose_;
23  bool AndOr_;
24  std::vector<std::string> DetNames_;
25  std::bitset<DcsStatus::nPartitions> requestedPartitions_;
26  unsigned int DetMap_;
29 
30  bool checkForDCSStatus(const DcsStatusCollection& dcsStatus);
31  bool checkForDCSRecord(const DCSRecord& dcsRecod);
32 };
33 
34 using namespace std;
35 
36 //
37 // -- Constructor
38 //
40  verbose_ = pset.getUntrackedParameter<bool>("DebugOn", false);
41  AndOr_ = pset.getParameter<bool>("AndOr");
42  applyfilter_ = pset.getParameter<bool>("ApplyFilter");
43  DetNames_ = pset.getParameter<std::vector<std::string>>("DetectorType");
44 
45  // build a map
46  DetMap_ = 0;
47 
48  for (unsigned int detreq = 0; detreq < DetNames_.size(); detreq++) {
49  for (unsigned int detlist = 0; detlist < DcsStatus::nPartitions; detlist++) {
50  if (DetNames_[detreq] == DcsStatus::partitionName[detlist]) {
51  //edm::LogPrint("DetStatus") << __PRETTY_FUNCTION__ << " requested:" << DetNames_[detreq] << std::endl;
52 
53  // set for DCSRecord
54  requestedPartitions_.set(detlist, true);
55 
56  // set for DCSStatus
57  DetMap_ |= (1 << DcsStatus::partitionList[detlist]);
58 
59  if (verbose_) {
60  edm::LogInfo("DetStatus") << "DCSStatus filter: asked partition " << DcsStatus::partitionName[detlist]
61  << " bit " << DcsStatus::partitionList[detlist] << std::endl;
62  }
63  }
64  }
65  }
66  scalersToken_ = consumes<DcsStatusCollection>(edm::InputTag("scalersRawToDigi"));
67  dcsRecordToken_ = consumes<DCSRecord>(edm::InputTag("onlineMetaDataDigis"));
68 }
69 
70 //
71 // -- Destructor
72 //
73 DetStatus::~DetStatus() = default;
74 
75 //*********************************************************************//
77 //*********************************************************************//
78 {
79  if (verbose_) {
80  edm::LogInfo("DetStatus") << "Using FED#735 for reading DCS bits" << std::endl;
81  }
82 
83  bool accepted = false;
84  unsigned int curr_dcs = (dcsStatus)[0].ready();
85  if (verbose_) {
86  edm::LogVerbatim("DetStatus") << "curr_dcs = " << curr_dcs << std::endl;
87  }
88 
89  if (AndOr_)
90  accepted = ((DetMap_ & curr_dcs) == DetMap_);
91  else
92  accepted = ((DetMap_ & curr_dcs) != 0);
93 
94  if (verbose_) {
95  edm::LogInfo("DetStatus") << "DCSStatus filter: requested map: " << DetMap_ << " dcs in event: " << curr_dcs
96  << " filter: " << accepted << "( AndOr: " << AndOr_ << ")" << std::endl;
97  edm::LogVerbatim("DetStatus") << "Partitions ON: ";
98  for (unsigned int detlist = 0; detlist < DcsStatus::nPartitions; detlist++) {
99  if ((dcsStatus)[0].ready(DcsStatus::partitionList[detlist])) {
100  edm::LogVerbatim("DetStatus") << " " << DcsStatus::partitionName[detlist];
101  }
102  }
103  edm::LogVerbatim("DetStatus") << std::endl;
104  }
105  return accepted;
106 }
107 
108 //*********************************************************************//
110 //*********************************************************************//
111 {
112  bool accepted = false;
113 
114  if (verbose_) {
115  edm::LogInfo("DetStatus") << "Using softFED#1022 for reading DCS bits" << std::endl;
116  }
117 
118  for (unsigned int detlist = 0; detlist < DcsStatus::nPartitions; detlist++) {
119  if (verbose_)
120  edm::LogInfo("DetStatus") << "testing " << DcsStatus::partitionName[detlist];
121  if (requestedPartitions_.test(detlist)) {
122  if (verbose_)
123  edm::LogInfo("DetStatus") << " " << DcsStatus::partitionName[detlist] << "in the requested list" << std::endl;
124  if (AndOr_) {
125  accepted = dcsRecord.highVoltageReady(detlist);
126  if (!accepted)
127  break;
128  } else {
129  accepted = (accepted || dcsRecord.highVoltageReady(detlist));
130  }
131  }
132  }
133 
134  if (verbose_) {
135  edm::LogInfo("DetStatus") << "DCSStatus filter: " << accepted << " ( AndOr: " << AndOr_ << ")" << std::endl;
136  edm::LogVerbatim("DetStatus") << "Partitions ON: ";
137  for (unsigned int detlist = 0; detlist < DcsStatus::nPartitions; detlist++) {
138  if ((dcsRecord.highVoltageReady(detlist))) {
139  edm::LogVerbatim("DetStatus") << " " << DcsStatus::partitionName[detlist];
140  }
141  }
142  edm::LogVerbatim("DetStatus") << std::endl;
143  }
144 
145  return accepted;
146 }
147 
148 //*********************************************************************//
150 //*********************************************************************//
151 {
152  bool accepted = false;
153 
154  // If FED#735 is available use it to extract DcsStatusCollection.
155  // If not, use softFED#1022 to extract DCSRecord.
156  // Populate DCS Bits array with received information.
157 
159  evt.getByToken(scalersToken_, dcsStatus);
161  evt.getByToken(dcsRecordToken_, dcsRecord);
162 
163  // if the old style DCS status is valid (Run1 + Run2)
164  if (dcsStatus.isValid() && !dcsStatus->empty()) {
165  accepted = checkForDCSStatus(*dcsStatus);
166  } else if (dcsRecord.isValid()) {
167  if (evt.eventAuxiliary().isRealData()) {
168  // in case of real data check for DCSRecord content (Run >=3)
169  accepted = checkForDCSRecord(*dcsRecord);
170  } else {
171  // in case of MC accept in any case
172  accepted = true;
173  }
174  } else {
175  edm::LogError("DetStatus")
176  << "Error! can't get the product, neither DCSRecord, nor scalersRawToDigi: accept in any case!";
177  accepted = true;
178  }
179 
180  if (!applyfilter_) {
181  accepted = true;
182  }
183 
184  return accepted;
185 }
186 
187 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
190  desc.addUntracked<bool>("DebugOn", false);
191  desc.add<bool>("AndOr", true);
192  desc.add<bool>("ApplyFilter", true);
193  desc.add<std::vector<std::string>>("DetectorType", {});
194  descriptions.add("detStatus", desc);
195 }
196 
DetStatus(const edm::ParameterSet &)
Definition: DetStatus.cc:39
~DetStatus() override
Log< level::Info, true > LogVerbatim
bool AndOr_
Definition: DetStatus.cc:23
bool verbose_
Definition: DetStatus.cc:21
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
std::bitset< DcsStatus::nPartitions > requestedPartitions_
Definition: DetStatus.cc:25
Class to contain DCS information from soft FED 1022.
Definition: DCSRecord.h:20
EventAuxiliary const & eventAuxiliary() const override
Definition: Event.h:95
Log< level::Error, false > LogError
edm::EDGetTokenT< DcsStatusCollection > scalersToken_
Definition: DetStatus.cc:27
bool applyfilter_
Definition: DetStatus.cc:22
bool isRealData() const
bool checkForDCSRecord(const DCSRecord &dcsRecod)
Definition: DetStatus.cc:109
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool filter(edm::Event &, edm::EventSetup const &) override
Definition: DetStatus.cc:149
static const char *const partitionName[]
Definition: DcsStatus.h:31
std::vector< DcsStatus > DcsStatusCollection
Definition: DcsStatus.h:110
Log< level::Info, false > LogInfo
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
bool checkForDCSStatus(const DcsStatusCollection &dcsStatus)
Definition: DetStatus.cc:76
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DetStatus.cc:188
std::vector< std::string > DetNames_
Definition: DetStatus.cc:24
static const int partitionList[]
Definition: DcsStatus.h:30
unsigned int DetMap_
Definition: DetStatus.cc:26
edm::EDGetTokenT< DCSRecord > dcsRecordToken_
Definition: DetStatus.cc:28