Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-24 01:11:21

0001 #include <string>
0002 #include <iostream>
0003 #include <map>
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
0012 #include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h"
0013 #include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h"
0014 #include "CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h"
0015 
0016 class SiPixelFEDChannelContainerTestReader : public edm::one::EDAnalyzer<> {
0017 public:
0018   explicit SiPixelFEDChannelContainerTestReader(edm::ParameterSet const& p);
0019   ~SiPixelFEDChannelContainerTestReader() override;
0020 
0021   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0022 
0023 private:
0024   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0025 
0026   // ----------member data ---------------------------
0027   const edm::ESGetToken<SiPixelFEDChannelContainer, SiPixelStatusScenariosRcd> siPixelBadFEDChToken_;
0028   const bool printdebug_;
0029   const std::string formatedOutput_;
0030 };
0031 
0032 SiPixelFEDChannelContainerTestReader::SiPixelFEDChannelContainerTestReader(edm::ParameterSet const& p)
0033     : siPixelBadFEDChToken_(esConsumes()),
0034       printdebug_(p.getUntrackedParameter<bool>("printDebug", true)),
0035       formatedOutput_(p.getUntrackedParameter<std::string>("outputFile", "")) {
0036   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << "SiPixelFEDChannelContainerTestReader" << std::endl;
0037 }
0038 
0039 SiPixelFEDChannelContainerTestReader::~SiPixelFEDChannelContainerTestReader() {
0040   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << "~SiPixelFEDChannelContainerTestReader " << std::endl;
0041 }
0042 
0043 void SiPixelFEDChannelContainerTestReader::analyze(const edm::Event& e, const edm::EventSetup& context) {
0044   edm::LogInfo("SiPixelFEDChannelContainerTestReader")
0045       << "### SiPixelFEDChannelContainerTestReader::analyze  ###" << std::endl;
0046   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0047   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << " ---EVENT NUMBER " << e.id().event() << std::endl;
0048 
0049   edm::eventsetup::EventSetupRecordKey recordKey(
0050       edm::eventsetup::EventSetupRecordKey::TypeTag::findType("SiPixelStatusScenariosRcd"));
0051 
0052   if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0053     //record not found
0054     edm::LogInfo("SiPixelFEDChannelContainerTestReader") << "Record \"SiPixelStatusScenariosRcd"
0055                                                          << "\" does not exist " << std::endl;
0056   }
0057 
0058   //this part gets the handle of the event source and the record (i.e. the Database)
0059   edm::ESHandle<SiPixelFEDChannelContainer> qualityCollectionHandle = context.getHandle(siPixelBadFEDChToken_);
0060   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << "got eshandle from context" << std::endl;
0061 
0062   const SiPixelFEDChannelContainer* quality_map = qualityCollectionHandle.product();
0063   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << "got SiPixelFEDChannelContainer* " << std::endl;
0064   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << "print  pointer address : " << quality_map << std::endl;
0065   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << "Size " << quality_map->size() << std::endl;
0066   edm::LogInfo("SiPixelFEDChannelContainerTestReader") << "Content of myQuality_Map " << std::endl;
0067   // use built-in method in the CondFormat to print the content
0068   if (printdebug_) {
0069     quality_map->printAll();
0070   }
0071 
0072   FILE* pFile = nullptr;
0073   if (!formatedOutput_.empty())
0074     pFile = fopen(formatedOutput_.c_str(), "w");
0075   if (pFile) {
0076     fprintf(pFile, "SiPixelFEDChannelContainer::printAll() \n");
0077     fprintf(pFile,
0078             " ========================================================================================================="
0079             "========== \n");
0080 
0081     SiPixelFEDChannelContainer::SiPixelBadFEDChannelsScenarioMap m_qualities = quality_map->getScenarioMap();
0082 
0083     for (auto it = m_qualities.begin(); it != m_qualities.end(); ++it) {
0084       fprintf(pFile,
0085               " ======================================================================================================="
0086               "============ \n");
0087       fprintf(pFile, "run : %s \n ", (it->first).c_str());
0088       for (const auto& thePixelFEDChannel : it->second) {
0089         DetId detId = thePixelFEDChannel.first;
0090         fprintf(pFile, "DetId : %i \n", detId.rawId());
0091         for (const auto& entry : thePixelFEDChannel.second) {
0092           //unsigned int fed, link, roc_first, roc_last;
0093           fprintf(pFile,
0094                   "fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
0095                   entry.fed,
0096                   entry.link,
0097                   entry.roc_first,
0098                   entry.roc_last);
0099         }
0100       }
0101     }
0102   }
0103 }
0104 
0105 void SiPixelFEDChannelContainerTestReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0106   edm::ParameterSetDescription desc;
0107   desc.setComment("Reads payloads of type SiPixelFEDChannelContainer");
0108   desc.addUntracked<bool>("printDebug", true);
0109   desc.addUntracked<std::string>("outputFile", "");
0110   descriptions.add("SiPixelFEDChannelContainerTestReader", desc);
0111 }
0112 
0113 DEFINE_FWK_MODULE(SiPixelFEDChannelContainerTestReader);