Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:16

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWL1TriggerTableView
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:
0010 //         Created:  Tue Jan 25 16:02:11 CET 2011
0011 //
0012 
0013 #include <boost/regex.hpp>
0014 #include "Fireworks/Core/interface/FWL1TriggerTableView.h"
0015 #include "Fireworks/Core/interface/fwLog.h"
0016 
0017 #include "DataFormats/FWLite/interface/Handle.h"
0018 #include "DataFormats/FWLite/interface/Event.h"
0019 #include "FWCore/Common/interface/TriggerNames.h"
0020 #include "DataFormats/Common/interface/TriggerResults.h"
0021 #include "FWCore/Utilities/interface/Exception.h"
0022 
0023 #include "DataFormats/L1GlobalTrigger/interface/L1GtTriggerMenuLite.h"
0024 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0025 
0026 FWL1TriggerTableView::FWL1TriggerTableView(TEveWindowSlot* iParent)
0027     : FWTriggerTableView(iParent, FWViewType::kTableL1) {
0028   m_columns[0].title = "Algorithm Name";
0029   m_columns.push_back(Column("Result"));
0030   m_columns.push_back(Column("Bit Number"));
0031   m_columns.push_back(Column("Prescale"));
0032 
0033   dataChanged();
0034 }
0035 
0036 void FWL1TriggerTableView::fillTable(fwlite::Event* event) {
0037   fwlite::Handle<L1GtTriggerMenuLite> triggerMenuLite;
0038   fwlite::Handle<L1GlobalTriggerReadoutRecord> triggerRecord;
0039 
0040   try {
0041     // FIXME: Replace magic strings with configurable ones
0042     triggerMenuLite.getByLabel(event->getRun(), "l1GtTriggerMenuLite", "", "");
0043     triggerRecord.getByLabel(*event, "gtDigis", "", "");
0044   } catch (cms::Exception&) {
0045     fwLog(fwlog::kWarning) << "FWL1TriggerTableView: no L1Trigger menu is available." << std::endl;
0046     return;
0047   }
0048 
0049   if (triggerMenuLite.isValid() && triggerRecord.isValid()) {
0050     const L1GtTriggerMenuLite::L1TriggerMap& algorithmMap = triggerMenuLite->gtAlgorithmMap();
0051 
0052     int pfIndexTechTrig = -1;
0053     int pfIndexAlgoTrig = -1;
0054 
0055     boost::regex filter(m_regex.value());
0056 
0057     /// prescale factors
0058     std::vector<std::vector<int> > prescaleFactorsAlgoTrig = triggerMenuLite->gtPrescaleFactorsAlgoTrig();
0059     std::vector<std::vector<int> > prescaleFactorsTechTrig = triggerMenuLite->gtPrescaleFactorsTechTrig();
0060     pfIndexAlgoTrig = (triggerRecord->gtFdlWord()).gtPrescaleFactorIndexAlgo();
0061     pfIndexTechTrig = (triggerRecord->gtFdlWord()).gtPrescaleFactorIndexTech();
0062 
0063     int pfIndexTechTrigValidSize = static_cast<int>(prescaleFactorsTechTrig.size());
0064     if (pfIndexTechTrigValidSize <= pfIndexTechTrig)
0065       fwLog(fwlog::kError) << Form(
0066           "FWL1TriggerTableView: Can't get Technical Trigger pre-scale factors. Index [%d] larger that table size "
0067           "[%d]\n",
0068           pfIndexTechTrig,
0069           (int)prescaleFactorsTechTrig.size());
0070     int pfIndexAlgoTrigValidSize = static_cast<int>(prescaleFactorsAlgoTrig.size());
0071     if (pfIndexAlgoTrigValidSize <= pfIndexAlgoTrig)
0072       fwLog(fwlog::kError) << Form(
0073           "FWL1TriggerTableView: Can't get L1 Algo pre-scale factors. Index [%d] larger that table size [%d]\n",
0074           pfIndexAlgoTrig,
0075           (int)prescaleFactorsAlgoTrig.size());
0076 
0077     const DecisionWord dWord = triggerRecord->decisionWord();
0078     for (L1GtTriggerMenuLite::CItL1Trig itTrig = algorithmMap.begin(), itTrigEnd = algorithmMap.end();
0079          itTrig != itTrigEnd;
0080          ++itTrig) {
0081       const unsigned int bitNumber = itTrig->first;
0082       const std::string& aName = itTrig->second;
0083       int errorCode = 0;
0084       const bool result = triggerMenuLite->gtTriggerResult(aName, dWord, errorCode);
0085 
0086       if (!boost::regex_search(aName, filter))
0087         continue;
0088 
0089       m_columns.at(0).values.push_back(aName);
0090       m_columns.at(1).values.push_back(Form("%d", result));
0091       m_columns.at(2).values.push_back(Form("%d", bitNumber));
0092 
0093       if ((pfIndexAlgoTrig < pfIndexAlgoTrigValidSize) &&
0094           static_cast<unsigned int>(prescaleFactorsAlgoTrig.at(pfIndexAlgoTrig).size()) > bitNumber) {
0095         m_columns.at(3).values.push_back(Form("%d", prescaleFactorsAlgoTrig.at(pfIndexAlgoTrig).at(bitNumber)));
0096       } else
0097         m_columns.at(3).values.push_back("invalid");
0098     }
0099 
0100     const static std::string kTechTriggerName = "TechTrigger";
0101     const TechnicalTriggerWord ttWord = triggerRecord->technicalTriggerWord();
0102 
0103     int tBitNumber = 0;
0104     int tBitResult = 0;
0105     if (boost::regex_search(kTechTriggerName, filter)) {
0106       for (TechnicalTriggerWord::const_iterator tBitIt = ttWord.begin(), tBitEnd = ttWord.end(); tBitIt != tBitEnd;
0107            ++tBitIt, ++tBitNumber) {
0108         if (*tBitIt)
0109           tBitResult = 1;
0110         else
0111           tBitResult = 0;
0112 
0113         m_columns.at(0).values.push_back(kTechTriggerName);
0114         m_columns.at(1).values.push_back(Form("%d", tBitResult));
0115         m_columns.at(2).values.push_back(Form("%d", tBitNumber));
0116 
0117         if ((pfIndexTechTrig < pfIndexTechTrigValidSize) &&
0118             static_cast<int>(prescaleFactorsTechTrig.at(pfIndexTechTrig).size()) > tBitNumber) {
0119           m_columns.at(3).values.push_back(Form("%d", prescaleFactorsTechTrig.at(pfIndexTechTrig).at(tBitNumber)));
0120         } else
0121           m_columns.at(3).values.push_back(Form("invalid"));
0122       }
0123     }
0124   }  // trigger valid
0125   else {
0126     m_columns.at(0).values.push_back("No L1Trigger menu available.");
0127     m_columns.at(1).values.push_back(" ");
0128     m_columns.at(2).values.push_back(" ");
0129     m_columns.at(3).values.push_back(" ");
0130   }
0131 }