From b2dd7338ad651e6b5367e5cb0694feb96be7ea56 Mon Sep 17 00:00:00 2001 From: wmtan Date: Mon, 15 Feb 2016 20:23:14 +0100 Subject: [PATCH] Implement propagate_const in FWLite --- DataFormats/FWLite/interface/ChainEvent.h | 9 ++-- .../FWLite/interface/DataGetterHelper.h | 11 ++--- DataFormats/FWLite/interface/ESHandle.h | 3 +- DataFormats/FWLite/interface/EntryFinder.h | 2 +- DataFormats/FWLite/interface/Event.h | 8 ++-- DataFormats/FWLite/interface/EventSetup.h | 3 +- DataFormats/FWLite/interface/Handle.h | 4 +- .../FWLite/interface/InternalDataKey.h | 3 +- .../FWLite/interface/LuminosityBlock.h | 4 +- .../FWLite/interface/MultiChainEvent.h | 3 +- DataFormats/FWLite/interface/Run.h | 4 +- DataFormats/FWLite/src/DataGetterHelper.cc | 2 +- DataFormats/FWLite/src/EntryFinder.cc | 2 +- DataFormats/FWLite/src/Event.cc | 8 ++-- DataFormats/FWLite/src/LuminosityBlock.cc | 4 +- DataFormats/FWLite/src/Run.cc | 8 ++-- FWCore/FWLite/interface/BranchMapReader.h | 23 +++++++---- FWCore/FWLite/src/BareRootProductGetter.cc | 2 +- FWCore/FWLite/src/BareRootProductGetter.h | 5 ++- FWCore/FWLite/src/BranchMapReader.cc | 35 ++++++++-------- .../interface/TFWLiteSelector.h | 5 ++- .../interface/TFWLiteSelectorBasic.h | 3 +- .../src/TFWLiteSelectorBasic.cc | 41 ++++++++++++------- .../src/ThingsTSelector.cc | 4 +- .../TFWLiteSelectorTest/src/ThingsTSelector.h | 6 ++- .../src/ThingsTSelector2.h | 6 +-- 26 files changed, 118 insertions(+), 90 deletions(-) diff --git a/DataFormats/FWLite/interface/ChainEvent.h b/DataFormats/FWLite/interface/ChainEvent.h index c4e732a507a26..1906a714b55ed 100644 --- a/DataFormats/FWLite/interface/ChainEvent.h +++ b/DataFormats/FWLite/interface/ChainEvent.h @@ -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 { @@ -100,7 +101,7 @@ namespace fwlite { Long64_t eventIndex() const { return eventIndex_; } virtual Long64_t fileIndex() const { return eventIndex_; } - void setGetter(std::shared_ptr getter){ + void setGetter(std::shared_ptr getter){ event_->setGetter(getter); } @@ -137,11 +138,11 @@ namespace fwlite { void switchToFile(Long64_t); // ---------- member data -------------------------------- std::vector fileNames_; - std::shared_ptr file_; - std::shared_ptr event_; + edm::propagate_const> file_; + edm::propagate_const> event_; Long64_t eventIndex_; std::vector accumulatedSize_; - std::shared_ptr getter_; + edm::propagate_const> getter_; }; diff --git a/DataFormats/FWLite/interface/DataGetterHelper.h b/DataFormats/FWLite/interface/DataGetterHelper.h index 903f275bc9e8e..3f3e5973e7ee0 100644 --- a/DataFormats/FWLite/interface/DataGetterHelper.h +++ b/DataFormats/FWLite/interface/DataGetterHelper.h @@ -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" @@ -79,11 +80,11 @@ namespace fwlite { // ---------- member functions --------------------------- - void setGetter(std::shared_ptr getter) { + void setGetter(std::shared_ptr getter) { getter_ = getter; } - edm::EDProductGetter* getter() { + edm::EDProductGetter const* getter() const { return getter_.get(); } @@ -95,7 +96,7 @@ namespace fwlite { typedef std::map > 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; @@ -110,8 +111,8 @@ namespace fwlite { mutable std::map,std::shared_ptr > idToData_; mutable std::map > bidToData_; - std::shared_ptr historyGetter_; - std::shared_ptr getter_; + edm::propagate_const> historyGetter_; + std::shared_ptr getter_; mutable bool tcTrained_; }; diff --git a/DataFormats/FWLite/interface/ESHandle.h b/DataFormats/FWLite/interface/ESHandle.h index 245915ed64362..1e836b5a7dbef 100644 --- a/DataFormats/FWLite/interface/ESHandle.h +++ b/DataFormats/FWLite/interface/ESHandle.h @@ -25,6 +25,7 @@ // user include files #include "FWCore/Utilities/interface/Exception.h" +#include "FWCore/Utilities/interface/propagate_const.h" // forward declarations namespace fwlite { @@ -77,7 +78,7 @@ class ESHandle // ---------- member data -------------------------------- const T* m_data; - std::shared_ptr m_exception; + std::shared_ptr m_exception; }; } diff --git a/DataFormats/FWLite/interface/EntryFinder.h b/DataFormats/FWLite/interface/EntryFinder.h index 366fe26f08560..7398c0344ad59 100644 --- a/DataFormats/FWLite/interface/EntryFinder.h +++ b/DataFormats/FWLite/interface/EntryFinder.h @@ -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_; diff --git a/DataFormats/FWLite/interface/Event.h b/DataFormats/FWLite/interface/Event.h index abf91fdc33f73..ee244499c3c4a 100644 --- a/DataFormats/FWLite/interface/Event.h +++ b/DataFormats/FWLite/interface/Event.h @@ -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 getter) { return dataHelper_.setGetter(getter);} + void setGetter(std::shared_ptr getter) { return dataHelper_.setGetter(getter);} // ---------- member data -------------------------------- - TFile* file_; + mutable TFile* file_; // TTree* eventTree_; TTree* eventHistoryTree_; // Long64_t eventIndex_; @@ -191,8 +191,8 @@ namespace fwlite { mutable std::vector 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_; diff --git a/DataFormats/FWLite/interface/EventSetup.h b/DataFormats/FWLite/interface/EventSetup.h index 5dc5d624091de..111e0c71b2aa4 100644 --- a/DataFormats/FWLite/interface/EventSetup.h +++ b/DataFormats/FWLite/interface/EventSetup.h @@ -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; @@ -105,7 +106,7 @@ namespace fwlite edm::EventID m_syncedEvent; edm::Timestamp m_syncedTimestamp; - TFile* m_file; + mutable TFile* m_file; mutable std::vector m_records; }; diff --git a/DataFormats/FWLite/interface/Handle.h b/DataFormats/FWLite/interface/Handle.h index fe90fe71033ac..8ce2d782db41c 100644 --- a/DataFormats/FWLite/interface/Handle.h +++ b/DataFormats/FWLite/interface/Handle.h @@ -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; } @@ -263,7 +263,7 @@ class Handle // ---------- member data -------------------------------- const T* data_; - ErrorThrower* errorThrower_; + ErrorThrower const* errorThrower_; }; } diff --git a/DataFormats/FWLite/interface/InternalDataKey.h b/DataFormats/FWLite/interface/InternalDataKey.h index 4936f47dd1b9f..07b5018970305 100644 --- a/DataFormats/FWLite/interface/InternalDataKey.h +++ b/DataFormats/FWLite/interface/InternalDataKey.h @@ -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" @@ -78,7 +79,7 @@ namespace fwlite { }; struct Data { - TBranch* branch_; + edm::propagate_const branch_; Long64_t lastProduct_; edm::ObjectWithDict obj_; // For wrapped object void* pObj_; // ROOT requires the address of the pointer be stable diff --git a/DataFormats/FWLite/interface/LuminosityBlock.h b/DataFormats/FWLite/interface/LuminosityBlock.h index ea689fa1129ff..d82cc6129f3bd 100644 --- a/DataFormats/FWLite/interface/LuminosityBlock.h +++ b/DataFormats/FWLite/interface/LuminosityBlock.h @@ -127,8 +127,8 @@ namespace fwlite { mutable std::vector 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_; diff --git a/DataFormats/FWLite/interface/MultiChainEvent.h b/DataFormats/FWLite/interface/MultiChainEvent.h index 507c7fdc9da1b..cebfa02af48e0 100644 --- a/DataFormats/FWLite/interface/MultiChainEvent.h +++ b/DataFormats/FWLite/interface/MultiChainEvent.h @@ -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 { @@ -160,7 +161,7 @@ class MultiChainEvent: public EventBase std::shared_ptr event1_; // primary files std::shared_ptr event2_; // secondary files - std::shared_ptr getter_; + std::shared_ptr 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. diff --git a/DataFormats/FWLite/interface/Run.h b/DataFormats/FWLite/interface/Run.h index 4a621bbbdaee6..8be5cab9967d8 100644 --- a/DataFormats/FWLite/interface/Run.h +++ b/DataFormats/FWLite/interface/Run.h @@ -120,8 +120,8 @@ namespace fwlite { mutable std::vector 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_; diff --git a/DataFormats/FWLite/src/DataGetterHelper.cc b/DataFormats/FWLite/src/DataGetterHelper.cc index f51f90412373e..29c11fe2148d9 100644 --- a/DataFormats/FWLite/src/DataGetterHelper.cc +++ b/DataFormats/FWLite/src/DataGetterHelper.cc @@ -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 { diff --git a/DataFormats/FWLite/src/EntryFinder.cc b/DataFormats/FWLite/src/EntryFinder.cc index f12c50f471e8c..af1c67c9faa51 100644 --- a/DataFormats/FWLite/src/EntryFinder.cc +++ b/DataFormats/FWLite/src/EntryFinder.cc @@ -105,7 +105,7 @@ namespace fwlite { } void - EntryFinder::fillIndex(BranchMapReader const& branchMap) { + EntryFinder::fillIndex(BranchMapReader& branchMap) { if (empty()) { TTree* meta = dynamic_cast(branchMap.getFile()->Get(edm::poolNames::metaDataTreeName().c_str())); if (nullptr == meta) { diff --git a/DataFormats/FWLite/src/Event.cc b/DataFormats/FWLite/src/Event.cc index aa46bd852e9c2..0b77e845ed0df 100644 --- a/DataFormats/FWLite/src/Event.cc +++ b/DataFormats/FWLite/src/Event.cc @@ -102,7 +102,7 @@ namespace fwlite { return 0U; } - Event* event_; + Event const* event_; }; } // @@ -119,9 +119,9 @@ namespace fwlite { fileVersion_(-1), parameterSetRegistryFilled_(false), dataHelper_(branchMap_.getEventTree(), - std::shared_ptr(new EventHistoryGetter(this)), + std::make_shared(this), std::shared_ptr(&branchMap_,NoDelete()), - std::shared_ptr(new internal::ProductGetter(this)), + std::make_shared(this), true) { if(nullptr == iFile) { throw cms::Exception("NoFile") << "The TFile pointer passed to the constructor was null"; @@ -159,7 +159,7 @@ namespace fwlite { if(fileVersion_ >= 7 && fileVersion_ < 17) { eventHistoryTree_ = dynamic_cast(iFile->Get(edm::poolNames::eventHistoryTreeName().c_str())); } - runFactory_ = std::shared_ptr(new RunFactory()); + runFactory_ = std::make_shared(); } diff --git a/DataFormats/FWLite/src/LuminosityBlock.cc b/DataFormats/FWLite/src/LuminosityBlock.cc index 2197e0912717c..939d444a74a0f 100644 --- a/DataFormats/FWLite/src/LuminosityBlock.cc +++ b/DataFormats/FWLite/src/LuminosityBlock.cc @@ -48,7 +48,7 @@ namespace fwlite { pOldAux_(nullptr), fileVersion_(-1), dataHelper_(branchMap_->getLuminosityBlockTree(), - std::shared_ptr(new LumiHistoryGetter(this)), + std::make_shared(this), branchMap_) { if(nullptr == iFile) { @@ -94,7 +94,7 @@ namespace fwlite { pOldAux_(nullptr), fileVersion_(-1), dataHelper_(branchMap_->getLuminosityBlockTree(), - std::shared_ptr(new LumiHistoryGetter(this)), + std::make_shared(this), branchMap_), runFactory_(runFactory) { diff --git a/DataFormats/FWLite/src/Run.cc b/DataFormats/FWLite/src/Run.cc index 4eebe26e4d139..210c2589e92d5 100644 --- a/DataFormats/FWLite/src/Run.cc +++ b/DataFormats/FWLite/src/Run.cc @@ -47,7 +47,7 @@ namespace fwlite { pOldAux_(nullptr), fileVersion_(-1), dataHelper_(branchMap_->getRunTree(), - std::shared_ptr(new RunHistoryGetter(this)), + std::make_shared(this), branchMap_) { if(nullptr == iFile) { @@ -84,7 +84,7 @@ namespace fwlite { // auxBranch_->SetAddress(&pOldAux_); } branchMap_->updateRun(0); -// getter_ = std::shared_ptr(new ProductGetter(this)); +// getter_ = std::make_shared(this); } Run::Run(std::shared_ptr branchMap): @@ -93,7 +93,7 @@ namespace fwlite { pOldAux_(nullptr), fileVersion_(-1), dataHelper_(branchMap_->getRunTree(), - std::shared_ptr(new RunHistoryGetter(this)), + std::make_shared(this), branchMap_) { if(nullptr == branchMap_->getRunTree()) { @@ -129,7 +129,7 @@ namespace fwlite { // eventHistoryTree_ = dynamic_cast(iFile->Get(edm::poolNames::eventHistoryTreeName().c_str())); // } -// getter_ = std::shared_ptr(new ProductGetter(this)); +// getter_ = std::make_shared(this); } Run::~Run() diff --git a/FWCore/FWLite/interface/BranchMapReader.h b/FWCore/FWLite/interface/BranchMapReader.h index 1a27ca6c10cf6..bf62347d54b96 100644 --- a/FWCore/FWLite/interface/BranchMapReader.h +++ b/FWCore/FWLite/interface/BranchMapReader.h @@ -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; @@ -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 currentFile_; + edm::propagate_const eventTree_; + edm::propagate_const luminosityBlockTree_; + edm::propagate_const runTree_; TUUID fileUUID_; Long_t eventEntry_; Long_t luminosityBlockEntry_; @@ -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_; } @@ -101,7 +106,7 @@ namespace fwlite { // ---------- member data -------------------------------- private: std::unique_ptr newStrategy(TFile* file, int fileVersion); - std::unique_ptr strategy_; + std::unique_ptr strategy_; // Contains caches, so we do not propagate_const int fileVersion_; }; } diff --git a/FWCore/FWLite/src/BareRootProductGetter.cc b/FWCore/FWLite/src/BareRootProductGetter.cc index db8c946966f6b..26779cb0ad8b6 100644 --- a/FWCore/FWLite/src/BareRootProductGetter.cc +++ b/FWCore/FWLite/src/BareRootProductGetter.cc @@ -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 diff --git a/FWCore/FWLite/src/BareRootProductGetter.h b/FWCore/FWLite/src/BareRootProductGetter.h index 0c77b234bc54a..645fad75637cf 100644 --- a/FWCore/FWLite/src/BareRootProductGetter.h +++ b/FWCore/FWLite/src/BareRootProductGetter.h @@ -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" @@ -92,10 +93,10 @@ class BareRootProductGetter : public edm::EDProductGetter { Buffer() : product_(), branch_(), address_(), eventEntry_(-1), class_(nullptr) {} std::shared_ptr product_; - TBranch* branch_; + edm::propagate_const 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 class_; }; BareRootProductGetter(BareRootProductGetter const&); // stop default diff --git a/FWCore/FWLite/src/BranchMapReader.cc b/FWCore/FWLite/src/BranchMapReader.cc index 174e8330aecb0..b44d3e9826dc7 100644 --- a/FWCore/FWLite/src/BranchMapReader.cc +++ b/FWCore/FWLite/src/BranchMapReader.cc @@ -26,6 +26,7 @@ #include "DataFormats/Provenance/interface/ProductRegistry.h" #include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h" #include "FWCore/Utilities/interface/EDMException.h" +#include "FWCore/Utilities/interface/propagate_const.h" #include "TBranch.h" #include "TFile.h" @@ -76,7 +77,7 @@ namespace fwlite { bidToDesc branchDescriptionMap_; std::vector bDesc_; bool mapperFilled_; - std::unique_ptr thinnedAssociationsHelper_; + edm::propagate_const> thinnedAssociationsHelper_; }; Strategy::Strategy(TFile* file, int fileVersion) @@ -222,9 +223,9 @@ namespace fwlite { virtual bool updateMap() override; virtual edm::BranchListIndexes const& branchListIndexes() const override {return dummyBranchListIndexes_;} private: - TBranch* entryInfoBranch_; + edm::propagate_const entryInfoBranch_; edm::EventEntryInfoVector eventEntryInfoVector_; - edm::EventEntryInfoVector* pEventEntryInfoVector_; + edm::EventEntryInfoVector const* pEventEntryInfoVector_; edm::BranchListIndexes dummyBranchListIndexes_; }; @@ -323,10 +324,10 @@ namespace fwlite { virtual edm::BranchID productToBranchID(edm::ProductID const& pid) override; virtual edm::BranchListIndexes const& branchListIndexes() const override {return history_.branchListIndexes();} private: - std::unique_ptr branchIDLists_; - TTree* eventHistoryTree_; + edm::propagate_const> branchIDLists_; + edm::propagate_const eventHistoryTree_; edm::History history_; - edm::History* pHistory_; + edm::History const* pHistory_; }; BranchMapReaderStrategyV11::BranchMapReaderStrategyV11(TFile* file, int fileVersion) @@ -368,7 +369,7 @@ namespace fwlite { throw edm::Exception(edm::errors::EventCorruption) <<"No "<(); edm::BranchIDLists* branchIDListsPtr = branchIDLists_.get(); if(metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != 0) { TBranch* b = metaDataTree->GetBranch(edm::poolNames::branchIDListBranchName().c_str()); @@ -440,10 +441,10 @@ namespace fwlite { virtual edm::BranchID productToBranchID(edm::ProductID const& pid) override; virtual edm::BranchListIndexes const& branchListIndexes() const override {return branchListIndexes_;} private: - std::unique_ptr branchIDLists_; - TTree* eventsTree_; + edm::propagate_const> branchIDLists_; + edm::propagate_const eventsTree_; edm::BranchListIndexes branchListIndexes_; - edm::BranchListIndexes* pBranchListIndexes_; + edm::propagate_const pBranchListIndexes_; }; BranchMapReaderStrategyV17::BranchMapReaderStrategyV17(TFile* file, int fileVersion) @@ -484,7 +485,7 @@ namespace fwlite { throw edm::Exception(edm::errors::EventCorruption) <<"No "<(); edm::ThinnedAssociationsHelper* thinnedAssociationsHelperPtr = thinnedAssociationsHelper_.get(); if(metaDataTree->FindBranch(edm::poolNames::thinnedAssociationsHelperBranchName().c_str()) != nullptr) { TBranch* b = metaDataTree->GetBranch(edm::poolNames::thinnedAssociationsHelperBranchName().c_str()); @@ -492,7 +493,7 @@ namespace fwlite { b->GetEntry(0); } - branchIDLists_.reset(new edm::BranchIDLists); + branchIDLists_ = std::make_unique(); edm::BranchIDLists* branchIDListsPtr = branchIDLists_.get(); if(metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != 0) { TBranch* b = metaDataTree->GetBranch(edm::poolNames::branchIDListBranchName().c_str()); @@ -648,15 +649,15 @@ BranchMapReader::newStrategy(TFile* file, int fileVersion) { std::unique_ptr s; if(fileVersion >= 17) { - s = std::unique_ptr(new internal::BranchMapReaderStrategyV17(file, fileVersion)); + s = std::make_unique(file, fileVersion); } else if(fileVersion >= 11) { - s = std::unique_ptr(new internal::BranchMapReaderStrategyV11(file, fileVersion)); + s = std::make_unique(file, fileVersion); } else if(fileVersion >= 8) { - s = std::unique_ptr(new internal::BranchMapReaderStrategyV8(file, fileVersion)); + s = std::make_unique(file, fileVersion); } else if(fileVersion >= 7) { - s = std::unique_ptr(new internal::BranchMapReaderStrategyV7(file, fileVersion)); + s = std::make_unique(file, fileVersion); } else { - s = std::unique_ptr(new internal::BranchMapReaderStrategyV1(file, fileVersion)); + s = std::make_unique(file, fileVersion); } return s; } diff --git a/FWCore/TFWLiteSelector/interface/TFWLiteSelector.h b/FWCore/TFWLiteSelector/interface/TFWLiteSelector.h index 55e4f7a56b712..560189c9b97b4 100644 --- a/FWCore/TFWLiteSelector/interface/TFWLiteSelector.h +++ b/FWCore/TFWLiteSelector/interface/TFWLiteSelector.h @@ -50,6 +50,7 @@ class TList; // user include files #include "FWCore/TFWLiteSelector/interface/TFWLiteSelectorBasic.h" +#include "FWCore/Utilities/interface/propagate_const.h" // forward declarations template @@ -72,7 +73,7 @@ class TFWLiteSelector : public TFWLiteSelectorBasic const TFWLiteSelector& operator=(const TFWLiteSelector&); // stop default virtual void preProcessing(const TList*in, TList& out) { - worker_.reset(new TWorker(in,out)); + worker_ = std::make_shared(in,out); } virtual void process(const edm::Event& iEvent) { worker_->process(iEvent); @@ -82,7 +83,7 @@ class TFWLiteSelector : public TFWLiteSelectorBasic } // ---------- member data -------------------------------- - std::shared_ptr worker_; + edm::propagate_const> worker_; ClassDef(TFWLiteSelector,2) }; diff --git a/FWCore/TFWLiteSelector/interface/TFWLiteSelectorBasic.h b/FWCore/TFWLiteSelector/interface/TFWLiteSelectorBasic.h index e0ec23a5c58ff..ef43725ea7827 100644 --- a/FWCore/TFWLiteSelector/interface/TFWLiteSelectorBasic.h +++ b/FWCore/TFWLiteSelector/interface/TFWLiteSelectorBasic.h @@ -24,6 +24,7 @@ allows you to access data using an edm::Event. #include "TSelector.h" // user include files +#include "FWCore/Utilities/interface/propagate_const.h" // forward declarations class TFile; @@ -96,7 +97,7 @@ class TFWLiteSelectorBasic : public TSelector void setupNewFile(TFile&); // ---------- member data -------------------------------- - std::shared_ptr m_; + edm::propagate_const> m_; bool everythingOK_; ClassDef(TFWLiteSelectorBasic,2) diff --git a/FWCore/TFWLiteSelector/src/TFWLiteSelectorBasic.cc b/FWCore/TFWLiteSelector/src/TFWLiteSelectorBasic.cc index 7db6fa3f70b9b..be603ec018532 100644 --- a/FWCore/TFWLiteSelector/src/TFWLiteSelectorBasic.cc +++ b/FWCore/TFWLiteSelector/src/TFWLiteSelectorBasic.cc @@ -45,6 +45,7 @@ #include "FWCore/Utilities/interface/ObjectWithDict.h" #include "FWCore/Utilities/interface/TypeWithDict.h" #include "FWCore/Utilities/interface/WrappedClassName.h" +#include "FWCore/Utilities/interface/get_underlying_safe.h" // system include files #include "TBranch.h" @@ -145,26 +146,36 @@ namespace edm { prov_(), pointerToBranchBuffer_(), provRetriever_(new edm::ProductProvenanceRetriever(0)) { - reader_->set(reg_); + reader_->set(reg()); } void setTree(TTree* iTree) { tree_ = iTree; reader_->setTree(iTree); } - TTree* tree_; - std::shared_ptr reg_; - std::shared_ptr phreg_; - std::shared_ptr branchIDListHelper_; - std::shared_ptr thinnedAssociationsHelper_; + + TTree const* tree() const {return get_underlying_safe(tree_);} + TTree*& tree() {return get_underlying_safe(tree_);} + std::shared_ptr reg() const {return get_underlying_safe(reg_);} + std::shared_ptr& reg() {return get_underlying_safe(reg_);} + std::shared_ptr branchIDListHelper() const {return get_underlying_safe(branchIDListHelper_);} + std::shared_ptr& branchIDListHelper() {return get_underlying_safe(branchIDListHelper_);} + std::shared_ptr thinnedAssociationsHelper() const {return get_underlying_safe(thinnedAssociationsHelper_);} + std::shared_ptr& thinnedAssociationsHelper() {return get_underlying_safe(thinnedAssociationsHelper_);} + + edm::propagate_const tree_; + edm::propagate_const> reg_; + edm::propagate_const> phreg_; + edm::propagate_const> branchIDListHelper_; + edm::propagate_const> thinnedAssociationsHelper_; ProcessHistory processNames_; - std::shared_ptr reader_; + edm::propagate_const> reader_; std::vector prov_; - std::vector pointerToBranchBuffer_; + std::vector pointerToBranchBuffer_; FileFormatVersion fileFormatVersion_; - std::shared_ptr provRetriever_; + edm::propagate_const> provRetriever_; edm::ProcessConfiguration pc_; - std::shared_ptr ep_; + edm::propagate_const> ep_; edm::ModuleDescription md_; }; } @@ -240,7 +251,7 @@ TFWLiteSelectorBasic::Notify() { TFile* file = m_->tree_->GetCurrentFile(); if(nullptr == file) { //When in Rome, do as the Romans - TChain* chain = dynamic_cast(m_->tree_); + TChain* chain = dynamic_cast(m_->tree()); if(nullptr == chain) { std::cout << "No file" << std::endl; return kFALSE; @@ -309,9 +320,9 @@ TFWLiteSelectorBasic::Process(Long64_t iEntry) { try { m_->reader_->setEntry(iEntry); auto runAux = std::make_shared(aux.run(), aux.time(), aux.time()); - auto rp = std::make_shared(runAux, m_->reg_, m_->pc_, nullptr, 0); + auto rp = std::make_shared(runAux, m_->reg(), m_->pc_, nullptr, 0); auto lumiAux = std::make_shared(rp->run(), 1, aux.time(), aux.time()); - auto lbp = std::make_shared(lumiAux, m_->reg_, m_->pc_, nullptr, 0); + auto lbp = std::make_shared(lumiAux, m_->reg(), m_->pc_, nullptr, 0); m_->ep_->fillEventPrincipal(*eaux, *m_->phreg_, std::move(eventSelectionIDs), @@ -452,7 +463,7 @@ TFWLiteSelectorBasic::setupNewFile(TFile& iFile) { prod.init(); } - m_->reg_.reset(newReg.release()); + m_->reg().reset(newReg.release()); } edm::ProductRegistry::ProductList& prodList2 = m_->reg_->productListUpdator(); @@ -479,7 +490,7 @@ TFWLiteSelectorBasic::setupNewFile(TFile& iFile) { } m_->branchIDListHelper_->updateFromInput(*branchIDListsPtr); m_->reg_->setFrozen(); - m_->ep_.reset(new edm::EventPrincipal(m_->reg_, m_->branchIDListHelper_, m_->thinnedAssociationsHelper_, m_->pc_, nullptr)); + m_->ep_ = std::make_shared(m_->reg(), m_->branchIDListHelper(), m_->thinnedAssociationsHelper(), m_->pc_, nullptr); everythingOK_ = true; } diff --git a/FWCore/TFWLiteSelectorTest/src/ThingsTSelector.cc b/FWCore/TFWLiteSelectorTest/src/ThingsTSelector.cc index b2b0fc7aea61b..98bf527e6fc32 100644 --- a/FWCore/TFWLiteSelectorTest/src/ThingsTSelector.cc +++ b/FWCore/TFWLiteSelectorTest/src/ThingsTSelector.cc @@ -18,7 +18,7 @@ void ThingsTSelector::begin(TList*&) void ThingsTSelector::preProcessing(const TList*, TList& out ) { if(nullptr != h_a) { out.Remove(h_a); - delete h_a; + delete h_a.get(); h_a = nullptr; } h_a = new TH1F( kA , "a" , 100, 0, 20 ); @@ -26,7 +26,7 @@ void ThingsTSelector::preProcessing(const TList*, TList& out ) { if(nullptr != h_refA) { out.Remove(h_refA); - delete h_refA; + delete h_refA.get(); h_refA = nullptr; } h_refA = new TH1F( kRefA , "refA" , 100, 0, 20 ); diff --git a/FWCore/TFWLiteSelectorTest/src/ThingsTSelector.h b/FWCore/TFWLiteSelectorTest/src/ThingsTSelector.h index 3d9f59246873f..5014278747eb4 100644 --- a/FWCore/TFWLiteSelectorTest/src/ThingsTSelector.h +++ b/FWCore/TFWLiteSelectorTest/src/ThingsTSelector.h @@ -8,8 +8,9 @@ * \author Luca Lista, INFN * */ -#include +#include "TH1.h" #include "FWCore/TFWLiteSelector/interface/TFWLiteSelectorBasic.h" +#include "FWCore/Utilities/interface/propagate_const.h" namespace tfwliteselectortest { class ThingsTSelector : public TFWLiteSelectorBasic { @@ -23,7 +24,8 @@ public : private: /// histograms - TH1F * h_a, *h_refA; + edm::propagate_const h_a; + edm::propagate_const h_refA; ThingsTSelector(ThingsTSelector const&); ThingsTSelector operator=(ThingsTSelector const&); diff --git a/FWCore/TFWLiteSelectorTest/src/ThingsTSelector2.h b/FWCore/TFWLiteSelectorTest/src/ThingsTSelector2.h index 106e15a0b646f..ade5d95e369ff 100644 --- a/FWCore/TFWLiteSelectorTest/src/ThingsTSelector2.h +++ b/FWCore/TFWLiteSelectorTest/src/ThingsTSelector2.h @@ -8,7 +8,7 @@ * \author Luca Lista, INFN * */ -#include +#include "TH1.h" #include "FWCore/TFWLiteSelector/interface/TFWLiteSelector.h" namespace tfwliteselectortest { @@ -16,8 +16,8 @@ namespace tfwliteselectortest { ThingsWorker(const TList*, TList&); void process( const edm::Event& iEvent ); void postProcess(TList&); - TH1F* h_a; - TH1F* h_refA; + edm::propagate_const h_a; + edm::propagate_const h_refA; }; class ThingsTSelector2 : public TFWLiteSelector {