File indexing completed on 2024-04-06 12:01:56
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 }
0046
0047
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
0095 void BeamSpotOnlineObjects::copyFromBeamSpotObject(const BeamSpotObjects& bs) {
0096 setType(bs.beamType());
0097 setPosition(bs.x(), bs.y(), bs.z());
0098 setSigmaZ(bs.sigmaZ());
0099 setdxdz(bs.dxdz());
0100 setdydz(bs.dydz());
0101 setBeamWidthX(bs.beamWidthX());
0102 setBeamWidthY(bs.beamWidthY());
0103 setBeamWidthXError(bs.beamWidthXError());
0104 setBeamWidthYError(bs.beamWidthYError());
0105 setEmittanceX(bs.emittanceX());
0106 setEmittanceY(bs.emittanceY());
0107 setBetaStar(bs.betaStar());
0108
0109 for (int i = 0; i < 7; ++i) {
0110 for (int j = 0; j < 7; ++j) {
0111 setCovariance(i, j, bs.covariance(i, j));
0112 }
0113 }
0114 }
0115
0116 void BeamSpotOnlineObjects::setNumTracks(int nTracks) {
0117 BeamSpotOnlineObjectsImpl::setOneParam(intParams_, NUM_TRACKS, nTracks);
0118 }
0119
0120 void BeamSpotOnlineObjects::setNumPVs(int nPVs) { BeamSpotOnlineObjectsImpl::setOneParam(intParams_, NUM_PVS, nPVs); }
0121
0122 void BeamSpotOnlineObjects::setUsedEvents(int usedEvents) {
0123 BeamSpotOnlineObjectsImpl::setOneParam(intParams_, USED_EVENTS, usedEvents);
0124 }
0125
0126 void BeamSpotOnlineObjects::setMaxPVs(int maxPVs) {
0127 BeamSpotOnlineObjectsImpl::setOneParam(intParams_, MAX_PVS, maxPVs);
0128 }
0129
0130 void BeamSpotOnlineObjects::setMeanPV(float meanPVs) {
0131 BeamSpotOnlineObjectsImpl::setOneParam(floatParams_, MEAN_PV, meanPVs);
0132 }
0133
0134 void BeamSpotOnlineObjects::setMeanErrorPV(float errMeanPVs) {
0135 BeamSpotOnlineObjectsImpl::setOneParam(floatParams_, ERR_MEAN_PV, errMeanPVs);
0136 }
0137
0138 void BeamSpotOnlineObjects::setRmsPV(float rmsPVs) {
0139 BeamSpotOnlineObjectsImpl::setOneParam(floatParams_, RMS_PV, rmsPVs);
0140 }
0141
0142 void BeamSpotOnlineObjects::setRmsErrorPV(float errRmsPVs) {
0143 BeamSpotOnlineObjectsImpl::setOneParam(floatParams_, ERR_RMS_PV, errRmsPVs);
0144 }
0145
0146 void BeamSpotOnlineObjects::setStartTime(std::string startTime) {
0147 BeamSpotOnlineObjectsImpl::setOneParam(stringParams_, START_TIME, startTime);
0148 }
0149
0150 void BeamSpotOnlineObjects::setEndTime(std::string endTime) {
0151 BeamSpotOnlineObjectsImpl::setOneParam(stringParams_, END_TIME, endTime);
0152 }
0153
0154 void BeamSpotOnlineObjects::setLumiRange(std::string lumiRange) {
0155 BeamSpotOnlineObjectsImpl::setOneParam(stringParams_, LUMI_RANGE, lumiRange);
0156 }
0157
0158 void BeamSpotOnlineObjects::setCreationTime(cond::Time_t createTime) {
0159 BeamSpotOnlineObjectsImpl::setOneParam(timeParams_, CREATE_TIME, createTime);
0160 }
0161
0162 void BeamSpotOnlineObjects::setStartTimeStamp(cond::Time_t starTimeStamp) {
0163 BeamSpotOnlineObjectsImpl::setOneParam(timeParams_, START_TIMESTAMP, starTimeStamp);
0164 }
0165
0166 void BeamSpotOnlineObjects::setEndTimeStamp(cond::Time_t endTimeStamp) {
0167 BeamSpotOnlineObjectsImpl::setOneParam(timeParams_, END_TIMESTAMP, endTimeStamp);
0168 }
0169
0170
0171 void BeamSpotOnlineObjects::print(std::stringstream& ss) const {
0172 ss << "-----------------------------------------------------\n"
0173 << " BeamSpotOnline Data\n\n"
0174 << " Beam type = " << beamType() << "\n"
0175 << " X0 = " << x() << " +/- " << xError() << " [cm]\n"
0176 << " Y0 = " << y() << " +/- " << yError() << " [cm]\n"
0177 << " Z0 = " << z() << " +/- " << zError() << " [cm]\n"
0178 << " Sigma Z0 = " << sigmaZ() << " +/- " << sigmaZError() << " [cm]\n"
0179 << " dxdz = " << dxdz() << " +/- " << dxdzError() << " [radians]\n"
0180 << " dydz = " << dydz() << " +/- " << dydzError() << " [radians]\n"
0181 << " Beam Width X = " << beamWidthX() << " +/- " << beamWidthXError() << " [cm]\n"
0182 << " Beam Width Y = " << beamWidthY() << " +/- " << beamWidthYError() << " [cm]\n"
0183 << " Emittance X = " << emittanceX() << " [cm]\n"
0184 << " Emittance Y = " << emittanceY() << " [cm]\n"
0185 << " Beta star = " << betaStar() << " [cm]\n"
0186 << " Last Lumi = " << lastAnalyzedLumi() << "\n"
0187 << " Last Run = " << lastAnalyzedRun() << "\n"
0188 << " Last Fill = " << lastAnalyzedFill() << "\n"
0189 << "-----------------------------------------------------\n\n";
0190 }
0191
0192 std::ostream& operator<<(std::ostream& os, BeamSpotOnlineObjects beam) {
0193 std::stringstream ss;
0194 beam.print(ss);
0195 os << ss.str();
0196 return os;
0197 }