Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-01 03:33:48

0001 /**
0002  * \class L1GtVhdlWriter
0003  *
0004  *
0005  * Description: write VHDL templates for the L1 GT.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: Philipp Wagner
0011  *
0012  *
0013  */
0014 
0015 // this class header
0016 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtVhdlWriter.h"
0017 
0018 // system include files
0019 #include <filesystem>
0020 #include <iostream>
0021 #include <sys/stat.h>
0022 
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Framework/interface/EventSetup.h"
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0029 
0030 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
0031 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
0032 
0033 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtVhdlWriterCore.h"
0034 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtVmeWriterCore.h"
0035 
0036 // constructor(s)
0037 L1GtVhdlWriter::L1GtVhdlWriter(const edm::ParameterSet& parSet) {
0038   // directory in /data for the VHDL templates
0039   vhdlDir_ = parSet.getParameter<std::string>("VhdlTemplatesDir");
0040   outputDir_ = parSet.getParameter<std::string>("OutputDir");
0041   menuToken_ = esConsumes();
0042 
0043   if (vhdlDir_[vhdlDir_.length() - 1] != '/')
0044     vhdlDir_ += "/";
0045   if (outputDir_[outputDir_.length() - 1] != '/')
0046     outputDir_ += "/";
0047 
0048   //    // def.xml file
0049   //    std::string defXmlFileName = parSet.getParameter<std::string>("DefXmlFile");
0050   //
0051   //    edm::FileInPath f1("L1TriggerConfig/L1GtConfigProducers/data/" +
0052   //                       vhdlDir + "/" + defXmlFileName);
0053   //
0054   //    m_defXmlFile = f1.fullPath();
0055 
0056   edm::LogInfo("L1GtConfigProducers") << "\n\nL1 GT VHDL directory: " << vhdlDir_ << "\n\n" << std::endl;
0057 }
0058 
0059 // loop over events
0060 void L1GtVhdlWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0061   edm::ESHandle<L1GtTriggerMenu> l1GtMenu = evSetup.getHandle(menuToken_);
0062 
0063   std::vector<ConditionMap> const& conditionMap = l1GtMenu->gtConditionMap();
0064   AlgorithmMap const& algorithmMap = l1GtMenu->gtAlgorithmMap();
0065 
0066   // print with various level of verbosities
0067   int printVerbosity = 0;
0068   l1GtMenu->print(std::cout, printVerbosity);
0069 
0070   //---------------------Here the VHDL files will be created---------------------------------------
0071 
0072   // information that will be delivered by the parser in future
0073   std::map<std::string, std::string> headerParameters;
0074   std::vector<std::string> channelVector;
0075 
0076   headerParameters["vhdl_path"] = "/vhdllibrarypath";
0077   headerParameters["designer_date"] = "20.05.1986";
0078   headerParameters["designer_name"] = "Philipp Wagner";
0079   headerParameters["version"] = "2.0";
0080   headerParameters["designer_comments"] = "produced in CMSSW";
0081   headerParameters["gtl_setup_name"] = "L1Menu2007NovGR";
0082 
0083   channelVector.reserve(10);
0084   channelVector.push_back("-- ca1: ieg");
0085   channelVector.push_back("-- ca2: eg");
0086   channelVector.push_back("-- ca3: jet");
0087   channelVector.push_back("-- ca4: fwdjet");
0088   channelVector.push_back("-- ca5: tau");
0089   channelVector.push_back("-- ca6: esums");
0090   channelVector.push_back("-- ca7: jet_cnts");
0091   channelVector.push_back("-- ca8: free");
0092   channelVector.push_back("-- ca9: free");
0093   channelVector.push_back("-- ca10: free");
0094 
0095   // check, weather output directory exists and create it on the fly if not
0096   if (std::filesystem::is_directory(outputDir_)) {
0097     std::cout << std::endl << "Ok - Output directory exists!" << std::endl;
0098   } else {
0099     if (!mkdir(outputDir_.c_str(), 0666))
0100       std::cout << std::endl << "Directory: " << outputDir_ << " has been created!" << std::endl;
0101     else
0102       std::cout << std::endl << "Error while creating directory: " << outputDir_ << " !" << std::endl;
0103   }
0104 
0105   // prepare a core with common header
0106   L1GtVhdlWriterCore vhdlWriter(vhdlDir_, outputDir_, true);
0107   vhdlWriter.buildCommonHeader(headerParameters, channelVector);
0108   // write the firmware
0109   if (vhdlWriter.makeFirmware(conditionMap, algorithmMap)) {
0110     std::cout << std::endl
0111               << std::endl
0112               << "***********************   I'm ready ;-) **************************" << std::endl
0113               << std::endl
0114               << "You can find the firmware in dircetory: " << outputDir_ << std::endl
0115               << std::endl
0116               << "******************************************************************" << std::endl;
0117   }
0118 
0119   // Create the VME - XML
0120   std::string vmeFile = "vme.xml";
0121 
0122   L1GtVmeWriterCore vmeWriter(outputDir_, vmeFile);
0123   vmeWriter.writeVME(conditionMap, vhdlWriter.getCond2IntMap(), vhdlWriter.retrunCommonHeader());
0124 }