Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:15

0001 #include "CondTools/RPC/interface/RPCAMCLinkMapHandler.h"
0002 
0003 #include <fstream>
0004 #include <memory>
0005 #include <sstream>
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/FileInPath.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 
0012 #include "CondTools/RPC/interface/RPCLBLinkNameParser.h"
0013 
0014 RPCAMCLinkMapHandler::RPCAMCLinkMapHandler(edm::ParameterSet const& config)
0015     : id_(config.getParameter<std::string>("identifier")),
0016       data_tag_(config.getParameter<std::string>("dataTag")),
0017       since_run_(config.getParameter<unsigned long long>("sinceRun")),
0018       input_file_(config.getParameter<edm::FileInPath>("inputFile").fullPath()),
0019       wheel_not_side_(config.getParameter<bool>("wheelNotSide")),
0020       wos_fed_(config.getParameter<std::vector<int> >("wheelOrSideFED")),
0021       n_sectors_(config.getParameter<unsigned int>("nSectors")),
0022       wos_sector_amc_(wos_fed_.size(), std::vector<int>(n_sectors_, 0)),
0023       txt_file_(config.getUntrackedParameter<std::string>("txtFile", "")) {
0024   std::vector<long long> wos_sector_amc_packed(config.getParameter<std::vector<long long> >("wheelOrSideSectorAMC"));
0025 
0026   if (wos_fed_.size() != wos_sector_amc_packed.size()) {
0027     throw cms::Exception("RPCAMCLinkMapHandler") << "Refuse to handle inconsistent input: "
0028                                                  << "sizes of wheelOrSideFED and wheelOrSideSectorAMC don't match";
0029   }
0030 
0031   std::vector<std::vector<int> >::iterator sector_amc = wos_sector_amc_.begin();
0032   for (std::vector<long long>::const_iterator sector_amc_packed = wos_sector_amc_packed.begin();
0033        sector_amc_packed != wos_sector_amc_packed.end();
0034        ++sector_amc_packed, ++sector_amc) {
0035     for (unsigned int sector = 0; sector < n_sectors_; ++sector) {
0036       sector_amc->at(sector) = ((*sector_amc_packed) >> (4 * (n_sectors_ - sector - 1))) & 0xf;
0037     }
0038   }
0039 }
0040 
0041 RPCAMCLinkMapHandler::~RPCAMCLinkMapHandler() {}
0042 
0043 void RPCAMCLinkMapHandler::getNewObjects() {
0044   edm::LogInfo("RPCAMCLinkMapHandler") << "getNewObjects";
0045   cond::TagInfo_t const& tag_info = tagInfo();
0046   if (since_run_ < tag_info.lastInterval.since) {
0047     throw cms::Exception("RPCAMCLinkMapHandler") << "Refuse to create RPCAMCLinkMap for run " << since_run_
0048                                                  << ", older than most recent tag" << tag_info.lastInterval.since;
0049   }
0050 
0051   std::string amc_name, link_name;
0052   unsigned int wos, sector, amc_number, amc_input;
0053 
0054   std::unique_ptr<RPCAMCLinkMap> amc_link_map_object(new RPCAMCLinkMap());
0055   RPCAMCLinkMap::map_type& amc_link_map = amc_link_map_object->getMap();
0056   RPCLBLink lb_link;
0057 
0058   std::string line;
0059   std::istringstream conv;
0060 
0061   std::ifstream input_file(input_file_);
0062 
0063   input_file >> amc_name >> amc_input >> link_name;
0064   std::getline(input_file, line);
0065 
0066   while (input_file) {
0067     // parse AMC Slot Name - no checking: failure is an error
0068     if (wheel_not_side_) {                     // wheel
0069       std::string::size_type pos(2), next(2);  // skip YB
0070       int wheel;
0071       next = amc_name.find_first_not_of("+-0123456789", pos);
0072       conv.clear();
0073       conv.str(amc_name.substr(pos, next - pos));
0074       conv >> wheel;
0075       wos = wheel + 2;
0076 
0077       pos = next + 2;
0078       next = amc_name.find_first_not_of("+-0123456789", pos);
0079       if (next == std::string::npos)
0080         next = amc_name.size();
0081       conv.clear();
0082       conv.str(amc_name.substr(pos, next - pos));
0083       conv >> sector;
0084     } else {                                  // side
0085       wos = (amc_name.at(4) == 'n' ? 0 : 1);  // skip CPPF or OMTF
0086       conv.clear();
0087       conv.str(amc_name.substr(5, 1));
0088       conv >> sector;
0089     }
0090 
0091     if (sector > n_sectors_) {
0092       throw cms::Exception("RPCAMCLinkMapHandler")
0093           << "Found sector greater than the number of sectors: " << sector << " > " << n_sectors_;
0094     }
0095 
0096     if (wos >= wos_fed_.size()) {
0097       throw cms::Exception("RPCAMCLinkMapHandler")
0098           << "Found " << (wheel_not_side_ ? "wheel" : "side") << " outside range: " << wos << " >= " << wos_fed_.size();
0099     }
0100 
0101     amc_number = wos_sector_amc_.at(wos).at(sector - 1);
0102 
0103     RPCLBLinkNameParser::parse(link_name, lb_link);
0104 
0105     amc_link_map.insert(std::pair<RPCAMCLink, RPCLBLink>(RPCAMCLink(wos_fed_.at(wos), amc_number, amc_input), lb_link));
0106 
0107     input_file >> amc_name >> amc_input >> link_name;
0108     std::getline(input_file, line);
0109   }
0110   input_file.close();
0111 
0112   if (!txt_file_.empty()) {
0113     edm::LogInfo("RPCAMCLinkMapHandler") << "Fill txtFile";
0114     std::ofstream ofstream(txt_file_);
0115     for (auto const link : amc_link_map) {
0116       ofstream << link.first << ": " << link.second << std::endl;
0117     }
0118   }
0119 
0120   edm::LogInfo("RPCAMCLinkMapHandler") << "Add to transfer list";
0121   m_to_transfer.push_back(std::make_pair(amc_link_map_object.release(), since_run_));
0122 }
0123 
0124 std::string RPCAMCLinkMapHandler::id() const { return id_; }