00001 #include "CondTools/RPC/interface/L1RPCConfigSourceHandler.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00005
00006 popcon::L1RPCConfigSourceHandler::L1RPCConfigSourceHandler(const edm::ParameterSet& ps):
00007 m_name(ps.getUntrackedParameter<std::string>("name","L1RPCConfigSourceHandler")),
00008 m_validate(ps.getUntrackedParameter<int>("Validate",0)),
00009 m_ppt(ps.getUntrackedParameter<int>("PACsPerTower")),
00010 m_dataDir(ps.getUntrackedParameter<std::string>("filedir","L1Trigger/RPCTrigger/data/Eff90PPT12/"))
00011 {
00012
00013 edm::FileInPath fp(m_dataDir+"pacPat_t0sc0sg0.xml");
00014 std::string patternsDirNameUnstriped = fp.fullPath();
00015 m_patternsDir = patternsDirNameUnstriped.substr(0,patternsDirNameUnstriped.find_last_of("/")+1);
00016 }
00017
00018 popcon::L1RPCConfigSourceHandler::~L1RPCConfigSourceHandler()
00019 {
00020 }
00021
00022 void popcon::L1RPCConfigSourceHandler::getNewObjects()
00023 {
00024
00025 edm::Service<cond::service::PoolDBOutputService> mydbservice;
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 const L1RPCConfig* patterns_prev;
00039
00040 if(m_validate==1) {
00041 std::cout<<" Validation was requested, so will check present contents"<<std::endl;
00042 }
00043
00044 readConfig();
00045
00046 cond::Time_t snc=mydbservice->currentTime();
00047
00048
00049 int difference=1;
00050 if (m_validate==1) difference=Compare2Configs(patterns_prev,patterns);
00051 if (!difference) cout<<"No changes - will not write anything!!!"<<endl;
00052 if (difference==1) {
00053 cout<<"Will write new object to offline DB!!!"<<endl;
00054 m_to_transfer.push_back(std::make_pair((L1RPCConfig*)patterns,snc));
00055 }
00056
00057 std::cout << "L1RPCConfigSourceHandler: L1RPCConfigSourceHandler::getNewObjects ends\n";
00058 }
00059
00060 void popcon::L1RPCConfigSourceHandler::readConfig()
00061 {
00062 patterns = new L1RPCConfig();
00063 patterns->setPPT(m_ppt);
00064
00065 int scCnt = 0, sgCnt = 0;
00066 if(m_ppt == 1) {
00067 scCnt = 1;
00068 sgCnt = 1;
00069 }
00070 else if(m_ppt == 12) {
00071 scCnt = 1;
00072 sgCnt = 12;
00073 }
00074 else if(m_ppt == 144) {
00075 scCnt = 12;
00076 sgCnt = 12;
00077 }
00078 else {
00079 throw cms::Exception("BadConfig") << "Bad number of ppt requested: " << m_ppt << "\n";
00080 }
00081
00082 for (int tower = 0; tower < RPCConst::m_TOWER_COUNT; ++tower) {
00083 for (int logSector = 0; logSector < scCnt; ++logSector) {
00084 for (int logSegment = 0; logSegment < sgCnt; ++logSegment) {
00085
00086 std::stringstream fname;
00087 fname << m_patternsDir
00088 << "pacPat_t" << tower
00089 << "sc" << logSector
00090 << "sg" <<logSegment
00091 << ".xml";
00092
00093 cout<<"Parsing "<<fname.str()<<flush;
00094 RPCPatternsParser parser;
00095 parser.parse(fname.str());
00096 cout<<" - done "<<endl;
00097
00098 RPCPattern::RPCPatVec npats = parser.getPatternsVec(tower, logSector, logSegment);
00099
00100 for (unsigned int ip=0; ip<npats.size(); ip++) {
00101 npats[ip].setCoords(tower,logSector,logSegment);
00102 patterns->m_pats.push_back(npats[ip]);
00103 }
00104
00105 RPCPattern::TQualityVec nquals = parser.getQualityVec();
00106 for (unsigned int iq=0; iq<nquals.size(); iq++) {
00107 nquals[iq].m_tower=tower;
00108 nquals[iq].m_logsector=logSector;
00109 nquals[iq].m_logsegment=logSegment;
00110 patterns->m_quals.push_back(nquals[iq]);
00111 }
00112
00113 }
00114 }
00115 }
00116 }
00117
00118 int popcon::L1RPCConfigSourceHandler::Compare2Configs(const L1RPCConfig* pat1, L1RPCConfig* pat2) {
00119 std::cout<<" L1RPCConfigSourceHandler::Compare2Configs: sorry, option not available - different configs assumed"<<std::endl;
00120 return 1;
00121 }