Skip to content

Commit

Permalink
add vector members to BeamSpotOnlineObjects class
Browse files Browse the repository at this point in the history
  • Loading branch information
francescobrivio committed May 12, 2020
1 parent b7e11f6 commit 7e06886
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
21 changes: 21 additions & 0 deletions CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <cmath>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>

class BeamSpotOnlineObjects : public BeamSpotObjects {
public:
Expand All @@ -27,10 +29,14 @@ class BeamSpotOnlineObjects : public BeamSpotObjects {
lastAnalyzedLumi_ = 0;
lastAnalyzedRun_ = 0;
lastAnalyzedFill_ = 0;
intParams_.resize(ISIZE, std::vector<int>(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; }
Expand All @@ -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_; }
Expand All @@ -51,13 +63,22 @@ 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;

private:
int lastAnalyzedLumi_;
int lastAnalyzedRun_;
int lastAnalyzedFill_;
std::vector<std::vector<int> > intParams_;
std::vector<std::vector<float> > floatParams_;
std::vector<std::vector<std::string> > stringParams_;

COND_SERIALIZABLE;
};
Expand Down
57 changes: 57 additions & 0 deletions CondFormats/BeamSpotObjects/src/BeamSpotOnlineObjects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,63 @@

#include <iostream>

namespace BeamSpotOnlineObjectsImpl {
template <typename T>
const T& getParams(const std::vector<T>& 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 <typename T>
T& accessParams(std::vector<T>& 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 <typename T>
const T& getOneParam(const std::vector<std::vector<T> >& 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<T>& 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 <typename T>
void setOneParam(std::vector<std::vector<T> >& 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<T>(1, value);
}

template <typename T>
void setParams(std::vector<T>& 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"
Expand Down

0 comments on commit 7e06886

Please sign in to comment.