Skip to content

Commit

Permalink
Merge pull request cms-sw#944 from Dr15Jones/noMutablesFromSourceInEv…
Browse files Browse the repository at this point in the history
…entPrincipal

Multithreading fixes -- No mutables from source in EventPrincipal.
  • Loading branch information
ktf committed Oct 1, 2013
2 parents f00a5d2 + dc80a00 commit 4e22899
Show file tree
Hide file tree
Showing 31 changed files with 344 additions and 256 deletions.
24 changes: 19 additions & 5 deletions DataFormats/Provenance/interface/BranchIDListHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,41 @@
#include "DataFormats/Provenance/interface/ProvenanceFwd.h"

#include <map>
#include <vector>
#include <limits>

namespace edm {

class BranchIDListHelper {
public:
typedef std::pair<BranchListIndex, ProductIndex> IndexPair;
typedef std::multimap<BranchID, IndexPair> BranchIDToIndexMap;
typedef std::map<BranchListIndex, BranchListIndex> BranchListIndexMapper;

BranchIDListHelper();

//CMS-THREADING called when a new file is opened
bool updateFromInput(BranchIDLists const& bidlists);
void updateRegistries(ProductRegistry& reg);
void fixBranchListIndexes(BranchListIndexes& indexes);
///Called by sources to convert their read indexes into the indexes used by the job
void fixBranchListIndexes(BranchListIndexes& indexes) const;

BranchIDLists const& branchIDLists() const {return branchIDLists_;}
void updateFromRegistry(ProductRegistry const& reg);

//CMS-THREADING this is called in SubJob::beginJob
BranchIDLists& mutableBranchIDLists() {return branchIDLists_;}

//Used by the EventPrincipal
BranchIDLists const& branchIDLists() const {return branchIDLists_;}
BranchIDToIndexMap const& branchIDToIndexMap() const {return branchIDToIndexMap_;}
BranchListIndex producedBranchListIndex() const {return producedBranchListIndex_;}
bool hasProducedProducts() const {
return producedBranchListIndex_ != std::numeric_limits<BranchListIndex>::max();
}

private:
BranchIDLists branchIDLists_;
BranchIDToIndexMap branchIDToIndexMap_;
BranchListIndexMapper branchListIndexMapper_;
std::vector<BranchListIndex> inputIndexToJobIndex_;
BranchListIndex producedBranchListIndex_;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*----------------------------------------------------------------------
BranchMapper: Manages the per event/lumi/run per product provenance.
ProductProvenanceRetriever: Manages the per event/lumi/run per product provenance.
----------------------------------------------------------------------*/
#include "DataFormats/Provenance/interface/BranchID.h"
Expand All @@ -19,44 +19,50 @@ BranchMapper: Manages the per event/lumi/run per product provenance.
#include <set>

/*
BranchMapper
ProductProvenanceRetriever
*/

namespace edm {
class ProvenanceReaderBase;

class BranchMapper : private boost::noncopyable {
class ProductProvenanceRetriever : private boost::noncopyable {
public:
BranchMapper();
explicit ProductProvenanceRetriever(unsigned int iTransitionIndex);
#ifndef __GCCXML__
explicit BranchMapper(std::unique_ptr<ProvenanceReaderBase> reader);
explicit ProductProvenanceRetriever(std::unique_ptr<ProvenanceReaderBase> reader);
#endif

~BranchMapper();
~ProductProvenanceRetriever();

ProductProvenance const* branchIDToProvenance(BranchID const& bid) const;

void insertIntoSet(ProductProvenance const& provenanceProduct) const;

void mergeMappers(boost::shared_ptr<BranchMapper> other);
void mergeProvenanceRetrievers(boost::shared_ptr<ProductProvenanceRetriever> other);

void deepSwap(ProductProvenanceRetriever&);

void reset();
private:
void readProvenance() const;
void setTransitionIndex(unsigned int transitionIndex) {
transitionIndex_=transitionIndex;
}

typedef std::set<ProductProvenance> eiSet;

mutable eiSet entryInfoSet_;
boost::shared_ptr<BranchMapper> nextMapper_;
boost::shared_ptr<ProductProvenanceRetriever> nextRetriever_;
mutable boost::shared_ptr<ProvenanceReaderBase> provenanceReader_;
unsigned int transitionIndex_;
mutable bool delayedRead_;
mutable boost::scoped_ptr<ProvenanceReaderBase> provenanceReader_;
};

class ProvenanceReaderBase {
public:
ProvenanceReaderBase() {}
virtual ~ProvenanceReaderBase();
virtual void readProvenance(BranchMapper const& mapper) const = 0;
virtual void readProvenance(ProductProvenanceRetriever const& mapper, unsigned int transitionIndex) const = 0;
};

}
Expand Down
7 changes: 0 additions & 7 deletions DataFormats/Provenance/interface/ProductRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ namespace edm {

bool productProduced(BranchType branchType) const {return transient_.productProduced_[branchType];}
bool anyProductProduced() const {return transient_.anyProductProduced_;}
BranchListIndex producedBranchListIndex() const {return transient_.producedBranchListIndex_;}

void setProducedBranchListIndex(BranchListIndex blix) {
transient_.producedBranchListIndex_ = blix;
}

std::vector<std::string> const& missingDictionaries() const {
return transient_.missingDictionaries_;
Expand Down Expand Up @@ -147,8 +142,6 @@ namespace edm {

std::map<BranchID, ProductHolderIndex> branchIDToIndex_;

BranchListIndex producedBranchListIndex_;

std::vector<std::string> missingDictionaries_;
};

Expand Down
8 changes: 4 additions & 4 deletions DataFormats/Provenance/interface/Provenance.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ existence.
----------------------------------------------------------------------*/

#include "DataFormats/Provenance/interface/BranchDescription.h"
#include "DataFormats/Provenance/interface/BranchMapper.h"
#include "DataFormats/Provenance/interface/ProductProvenanceRetriever.h"
#include "DataFormats/Provenance/interface/ParameterSetID.h"
#include "DataFormats/Provenance/interface/ProcessHistory.h"
#include "DataFormats/Provenance/interface/Parentage.h"
Expand Down Expand Up @@ -61,7 +61,7 @@ namespace edm {
std::string const& processName() const {return product().processName();}
std::string const& productInstanceName() const {return product().productInstanceName();}
std::string const& friendlyClassName() const {return product().friendlyClassName();}
boost::shared_ptr<BranchMapper> const& store() const {return store_;}
boost::shared_ptr<ProductProvenanceRetriever> const& store() const {return store_;}
ProcessHistory const& processHistory() const {return *processHistory_;}
bool getProcessConfiguration(ProcessConfiguration& pc) const;
ReleaseVersion releaseVersion() const;
Expand All @@ -71,7 +71,7 @@ namespace edm {

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

void setStore(boost::shared_ptr<BranchMapper> store) const {store_ = store;}
void setStore(boost::shared_ptr<ProductProvenanceRetriever> store) const {store_ = store;}

void setProcessHistory(ProcessHistory const& ph) {processHistory_ = &ph;}

Expand All @@ -97,7 +97,7 @@ namespace edm {
ProcessHistory const* processHistory_; // We don't own this
mutable bool productProvenanceValid_;
mutable boost::shared_ptr<ProductProvenance> productProvenancePtr_;
mutable boost::shared_ptr<BranchMapper> store_;
mutable boost::shared_ptr<ProductProvenanceRetriever> store_;
};

inline
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/Provenance/interface/ProvenanceFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace edm {
class RunAuxiliary;
class RunID;
class Timestamp;
class BranchMapper;
class ProductProvenanceRetriever;
}

namespace cms {
Expand Down
28 changes: 17 additions & 11 deletions DataFormats/Provenance/src/BranchIDListHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
#include "DataFormats/Provenance/interface/ProductRegistry.h"
#include "FWCore/Utilities/interface/Algorithms.h"

#include <cassert>

namespace edm {

BranchIDListHelper::BranchIDListHelper() :
branchIDLists_(),
branchIDToIndexMap_(),
branchListIndexMapper_() {}
inputIndexToJobIndex_(),
producedBranchListIndex_(std::numeric_limits<BranchListIndex>::max())
{}

bool
BranchIDListHelper:: updateFromInput(BranchIDLists const& bidlists) {
BranchIDListHelper::updateFromInput(BranchIDLists const& bidlists) {
//The BranchIDLists is a list of lists
// this routine compares bidlists to branchIDLists_ to see if a list
// in branchIDLists_ is already in bidlist and if it isn't we insert
// that new list into branchIDLists_
bool unchanged = true;
branchListIndexMapper_.clear();
typedef BranchIDLists::const_iterator Iter;
for(Iter it = bidlists.begin(), itEnd = bidlists.end(); it != itEnd; ++it) {
inputIndexToJobIndex_.clear();
inputIndexToJobIndex_.resize(bidlists.size());
for(auto it = bidlists.begin(), itEnd = bidlists.end(); it != itEnd; ++it) {
BranchListIndex oldBlix = it - bidlists.begin();
Iter j = find_in_all(branchIDLists_, *it);
auto j = find_in_all(branchIDLists_, *it);
BranchListIndex blix = j - branchIDLists_.begin();
if(j == branchIDLists_.end()) {
branchIDLists_.push_back(*it);
Expand All @@ -30,7 +34,7 @@ namespace edm {
branchIDToIndexMap_.insert(std::make_pair(BranchID(*i), std::make_pair(blix, pix)));
}
}
branchListIndexMapper_.insert(std::make_pair(oldBlix, blix));
inputIndexToJobIndex_[oldBlix]=blix;
if(oldBlix != blix) {
unchanged = false;
}
Expand All @@ -39,7 +43,7 @@ namespace edm {
}

void
BranchIDListHelper::updateRegistries(ProductRegistry& preg) {
BranchIDListHelper::updateFromRegistry(ProductRegistry const& preg) {
BranchIDList bidlist;
// Add entries for current process for ProductID to BranchID mapping.
for(ProductRegistry::ProductList::const_iterator it = preg.productList().begin(), itEnd = preg.productList().end();
Expand All @@ -52,7 +56,8 @@ namespace edm {
}
if(!bidlist.empty()) {
BranchListIndex blix = branchIDLists_.size();
preg.setProducedBranchListIndex(blix);
producedBranchListIndex_ = blix;
//preg.setProducedBranchListIndex(blix);
branchIDLists_.push_back(bidlist);
for(BranchIDList::const_iterator i = bidlist.begin(), iEnd = bidlist.end(); i != iEnd; ++i) {
ProductIndex pix = i - bidlist.begin();
Expand All @@ -62,9 +67,10 @@ namespace edm {
}

void
BranchIDListHelper::fixBranchListIndexes(BranchListIndexes& indexes) {
BranchIDListHelper::fixBranchListIndexes(BranchListIndexes& indexes) const {
for(BranchListIndex& i : indexes) {
i = branchListIndexMapper_[i];
assert(i<inputIndexToJobIndex_.size());
i = inputIndexToJobIndex_[i];
}
}
}
74 changes: 0 additions & 74 deletions DataFormats/Provenance/src/BranchMapper.cc

This file was deleted.

Loading

0 comments on commit 4e22899

Please sign in to comment.