CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/L1TriggerConfig/RPCTriggerConfig/src/RPCTriggerConfig.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    RPCTriggerConfig
00004 // Class:      RPCTriggerConfig
00005 // 
00013 //
00014 // Original Author:  Tomasz Maciej Frueboes
00015 //         Created:  Tue Mar 20 12:30:19 CET 2007
00016 // $Id: RPCTriggerConfig.cc,v 1.6 2009/03/26 12:06:38 fruboes Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include "boost/shared_ptr.hpp"
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/ModuleFactory.h"
00027 #include "FWCore/Framework/interface/ESProducer.h"
00028 
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 #include <FWCore/ParameterSet/interface/FileInPath.h>
00032 
00033 
00034 #include "CondFormats/DataRecord/interface/L1RPCConfigRcd.h"
00035 #include "CondFormats/L1TObjects/interface/L1RPCConfig.h"
00036 #include <string>
00037 
00038 
00039 #include "L1Trigger/RPCTrigger/interface/RPCPatternsParser.h"
00040 //
00041 // class decleration
00042 //
00043 
00044 class RPCTriggerConfig : public edm::ESProducer {
00045    public:
00046       RPCTriggerConfig(const edm::ParameterSet&);
00047       ~RPCTriggerConfig();
00048 
00049       typedef std::auto_ptr<L1RPCConfig> ReturnType;
00050 
00051       ReturnType produce(const L1RPCConfigRcd&);
00052    private:
00053       // ----------member data ---------------------------
00054 
00055      int m_ppt;
00056      std::string m_patternsDir;
00057 };
00058 
00059 //
00060 // constants, enums and typedefs
00061 //
00062 
00063 //
00064 // static data member definitions
00065 //
00066 
00067 //
00068 // constructors and destructor
00069 //
00070 RPCTriggerConfig::RPCTriggerConfig(const edm::ParameterSet& iConfig)
00071 {
00072    //the following line is needed to tell the framework what
00073    // data is being produced
00074    setWhatProduced(this);
00075 
00076    //now do what ever other initialization is needed
00077 
00078 
00079    m_ppt = iConfig.getUntrackedParameter<int>("PACsPerTower");
00080    std::string dataDir = iConfig.getUntrackedParameter<std::string>("filedir");
00081    
00082    edm::FileInPath fp(dataDir+"pacPat_t0sc0sg0.xml");
00083    std::string patternsDirNameUnstriped = fp.fullPath();
00084    m_patternsDir = patternsDirNameUnstriped.substr(0,patternsDirNameUnstriped.find_last_of("/")+1);
00085 
00086   
00087                
00088 
00089 }
00090 
00091 
00092 RPCTriggerConfig::~RPCTriggerConfig()
00093 {
00094  
00095    // do anything here that needs to be done at desctruction time
00096    // (e.g. close files, deallocate resources etc.)
00097 
00098 }
00099 
00100 
00101 //
00102 // member functions
00103 //
00104 
00105 // ------------ method called to produce the data  ------------
00106 RPCTriggerConfig::ReturnType
00107 RPCTriggerConfig::produce(const L1RPCConfigRcd& iRecord)
00108 {
00109    using namespace edm::es;
00110    std::auto_ptr<L1RPCConfig> pL1RPCConfig = std::auto_ptr<L1RPCConfig>( new L1RPCConfig() );
00111 
00112    pL1RPCConfig->setPPT(m_ppt);
00113    
00114    // parse and isert patterns
00115    int scCnt = 0, sgCnt = 0;
00116    if(m_ppt == 1) {
00117        scCnt = 1;
00118        sgCnt = 1;
00119     }
00120     else if(m_ppt == 12) {
00121        scCnt = 1;
00122        sgCnt = 12;
00123     }
00124     else if(m_ppt == 144) {
00125        scCnt = 12;
00126        sgCnt = 12;
00127     }
00128     else {
00129        throw cms::Exception("BadConfig") << "Bad number of ppt requested: " << m_ppt << "\n";
00130     }
00131 
00132 
00133     for (int tower = 0; tower < RPCConst::m_TOWER_COUNT; ++tower) {
00134       for (int logSector = 0; logSector < scCnt; ++logSector) {
00135          for (int logSegment = 0; logSegment < sgCnt; ++logSegment) {
00136          
00137             std::stringstream fname;
00138             fname << m_patternsDir
00139                   << "pacPat_t" << tower 
00140                   << "sc"  << logSector 
00141                   << "sg" <<logSegment 
00142                   << ".xml";
00143                   
00144             // TODO: this should go to logSth
00145             LogDebug("RPCTriggerConfig") << "Parsing: " << fname.str() <<std::endl;
00146                   
00147             RPCPatternsParser parser;
00148             parser.parse(fname.str());
00149 
00150             RPCPattern::RPCPatVec npats = parser.getPatternsVec(tower, logSector, logSegment);
00151             for (unsigned int ip=0; ip<npats.size(); ip++) {
00152               npats[ip].setCoords(tower,logSector,logSegment);
00153               pL1RPCConfig->m_pats.push_back(npats[ip]);
00154             }
00155 
00156             RPCPattern::TQualityVec nquals = parser.getQualityVec(); 
00157             for (unsigned int iq=0; iq<nquals.size(); iq++) {
00158               nquals[iq].m_tower=tower;
00159               nquals[iq].m_logsector=logSector;
00160               nquals[iq].m_logsegment=logSegment;
00161               pL1RPCConfig->m_quals.push_back(nquals[iq]);
00162             }
00163             
00164             LogDebug("RPCTriggerConfig") 
00165                       << "  RPCPatterns: " << npats.size() 
00166                       << " qualities: "<<  nquals.size()
00167                       << std::endl;
00168             
00169          
00170          } // segments
00171       } // sectors
00172     } // towers
00173 
00174 
00175 
00176    return pL1RPCConfig ;
00177 }
00178 
00179 //define this as a plug-in
00180 DEFINE_FWK_EVENTSETUP_MODULE(RPCTriggerConfig);