Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:07

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  $Date: 2008/12/11 09:44:53 $
0005  *  $Revision: 1.16 $
0006  *  \author Paolo Ronchese INFN Padova
0007  *
0008  */
0009 
0010 //----------------------
0011 // This Class' Header --
0012 //----------------------
0013 #include "CondFormats/DTObjects/interface/DTTtrig.h"
0014 
0015 //-------------------------------
0016 // Collaborating Class Headers --
0017 //-------------------------------
0018 //#include "CondFormats/DTObjects/interface/DTDataBuffer.h"
0019 #include "CondFormats/DTObjects/interface/DTBufferTree.h"
0020 
0021 //---------------
0022 // C++ Headers --
0023 //---------------
0024 #include <iostream>
0025 #include <sstream>
0026 
0027 //-------------------
0028 // Initializations --
0029 //-------------------
0030 
0031 //----------------
0032 // Constructors --
0033 //----------------
0034 DTTtrig::DTTtrig() : dataVersion(" "), nsPerCount(25.0 / 32.0), dBuf(new DTBufferTree<int, int>) {
0035   dataList.reserve(1000);
0036 }
0037 
0038 DTTtrig::DTTtrig(const std::string& version)
0039     : dataVersion(version), nsPerCount(25.0 / 32.0), dBuf(new DTBufferTree<int, int>) {
0040   dataList.reserve(1000);
0041 }
0042 
0043 DTTtrigId::DTTtrigId() : wheelId(0), stationId(0), sectorId(0), slId(0), layerId(0), cellId(0) {}
0044 
0045 DTTtrigData::DTTtrigData() : tTrig(0.0), tTrms(0.0), kFact(0.0) {}
0046 
0047 //--------------
0048 // Destructor --
0049 //--------------
0050 DTTtrig::~DTTtrig() {}
0051 
0052 DTTtrigId::~DTTtrigId() {}
0053 
0054 DTTtrigData::~DTTtrigData() {}
0055 
0056 //--------------
0057 // Operations --
0058 //--------------
0059 int DTTtrig::get(int wheelId,
0060                  int stationId,
0061                  int sectorId,
0062                  int slId,
0063                  float& tTrig,
0064                  float& tTrms,
0065                  float& kFact,
0066                  DTTimeUnits::type unit) const {
0067   return get(wheelId, stationId, sectorId, slId, 0, 0, tTrig, tTrms, kFact, unit);
0068 }
0069 
0070 int DTTtrig::get(int wheelId,
0071                  int stationId,
0072                  int sectorId,
0073                  int slId,
0074                  int layerId,
0075                  int cellId,
0076                  float& tTrig,
0077                  float& tTrms,
0078                  float& kFact,
0079                  DTTimeUnits::type unit) const {
0080   tTrig = tTrms = kFact = 0.0;
0081 
0082   std::vector<int> chanKey;
0083   chanKey.reserve(6);
0084   chanKey.push_back(wheelId);
0085   chanKey.push_back(stationId);
0086   chanKey.push_back(sectorId);
0087   chanKey.push_back(slId);
0088   chanKey.push_back(layerId);
0089   chanKey.push_back(cellId);
0090   int ientry;
0091   int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0092   if (!searchStatus) {
0093     const DTTtrigData& data(dataList[ientry].second);
0094     tTrig = data.tTrig;
0095     tTrms = data.tTrms;
0096     kFact = data.kFact;
0097     if (unit == DTTimeUnits::ns) {
0098       tTrig *= nsPerCount;
0099       tTrms *= nsPerCount;
0100     }
0101   }
0102 
0103   return searchStatus;
0104 }
0105 
0106 int DTTtrig::get(const DTSuperLayerId& id, float& tTrig, float& tTrms, float& kFact, DTTimeUnits::type unit) const {
0107   return get(id.wheel(), id.station(), id.sector(), id.superLayer(), 0, 0, tTrig, tTrms, kFact, unit);
0108 }
0109 
0110 int DTTtrig::get(const DetId& id, float& tTrig, float& tTrms, float& kFact, DTTimeUnits::type unit) const {
0111   DTWireId wireId(id.rawId());
0112   return get(wireId.wheel(),
0113              wireId.station(),
0114              wireId.sector(),
0115              wireId.superLayer(),
0116              wireId.layer(),
0117              wireId.wire(),
0118              tTrig,
0119              tTrms,
0120              kFact,
0121              unit);
0122 }
0123 
0124 int DTTtrig::get(int wheelId, int stationId, int sectorId, int slId, float& tTrig, DTTimeUnits::type unit) const {
0125   return get(wheelId, stationId, sectorId, slId, 0, 0, tTrig, unit);
0126 }
0127 
0128 int DTTtrig::get(int wheelId,
0129                  int stationId,
0130                  int sectorId,
0131                  int slId,
0132                  int layerId,
0133                  int cellId,
0134                  float& tTrig,
0135                  DTTimeUnits::type unit) const {
0136   float tMean;
0137   float tTrms;
0138   float kFact;
0139   int status = get(wheelId, stationId, sectorId, slId, layerId, cellId, tMean, tTrms, kFact, unit);
0140   tTrig = tMean + (kFact * tTrms);
0141   return status;
0142 }
0143 
0144 int DTTtrig::get(const DTSuperLayerId& id, float& tTrig, DTTimeUnits::type unit) const {
0145   return get(id.wheel(), id.station(), id.sector(), id.superLayer(), 0, 0, tTrig, unit);
0146 }
0147 
0148 int DTTtrig::get(const DetId& id, float& tTrig, DTTimeUnits::type unit) const {
0149   DTWireId wireId(id.rawId());
0150   return get(wireId.wheel(),
0151              wireId.station(),
0152              wireId.sector(),
0153              wireId.superLayer(),
0154              wireId.layer(),
0155              wireId.wire(),
0156              tTrig,
0157              unit);
0158 }
0159 
0160 float DTTtrig::unit() const { return nsPerCount; }
0161 
0162 const std::string& DTTtrig::version() const { return dataVersion; }
0163 
0164 std::string& DTTtrig::version() { return dataVersion; }
0165 
0166 void DTTtrig::clear() {
0167   dataList.clear();
0168   initialize();
0169   return;
0170 }
0171 
0172 int DTTtrig::set(
0173     int wheelId, int stationId, int sectorId, int slId, float tTrig, float tTrms, float kFact, DTTimeUnits::type unit) {
0174   return set(wheelId, stationId, sectorId, slId, 0, 0, tTrig, tTrms, kFact, unit);
0175 }
0176 
0177 int DTTtrig::set(int wheelId,
0178                  int stationId,
0179                  int sectorId,
0180                  int slId,
0181                  int layerId,
0182                  int cellId,
0183                  float tTrig,
0184                  float tTrms,
0185                  float kFact,
0186                  DTTimeUnits::type unit) {
0187   if (unit == DTTimeUnits::ns) {
0188     tTrig /= nsPerCount;
0189     tTrms /= nsPerCount;
0190   }
0191 
0192   std::vector<int> chanKey;
0193   chanKey.reserve(6);
0194   chanKey.push_back(wheelId);
0195   chanKey.push_back(stationId);
0196   chanKey.push_back(sectorId);
0197   chanKey.push_back(slId);
0198   chanKey.push_back(layerId);
0199   chanKey.push_back(cellId);
0200   int ientry;
0201   int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0202 
0203   if (!searchStatus) {
0204     DTTtrigData& data(dataList[ientry].second);
0205     data.tTrig = tTrig;
0206     data.tTrms = tTrms;
0207     data.kFact = kFact;
0208     return -1;
0209   } else {
0210     DTTtrigId key;
0211     key.wheelId = wheelId;
0212     key.stationId = stationId;
0213     key.sectorId = sectorId;
0214     key.slId = slId;
0215     key.layerId = layerId;
0216     key.cellId = cellId;
0217     DTTtrigData data;
0218     data.tTrig = tTrig;
0219     data.tTrms = tTrms;
0220     data.kFact = kFact;
0221     ientry = dataList.size();
0222     dataList.push_back(std::pair<DTTtrigId, DTTtrigData>(key, data));
0223     dBuf->insert(chanKey.begin(), chanKey.end(), ientry);
0224     return 0;
0225   }
0226 
0227   return 99;
0228 }
0229 
0230 int DTTtrig::set(const DTSuperLayerId& id, float tTrig, float tTrms, float kFact, DTTimeUnits::type unit) {
0231   return set(id.wheel(), id.station(), id.sector(), id.superLayer(), 0, 0, tTrig, tTrms, kFact, unit);
0232 }
0233 
0234 int DTTtrig::set(const DetId& id, float tTrig, float tTrms, float kFact, DTTimeUnits::type unit) {
0235   DTWireId wireId(id.rawId());
0236   return set(wireId.wheel(),
0237              wireId.station(),
0238              wireId.sector(),
0239              wireId.superLayer(),
0240              wireId.layer(),
0241              wireId.wire(),
0242              tTrig,
0243              tTrms,
0244              kFact,
0245              unit);
0246 }
0247 
0248 void DTTtrig::setUnit(float unit) { nsPerCount = unit; }
0249 
0250 DTTtrig::const_iterator DTTtrig::begin() const { return dataList.begin(); }
0251 
0252 DTTtrig::const_iterator DTTtrig::end() const { return dataList.end(); }
0253 
0254 std::string DTTtrig::mapName() const {
0255   std::stringstream name;
0256   name << dataVersion << "_map_Ttrig" << this;
0257   return name.str();
0258 }
0259 
0260 void DTTtrig::initialize() {
0261   dBuf->clear();
0262 
0263   int entryNum = 0;
0264   int entryMax = dataList.size();
0265   std::vector<int> chanKey;
0266   chanKey.reserve(6);
0267   while (entryNum < entryMax) {
0268     const DTTtrigId& chan = dataList[entryNum].first;
0269 
0270     chanKey.clear();
0271     chanKey.push_back(chan.wheelId);
0272     chanKey.push_back(chan.stationId);
0273     chanKey.push_back(chan.sectorId);
0274     chanKey.push_back(chan.slId);
0275     chanKey.push_back(chan.layerId);
0276     chanKey.push_back(chan.cellId);
0277     dBuf->insert(chanKey.begin(), chanKey.end(), entryNum++);
0278   }
0279   return;
0280 }