Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-14 11:44:46

0001 #include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h"
0002 
0003 #include <iostream>
0004 
0005 namespace BeamSpotOnlineObjectsImpl {
0006   template <typename T>
0007   const T& getParams(const std::vector<T>& params, size_t index) {
0008     if (index >= params.size())
0009       throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
0010     return params[index];
0011   }
0012 
0013   template <typename T>
0014   T& accessParams(std::vector<T>& params, size_t index) {
0015     if (index >= params.size())
0016       throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
0017     return params[index];
0018   }
0019 
0020   template <typename T>
0021   const T& getOneParam(const std::vector<std::vector<T> >& params, size_t index) {
0022     if (index >= params.size())
0023       throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
0024     const std::vector<T>& inner = params[index];
0025     if (inner.empty())
0026       throw std::out_of_range("Parameter with index " + std::to_string(index) + " type=" + typeid(T).name() +
0027                               " has no value stored.");
0028     return inner[0];
0029   }
0030 
0031   template <typename T>
0032   void setOneParam(std::vector<std::vector<T> >& params, size_t index, const T& value) {
0033     if (index >= params.size())
0034       throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
0035     params[index] = std::vector<T>(1, value);
0036   }
0037 
0038   template <typename T>
0039   void setParams(std::vector<T>& params, size_t index, const T& value) {
0040     if (index >= params.size())
0041       throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
0042     params[index] = value;
0043   }
0044 
0045 }  //namespace BeamSpotOnlineObjectsImpl
0046 
0047 // getters
0048 int BeamSpotOnlineObjects::numTracks() const { return BeamSpotOnlineObjectsImpl::getOneParam(intParams_, NUM_TRACKS); }
0049 
0050 int BeamSpotOnlineObjects::numPVs() const { return BeamSpotOnlineObjectsImpl::getOneParam(intParams_, NUM_PVS); }
0051 
0052 int BeamSpotOnlineObjects::usedEvents() const {
0053   return BeamSpotOnlineObjectsImpl::getOneParam(intParams_, USED_EVENTS);
0054 }
0055 
0056 int BeamSpotOnlineObjects::maxPVs() const { return BeamSpotOnlineObjectsImpl::getOneParam(intParams_, MAX_PVS); }
0057 
0058 float BeamSpotOnlineObjects::meanPV() const { return BeamSpotOnlineObjectsImpl::getOneParam(floatParams_, MEAN_PV); }
0059 
0060 float BeamSpotOnlineObjects::meanErrorPV() const {
0061   return BeamSpotOnlineObjectsImpl::getOneParam(floatParams_, ERR_MEAN_PV);
0062 }
0063 
0064 float BeamSpotOnlineObjects::rmsPV() const { return BeamSpotOnlineObjectsImpl::getOneParam(floatParams_, RMS_PV); }
0065 
0066 float BeamSpotOnlineObjects::rmsErrorPV() const {
0067   return BeamSpotOnlineObjectsImpl::getOneParam(floatParams_, ERR_RMS_PV);
0068 }
0069 
0070 std::string BeamSpotOnlineObjects::startTime() const {
0071   return BeamSpotOnlineObjectsImpl::getOneParam(stringParams_, START_TIME);
0072 }
0073 
0074 std::string BeamSpotOnlineObjects::endTime() const {
0075   return BeamSpotOnlineObjectsImpl::getOneParam(stringParams_, END_TIME);
0076 }
0077 
0078 std::string BeamSpotOnlineObjects::lumiRange() const {
0079   return BeamSpotOnlineObjectsImpl::getOneParam(stringParams_, LUMI_RANGE);
0080 }
0081 
0082 cond::Time_t BeamSpotOnlineObjects::creationTime() const {
0083   return BeamSpotOnlineObjectsImpl::getOneParam(timeParams_, CREATE_TIME);
0084 }
0085 
0086 cond::Time_t BeamSpotOnlineObjects::startTimeStamp() const {
0087   return BeamSpotOnlineObjectsImpl::getOneParam(timeParams_, START_TIMESTAMP);
0088 }
0089 
0090 cond::Time_t BeamSpotOnlineObjects::endTimeStamp() const {
0091   return BeamSpotOnlineObjectsImpl::getOneParam(timeParams_, END_TIMESTAMP);
0092 }
0093 
0094 // setters
0095 void BeamSpotOnlineObjects::setNumTracks(int nTracks) {
0096   BeamSpotOnlineObjectsImpl::setOneParam(intParams_, NUM_TRACKS, nTracks);
0097 }
0098 
0099 void BeamSpotOnlineObjects::setNumPVs(int nPVs) { BeamSpotOnlineObjectsImpl::setOneParam(intParams_, NUM_PVS, nPVs); }
0100 
0101 void BeamSpotOnlineObjects::setUsedEvents(int usedEvents) {
0102   BeamSpotOnlineObjectsImpl::setOneParam(intParams_, USED_EVENTS, usedEvents);
0103 }
0104 
0105 void BeamSpotOnlineObjects::setMaxPVs(int maxPVs) {
0106   BeamSpotOnlineObjectsImpl::setOneParam(intParams_, MAX_PVS, maxPVs);
0107 }
0108 
0109 void BeamSpotOnlineObjects::setMeanPV(float meanPVs) {
0110   BeamSpotOnlineObjectsImpl::setOneParam(floatParams_, MEAN_PV, meanPVs);
0111 }
0112 
0113 void BeamSpotOnlineObjects::setMeanErrorPV(float errMeanPVs) {
0114   BeamSpotOnlineObjectsImpl::setOneParam(floatParams_, ERR_MEAN_PV, errMeanPVs);
0115 }
0116 
0117 void BeamSpotOnlineObjects::setRmsPV(float rmsPVs) {
0118   BeamSpotOnlineObjectsImpl::setOneParam(floatParams_, RMS_PV, rmsPVs);
0119 }
0120 
0121 void BeamSpotOnlineObjects::setRmsErrorPV(float errRmsPVs) {
0122   BeamSpotOnlineObjectsImpl::setOneParam(floatParams_, ERR_RMS_PV, errRmsPVs);
0123 }
0124 
0125 void BeamSpotOnlineObjects::setStartTime(std::string startTime) {
0126   BeamSpotOnlineObjectsImpl::setOneParam(stringParams_, START_TIME, startTime);
0127 }
0128 
0129 void BeamSpotOnlineObjects::setEndTime(std::string endTime) {
0130   BeamSpotOnlineObjectsImpl::setOneParam(stringParams_, END_TIME, endTime);
0131 }
0132 
0133 void BeamSpotOnlineObjects::setLumiRange(std::string lumiRange) {
0134   BeamSpotOnlineObjectsImpl::setOneParam(stringParams_, LUMI_RANGE, lumiRange);
0135 }
0136 
0137 void BeamSpotOnlineObjects::setCreationTime(cond::Time_t createTime) {
0138   BeamSpotOnlineObjectsImpl::setOneParam(timeParams_, CREATE_TIME, createTime);
0139 }
0140 
0141 void BeamSpotOnlineObjects::setStartTimeStamp(cond::Time_t starTimeStamp) {
0142   BeamSpotOnlineObjectsImpl::setOneParam(timeParams_, START_TIMESTAMP, starTimeStamp);
0143 }
0144 
0145 void BeamSpotOnlineObjects::setEndTimeStamp(cond::Time_t endTimeStamp) {
0146   BeamSpotOnlineObjectsImpl::setOneParam(timeParams_, END_TIMESTAMP, endTimeStamp);
0147 }
0148 
0149 // printers
0150 void BeamSpotOnlineObjects::print(std::stringstream& ss) const {
0151   ss << "-----------------------------------------------------\n"
0152      << "              BeamSpotOnline Data\n\n"
0153      << " Beam type    = " << beamType() << "\n"
0154      << "       X0     = " << x() << " +/- " << xError() << " [cm]\n"
0155      << "       Y0     = " << y() << " +/- " << yError() << " [cm]\n"
0156      << "       Z0     = " << z() << " +/- " << zError() << " [cm]\n"
0157      << " Sigma Z0     = " << sigmaZ() << " +/- " << sigmaZError() << " [cm]\n"
0158      << " dxdz         = " << dxdz() << " +/- " << dxdzError() << " [radians]\n"
0159      << " dydz         = " << dydz() << " +/- " << dydzError() << " [radians]\n"
0160      << " Beam Width X = " << beamWidthX() << " +/- " << beamWidthXError() << " [cm]\n"
0161      << " Beam Width Y = " << beamWidthY() << " +/- " << beamWidthYError() << " [cm]\n"
0162      << " Emittance X  = " << emittanceX() << " [cm]\n"
0163      << " Emittance Y  = " << emittanceY() << " [cm]\n"
0164      << " Beta star    = " << betaStar() << " [cm]\n"
0165      << " Last Lumi    = " << lastAnalyzedLumi() << "\n"
0166      << " Last Run     = " << lastAnalyzedRun() << "\n"
0167      << " Last Fill    = " << lastAnalyzedFill() << "\n"
0168      << "-----------------------------------------------------\n\n";
0169 }
0170 
0171 std::ostream& operator<<(std::ostream& os, BeamSpotOnlineObjects beam) {
0172   std::stringstream ss;
0173   beam.print(ss);
0174   os << ss.str();
0175   return os;
0176 }