Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix throwing CapacityExausted #15529

Merged
merged 3 commits into from Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion DataFormats/Common/interface/DetSetVectorNew.h
Expand Up @@ -299,7 +299,7 @@ namespace edmNew {
bool expected=false;
while (!m_v.m_filling.compare_exchange_weak(expected,true)) { expected=false; nanosleep(0,0);}
int offset = m_v.m_data.size();
if (m_v.onDemand() && m_v.m_data.capacity()<offset+m_lv.size()) {
if (m_v.onDemand() && full()) {
m_v.m_filling = false;
dstvdetails::throwCapacityExausted();
}
Expand All @@ -313,6 +313,11 @@ namespace edmNew {

#endif

bool full() const {
int offset = m_v.m_data.size();
return m_v.m_data.capacity()<offset+m_lv.size();
}

void abort() {
m_lv.clear();
}
Expand Down
32 changes: 26 additions & 6 deletions DataFormats/Common/test/DetSetNew_t.cpp
Expand Up @@ -328,6 +328,10 @@ namespace {
n(in), incr(iincr), test(*itest){}

void operator()(DST const & df) {
if (df.id()>1000) {
CPPUNIT_ASSERT(df.size()==0);
return;
}
CPPUNIT_ASSERT(df.id()==20+n);
CPPUNIT_ASSERT(df.size()==n);
std::vector<DST::data_type> v1(n);
Expand All @@ -347,16 +351,21 @@ namespace {
Getter(TestDetSet * itest):ntot(0), test(*itest){}

void fill(TSFF& ff) override {
aborted=false;
try {
int n=ff.id()-20;
CPPUNIT_ASSERT(n>0);
ff.resize(n);
std::copy(test.sv.begin(),test.sv.begin()+n,ff.begin());
ntot+=n;
} catch (edmNew::CapacityExaustedException) {}
if (ff.full()) { ff.abort(); aborted=true;}
else { ntot+=n; }
} catch (edmNew::CapacityExaustedException) {
CPPUNIT_ASSERT("cannot be here"==0);
}
}

unsigned int ntot;
bool aborted=false;
TestDetSet & test;
};

Expand Down Expand Up @@ -502,7 +511,8 @@ using namespace boost::assign;
void TestDetSet::onDemand() {
auto pg = std::make_shared<Getter>(this);
Getter & g = *pg;
std::vector<unsigned int> v; v+= 21,23,25,27;
assert(!g.aborted);
std::vector<unsigned int> v; v+= 21,23,25,27,1020;
DSTV detsets(pg,v,2);
CPPUNIT_ASSERT(g.ntot==0);
CPPUNIT_ASSERT(detsets.onDemand());
Expand All @@ -520,13 +530,23 @@ void TestDetSet::onDemand() {
CPPUNIT_ASSERT(detsets.isValid(21));
CPPUNIT_ASSERT(!detsets.isValid(23));
CPPUNIT_ASSERT(g.ntot==1);
assert(!g.aborted);
}
{
DST df = detsets[25];
CPPUNIT_ASSERT(df.id()==25);
CPPUNIT_ASSERT(df.size()==5);
CPPUNIT_ASSERT(g.ntot==1+5);
assert(!g.aborted);
}
{
DST df = detsets[1020];
CPPUNIT_ASSERT(df.id()==1020);
CPPUNIT_ASSERT(df.size()==0);
CPPUNIT_ASSERT(g.ntot==1+5);
assert(g.aborted);
}

}
catch (edm::Exception const &) {
CPPUNIT_ASSERT("DetSetVector threw when not expected"==0);
Expand All @@ -538,11 +558,11 @@ void TestDetSet::onDemand() {
++i;
auto ds = *di;
auto id = ds.id();
CPPUNIT_ASSERT(id>20&&id<28&& id%2==1);
if (21==id || 25==id) CPPUNIT_ASSERT(ds.isValid());
CPPUNIT_ASSERT(id==1020 || (id>20&&id<28&& id%2==1));
if (1020==id || 21==id || 25==id) CPPUNIT_ASSERT(ds.isValid());
else CPPUNIT_ASSERT(!ds.isValid());
}
CPPUNIT_ASSERT(4==i);
CPPUNIT_ASSERT(5==i);
CPPUNIT_ASSERT(g.ntot==1+5);

// CPPUNIT_ASSERT(std::for_each(detsets.begin(),detsets.end(),VerifyIter(this,1,2)).n==9);
Expand Down
Expand Up @@ -141,12 +141,13 @@ namespace {

#ifdef VIDEBUG
struct Stat {
Stat() : totDet(0), detReady(0),detSet(0),detAct(0),detNoZ(0),totClus(0){}
Stat() : totDet(0), detReady(0),detSet(0),detAct(0),detNoZ(0),detAbrt(0),totClus(0){}
std::atomic<int> totDet; // all dets
std::atomic<int> detReady; // dets "updated"
std::atomic<int> detSet; // det actually set not empty
std::atomic<int> detAct; // det actually set with content
std::atomic<int> detNoZ; // det actually set with content
std::atomic<int> detAbrt; // det aborted
std::atomic<int> totClus; // total number of clusters
};

Expand All @@ -157,9 +158,10 @@ namespace {
void incSet() const { stat.detSet++;}
void incAct() const { stat.detAct++;}
void incNoZ() const { stat.detNoZ++;}
void incAbrt() const { stat.detAbrt++;}
void incClus(int n) const { stat.totClus+=n;}
void printStat() const {
COUT << "VI clusters " << stat.totDet <<','<< stat.detReady <<','<< stat.detSet <<','<< stat.detAct<<','<< stat.detNoZ <<','<< stat.totClus << std::endl;
COUT << "VI clusters " << stat.totDet <<','<< stat.detReady <<','<< stat.detSet <<','<< stat.detAct<<','<< stat.detNoZ <<','<<stat.detAbrt <<','<<stat.totClus << std::endl;
}

#else
Expand All @@ -169,6 +171,7 @@ namespace {
static void incSet() {}
static void incAct() {}
static void incNoZ() {}
static void incAbrt(){}
static void incClus(int){}
static void printStat(){}
#endif
Expand Down Expand Up @@ -459,6 +462,13 @@ try { // edmNew::CapacityExaustedException
clusterizer.stripByStripEnd(state,record);

incAct();

if (record.full()) {
edm::LogError(sistrip::mlRawToCluster_) << "too many Sistrip Clusters to fit space allocated for OnDemand for " << record.id() << ' ' << record.size();
record.abort();
incAbrt();
}

if(!record.empty()) incNoZ();

COUT << "filled " << record.size() << std::endl;
Expand Down