Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:02

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author Paolo Ronchese INFN Padova
0005  *
0006  */
0007 
0008 //----------------------
0009 // This Class' Header --
0010 //----------------------
0011 #include "CondFormats/DTObjects/interface/DTRangeT0.h"
0012 
0013 //-------------------------------
0014 // Collaborating Class Headers --
0015 //-------------------------------
0016 #include "CondFormats/DTObjects/interface/DTBufferTree.h"
0017 
0018 //---------------
0019 // C++ Headers --
0020 //---------------
0021 #include <iostream>
0022 #include <sstream>
0023 
0024 //-------------------
0025 // Initializations --
0026 //-------------------
0027 
0028 //----------------
0029 // Constructors --
0030 //----------------
0031 DTRangeT0::DTRangeT0() : dataVersion(" "), dBuf(new DTBufferTree<int, int>) { dataList.reserve(1000); }
0032 
0033 DTRangeT0::DTRangeT0(const std::string& version) : dataVersion(version), dBuf(new DTBufferTree<int, int>) {
0034   dataList.reserve(1000);
0035 }
0036 
0037 DTRangeT0Id::DTRangeT0Id() : wheelId(0), stationId(0), sectorId(0), slId(0) {}
0038 
0039 DTRangeT0Data::DTRangeT0Data() : t0min(0), t0max(0) {}
0040 
0041 //--------------
0042 // Destructor --
0043 //--------------
0044 DTRangeT0::~DTRangeT0() {}
0045 
0046 DTRangeT0Id::~DTRangeT0Id() {}
0047 
0048 DTRangeT0Data::~DTRangeT0Data() {}
0049 
0050 //--------------
0051 // Operations --
0052 //--------------
0053 int DTRangeT0::get(int wheelId, int stationId, int sectorId, int slId, int& t0min, int& t0max) const {
0054   t0min = t0max = 0;
0055 
0056   std::vector<int> chanKey;
0057   chanKey.reserve(4);
0058   chanKey.push_back(wheelId);
0059   chanKey.push_back(stationId);
0060   chanKey.push_back(sectorId);
0061   chanKey.push_back(slId);
0062   int ientry;
0063   //Guarantee const correctness for thread-safety
0064   const DTBufferTree<int, int>* constDBuf = dBuf;
0065   int searchStatus = constDBuf->find(chanKey.begin(), chanKey.end(), ientry);
0066   if (!searchStatus) {
0067     const DTRangeT0Data& data(dataList[ientry].second);
0068     t0min = data.t0min;
0069     t0max = data.t0max;
0070   }
0071 
0072   return searchStatus;
0073 }
0074 
0075 int DTRangeT0::get(const DTSuperLayerId& id, int& t0min, int& t0max) const {
0076   return get(id.wheel(), id.station(), id.sector(), id.superLayer(), t0min, t0max);
0077 }
0078 
0079 const std::string& DTRangeT0::version() const { return dataVersion; }
0080 
0081 std::string& DTRangeT0::version() { return dataVersion; }
0082 
0083 void DTRangeT0::clear() {
0084   dataList.clear();
0085   initialize();
0086   return;
0087 }
0088 
0089 int DTRangeT0::set(int wheelId, int stationId, int sectorId, int slId, int t0min, int t0max) {
0090   std::vector<int> chanKey;
0091   chanKey.reserve(4);
0092   chanKey.push_back(wheelId);
0093   chanKey.push_back(stationId);
0094   chanKey.push_back(sectorId);
0095   chanKey.push_back(slId);
0096   int ientry;
0097   int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0098 
0099   if (!searchStatus) {
0100     DTRangeT0Data& data(dataList[ientry].second);
0101     data.t0min = t0min;
0102     data.t0max = t0max;
0103     return -1;
0104   } else {
0105     DTRangeT0Id key;
0106     key.wheelId = wheelId;
0107     key.stationId = stationId;
0108     key.sectorId = sectorId;
0109     key.slId = slId;
0110     DTRangeT0Data data;
0111     data.t0min = t0min;
0112     data.t0max = t0max;
0113     ientry = dataList.size();
0114     dataList.push_back(std::pair<DTRangeT0Id, DTRangeT0Data>(key, data));
0115     dBuf->insert(chanKey.begin(), chanKey.end(), ientry);
0116     return 0;
0117   }
0118 
0119   return 99;
0120 }
0121 
0122 int DTRangeT0::set(const DTSuperLayerId& id, int t0min, int t0max) {
0123   return set(id.wheel(), id.station(), id.sector(), id.superLayer(), t0min, t0max);
0124 }
0125 
0126 DTRangeT0::const_iterator DTRangeT0::begin() const { return dataList.begin(); }
0127 
0128 DTRangeT0::const_iterator DTRangeT0::end() const { return dataList.end(); }
0129 
0130 std::string DTRangeT0::mapName() const {
0131   std::stringstream name;
0132   name << dataVersion << "_map_RangeT0" << this;
0133   return name.str();
0134 }
0135 
0136 void DTRangeT0::initialize() {
0137   dBuf->clear();
0138 
0139   int entryNum = 0;
0140   int entryMax = dataList.size();
0141   std::vector<int> chanKey;
0142   chanKey.reserve(4);
0143   while (entryNum < entryMax) {
0144     const DTRangeT0Id& chan = dataList[entryNum].first;
0145 
0146     chanKey.clear();
0147     chanKey.push_back(chan.wheelId);
0148     chanKey.push_back(chan.stationId);
0149     chanKey.push_back(chan.sectorId);
0150     chanKey.push_back(chan.slId);
0151     dBuf->insert(chanKey.begin(), chanKey.end(), entryNum++);
0152   }
0153   return;
0154 }