CMS 3D CMS Logo

TKStatus.cc
Go to the documentation of this file.
1 
8 // C++
9 #include <array>
10 #include <fstream>
11 #include <string>
12 
13 // CMS
27 
28 //
29 // class declaration
30 //
31 class TKStatus : public edm::one::EDAnalyzer<> {
32 public:
34 
35 protected:
36  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
37 
38 private:
39  void dumpTkDcsStatus(std::string const&, edm::RunNumber_t, std::array<bool, 6> const&);
40 
44 
45  int lastlumi_ = -1;
46  // ----------member data ---------------------------
47 };
48 
49 // ----------------------------------------------------------
51  : dcsStatusToken_(consumes<DcsStatusCollection>(edm::InputTag("scalersRawToDigi"))),
52  dcsRecordToken_(consumes<DCSRecord>(edm::InputTag("onlineMetaDataDigis"))) {
53  dcsTkFileName_ = ps.getParameter<edm::ParameterSet>("BeamFitter").getUntrackedParameter<std::string>("DIPFileName");
54  {
55  std::string tmpname = dcsTkFileName_;
56  tmpname.insert(dcsTkFileName_.length() - 4, "_TkStatus");
57  dcsTkFileName_ = std::move(tmpname);
58  }
59 }
60 
61 // ----------------------------------------------------------
62 void TKStatus::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
63  int nthlumi = iEvent.luminosityBlock();
64  if (nthlumi > lastlumi_) { // check every LS
65  lastlumi_ = nthlumi;
66 
67  // Checking TK status
68  const auto& dcsStatus = iEvent.getHandle(dcsStatusToken_);
69  const auto& dcsRecord = iEvent.getHandle(dcsRecordToken_);
70 
71  std::array<bool, 6> dcsTk;
72  for (auto& e : dcsTk) {
73  e = true;
74  }
75 
76  // Check that the DCS information is available in some form
77  if (!dcsStatus.isValid() && !dcsRecord.isValid()) {
78  edm::LogWarning("TkStatus") << "DcsStatusCollection product with InputTag \"scalersRawToDigi\" not in event \n"
79  << "DCSRecord product with InputTag \"onlineMetaDataDigis\" not in event \n";
80  dumpTkDcsStatus(dcsTkFileName_, iEvent.run(), dcsTk);
81  return;
82  }
83 
84  if (dcsStatus.isValid() && (*dcsStatus).empty()) {
85  if (iEvent.eventAuxiliary().isRealData()) {
86  // This is the Data case for >= Run3, DCSStatus is available (unpacked), but empty
87  // because SCAL is not in data-taking. In this case we fall back to s/w FED 1022
88  if (dcsRecord.isValid()) {
89  edm::LogPrint("TkStatus") << "Using dcsRecord because dcsStatus is empty";
90  dcsTk[0] = (*dcsRecord).highVoltageReady(DCSRecord::Partition::BPIX);
91  dcsTk[1] = (*dcsRecord).highVoltageReady(DCSRecord::Partition::FPIX);
92  dcsTk[2] = (*dcsRecord).highVoltageReady(DCSRecord::Partition::TIBTID);
93  dcsTk[3] = (*dcsRecord).highVoltageReady(DCSRecord::Partition::TOB);
94  dcsTk[4] = (*dcsRecord).highVoltageReady(DCSRecord::Partition::TECp);
95  dcsTk[5] = (*dcsRecord).highVoltageReady(DCSRecord::Partition::TECm);
96  } else {
97  // DCS status is empty, and the DCS record is not available
98  edm::LogWarning("TkStatus") << "DCSRecord product with InputTag \"onlineMetaDataDigis\" empty \n";
99  dumpTkDcsStatus(dcsTkFileName_, iEvent.run(), dcsTk);
100  return;
101  }
102  } else {
103  // DCS status is empty, but it's not real data
104  edm::LogPrint("TkStatus") << "Running on MC";
105  dumpTkDcsStatus(dcsTkFileName_, iEvent.run(), dcsTk);
106  return;
107  }
108  } else {
109  // This is the case for <= Run2
110  edm::LogPrint("TkStatus") << "Using dcsStatus (Run 1 and Run 2 SCAL)";
111  for (auto const& status : *dcsStatus) {
112  if (!status.ready(DcsStatus::BPIX))
113  dcsTk[0] = false;
114  if (!status.ready(DcsStatus::FPIX))
115  dcsTk[1] = false;
116  if (!status.ready(DcsStatus::TIBTID))
117  dcsTk[2] = false;
118  if (!status.ready(DcsStatus::TOB))
119  dcsTk[3] = false;
120  if (!status.ready(DcsStatus::TECp))
121  dcsTk[4] = false;
122  if (!status.ready(DcsStatus::TECm))
123  dcsTk[5] = false;
124  }
125  }
126 
127  dumpTkDcsStatus(dcsTkFileName_, iEvent.run(), dcsTk);
128  }
129 }
130 
131 //--------------------------------------------------------
132 void TKStatus::dumpTkDcsStatus(std::string const& fileName, edm::RunNumber_t runnum, std::array<bool, 6> const& dcsTk) {
133  std::ofstream outFile;
134 
135  outFile.open(fileName.c_str());
136  outFile << "BPIX " << (dcsTk[0] ? "On" : "Off") << std::endl;
137  outFile << "FPIX " << (dcsTk[1] ? "On" : "Off") << std::endl;
138  outFile << "TIBTID " << (dcsTk[2] ? "On" : "Off") << std::endl;
139  outFile << "TOB " << (dcsTk[3] ? "On" : "Off") << std::endl;
140  outFile << "TECp " << (dcsTk[4] ? "On" : "Off") << std::endl;
141  outFile << "TECm " << (dcsTk[5] ? "On" : "Off") << std::endl;
142  bool AllTkOn = true;
143  for (auto status : dcsTk) {
144  if (!status) {
145  AllTkOn = false;
146  break;
147  }
148  }
149  outFile << "WholeTrackerOn " << (AllTkOn ? "Yes" : "No") << std::endl;
150  outFile << "Runnumber " << runnum << std::endl;
151 
152  outFile.close();
153 }
154 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int runnum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Class to contain DCS information from soft FED 1022.
Definition: DCSRecord.h:20
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< DcsStatusCollection > dcsStatusToken_
Definition: TKStatus.cc:42
std::string dcsTkFileName_
Definition: TKStatus.cc:41
Log< level::Warning, true > LogPrint
const edm::EDGetTokenT< DCSRecord > dcsRecordToken_
Definition: TKStatus.cc:43
std::vector< DcsStatus > DcsStatusCollection
Definition: DcsStatus.h:110
#define BPIX
TKStatus(const edm::ParameterSet &)
Definition: TKStatus.cc:50
HLT enums.
unsigned int RunNumber_t
Log< level::Warning, false > LogWarning
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: TKStatus.cc:62
void dumpTkDcsStatus(std::string const &, edm::RunNumber_t, std::array< bool, 6 > const &)
Definition: TKStatus.cc:132
def move(src, dest)
Definition: eostools.py:511
int lastlumi_
Definition: TKStatus.cc:45