Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:26

0001 #include <iomanip>
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 
0010 #include "CondFormats/DataRecord/interface/L1TGlobalPrescalesVetosRcd.h"
0011 #include "CondFormats/L1TObjects/interface/L1TGlobalPrescalesVetos.h"
0012 
0013 class L1TGlobalPrescalesVetosViewer : public edm::one::EDAnalyzer<> {
0014 private:
0015   int32_t prescale_table_verbosity;
0016   int32_t bxmask_map_verbosity;
0017   int32_t veto_verbosity;
0018   edm::ESGetToken<L1TGlobalPrescalesVetos, L1TGlobalPrescalesVetosRcd> token_;
0019 
0020   std::string hash(void* buf, size_t len) const;
0021 
0022 public:
0023   void analyze(const edm::Event&, const edm::EventSetup&) override;
0024 
0025   explicit L1TGlobalPrescalesVetosViewer(const edm::ParameterSet& pset) {
0026     token_ = esConsumes();
0027     prescale_table_verbosity = pset.getUntrackedParameter<int32_t>("prescale_table_verbosity", 0);
0028     bxmask_map_verbosity = pset.getUntrackedParameter<int32_t>("bxmask_map_verbosity", 0);
0029     veto_verbosity = pset.getUntrackedParameter<int32_t>("veto_verbosity", 0);
0030   }
0031 };
0032 
0033 #include "Utilities/OpenSSL/interface/openssl_init.h"
0034 #include <cmath>
0035 #include <iostream>
0036 using namespace std;
0037 
0038 std::string L1TGlobalPrescalesVetosViewer::hash(void* buf, size_t len) const {
0039   cms::openssl_init();
0040   EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
0041   const EVP_MD* md = EVP_get_digestbyname("SHA1");
0042   if (!EVP_DigestInit_ex(mdctx, md, nullptr))
0043     throw cms::Exception("L1TGlobalPrescalesVetosViewer::hash") << "SHA1 initialization error";
0044 
0045   if (!EVP_DigestUpdate(mdctx, buf, len))
0046     throw cms::Exception("L1TGlobalPrescalesVetosViewer::hash") << "SHA1 processing error";
0047 
0048   unsigned char hash[EVP_MAX_MD_SIZE];
0049   unsigned int md_len = 0;
0050   if (!EVP_DigestFinal_ex(mdctx, hash, &md_len))
0051     throw cms::Exception("L1TGlobalPrescalesVetosViewer::hash") << "SHA1 finalization error";
0052 
0053   EVP_MD_CTX_free(mdctx);
0054 
0055   // re-write bytes in hex
0056   char tmp[EVP_MAX_MD_SIZE * 2 + 1];
0057   if (md_len > 20)
0058     md_len = 20;
0059   for (unsigned int i = 0; i < md_len; i++)
0060     ::sprintf(&tmp[i * 2], "%02x", hash[i]);
0061 
0062   tmp[md_len * 2] = 0;
0063   return std::string(tmp);
0064 }
0065 
0066 void L1TGlobalPrescalesVetosViewer::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0067   L1TGlobalPrescalesVetos const& ptr = evSetup.getData(token_);
0068 
0069   edm::LogInfo("") << "L1TGlobalPrescalesVetosViewer:";
0070 
0071   cout << endl;
0072   cout << "  version_        = " << ptr.version_ << endl;
0073   cout << "  bxmask_default_ = " << ptr.bxmask_default_ << endl;
0074 
0075   size_t len_prescale_table_ = 0;
0076   for (size_t col = 0; col < ptr.prescale_table_.size(); col++) {
0077     size_t nRows = (ptr.prescale_table_)[col].size();
0078     len_prescale_table_ += nRows;
0079     if (prescale_table_verbosity > 0) {
0080       int column[nRows];
0081       for (size_t row = 0; row < nRows; row++)
0082         column[row] = (ptr.prescale_table_)[col][row];
0083       cout << "  prescale_table_[" << col << "][" << nRows << "] = ";
0084       if (nRows)
0085         cout << hash(column, sizeof(int) * nRows) << endl;
0086       else
0087         cout << 0 << endl;
0088     }
0089   }
0090   int prescale_table_[len_prescale_table_];
0091   for (size_t col = 0, pos = 0; col < ptr.prescale_table_.size(); col++) {
0092     size_t nRows = (ptr.prescale_table_)[col].size();
0093     for (size_t row = 0; row < nRows; row++, pos++)
0094       prescale_table_[pos] = (ptr.prescale_table_)[col][row];
0095   }
0096   cout << "  prescale_table_[[" << len_prescale_table_ << "]] = ";
0097   if (len_prescale_table_)
0098     cout << hash(prescale_table_, sizeof(int) * len_prescale_table_) << endl;
0099   else
0100     cout << 0 << endl;
0101 
0102   if (prescale_table_verbosity > 1) {
0103     cout << endl << " Detailed view on the prescales * masks: " << endl;
0104     for (size_t col = 0; col < ptr.prescale_table_.size(); col++)
0105       cout << setw(8) << " Index " << col;
0106     cout << endl;
0107     size_t nRows = (ptr.prescale_table_)[0].size();
0108     for (size_t row = 0; row < nRows; row++) {
0109       for (size_t col = 0; col < ptr.prescale_table_.size(); col++)
0110         cout << setw(8) << (ptr.prescale_table_)[col][row];
0111       cout << endl;
0112     }
0113     cout << endl;
0114   }
0115 
0116   size_t len_bxmask_map_ = 0;
0117   for (std::map<int, std::vector<int> >::const_iterator it = (ptr.bxmask_map_).begin(); it != (ptr.bxmask_map_).end();
0118        it++) {
0119     len_bxmask_map_ += it->second.size();
0120     if (bxmask_map_verbosity == 1) {
0121       int masks[it->second.size()];
0122       for (size_t i = 0; i < it->second.size(); i++)
0123         masks[i] = it->second[i];
0124       cout << "  bxmask_map_[" << it->first << "][" << it->second.size() << "] = ";
0125       if (!it->second.empty())
0126         cout << hash(masks, sizeof(int) * it->second.size()) << endl;
0127       else
0128         cout << 0 << endl;
0129     }
0130     if (bxmask_map_verbosity > 1) {
0131       cout << "  bxmask_map_[" << it->first << "][" << it->second.size() << "] = ";
0132       for (size_t algo = 0; algo < it->second.size(); algo++)
0133         cout << it->second[algo] << ", ";
0134       cout << endl;
0135     }
0136   }
0137   int bxmask_map_[len_bxmask_map_];
0138   size_t pos = 0;
0139   for (std::map<int, std::vector<int> >::const_iterator it = (ptr.bxmask_map_).begin(); it != (ptr.bxmask_map_).end();
0140        it++) {
0141     for (size_t i = 0; i < it->second.size(); i++, pos++)
0142       bxmask_map_[pos] = it->second[i];
0143   }
0144   cout << "  bxmask_map_[[" << len_bxmask_map_ << "]]        = ";
0145   if (len_bxmask_map_)
0146     cout << hash(bxmask_map_, sizeof(int) * len_bxmask_map_) << endl;
0147   else
0148     cout << 0 << endl;
0149 
0150   int veto_[(ptr.veto_).size()];
0151   bool veto_allZeros = true;
0152   for (size_t i = 0; i < (ptr.veto_).size(); i++) {
0153     veto_[i] = (ptr.veto_)[i];
0154     if (veto_[i])
0155       veto_allZeros = false;
0156   }
0157   cout << "  veto_[" << (ptr.veto_).size() << "]              = ";
0158   if (veto_verbosity == 0) {
0159     if (!(ptr.veto_).empty()) {
0160       cout << hash(veto_, sizeof(int) * (ptr.veto_).size());
0161       if (veto_allZeros)
0162         cout << " (all zeros)" << endl;
0163       else
0164         cout << endl;
0165     } else
0166       cout << 0 << endl;
0167   } else
0168     for (size_t i = 0; i < (ptr.veto_).size(); i++)
0169       cout << veto_[i] << endl;
0170 
0171   int exp_ints_[(ptr.exp_ints_).size()];
0172   for (size_t i = 0; i < (ptr.exp_ints_).size(); i++)
0173     exp_ints_[i] = (ptr.exp_ints_)[i];
0174   cout << "  exp_ints_[" << (ptr.exp_ints_).size() << "]            = ";
0175   if (!(ptr.exp_ints_).empty())
0176     cout << hash(exp_ints_, sizeof(int) * (ptr.exp_ints_).size()) << endl;
0177   else
0178     cout << 0 << endl;
0179 
0180   int exp_doubles_[(ptr.exp_doubles_).size()];
0181   for (size_t i = 0; i < (ptr.exp_doubles_).size(); i++)
0182     exp_ints_[i] = (ptr.exp_doubles_)[i];
0183   cout << "  exp_doubles_[" << (ptr.exp_doubles_).size() << "]         = ";
0184   if (!(ptr.exp_doubles_).empty())
0185     cout << hash(exp_doubles_, sizeof(int) * (ptr.exp_doubles_).size()) << endl;
0186   else
0187     cout << 0 << endl;
0188 }
0189 
0190 #include "FWCore/PluginManager/interface/ModuleDef.h"
0191 #include "FWCore/Framework/interface/MakerMacros.h"
0192 #include "FWCore/Framework/interface/ModuleFactory.h"
0193 
0194 DEFINE_FWK_MODULE(L1TGlobalPrescalesVetosViewer);