diff --git a/CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h b/CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h index cf9448a5b640e..fc4c8ecdf6aa5 100644 --- a/CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h +++ b/CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include class BeamSpotOnlineObjects : public BeamSpotObjects { public: @@ -27,10 +29,14 @@ class BeamSpotOnlineObjects : public BeamSpotObjects { lastAnalyzedLumi_ = 0; lastAnalyzedRun_ = 0; lastAnalyzedFill_ = 0; + intParams_.resize(ISIZE, std::vector(1, 0)); } ~BeamSpotOnlineObjects() override {} + /// Enums + enum IntParamIndex { NUM_TRACKS = 0, NUM_PVS = 1, ISIZE = 2 }; + /// Setters Methods // set lastAnalyzedLumi_, last analyzed lumisection void SetLastAnalyzedLumi(int val) { lastAnalyzedLumi_ = val; } @@ -41,6 +47,12 @@ class BeamSpotOnlineObjects : public BeamSpotObjects { // set lastAnalyzedFill_, fill of the last analyzed lumisection void SetLastAnalyzedFill(int val) { lastAnalyzedFill_ = val; } + // set number of tracks used in the BeamSpot fit + void SetNumTracks(int val); + + // set number of Primary Vertices used in the BeamSpot fit + void SetNumPVs(int val); + /// Getters Methods // get lastAnalyzedLumi_, last analyzed lumisection int GetLastAnalyzedLumi() const { return lastAnalyzedLumi_; } @@ -51,6 +63,12 @@ class BeamSpotOnlineObjects : public BeamSpotObjects { // get lastAnalyzedFill_, fill of the last analyzed lumisection int GetLastAnalyzedFill() const { return lastAnalyzedFill_; } + // get number of tracks used in the BeamSpot fit + int GetNumTracks() const; + + // get number of Primary Vertices used in the BeamSpot fit + int GetNumPVs() const; + /// Print BeamSpotOnline parameters void print(std::stringstream& ss) const; @@ -58,6 +76,9 @@ class BeamSpotOnlineObjects : public BeamSpotObjects { int lastAnalyzedLumi_; int lastAnalyzedRun_; int lastAnalyzedFill_; + std::vector > intParams_; + std::vector > floatParams_; + std::vector > stringParams_; COND_SERIALIZABLE; }; diff --git a/CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc b/CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc index 3ce7490decdac..baf93c67d7ac9 100644 --- a/CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc +++ b/CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc @@ -2,6 +2,63 @@ #include +namespace BeamSpotOnlineObjectsImpl { + template + const T& getParams(const std::vector& params, size_t index) { + if (index >= params.size()) + throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range."); + return params[index]; + } + + template + T& accessParams(std::vector& params, size_t index) { + if (index >= params.size()) + throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range."); + return params[index]; + } + + template + const T& getOneParam(const std::vector >& params, size_t index) { + if (index >= params.size()) + throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range."); + const std::vector& inner = params[index]; + if (inner.empty()) + throw std::out_of_range("Parameter with index " + std::to_string(index) + " type=" + typeid(T).name() + + " has no value stored."); + return inner[0]; + } + + template + void setOneParam(std::vector >& params, size_t index, const T& value) { + if (index >= params.size()) + throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range."); + params[index] = std::vector(1, value); + } + + template + void setParams(std::vector& params, size_t index, const T& value) { + if (index >= params.size()) + throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range."); + params[index] = value; + } + +} //namespace BeamSpotOnlineObjectsImpl + +// getters +int BeamSpotOnlineObjects::GetNumTracks() const { + return BeamSpotOnlineObjectsImpl::getOneParam(intParams_, NUM_TRACKS); +} + +int BeamSpotOnlineObjects::GetNumPVs() const { return BeamSpotOnlineObjectsImpl::getOneParam(intParams_, NUM_PVS); } + +// setters +void BeamSpotOnlineObjects::SetNumTracks(int nTracks) { + BeamSpotOnlineObjectsImpl::setOneParam(intParams_, NUM_TRACKS, nTracks); +} + +void BeamSpotOnlineObjects::SetNumPVs(int nPVs) { BeamSpotOnlineObjectsImpl::setOneParam(intParams_, NUM_PVS, nPVs); } + +// printers void BeamSpotOnlineObjects::print(std::stringstream& ss) const { ss << "-----------------------------------------------------\n" << " BeamSpotOnline Data\n\n"