CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/L1TriggerConfig/L1GtConfigProducers/src/L1GtVhdlWriter.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtVhdlWriter.h"
00019 
00020 // system include files
00021 #include <iostream>
00022 #include <sys/stat.h>
00023 
00024 // user include files
00025 #include "boost/filesystem.hpp"
00026 
00027 //   base class
00028 #include "FWCore/Framework/interface/EDAnalyzer.h"
00029 
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "FWCore/Framework/interface/EventSetup.h"
00033 #include "FWCore/Framework/interface/ESHandle.h"
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00036 
00037 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00038 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00039 
00040 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtVhdlWriterCore.h"
00041 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtVmeWriterCore.h"
00042 
00043 // constructor(s)
00044 L1GtVhdlWriter::L1GtVhdlWriter(const edm::ParameterSet& parSet)
00045 {
00046 
00047     // directory in /data for the VHDL templates
00048     vhdlDir_ = parSet.getParameter<std::string>("VhdlTemplatesDir");
00049     outputDir_ = parSet.getParameter<std::string>("OutputDir");
00050 
00051     if (vhdlDir_[vhdlDir_.length()-1]!= '/')
00052         vhdlDir_+="/";
00053     if (outputDir_[outputDir_.length()-1]!= '/')
00054         outputDir_+="/";
00055 
00056     //    // def.xml file
00057     //    std::string defXmlFileName = parSet.getParameter<std::string>("DefXmlFile");
00058     //
00059     //    edm::FileInPath f1("L1TriggerConfig/L1GtConfigProducers/data/" +
00060     //                       vhdlDir + "/" + defXmlFileName);
00061     //
00062     //    m_defXmlFile = f1.fullPath();
00063 
00064     edm::LogInfo("L1GtConfigProducers") << "\n\nL1 GT VHDL directory: "
00065             << vhdlDir_ << "\n\n" << std::endl;
00066 
00067 }
00068 
00069 // destructor
00070 L1GtVhdlWriter::~L1GtVhdlWriter()
00071 {
00072     // empty
00073 }
00074 
00075 // loop over events
00076 void L1GtVhdlWriter::analyze(const edm::Event& iEvent,
00077         const edm::EventSetup& evSetup)
00078 {
00079 
00080     edm::ESHandle< L1GtTriggerMenu > l1GtMenu;
00081     evSetup.get< L1GtTriggerMenuRcd >().get(l1GtMenu) ;
00082 
00083     std::vector<ConditionMap> conditionMap = l1GtMenu->gtConditionMap();
00084     AlgorithmMap algorithmMap = l1GtMenu->gtAlgorithmMap();
00085 
00086     // print with various level of verbosities
00087     int printVerbosity = 0;
00088     l1GtMenu->print(std::cout, printVerbosity);
00089 
00090     //---------------------Here the VHDL files will be created---------------------------------------
00091 
00092     // information that will be delivered by the parser in future
00093     std::map<std::string,std::string> headerParameters;
00094     std::vector<std::string> channelVector;
00095 
00096     headerParameters["vhdl_path"]="/vhdllibrarypath";
00097     headerParameters["designer_date"]="20.05.1986";
00098     headerParameters["designer_name"]="Philipp Wagner";
00099     headerParameters["version"]="2.0";
00100     headerParameters["designer_comments"]="produced in CMSSW";
00101     headerParameters["gtl_setup_name"]="L1Menu2007NovGR";
00102 
00103     channelVector.push_back("-- ca1: ieg");
00104     channelVector.push_back("-- ca2: eg");
00105     channelVector.push_back("-- ca3: jet");
00106     channelVector.push_back("-- ca4: fwdjet");
00107     channelVector.push_back("-- ca5: tau");
00108     channelVector.push_back("-- ca6: esums");
00109     channelVector.push_back("-- ca7: jet_cnts");
00110     channelVector.push_back("-- ca8: free");
00111     channelVector.push_back("-- ca9: free");
00112     channelVector.push_back("-- ca10: free");
00113     
00114     // check, weather output directory exists and create it on the fly if not
00115     if (boost::filesystem::is_directory(outputDir_))
00116     {
00117         std::cout<<std::endl<<"Ok - Output directory exists!"<<std::endl;
00118     } else
00119     {
00120         if (!mkdir(outputDir_.c_str(), 0666))
00121             std::cout<<std::endl<<"Directory: "<<outputDir_<<" has been created!"<<std::endl;
00122         else 
00123             std::cout<<std::endl<<"Error while creating directory: "<<outputDir_<<" !"<<std::endl;
00124     }
00125     
00126     // prepare a core with common header
00127     L1GtVhdlWriterCore vhdlWriter(vhdlDir_, outputDir_, true);
00128     vhdlWriter.buildCommonHeader(headerParameters, channelVector);
00129     // write the firmware
00130     if (vhdlWriter.makeFirmware(conditionMap, algorithmMap))
00131     {
00132         std::cout << std::endl << std::endl
00133                 <<"***********************   I'm ready ;-) **************************"
00134                 <<std::endl <<std::endl
00135                 <<"You can find the firmware in dircetory: " <<outputDir_
00136                 <<std::endl <<std::endl
00137                 <<"******************************************************************"
00138                 <<std::endl;
00139     }
00140 
00141     // Create the VME - XML
00142     std::string vmeFile = "vme.xml";
00143 
00144     L1GtVmeWriterCore vmeWriter(outputDir_, vmeFile);
00145     vmeWriter.writeVME(conditionMap, vhdlWriter.getCond2IntMap(),
00146             vhdlWriter.retrunCommonHeader());
00147 }