From 20b7735c1bfe236891a5078b4020a3cea69f12b1 Mon Sep 17 00:00:00 2001 From: Danilo Piparo <danilo.piparo@cern.ch> Date: Tue, 25 Apr 2017 17:19:38 +0200 Subject: [PATCH] [TDF] Formatting --- .../inc/ROOT/TDataFrameInterface.hxx | 26 +++++++++++-------- tree/treeplayer/src/TDFNodes.cxx | 3 ++- tutorials/dataframe/tdf007_snapshot.C | 10 +++++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tree/treeplayer/inc/ROOT/TDataFrameInterface.hxx b/tree/treeplayer/inc/ROOT/TDataFrameInterface.hxx index 3ea4752ca9e..58202d3b783 100644 --- a/tree/treeplayer/inc/ROOT/TDataFrameInterface.hxx +++ b/tree/treeplayer/inc/ROOT/TDataFrameInterface.hxx @@ -36,9 +36,9 @@ using TmpBranchBasePtr_t = std::shared_ptr<ROOT::Detail::TDataFrameBranchBase>; namespace ROOT { namespace Detail { - // StringParameter<T> is a std::string for any type T - template<typename T> - using StringParameter = const std::string&; +// StringParameter<T> is a std::string for any type T +template <typename T> +using StringParameter = const std::string &; } namespace Detail { @@ -243,8 +243,9 @@ public: /// \param[in] treename The name of the TTree /// \param[in] filename The name of the TFile /// \param[in] bnames The list of names of the branches to be written - template<typename...Args> - TDataFrameInterface<ROOT::Detail::TDataFrameImpl> Snapshot(const std::string& treename, const std::string& filename, const BranchNames_t &bnames) + template <typename... Args> + TDataFrameInterface<ROOT::Detail::TDataFrameImpl> Snapshot(const std::string &treename, const std::string &filename, + const BranchNames_t &bnames) { using TypeInd_t = typename ROOT::Internal::TDFTraitsUtils::TGenStaticSeq<sizeof...(Args)>::Type_t; return SnapshotImpl<Args...>(treename, filename, bnames, TypeInd_t()); @@ -1043,18 +1044,20 @@ protected: /// since there are no copies, the address of the value passed by reference /// is the address pointing to the storage of the read/created object in/by /// the TTreeReaderValue/TemporaryBranch - template<typename...Args, int...S> - TDataFrameInterface<ROOT::Detail::TDataFrameImpl> SnapshotImpl(const std::string& treename, const std::string& filename, const BranchNames_t &bnames, ROOT::Internal::TDFTraitsUtils::TStaticSeq<S...> /*dummy*/) { + template <typename... Args, int... S> + TDataFrameInterface<ROOT::Detail::TDataFrameImpl> SnapshotImpl( + const std::string &treename, const std::string &filename, const BranchNames_t &bnames, + ROOT::Internal::TDFTraitsUtils::TStaticSeq<S...> /*dummy*/) + { std::unique_ptr<TFile> ofile(TFile::Open(filename.c_str(), "RECREATE")); TTree t(treename.c_str(), treename.c_str()); - auto fillTree = [&t,&bnames](Args&...args) - { + auto fillTree = [&t, &bnames](Args &... args) { static bool firstEvt = true; if (firstEvt) { // hack to call TTree::Branch on all variadic template arguments - std::initializer_list<int> expander = { (t.Branch(bnames[S].c_str(), &args),0)...,0 }; + std::initializer_list<int> expander = {(t.Branch(bnames[S].c_str(), &args), 0)..., 0}; (void)expander; // avoid unused variable warnings for older compilers such as gcc 4.9 firstEvt = false; @@ -1068,7 +1071,8 @@ protected: // Now we mimic a constructor for the TDataFrame. We cannot invoke it here // since this would introduce a cyclic headers dependency. - TDataFrameInterface<ROOT::Detail::TDataFrameImpl> snapshotTDF(std::make_shared<ROOT::Detail::TDataFrameImpl>(nullptr, bnames)); + TDataFrameInterface<ROOT::Detail::TDataFrameImpl> snapshotTDF( + std::make_shared<ROOT::Detail::TDataFrameImpl>(nullptr, bnames)); auto chain = new TChain(treename.c_str()); chain->Add(filename.c_str()); snapshotTDF.fProxiedPtr->SetTree(std::shared_ptr<TTree>(static_cast<TTree *>(chain))); diff --git a/tree/treeplayer/src/TDFNodes.cxx b/tree/treeplayer/src/TDFNodes.cxx index b8e5c9ae2f1..dc9b7fdb8d2 100644 --- a/tree/treeplayer/src/TDFNodes.cxx +++ b/tree/treeplayer/src/TDFNodes.cxx @@ -120,7 +120,8 @@ unsigned int TSlotStack::Pop() } TDataFrameImpl::TDataFrameImpl(TTree *tree, const BranchNames_t &defaultBranches) - : fTree(std::shared_ptr<TTree>(tree,[](TTree*){})), fDefaultBranches(defaultBranches), fNSlots(ROOT::Internal::GetNSlots()) + : fTree(std::shared_ptr<TTree>(tree, [](TTree *) {})), fDefaultBranches(defaultBranches), + fNSlots(ROOT::Internal::GetNSlots()) { } diff --git a/tutorials/dataframe/tdf007_snapshot.C b/tutorials/dataframe/tdf007_snapshot.C index 312c5188178..d1d89c417ba 100644 --- a/tutorials/dataframe/tdf007_snapshot.C +++ b/tutorials/dataframe/tdf007_snapshot.C @@ -51,7 +51,13 @@ int tdf007_snapshot() // ## Enrich the dataset // Build some temporary branches: we'll write them out auto d2 = d_cut.Define("b1_square", "b1 * b1") - .Define("b2_vector", [](float b2){ std::vector<float> v; for (int i=0;i < 3; i++) v.push_back(i); return v;}, {"b2"}); + .Define("b2_vector", + [](float b2) { + std::vector<float> v; + for (int i = 0; i < 3; i++) v.push_back(i); + return v; + }, + {"b2"}); // ## Write it to disk in ROOT format // We now write to disk a new dataset with one of the variables originally present in the tree and the new variables. @@ -59,7 +65,7 @@ int tdf007_snapshot() // Open the new file and list the branches of the tree TFile f(outFileName); - TTree* t; + TTree *t; f.GetObject(treeName, t); for (auto branch : *t->GetListOfBranches()) { std::cout << "Branch: " << branch->GetName() << std::endl; -- GitLab