Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:25

0001 #include <array>
0002 #include <string>
0003 #include <iostream>
0004 #include <map>
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
0010 #include "CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h"
0011 #include "CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h"
0012 #include "CondFormats/DataRecord/interface/AlignPCLThresholdsHGRcd.h"
0013 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0014 
0015 namespace edmtest {
0016   template <typename T, typename R>
0017   class AlignPCLThresholdsReader : public edm::one::EDAnalyzer<> {
0018   public:
0019     explicit AlignPCLThresholdsReader(edm::ParameterSet const& p);
0020     ~AlignPCLThresholdsReader() override;
0021 
0022     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0023 
0024   private:
0025     void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0026 
0027     // ----------member data ---------------------------
0028     const edm::ESGetToken<T, R> thresholdToken_;
0029     const bool printdebug_;
0030     const std::string formatedOutput_;
0031   };
0032 
0033   template <typename T, typename R>
0034   AlignPCLThresholdsReader<T, R>::AlignPCLThresholdsReader(edm::ParameterSet const& p)
0035       : thresholdToken_(esConsumes()),
0036         printdebug_(p.getUntrackedParameter<bool>("printDebug", true)),
0037         formatedOutput_(p.getUntrackedParameter<std::string>("outputFile", "")) {
0038     edm::LogInfo("AlignPCLThresholdsReader") << "AlignPCLThresholdsReader" << std::endl;
0039   }
0040 
0041   template <typename T, typename R>
0042   AlignPCLThresholdsReader<T, R>::~AlignPCLThresholdsReader() {
0043     edm::LogInfo("AlignPCLThresholdsReader") << "~AlignPCLThresholdsReader " << std::endl;
0044   }
0045 
0046   template <typename T, typename R>
0047   void AlignPCLThresholdsReader<T, R>::analyze(const edm::Event& e, const edm::EventSetup& context) {
0048     edm::LogInfo("AlignPCLThresholdsReader") << "### AlignPCLThresholdsReader::analyze  ###" << std::endl;
0049     edm::LogInfo("AlignPCLThresholdsReader") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0050     edm::LogInfo("AlignPCLThresholdsReader") << " ---EVENT NUMBER " << e.id().event() << std::endl;
0051 
0052     edm::eventsetup::EventSetupRecordKey inputKey = edm::eventsetup::EventSetupRecordKey::makeKey<R>();
0053     edm::eventsetup::EventSetupRecordKey recordKey(
0054         edm::eventsetup::EventSetupRecordKey::TypeTag::findType(inputKey.type().name()));
0055 
0056     if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0057       //record not found
0058       edm::LogInfo("AlignPCLThresholdsReader")
0059           << "Record \"" << inputKey.type().name() << "\" does not exist " << std::endl;
0060     }
0061 
0062     //this part gets the handle of the event source and the record (i.e. the Database)
0063     edm::ESHandle<T> thresholdHandle = context.getHandle(thresholdToken_);
0064     edm::LogInfo("AlignPCLThresholdsReader") << "got eshandle" << std::endl;
0065 
0066     if (!thresholdHandle.isValid()) {
0067       edm::LogError("AlignPCLThresholdsReader") << " Could not get Handle" << std::endl;
0068       return;
0069     }
0070 
0071     const T* thresholds = thresholdHandle.product();
0072     edm::LogInfo("AlignPCLThresholdsReader") << "got AlignPCLThresholds* " << std::endl;
0073     edm::LogInfo("AlignPCLThresholdsReader") << "print  pointer address : ";
0074     edm::LogInfo("AlignPCLThresholdsReader") << thresholds << std::endl;
0075 
0076     edm::LogInfo("AlignPCLThresholdsReader") << "Size " << thresholds->size() << std::endl;
0077     edm::LogInfo("AlignPCLThresholdsReader") << "Content of myThresholds " << std::endl;
0078     // use built-in method in the CondFormat to print the content
0079     if (thresholds && printdebug_) {
0080       thresholds->printAll();
0081     }
0082 
0083     FILE* pFile = nullptr;
0084     if (!formatedOutput_.empty())
0085       pFile = fopen(formatedOutput_.c_str(), "w");
0086     if (pFile) {
0087       fprintf(pFile, "AlignPCLThresholds::printAll() \n");
0088       fprintf(pFile,
0089               " ======================================================================================================="
0090               "============\n");
0091       fprintf(pFile, "N records cut: %i \n", thresholds->getNrecords());
0092 
0093       AlignPCLThresholds::threshold_map m_thresholds = thresholds->getThreshold_Map();
0094       AlignPCLThresholdsHG::param_map m_floatMap{};
0095 
0096       if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
0097         m_floatMap = thresholds->getFloatMap();
0098       }
0099 
0100       for (auto it = m_thresholds.begin(); it != m_thresholds.end(); ++it) {
0101         bool hasFractionCut = (m_floatMap.find(it->first) != m_floatMap.end());
0102 
0103         fprintf(pFile,
0104                 " ====================================================================================================="
0105                 "==============\n");
0106         fprintf(pFile, "key : %s \n", (it->first).c_str());
0107         fprintf(pFile, "- Xcut             : %8.3f   um   ", (it->second).getXcut());
0108         fprintf(pFile, "| sigXcut          : %8.3f        ", (it->second).getSigXcut());
0109         fprintf(pFile, "| maxMoveXcut      : %8.3f   um   ", (it->second).getMaxMoveXcut());
0110         fprintf(pFile, "| ErrorXcut        : %8.3f   um   ", (it->second).getErrorXcut());
0111         if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
0112           if (hasFractionCut) {
0113             fprintf(pFile,
0114                     "| X_fractionCut      : %8.3f    \n",
0115                     thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::X));
0116           } else {
0117             fprintf(pFile, "\n");
0118           }
0119         } else {
0120           fprintf(pFile, "\n");
0121         }
0122 
0123         fprintf(pFile, "- thetaXcut        : %8.3f urad   ", (it->second).getThetaXcut());
0124         fprintf(pFile, "| sigThetaXcut     : %8.3f        ", (it->second).getSigThetaXcut());
0125         fprintf(pFile, "| maxMoveThetaXcut : %8.3f urad   ", (it->second).getMaxMoveThetaXcut());
0126         fprintf(pFile, "| ErrorThetaXcut   : %8.3f urad   ", (it->second).getErrorThetaXcut());
0127         if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
0128           if (hasFractionCut) {
0129             fprintf(pFile,
0130                     "| thetaX_fractionCut : %8.3f    \n",
0131                     thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_X));
0132           } else {
0133             fprintf(pFile, "\n");
0134           }
0135         } else {
0136           fprintf(pFile, "\n");
0137         }
0138 
0139         fprintf(pFile, "- Ycut             : %8.3f   um   ", (it->second).getYcut());
0140         fprintf(pFile, "| sigYcut          : %8.3f        ", (it->second).getSigXcut());
0141         fprintf(pFile, "| maxMoveYcut      : %8.3f   um   ", (it->second).getMaxMoveYcut());
0142         fprintf(pFile, "| ErrorYcut        : %8.3f   um   ", (it->second).getErrorYcut());
0143         if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
0144           if (hasFractionCut) {
0145             fprintf(pFile,
0146                     "| Y_fractionCut      : %8.3f    \n",
0147                     thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::Y));
0148           } else {
0149             fprintf(pFile, "\n");
0150           }
0151         } else {
0152           fprintf(pFile, "\n");
0153         }
0154 
0155         fprintf(pFile, "- thetaYcut        : %8.3f urad   ", (it->second).getThetaYcut());
0156         fprintf(pFile, "| sigThetaYcut     : %8.3f        ", (it->second).getSigThetaYcut());
0157         fprintf(pFile, "| maxMoveThetaYcut : %8.3f urad   ", (it->second).getMaxMoveThetaYcut());
0158         fprintf(pFile, "| ErrorThetaYcut   : %8.3f urad   ", (it->second).getErrorThetaYcut());
0159         if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
0160           if (hasFractionCut) {
0161             fprintf(pFile,
0162                     "| thetaY_fractionCut : %8.3f    \n",
0163                     thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_Y));
0164           } else {
0165             fprintf(pFile, "\n");
0166           }
0167         } else {
0168           fprintf(pFile, "\n");
0169         }
0170 
0171         fprintf(pFile, "- Zcut             : %8.3f   um   ", (it->second).getZcut());
0172         fprintf(pFile, "| sigZcut          : %8.3f        ", (it->second).getSigZcut());
0173         fprintf(pFile, "| maxMoveZcut      : %8.3f   um   ", (it->second).getMaxMoveZcut());
0174         fprintf(pFile, "| ErrorZcut        : %8.3f   um   ", (it->second).getErrorZcut());
0175         if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
0176           if (hasFractionCut) {
0177             fprintf(pFile,
0178                     "| Z_fractionCut      : %8.3f    \n",
0179                     thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::Z));
0180           } else {
0181             fprintf(pFile, "\n");
0182           }
0183         } else {
0184           fprintf(pFile, "\n");
0185         }
0186 
0187         fprintf(pFile, "- thetaZcut        : %8.3f urad   ", (it->second).getThetaZcut());
0188         fprintf(pFile, "| sigThetaZcut     : %8.3f        ", (it->second).getSigThetaZcut());
0189         fprintf(pFile, "| maxMoveThetaZcut : %8.3f urad   ", (it->second).getMaxMoveThetaZcut());
0190         fprintf(pFile, "| ErrorThetaZcut   : %8.3f urad   ", (it->second).getErrorThetaZcut());
0191         if constexpr (std::is_same_v<T, AlignPCLThresholdsHG>) {
0192           if (hasFractionCut) {
0193             fprintf(pFile,
0194                     "| thetaZ_fractionCut : %8.3f    \n",
0195                     thresholds->getFractionCut(it->first, AlignPCLThresholds::coordType::theta_Z));
0196           } else {
0197             fprintf(pFile, "\n");
0198           }
0199         } else {
0200           fprintf(pFile, "\n");
0201         }
0202 
0203         if ((it->second).hasExtraDOF()) {
0204           for (unsigned int j = 0; j < (it->second).extraDOFSize(); j++) {
0205             std::array<float, 4> extraDOFCuts = thresholds->getExtraDOFCutsForAlignable(it->first, j);
0206             fprintf(pFile,
0207                     "Extra DOF: %i with label %s \n ",
0208                     j,
0209                     thresholds->getExtraDOFLabelForAlignable(it->first, j).c_str());
0210             fprintf(pFile, "- cut              : %8.3f        ", extraDOFCuts.at(0));
0211             fprintf(pFile, "| sigCut           : %8.3f        ", extraDOFCuts.at(1));
0212             fprintf(pFile, "| maxMoveCut       : %8.3f        ", extraDOFCuts.at(2));
0213             fprintf(pFile, "| maxErrorCut      : %8.3f     \n ", extraDOFCuts.at(3));
0214           }
0215         }
0216       }
0217     }
0218   }
0219 
0220   template <typename T, typename R>
0221   void AlignPCLThresholdsReader<T, R>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0222     edm::ParameterSetDescription desc;
0223     desc.setComment("Reads payloads of type AlignPCLThresholds");
0224     desc.addUntracked<bool>("printDebug", true);
0225     desc.addUntracked<std::string>("outputFile", "");
0226     descriptions.add(defaultModuleLabel<AlignPCLThresholdsReader<T, R>>(), desc);
0227   }
0228 
0229   typedef AlignPCLThresholdsReader<AlignPCLThresholds, AlignPCLThresholdsRcd> AlignPCLThresholdsLGReader;
0230   typedef AlignPCLThresholdsReader<AlignPCLThresholdsHG, AlignPCLThresholdsHGRcd> AlignPCLThresholdsHGReader;
0231 
0232   DEFINE_FWK_MODULE(AlignPCLThresholdsLGReader);
0233   DEFINE_FWK_MODULE(AlignPCLThresholdsHGReader);
0234 }  // namespace edmtest