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

Implement propagate_const in FWLite #13200

Merged
merged 1 commit into from
Feb 16, 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
9 changes: 5 additions & 4 deletions DataFormats/FWLite/interface/ChainEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// user include files
#include "DataFormats/FWLite/interface/Event.h"
#include "DataFormats/FWLite/interface/EventBase.h"
#include "FWCore/Utilities/interface/propagate_const.h"

// forward declarations
namespace edm {
Expand Down Expand Up @@ -100,7 +101,7 @@ namespace fwlite {
Long64_t eventIndex() const { return eventIndex_; }
virtual Long64_t fileIndex() const { return eventIndex_; }

void setGetter(std::shared_ptr<edm::EDProductGetter> getter){
void setGetter(std::shared_ptr<edm::EDProductGetter const> getter){
event_->setGetter(getter);
}

Expand Down Expand Up @@ -137,11 +138,11 @@ namespace fwlite {
void switchToFile(Long64_t);
// ---------- member data --------------------------------
std::vector<std::string> fileNames_;
std::shared_ptr<TFile> file_;
std::shared_ptr<Event> event_;
edm::propagate_const<std::shared_ptr<TFile>> file_;
edm::propagate_const<std::shared_ptr<Event>> event_;
Long64_t eventIndex_;
std::vector<Long64_t> accumulatedSize_;
std::shared_ptr<edm::EDProductGetter> getter_;
edm::propagate_const<std::shared_ptr<edm::EDProductGetter>> getter_;

};

Expand Down
11 changes: 6 additions & 5 deletions DataFormats/FWLite/interface/DataGetterHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "DataFormats/FWLite/interface/HistoryGetterBase.h"
#include "DataFormats/FWLite/interface/InternalDataKey.h"
#include "FWCore/FWLite/interface/BranchMapReader.h"
#include "FWCore/Utilities/interface/propagate_const.h"

#include "Rtypes.h"

Expand Down Expand Up @@ -79,11 +80,11 @@ namespace fwlite {

// ---------- member functions ---------------------------

void setGetter(std::shared_ptr<edm::EDProductGetter> getter) {
void setGetter(std::shared_ptr<edm::EDProductGetter const> getter) {
getter_ = getter;
}

edm::EDProductGetter* getter() {
edm::EDProductGetter const* getter() const {
return getter_.get();
}

Expand All @@ -95,7 +96,7 @@ namespace fwlite {
typedef std::map<internal::DataKey, std::shared_ptr<internal::Data> > KeyToDataMap;

internal::Data& getBranchDataFor(std::type_info const&, char const*, char const*, char const*) const;
void getBranchData(edm::EDProductGetter*, Long64_t, internal::Data&) const;
void getBranchData(edm::EDProductGetter const*, Long64_t, internal::Data&) const;
bool getByBranchDescription(edm::BranchDescription const&, Long_t eventEntry, KeyToDataMap::iterator&) const;
edm::WrapperBase const* getByBranchID(edm::BranchID const& bid, Long_t eventEntry) const;
edm::WrapperBase const* wrapperBasePtr(edm::ObjectWithDict const&) const;
Expand All @@ -110,8 +111,8 @@ namespace fwlite {

mutable std::map<std::pair<edm::ProductID, edm::BranchListIndex>,std::shared_ptr<internal::Data> > idToData_;
mutable std::map<edm::BranchID, std::shared_ptr<internal::Data> > bidToData_;
std::shared_ptr<fwlite::HistoryGetterBase> historyGetter_;
std::shared_ptr<edm::EDProductGetter> getter_;
edm::propagate_const<std::shared_ptr<fwlite::HistoryGetterBase>> historyGetter_;
std::shared_ptr<edm::EDProductGetter const> getter_;
mutable bool tcTrained_;
};

Expand Down
3 changes: 2 additions & 1 deletion DataFormats/FWLite/interface/ESHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

// user include files
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/propagate_const.h"

// forward declarations
namespace fwlite {
Expand Down Expand Up @@ -77,7 +78,7 @@ class ESHandle

// ---------- member data --------------------------------
const T* m_data;
std::shared_ptr<cms::Exception> m_exception;
std::shared_ptr<cms::Exception const> m_exception;
};

}
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/FWLite/interface/EntryFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace fwlite {
EntryNumber_t findEvent(edm::RunNumber_t const& run, edm::LuminosityBlockNumber_t const& lumi, edm::EventNumber_t const& event) const;
EntryNumber_t findLumi(edm::RunNumber_t const& run, edm::LuminosityBlockNumber_t const& lumi) const;
EntryNumber_t findRun(edm::RunNumber_t const& run) const;
void fillIndex(BranchMapReader const& branchMap);
void fillIndex(BranchMapReader& branchMap);
static EntryNumber_t const invalidEntry = -1LL;
private:
edm::IndexIntoFile indexIntoFile_;
Expand Down
8 changes: 4 additions & 4 deletions DataFormats/FWLite/interface/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ namespace fwlite {
edm::ProcessHistory const& history() const;
void updateAux(Long_t eventIndex) const;
void fillParameterSetRegistry() const;
void setGetter(std::shared_ptr<edm::EDProductGetter> getter) { return dataHelper_.setGetter(getter);}
void setGetter(std::shared_ptr<edm::EDProductGetter const> getter) { return dataHelper_.setGetter(getter);}

// ---------- member data --------------------------------
TFile* file_;
mutable TFile* file_;
// TTree* eventTree_;
TTree* eventHistoryTree_;
// Long64_t eventIndex_;
Expand All @@ -191,8 +191,8 @@ namespace fwlite {
mutable std::vector<std::string> procHistoryNames_;
mutable edm::EventAuxiliary aux_;
mutable EntryFinder entryFinder_;
edm::EventAuxiliary* pAux_;
edm::EventAux* pOldAux_;
edm::EventAuxiliary const* pAux_;
edm::EventAux const* pOldAux_;
TBranch* auxBranch_;
int fileVersion_;
mutable bool parameterSetRegistryFilled_;
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/FWLite/interface/EventSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
// user include files
#include "DataFormats/Provenance/interface/EventID.h"
#include "DataFormats/Provenance/interface/Timestamp.h"
#include "FWCore/Utilities/interface/propagate_const.h"

// forward declarations
class TFile;
Expand Down Expand Up @@ -105,7 +106,7 @@ namespace fwlite
edm::EventID m_syncedEvent;
edm::Timestamp m_syncedTimestamp;

TFile* m_file;
mutable TFile* m_file;

mutable std::vector<Record*> m_records;
};
Expand Down
4 changes: 2 additions & 2 deletions DataFormats/FWLite/interface/Handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class Handle
const T* temp = data_;
data_ = iOther.data_;
iOther.data_ = temp;
ErrorThrower* tempE = errorThrower_;
ErrorThrower const* tempE = errorThrower_;
errorThrower_ = iOther.errorThrower_;
iOther.errorThrower_ = tempE;
}
Expand All @@ -263,7 +263,7 @@ class Handle

// ---------- member data --------------------------------
const T* data_;
ErrorThrower* errorThrower_;
ErrorThrower const* errorThrower_;
};

}
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/FWLite/interface/InternalDataKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "FWCore/Utilities/interface/ObjectWithDict.h"
#include "FWCore/Utilities/interface/TypeID.h"
#include "FWCore/Utilities/interface/propagate_const.h"

#include "TBranch.h"

Expand Down Expand Up @@ -78,7 +79,7 @@ namespace fwlite {
};

struct Data {
TBranch* branch_;
edm::propagate_const<TBranch*> branch_;
Long64_t lastProduct_;
edm::ObjectWithDict obj_; // For wrapped object
void* pObj_; // ROOT requires the address of the pointer be stable
Expand Down
4 changes: 2 additions & 2 deletions DataFormats/FWLite/interface/LuminosityBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ namespace fwlite {
mutable std::vector<std::string> procHistoryNames_;
mutable edm::LuminosityBlockAuxiliary aux_;
mutable EntryFinder entryFinder_;
edm::LuminosityBlockAuxiliary* pAux_;
edm::LuminosityBlockAux* pOldAux_;
edm::LuminosityBlockAuxiliary const* pAux_;
edm::LuminosityBlockAux const* pOldAux_;
TBranch* auxBranch_;
int fileVersion_;

Expand Down
3 changes: 2 additions & 1 deletion DataFormats/FWLite/interface/MultiChainEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// user include files
#include "DataFormats/FWLite/interface/EventBase.h"
#include "DataFormats/FWLite/interface/ChainEvent.h"
#include "FWCore/Utilities/interface/propagate_const.h"

// forward declarations
namespace edm {
Expand Down Expand Up @@ -160,7 +161,7 @@ class MultiChainEvent: public EventBase

std::shared_ptr<ChainEvent> event1_; // primary files
std::shared_ptr<ChainEvent> event2_; // secondary files
std::shared_ptr<internal::MultiProductGetter> getter_;
std::shared_ptr<internal::MultiProductGetter const> getter_;

// speed up secondary file access with a (run range)_1 ---> index_2 map,
// when the files are sorted by run,event within the file.
Expand Down
4 changes: 2 additions & 2 deletions DataFormats/FWLite/interface/Run.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ namespace fwlite {
mutable std::vector<std::string> procHistoryNames_;
mutable edm::RunAuxiliary aux_;
mutable EntryFinder entryFinder_;
edm::RunAuxiliary* pAux_;
edm::RunAux* pOldAux_;
edm::RunAuxiliary const* pAux_;
edm::RunAux const* pOldAux_;
TBranch* auxBranch_;
int fileVersion_;

Expand Down
2 changes: 1 addition & 1 deletion DataFormats/FWLite/src/DataGetterHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace fwlite {
}

void
DataGetterHelper::getBranchData(edm::EDProductGetter* iGetter,
DataGetterHelper::getBranchData(edm::EDProductGetter const* iGetter,
Long64_t eventEntry,
internal::Data& iData) const
{
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/FWLite/src/EntryFinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace fwlite {
}

void
EntryFinder::fillIndex(BranchMapReader const& branchMap) {
EntryFinder::fillIndex(BranchMapReader& branchMap) {
if (empty()) {
TTree* meta = dynamic_cast<TTree*>(branchMap.getFile()->Get(edm::poolNames::metaDataTreeName().c_str()));
if (nullptr == meta) {
Expand Down
8 changes: 4 additions & 4 deletions DataFormats/FWLite/src/Event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace fwlite {
return 0U;
}

Event* event_;
Event const* event_;
};
}
//
Expand All @@ -119,9 +119,9 @@ namespace fwlite {
fileVersion_(-1),
parameterSetRegistryFilled_(false),
dataHelper_(branchMap_.getEventTree(),
std::shared_ptr<HistoryGetterBase>(new EventHistoryGetter(this)),
std::make_shared<EventHistoryGetter>(this),
std::shared_ptr<BranchMapReader>(&branchMap_,NoDelete()),
std::shared_ptr<edm::EDProductGetter>(new internal::ProductGetter(this)),
std::make_shared<internal::ProductGetter>(this),
true) {
if(nullptr == iFile) {
throw cms::Exception("NoFile") << "The TFile pointer passed to the constructor was null";
Expand Down Expand Up @@ -159,7 +159,7 @@ namespace fwlite {
if(fileVersion_ >= 7 && fileVersion_ < 17) {
eventHistoryTree_ = dynamic_cast<TTree*>(iFile->Get(edm::poolNames::eventHistoryTreeName().c_str()));
}
runFactory_ = std::shared_ptr<RunFactory>(new RunFactory());
runFactory_ = std::make_shared<RunFactory>();

}

Expand Down
4 changes: 2 additions & 2 deletions DataFormats/FWLite/src/LuminosityBlock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace fwlite {
pOldAux_(nullptr),
fileVersion_(-1),
dataHelper_(branchMap_->getLuminosityBlockTree(),
std::shared_ptr<HistoryGetterBase>(new LumiHistoryGetter(this)),
std::make_shared<LumiHistoryGetter>(this),
branchMap_)
{
if(nullptr == iFile) {
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace fwlite {
pOldAux_(nullptr),
fileVersion_(-1),
dataHelper_(branchMap_->getLuminosityBlockTree(),
std::shared_ptr<HistoryGetterBase>(new LumiHistoryGetter(this)),
std::make_shared<LumiHistoryGetter>(this),
branchMap_),
runFactory_(runFactory)
{
Expand Down
8 changes: 4 additions & 4 deletions DataFormats/FWLite/src/Run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace fwlite {
pOldAux_(nullptr),
fileVersion_(-1),
dataHelper_(branchMap_->getRunTree(),
std::shared_ptr<HistoryGetterBase>(new RunHistoryGetter(this)),
std::make_shared<RunHistoryGetter>(this),
branchMap_)
{
if(nullptr == iFile) {
Expand Down Expand Up @@ -84,7 +84,7 @@ namespace fwlite {
// auxBranch_->SetAddress(&pOldAux_);
}
branchMap_->updateRun(0);
// getter_ = std::shared_ptr<edm::EDProductGetter>(new ProductGetter(this));
// getter_ = std::make_shared<ProductGetter>(this);
}

Run::Run(std::shared_ptr<BranchMapReader> branchMap):
Expand All @@ -93,7 +93,7 @@ namespace fwlite {
pOldAux_(nullptr),
fileVersion_(-1),
dataHelper_(branchMap_->getRunTree(),
std::shared_ptr<HistoryGetterBase>(new RunHistoryGetter(this)),
std::make_shared<RunHistoryGetter>(this),
branchMap_)
{
if(nullptr == branchMap_->getRunTree()) {
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace fwlite {
// eventHistoryTree_ = dynamic_cast<TTree*>(iFile->Get(edm::poolNames::eventHistoryTreeName().c_str()));
// }

// getter_ = std::shared_ptr<edm::EDProductGetter>(new ProductGetter(this));
// getter_ = std::make_shared<ProductGetter>(this);
}

Run::~Run()
Expand Down
23 changes: 14 additions & 9 deletions FWCore/FWLite/interface/BranchMapReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// user include files
#include "DataFormats/Provenance/interface/BranchDescription.h"
#include "DataFormats/Provenance/interface/BranchListIndex.h"
#include "FWCore/Utilities/interface/propagate_const.h"

// forward declarations
class TFile;
Expand Down Expand Up @@ -54,10 +55,10 @@ namespace fwlite {
virtual const edm::BranchListIndexes& branchListIndexes() const = 0;
virtual const edm::ThinnedAssociationsHelper& thinnedAssociationsHelper() const = 0;

TFile* currentFile_;
TTree* eventTree_;
TTree* luminosityBlockTree_;
TTree* runTree_;
edm::propagate_const<TFile*> currentFile_;
edm::propagate_const<TTree*> eventTree_;
edm::propagate_const<TTree*> luminosityBlockTree_;
edm::propagate_const<TTree*> runTree_;
TUUID fileUUID_;
Long_t eventEntry_;
Long_t luminosityBlockEntry_;
Expand Down Expand Up @@ -86,10 +87,14 @@ namespace fwlite {
int getFileVersion(TFile* file);
int getFileVersion() const { return fileVersion_;}

TFile* getFile() const { return strategy_->currentFile_; }
TTree* getEventTree() const { return strategy_->eventTree_; }
TTree* getLuminosityBlockTree() const { return strategy_->luminosityBlockTree_; }
TTree* getRunTree() const { return strategy_->runTree_; }
TFile const* getFile() const { return strategy_->currentFile_; }
TFile* getFile() { return strategy_->currentFile_; }
TTree const* getEventTree() const { return strategy_->eventTree_; }
TTree* getEventTree() { return strategy_->eventTree_; }
TTree const* getLuminosityBlockTree() const { return strategy_->luminosityBlockTree_; }
TTree* getLuminosityBlockTree() { return strategy_->luminosityBlockTree_; }
TTree const* getRunTree() const { return strategy_->runTree_; }
TTree* getRunTree() { return strategy_->runTree_; }
TUUID getFileUUID() const { return strategy_->fileUUID_; }
Long_t getEventEntry() const { return strategy_->eventEntry_; }
Long_t getLuminosityBlockEntry() const { return strategy_->luminosityBlockEntry_; }
Expand All @@ -101,7 +106,7 @@ namespace fwlite {
// ---------- member data --------------------------------
private:
std::unique_ptr<internal::BMRStrategy> newStrategy(TFile* file, int fileVersion);
std::unique_ptr<internal::BMRStrategy> strategy_;
std::unique_ptr<internal::BMRStrategy> strategy_; // Contains caches, so we do not propagate_const
int fileVersion_;
};
}
Expand Down
2 changes: 1 addition & 1 deletion FWCore/FWLite/src/BareRootProductGetter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ BareRootProductGetter::createNewBuffer(edm::BranchID const& branchID) const {
//connect the instance to the branch
//void* address = wrapperObj.Address();
Buffer b(prod, branch, address, rootClassType);
idToBuffers_[branchID] = b;
idToBuffers_[branchID] = std::move(b);

//As of 5.13 ROOT expects the memory address held by the pointer passed to
// SetAddress to be valid forever
Expand Down
5 changes: 3 additions & 2 deletions FWCore/FWLite/src/BareRootProductGetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DataFormats/Common/interface/WrapperBase.h"
#include "DataFormats/Common/interface/EDProductGetter.h"
#include "FWCore/FWLite/interface/BranchMapReader.h"
#include "FWCore/Utilities/interface/propagate_const.h"

// system include files
#include "Rtypes.h"
Expand Down Expand Up @@ -92,10 +93,10 @@ class BareRootProductGetter : public edm::EDProductGetter {
Buffer() : product_(), branch_(), address_(), eventEntry_(-1), class_(nullptr) {}

std::shared_ptr<edm::WrapperBase const> product_;
TBranch* branch_;
edm::propagate_const<TBranch*> branch_;
void* address_; //the address to pass to Root since as of 5.13 they cache that info
Long_t eventEntry_; //the event Entry used with the last GetEntry call
TClass* class_;
edm::propagate_const<TClass*> class_;
};

BareRootProductGetter(BareRootProductGetter const&); // stop default
Expand Down