Skip to content

Commit

Permalink
Make all registry data members non-mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
wmtan committed Jul 23, 2013
1 parent 7251e9d commit ec80129
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 91 deletions.
5 changes: 2 additions & 3 deletions DataFormats/FWLite/src/Event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,8 @@ Event::history() const {
TBranch* b = meta->GetBranch(edm::poolNames::processHistoryBranchName().c_str());
b->SetAddress(&pPhv);
b->GetEntry(0);
for (edm::ProcessHistoryVector::const_iterator i = historyVector.begin(), e = historyVector.end();
i != e; ++i) {
historyMap_.insert(std::make_pair(i->id(), *i));
for (auto& history : historyVector) {
historyMap_.insert(std::make_pair(history.setProcessHistoryID(), history));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions DataFormats/FWLite/src/LuminosityBlock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,8 @@ LuminosityBlock::history() const
TBranch* b = meta->GetBranch(edm::poolNames::processHistoryBranchName().c_str());
b->SetAddress(&pPhv);
b->GetEntry(0);
for (edm::ProcessHistoryVector::const_iterator i = historyVector.begin(), e = historyVector.end();
i != e; ++i) {
historyMap_.insert(std::make_pair(i->id(), *i));
for (auto& history : historyVector) {
historyMap_.insert(std::make_pair(history.setProcessHistoryID(), history));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions DataFormats/FWLite/src/Run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ Run::history() const
TBranch* b = meta->GetBranch(edm::poolNames::processHistoryBranchName().c_str());
b->SetAddress(&pPhv);
b->GetEntry(0);
for (edm::ProcessHistoryVector::const_iterator i = historyVector.begin(), e = historyVector.end();
i != e; ++i) {
historyMap_.insert(std::make_pair(i->id(), *i));
for (auto& history : historyVector) {
historyMap_.insert(std::make_pair(history.setProcessHistoryID(), history));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/Provenance/interface/EventEntryDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace edm {
void write(std::ostream& os) const;

std::vector<BranchID> const& parents() const {return parents_;}
std::vector<BranchID> & parents() {return parents_;}

void setParents(std::vector<BranchID> const& parents) {parents_ = parents;}

private:

Expand Down
16 changes: 5 additions & 11 deletions DataFormats/Provenance/interface/Parentage.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,24 @@ namespace edm {

~Parentage() {}

// Only the 'salient attributes' are encoded into the ID.
ParentageID id() const;

void write(std::ostream& os) const;

std::vector<BranchID> const& parents() const {return parents_;}
std::vector<BranchID> & parents() {return parents_;}
void swap(Parentage& other) {parents_.swap(other.parents_); parentageID().swap(other.parentageID());}

std::vector<BranchID>& parentsForUpdate() {return parents_;}
void setParents(std::vector<BranchID> const& parents) {parents_ = parents;}
void swap(Parentage& other) {parents_.swap(other.parents_);}
void initializeTransients() {transient_.reset();}

struct Transients {
Transients() : parentageID_() {}
void reset() {parentageID_.reset();}
mutable ParentageID parentageID_;
Transients() {}
void reset() {}
};


private:
ParentageID& parentageID() const {return transient_.parentageID_;}
// The Branch IDs of the parents
std::vector<BranchID> parents_;
Transients transient_;

};

// Free swap function
Expand Down
5 changes: 3 additions & 2 deletions DataFormats/Provenance/interface/ProcessConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace edm {

void setParameterSetID(ParameterSetID const& pSetID);

ProcessConfigurationID setProcessConfigurationID();

void reduce();

void initializeTransients() {transient_.reset();}
Expand All @@ -42,12 +44,11 @@ namespace edm {
pcid_.reset();
isCurrentProcess_ = false;
}
mutable ProcessConfigurationID pcid_;
ProcessConfigurationID pcid_;
bool isCurrentProcess_;
};

private:
ProcessConfigurationID const& pcid() const {return transient_.pcid_;}
void setPCID(ProcessConfigurationID const& pcid) {transient_.pcid_ = pcid;}
bool isCurrentProcess() const {return transient_.isCurrentProcess_;}
void setCurrentProcess() {transient_.isCurrentProcess_ = true;}
Expand Down
5 changes: 3 additions & 2 deletions DataFormats/Provenance/interface/ProcessHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace edm {

collection_type const& data() const {return data_;}
ProcessHistoryID id() const;
ProcessHistoryID setProcessHistoryID();

// Return true, and fill in config appropriately, if the a process
// with the given name is recorded in this ProcessHistory. Return
Expand All @@ -82,11 +83,11 @@ namespace edm {
struct Transients {
Transients() : phid_() {}
void reset() {phid_.reset();}
mutable ProcessHistoryID phid_;
ProcessHistoryID phid_;
};

private:
ProcessHistoryID& phid() const {return transient_.phid_;}
ProcessHistoryID& phid() {return transient_.phid_;}
collection_type data_;
Transients transient_;
};
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/Provenance/src/FullHistoryToReducedHistoryMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace edm {
// ProcessHistoryID is strangely also defined as the ID of the empty
// Process History (maybe that should be fixed ...).
ProcessHistory ph;
ph.setProcessHistoryID();
std::pair<ProcessHistoryID, ProcessHistoryID> newEntry(ph.id(), ph.id());
std::pair<Map::iterator, bool> result = cache_.insert(newEntry);
previous_ = result.first;
Expand All @@ -36,7 +37,7 @@ namespace edm {
<< "Contact a Framework developer\n";
}
ph.reduce();
std::pair<ProcessHistoryID, ProcessHistoryID> newEntry(fullID, ph.id());
std::pair<ProcessHistoryID, ProcessHistoryID> newEntry(fullID, ph.setProcessHistoryID());
std::pair<Map::iterator, bool> result = cache_.insert(newEntry);
previous_ = result.first;
return result.first->second;
Expand Down
32 changes: 10 additions & 22 deletions DataFormats/Provenance/src/Parentage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,24 @@
----------------------------------------------------------------------*/

namespace edm {
Parentage::Parentage() :
parents_()
{}
Parentage::Parentage() : parents_() {
}

Parentage::Parentage(std::vector<BranchID> const& parents) :
parents_(parents)
{}
parents_(parents) {
}

ParentageID
Parentage::id() const {
// This implementation is ripe for optimization.
if(parentageID().isValid()) {
return parentageID();
}
std::ostringstream oss;
for (std::vector<BranchID>::const_iterator
i = parents_.begin(),
e = parents_.end();
i != e;
++i)
{
oss << *i << ' ';
}
for (auto const& parent : parents_) {
oss << parent << ' ';
}

std::string stringrep = oss.str();
cms::Digest md5alg(stringrep);
ParentageID tmp(md5alg.digest().toString());
parentageID().swap(tmp);
return parentageID();
ParentageID id(md5alg.digest().toString());
return id;
}

void
Expand All @@ -47,7 +36,6 @@ namespace edm {

bool
operator==(Parentage const& a, Parentage const& b) {
return
a.parents() == b.parents();
return a.parents() == b.parents();
}
}
19 changes: 13 additions & 6 deletions DataFormats/Provenance/src/ProcessConfiguration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ namespace edm {

ProcessConfigurationID
ProcessConfiguration::id() const {
if(pcid().isValid()) {
return pcid();
if(transient_.pcid_.isValid()) {
return transient_.pcid_;
}
// This implementation is ripe for optimization.
std::ostringstream oss;
oss << *this;
std::string stringrep = oss.str();
cms::Digest md5alg(stringrep);
ProcessConfigurationID tmp(md5alg.digest().toString());
transient_.pcid_.swap(tmp);
return pcid();
ProcessConfigurationID pcid(md5alg.digest().toString());
return pcid;
}

void
Expand All @@ -71,6 +70,14 @@ namespace edm {
parameterSetID_ = pSetID;
}

ProcessConfigurationID
ProcessConfiguration::setProcessConfigurationID() {
if(!transient_.pcid_.isValid()) {
transient_.pcid_ = id();
}
return transient_.pcid_;
}

void
ProcessConfiguration::reduce() {
// Skip to the part of the release version just after
Expand All @@ -82,7 +89,7 @@ namespace edm {
while(iter != iEnd && isdigit(*iter) == 0) ++iter;
while(iter != iEnd && isdigit(*iter) != 0) ++iter;
if (iter == iEnd) return;
setPCID(ProcessConfigurationID());
transient_.pcid_ = ProcessConfigurationID();
releaseVersion_.erase(iter,iEnd);
}

Expand Down
18 changes: 12 additions & 6 deletions DataFormats/Provenance/src/ProcessHistory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

#include "DataFormats/Provenance/interface/ProcessHistory.h"


namespace edm {
ProcessHistoryID
ProcessHistory::id() const {
if(phid().isValid()) {
return phid();
if(transient_.phid_.isValid()) {
return transient_.phid_;
}
// This implementation is ripe for optimization.
// We do not use operator<< because it does not write out everything.
Expand All @@ -24,9 +23,16 @@ namespace edm {
}
std::string stringrep = oss.str();
cms::Digest md5alg(stringrep);
ProcessHistoryID tmp(md5alg.digest().toString());
phid().swap(tmp);
return phid();
ProcessHistoryID phID(md5alg.digest().toString());
return phID;
}

ProcessHistoryID
ProcessHistory::setProcessHistoryID() {
if(!transient_.phid_.isValid()) {
transient_.phid_ = id();
}
return transient_.phid_;
}

bool
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/Provenance/src/ProductProvenance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace edm {
parentageID_(),
transient_() {
parentagePtr() = boost::shared_ptr<Parentage>(new Parentage);
parentagePtr()->parents() = parents;
parentagePtr()->setParents(parents);
parentageID_ = parentagePtr()->id();
ParentageRegistry::instance()->insertMapped(*parentagePtr());
}
Expand Down
6 changes: 3 additions & 3 deletions DataFormats/Provenance/test/EntryDescription_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ int main() {
edm::Parentage ed2;
assert(ed1 == ed2);

ed2.parents() = std::vector<edm::BranchID>(1);
ed2.setParents(std::vector<edm::BranchID>(1));
edm::Parentage ed3;
ed3.parents() = std::vector<edm::BranchID>(2);
ed3.setParents(std::vector<edm::BranchID>(2));

try {
edm::ParentageID id1 = ed1.id();
Expand All @@ -27,7 +27,7 @@ int main() {
assert(ed2 != ed3);

edm::Parentage ed4;
ed4.parents() = std::vector<edm::BranchID>(1);
ed4.setParents(std::vector<edm::BranchID>(1));
edm::ParentageID id4 = ed4.id();
assert(ed4 == ed2);
assert (id4 == id2);
Expand Down
2 changes: 1 addition & 1 deletion FWCore/Framework/src/HistoryAppender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace edm {
checkProcessHistory(newProcessHistory, pc);
newProcessHistory.push_back(pc);
registry->insertMapped(newProcessHistory);
ProcessHistoryID newProcessHistoryID = newProcessHistory.id();
ProcessHistoryID newProcessHistoryID = newProcessHistory.setProcessHistoryID();
CachedHistory newValue(inputProcessHistory,
registry->getMapped(newProcessHistoryID),
newProcessHistoryID);
Expand Down
1 change: 1 addition & 0 deletions FWCore/Framework/src/Schedule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ namespace edm {
proc_pset.registerIt();
pset::Registry::instance()->extra().setID(proc_pset.id());
processConfiguration->setParameterSetID(proc_pset.id());
processConfiguration->setProcessConfigurationID();

initializeEarlyDelete(opts,preg,subProcPSet);

Expand Down
Loading

0 comments on commit ec80129

Please sign in to comment.