Skip to content

Commit

Permalink
Merge pull request #40537 from VinInn/FixPixelPerMix
Browse files Browse the repository at this point in the history
remove memory-churn in SiPixelTemplate2D::pushfile
  • Loading branch information
cmsbuild committed Jan 25, 2023
2 parents 36656a3 + 9f0fe68 commit 9bf8071
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 175 deletions.
40 changes: 39 additions & 1 deletion CondFormats/SiPixelObjects/interface/SiPixel2DTemplateDBObject.h
Expand Up @@ -61,7 +61,7 @@ class SiPixel2DTemplateDBObject {
int maxIndex() const { return maxIndex_; }
int numOfTempl() const { return numOfTempl_; }
float version() const { return version_; }
std::vector<float> sVector() const { return sVector_; }
std::vector<float> const& sVector() const { return sVector_; }

//- Able to set the index for template header
void incrementIndex(int i) { index_ += i; }
Expand Down Expand Up @@ -97,6 +97,44 @@ class SiPixel2DTemplateDBObject {
return 0;
}

class Reader {
public:
Reader(SiPixel2DTemplateDBObject const& object) : object_(object), index_(0), isInvalid_(false) {}

bool fail() { return isInvalid_; }

int index() const { return index_; }
//- Able to set the index for template header
void incrementIndex(int i) { index_ += i; }

//- Fills integer from dbobject
Reader& operator>>(int& i) {
isInvalid_ = false;
if (index_ <= object_.maxIndex_) {
i = (int)object_.sVector_[index_];
index_++;
} else
isInvalid_ = true;
return *this;
}
//- Fills float from dbobject
Reader& operator>>(float& f) {
isInvalid_ = false;
if (index_ <= object_.maxIndex_) {
f = object_.sVector_[index_];
index_++;
} else
isInvalid_ = true;
return *this;
}

private:
SiPixel2DTemplateDBObject const& object_;
int index_;
bool isInvalid_;
};
friend class Reader;

private:
int index_;
int maxIndex_;
Expand Down
18 changes: 16 additions & 2 deletions CondFormats/SiPixelTransient/interface/SiPixelTemplate2D.h
Expand Up @@ -100,10 +100,24 @@ struct SiPixelTemplateHeader2D { //!< template header structure
};

struct SiPixelTemplateStore2D { //!< template storage structure

void resize(int ny, int nx) {
entry.resize(ny);
store.resize(nx * ny);
int off = 0;
for (int i = 0; i < ny; ++i) {
entry[i] = store.data() + off;
off += nx;
}
assert(nx * ny == off);
}

SiPixelTemplateHeader2D head; //!< Header information

//!< use 2d entry to store BPix and FPix entries [dynamically allocated]
std::vector<std::vector<SiPixelTemplateEntry2D>> entry;
//!< use 2d entry to store BPix and FPix entries [dynamically allocated
std::vector<SiPixelTemplateEntry2D*> entry;

std::vector<SiPixelTemplateEntry2D> store;
};

// ******************************************************************************************
Expand Down

0 comments on commit 9bf8071

Please sign in to comment.