Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-31 22:25:57

0001 #include <iomanip>
0002 #include <iostream>
0003 
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 
0012 #include "CondFormats/DataRecord/interface/L1TMuonOverlapParamsRcd.h"
0013 #include "CondFormats/L1TObjects/interface/L1TMuonOverlapParams.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0016 #include "CondCore/CondDB/interface/Session.h"
0017 
0018 #include <iostream>
0019 using namespace std;
0020 
0021 class L1TMuonOverlapParamsViewer : public edm::one::EDAnalyzer<> {
0022 private:
0023   edm::ESGetToken<L1TMuonOverlapParams, L1TMuonOverlapParamsRcd> token_;
0024   bool printLayerMap;
0025 
0026 public:
0027   void analyze(const edm::Event &, const edm::EventSetup &) override;
0028   string hash(void *buf, size_t len) const;
0029 
0030   explicit L1TMuonOverlapParamsViewer(const edm::ParameterSet &pset) : token_{esConsumes()} {
0031     printLayerMap = pset.getUntrackedParameter<bool>("printLayerMap", false);
0032   }
0033 };
0034 
0035 #include "Utilities/OpenSSL/interface/openssl_init.h"
0036 #include <cmath>
0037 #include <iostream>
0038 using namespace std;
0039 
0040 string L1TMuonOverlapParamsViewer::hash(void *buf, size_t len) const {
0041   cms::openssl_init();
0042   EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
0043   const EVP_MD *md = EVP_get_digestbyname("SHA1");
0044   if (!EVP_DigestInit_ex(mdctx, md, nullptr))
0045     throw cms::Exception("L1TCaloParamsViewer::hash") << "SHA1 initialization error";
0046 
0047   if (!EVP_DigestUpdate(mdctx, buf, len))
0048     throw cms::Exception("L1TCaloParamsViewer::hash") << "SHA1 processing error";
0049 
0050   unsigned char hash[EVP_MAX_MD_SIZE];
0051   unsigned int md_len = 0;
0052   if (!EVP_DigestFinal_ex(mdctx, hash, &md_len))
0053     throw cms::Exception("L1TCaloParamsViewer::hash") << "SHA1 finalization error";
0054 
0055   EVP_MD_CTX_free(mdctx);
0056 
0057   // re-write bytes in hex
0058   char tmp[EVP_MAX_MD_SIZE * 2 + 1];
0059   if (md_len > 20)
0060     md_len = 20;
0061   for (unsigned int i = 0; i < md_len; i++)
0062     ::sprintf(&tmp[i * 2], "%02x", hash[i]);
0063 
0064   tmp[md_len * 2] = 0;
0065   return string(tmp);
0066 }
0067 
0068 void L1TMuonOverlapParamsViewer::analyze(const edm::Event &iEvent, const edm::EventSetup &evSetup) {
0069   // Pull the config from the ES
0070   L1TMuonOverlapParams const &ptr1 = evSetup.getData(token_);
0071 
0072   cout << "Some fields in L1TMuonOverlapParamsParams: " << endl;
0073 
0074   cout << " fwVersion() = " << ptr1.fwVersion() << endl;
0075   cout << " nPdfAddrBits() = " << ptr1.nPdfAddrBits() << endl;
0076   cout << " nPdfValBits() = " << ptr1.nPdfValBits() << endl;
0077   cout << " nHitsPerLayer() = " << ptr1.nHitsPerLayer() << endl;
0078   cout << " nPhiBits() = " << ptr1.nPhiBits() << endl;
0079   cout << " nPhiBins() = " << ptr1.nPhiBins() << endl;
0080   cout << " nRefHits() = " << ptr1.nRefHits() << endl;
0081   cout << " nTestRefHits() = " << ptr1.nTestRefHits() << endl;
0082   cout << " nProcessors() = " << ptr1.nProcessors() << endl;
0083   cout << " nLogicRegions() = " << ptr1.nLogicRegions() << endl;
0084   cout << " nInputs() = " << ptr1.nInputs() << endl;
0085   cout << " nLayers() = " << ptr1.nLayers() << endl;
0086   cout << " nRefLayers() = " << ptr1.nRefLayers() << endl;
0087   cout << " nGoldenPatterns() = " << ptr1.nGoldenPatterns() << endl;
0088 
0089   const std::vector<int> *gp = ptr1.generalParams();
0090   cout << " number of general parameters: = " << gp->size() << endl;
0091   cout << "  ";
0092   for (auto a : *gp)
0093     cout << a << ", ";
0094   cout << endl;
0095 
0096   const std::vector<L1TMuonOverlapParams::LayerMapNode> *lm = ptr1.layerMap();
0097   if (!lm->empty()) {
0098     cout << " layerMap() =              [" << lm->size() << "] ";
0099     L1TMuonOverlapParams::LayerMapNode *lm_ = new L1TMuonOverlapParams::LayerMapNode[lm->size()];
0100     for (unsigned int i = 0; i < lm->size(); i++)
0101       lm_[i] = (*lm)[i];
0102     cout << hash(lm_, sizeof(L1TMuonOverlapParams::LayerMapNode) * (lm->size())) << endl;
0103     if (printLayerMap) {
0104       cout << sizeof(L1TMuonOverlapParams::LayerMapNode) << endl;
0105       for (unsigned int i = 0; i < lm->size(); i++) {
0106         cout << "  [" << i << "]: hwNumber = " << lm_[i].hwNumber << " logicNumber = " << lm_[i].logicNumber
0107              << " bendingLayer = " << lm_[i].bendingLayer << " connectedToLayer = " << lm_[i].connectedToLayer << " ("
0108              << flush;
0109         char *n = (char *)(&(lm_[i]));
0110         for (unsigned int j = 0; j < sizeof(L1TMuonOverlapParams::LayerMapNode); j++)
0111           cout << "0x" << hex << int(*(n + j)) << dec << ", ";
0112         cout << endl;
0113       }
0114       // hash( (void*)(&(lm_[i])), sizeof(L1TMuonOverlapParams::LayerMapNode) ) <<endl;
0115     }
0116     delete[] lm_;
0117   } else {
0118     cout << " layerMap() =              [0] " << endl;
0119   }
0120 
0121   const std::vector<L1TMuonOverlapParams::RefLayerMapNode> *rlm = ptr1.refLayerMap();
0122   if (!rlm->empty()) {
0123     cout << " refLayerMap() =           [" << rlm->size() << "] ";
0124     L1TMuonOverlapParams::RefLayerMapNode *rlm_ = new L1TMuonOverlapParams::RefLayerMapNode[rlm->size()];
0125     for (unsigned int i = 0; i < rlm->size(); i++)
0126       rlm_[i] = (*rlm)[i];
0127     cout << hash(rlm_, sizeof(L1TMuonOverlapParams::RefLayerMapNode) * (rlm->size())) << endl;
0128     delete[] rlm_;
0129   } else {
0130     cout << " refLayerMap() =           [0] " << endl;
0131   }
0132 
0133   const std::vector<L1TMuonOverlapParams::RefHitNode> *rhn = ptr1.refHitMap();
0134   if (!rhn->empty()) {
0135     cout << " refHitMap() =             [" << rhn->size() << "] ";
0136     L1TMuonOverlapParams::RefHitNode *rhn_ = new L1TMuonOverlapParams::RefHitNode[rhn->size()];
0137     for (unsigned int i = 0; i < rhn->size(); i++)
0138       rhn_[i] = (*rhn)[i];
0139     cout << hash(rhn_, sizeof(L1TMuonOverlapParams::RefHitNode) * (rhn->size())) << endl;
0140     delete[] rhn_;
0141   } else {
0142     cout << " refHitMap() =             [0] " << endl;
0143   }
0144 
0145   const std::vector<int> *gpsm = ptr1.globalPhiStartMap();
0146   if (!gpsm->empty()) {
0147     cout << " globalPhiStartMap() =     [" << gpsm->size() << "] ";
0148     int gpsm_[gpsm->size()];
0149     for (unsigned int i = 0; i < gpsm->size(); i++)
0150       gpsm_[i] = (*gpsm)[i];
0151     cout << hash(gpsm_, sizeof(int) * (gpsm->size())) << endl;
0152   } else {
0153     cout << " globalPhiStartMap() =     [0] " << endl;
0154   }
0155 
0156   const std::vector<L1TMuonOverlapParams::LayerInputNode> *lim = ptr1.layerInputMap();
0157   if (!lim->empty()) {
0158     cout << " layerInputMap() =         [" << lim->size() << "] ";
0159     L1TMuonOverlapParams::LayerInputNode *lim_ = new L1TMuonOverlapParams::LayerInputNode[lim->size()];
0160     for (unsigned int i = 0; i < lim->size(); i++)
0161       lim_[i] = (*lim)[i];
0162     cout << hash(lim_, sizeof(L1TMuonOverlapParams::LayerInputNode) * (lim->size())) << endl;
0163     delete[] lim_;
0164   } else {
0165     cout << " layerInputMap() =         [0] " << endl;
0166   }
0167 
0168   const std::vector<int> *css = ptr1.connectedSectorsStart();
0169   if (!css->empty()) {
0170     cout << " connectedSectorsStart() = [" << css->size() << "] ";
0171     int css_[css->size()];
0172     for (unsigned int i = 0; i < css->size(); i++)
0173       css_[i] = (*css)[i];
0174     cout << hash(css_, sizeof(int) * (css->size())) << endl;
0175   } else {
0176     cout << " connectedSectorsStart() = [0] " << endl;
0177   }
0178 
0179   const std::vector<int> *cse = ptr1.connectedSectorsEnd();
0180   if (!cse->empty()) {
0181     cout << " connectedSectorsEnd() = [" << cse->size() << "] ";
0182     int cse_[cse->size()];
0183     for (unsigned int i = 0; i < cse->size(); i++)
0184       cse_[i] = (*cse)[i];
0185     cout << hash(cse_, sizeof(int) * (cse->size())) << endl;
0186   } else {
0187     cout << " connectedSectorsEnd() = [0] " << endl;
0188   }
0189 
0190   const l1t::LUT *clut = ptr1.chargeLUT();
0191   if (clut->maxSize()) {
0192     cout << " chargeLUT =      [" << clut->maxSize() << "] ";
0193     int clut_[clut->maxSize()];
0194     for (unsigned int i = 0; i < clut->maxSize(); i++)
0195       clut_[i] = clut->data(i);
0196     cout << hash(clut_, sizeof(int) * (clut->maxSize())) << endl;
0197   } else {
0198     cout << " chargeLUT =      [0] " << endl;
0199   }
0200 
0201   const l1t::LUT *elut = ptr1.etaLUT();
0202   if (elut->maxSize()) {
0203     cout << " etaLUT =         [" << elut->maxSize() << "] ";
0204     int elut_[elut->maxSize()];
0205     for (unsigned int i = 0; i < elut->maxSize(); i++)
0206       elut_[i] = elut->data(i);
0207     cout << hash(elut_, sizeof(int) * (elut->maxSize())) << endl;
0208   } else {
0209     cout << " chargeLUT =      [0] " << endl;
0210   }
0211 
0212   const l1t::LUT *ptlut = ptr1.ptLUT();
0213   if (ptlut->maxSize()) {
0214     cout << " ptLUT =          [" << ptlut->maxSize() << "] " << flush;
0215     int ptlut_[ptlut->maxSize()];
0216     for (unsigned int i = 0; i < ptlut->maxSize(); i++)
0217       ptlut_[i] = ptlut->data(i);
0218     cout << hash(ptlut_, sizeof(int) * (ptlut->maxSize())) << endl;
0219   } else {
0220     cout << " ptLUT =          [0] " << endl;
0221   }
0222 
0223   const l1t::LUT *plut = ptr1.pdfLUT();
0224   if (plut->maxSize()) {
0225     cout << " pdfLUT =         [" << plut->maxSize() << "] " << flush;
0226     int plut_[plut->maxSize()];
0227     for (unsigned int i = 0; i < plut->maxSize(); i++)
0228       plut_[i] = plut->data(i);
0229     cout << hash(plut_, sizeof(int) * (plut->maxSize())) << endl;
0230   } else {
0231     cout << " pdfLUT =         [0] " << endl;
0232   }
0233 
0234   const l1t::LUT *mlut = ptr1.meanDistPhiLUT();
0235   if (mlut->maxSize()) {
0236     cout << " meanDistPhiLUT = [" << mlut->maxSize() << "] " << flush;
0237     int mlut_[mlut->maxSize()];
0238     for (unsigned int i = 0; i < mlut->maxSize(); i++)
0239       mlut_[i] = mlut->data(i);
0240     cout << hash(mlut_, sizeof(int) * (mlut->maxSize())) << endl;
0241   } else {
0242     cout << " meanDistPhiLUT = [0] " << endl;
0243   }
0244 }
0245 
0246 #include "FWCore/PluginManager/interface/ModuleDef.h"
0247 #include "FWCore/Framework/interface/MakerMacros.h"
0248 #include "FWCore/Framework/interface/ModuleFactory.h"
0249 
0250 DEFINE_FWK_MODULE(L1TMuonOverlapParamsViewer);