52
52
#include " ROOT/RNTupleDS.hxx"
53
53
#include " ROOT/RNTupleWriter.hxx" // for SnapshotRNTupleHelper
54
54
#endif
55
+ #include " ROOT/RTTreeDS.hxx"
55
56
56
57
#include < algorithm>
57
58
#include < functional>
@@ -1530,12 +1531,15 @@ class R__CLING_PTRCHECK(off) SnapshotTTreeHelper : public RActionImpl<SnapshotTT
1530
1531
std::vector<void *> fBranchAddresses ; // Addresses of objects associated to output branches
1531
1532
RBranchSet fOutputBranches ;
1532
1533
std::vector<bool > fIsDefine ;
1534
+ ROOT::Detail::RDF::RLoopManager *fOutputLoopManager ;
1535
+ ROOT::RDF::RDataSource *fInputDataSource ;
1533
1536
1534
1537
public:
1535
1538
using ColumnTypes_t = TypeList<ColTypes...>;
1536
1539
SnapshotTTreeHelper (std::string_view filename, std::string_view dirname, std::string_view treename,
1537
1540
const ColumnNames_t &vbnames, const ColumnNames_t &bnames, const RSnapshotOptions &options,
1538
- std::vector<bool > &&isDefine)
1541
+ std::vector<bool > &&isDefine, ROOT::Detail::RDF::RLoopManager *loopManager,
1542
+ ROOT::RDF::RDataSource *inputDataSource)
1539
1543
: fFileName (filename),
1540
1544
fDirName (dirname),
1541
1545
fTreeName (treename),
@@ -1544,7 +1548,9 @@ public:
1544
1548
fOutputBranchNames (ReplaceDotWithUnderscore (bnames)),
1545
1549
fBranches (vbnames.size (), nullptr ),
1546
1550
fBranchAddresses (vbnames.size (), nullptr ),
1547
- fIsDefine (std::move (isDefine))
1551
+ fIsDefine (std::move (isDefine)),
1552
+ fOutputLoopManager (loopManager),
1553
+ fInputDataSource (inputDataSource)
1548
1554
{
1549
1555
EnsureValidSnapshotTTreeOutput (fOptions , fTreeName , fFileName );
1550
1556
}
@@ -1571,6 +1577,8 @@ public:
1571
1577
{
1572
1578
if (r)
1573
1579
fInputTree = r->GetTree ();
1580
+ else if (auto treeDS = dynamic_cast <ROOT::Internal::RDF::RTTreeDS *>(fInputDataSource ))
1581
+ fInputTree = treeDS->GetTree ();
1574
1582
fBranchAddressesNeedReset = true ;
1575
1583
}
1576
1584
@@ -1650,6 +1658,10 @@ public:
1650
1658
// must destroy the TTree first, otherwise TFile will delete it too leading to a double delete
1651
1659
fOutputTree .reset ();
1652
1660
fOutputFile ->Close ();
1661
+
1662
+ // Now connect the data source to the loop manager so it can be used for further processing
1663
+ auto fullTreeName = fDirName .empty () ? fTreeName : fDirName + ' /' + fTreeName ;
1664
+ fOutputLoopManager ->SetDataSource (std::make_unique<ROOT::Internal::RDF::RTTreeDS>(fullTreeName, fFileName ));
1653
1665
}
1654
1666
1655
1667
std::string GetActionName () { return " Snapshot" ; }
@@ -1673,8 +1685,15 @@ public:
1673
1685
SnapshotTTreeHelper MakeNew (void *newName, std::string_view /* variation*/ = " nominal" )
1674
1686
{
1675
1687
const std::string finalName = *reinterpret_cast <const std::string *>(newName);
1676
- return SnapshotTTreeHelper{
1677
- finalName, fDirName , fTreeName , fInputBranchNames , fOutputBranchNames , fOptions , std::vector<bool >(fIsDefine )};
1688
+ return SnapshotTTreeHelper{finalName,
1689
+ fDirName ,
1690
+ fTreeName ,
1691
+ fInputBranchNames ,
1692
+ fOutputBranchNames ,
1693
+ fOptions ,
1694
+ std::vector<bool >(fIsDefine ),
1695
+ fOutputLoopManager ,
1696
+ fInputDataSource };
1678
1697
}
1679
1698
};
1680
1699
@@ -1699,12 +1718,16 @@ class R__CLING_PTRCHECK(off) SnapshotTTreeHelperMT : public RActionImpl<Snapshot
1699
1718
std::vector<std::vector<void *>> fBranchAddresses ;
1700
1719
std::vector<RBranchSet> fOutputBranches ;
1701
1720
std::vector<bool > fIsDefine ;
1721
+ ROOT::Detail::RDF::RLoopManager *fOutputLoopManager ;
1722
+ ROOT::RDF::RDataSource *fInputDataSource ;
1702
1723
1703
1724
public:
1704
1725
using ColumnTypes_t = TypeList<ColTypes...>;
1726
+
1705
1727
SnapshotTTreeHelperMT (const unsigned int nSlots, std::string_view filename, std::string_view dirname,
1706
1728
std::string_view treename, const ColumnNames_t &vbnames, const ColumnNames_t &bnames,
1707
- const RSnapshotOptions &options, std::vector<bool > &&isDefine)
1729
+ const RSnapshotOptions &options, std::vector<bool > &&isDefine,
1730
+ ROOT::Detail::RDF::RLoopManager *loopManager, ROOT::RDF::RDataSource *inputDataSource)
1708
1731
: fNSlots (nSlots),
1709
1732
fOutputFiles (fNSlots ),
1710
1733
fOutputTrees (fNSlots ),
@@ -1719,7 +1742,9 @@ public:
1719
1742
fBranches (fNSlots , std::vector<TBranch *>(vbnames.size (), nullptr )),
1720
1743
fBranchAddresses (fNSlots , std::vector<void *>(vbnames.size (), nullptr )),
1721
1744
fOutputBranches (fNSlots ),
1722
- fIsDefine (std::move (isDefine))
1745
+ fIsDefine (std::move (isDefine)),
1746
+ fOutputLoopManager (loopManager),
1747
+ fInputDataSource (inputDataSource)
1723
1748
{
1724
1749
EnsureValidSnapshotTTreeOutput (fOptions , fTreeName , fFileName );
1725
1750
}
@@ -1766,7 +1791,9 @@ public:
1766
1791
if (r) {
1767
1792
// not an empty-source RDF
1768
1793
fInputTrees [slot] = r->GetTree ();
1769
- }
1794
+ } else if (auto treeDS = dynamic_cast <ROOT::Internal::RDF::RTTreeDS *>(fInputDataSource ))
1795
+ fInputTrees [slot] = treeDS->GetTree ();
1796
+
1770
1797
fBranchAddressesNeedReset [slot] = 1 ; // reset first event flag for this slot
1771
1798
}
1772
1799
@@ -1855,6 +1882,10 @@ public:
1855
1882
// flush all buffers to disk by destroying the TBufferMerger
1856
1883
fOutputFiles .clear ();
1857
1884
fMerger .reset ();
1885
+
1886
+ // Now connect the data source to the loop manager so it can be used for further processing
1887
+ auto fullTreeName = fDirName .empty () ? fTreeName : fDirName + ' /' + fTreeName ;
1888
+ fOutputLoopManager ->SetDataSource (std::make_unique<ROOT::Internal::RDF::RTTreeDS>(fullTreeName, fFileName ));
1858
1889
}
1859
1890
1860
1891
std::string GetActionName () { return " Snapshot" ; }
@@ -1878,8 +1909,16 @@ public:
1878
1909
SnapshotTTreeHelperMT MakeNew (void *newName, std::string_view /* variation*/ = " nominal" )
1879
1910
{
1880
1911
const std::string finalName = *reinterpret_cast <const std::string *>(newName);
1881
- return SnapshotTTreeHelperMT{fNSlots , finalName, fDirName , fTreeName ,
1882
- fInputBranchNames , fOutputBranchNames , fOptions , std::vector<bool >(fIsDefine )};
1912
+ return SnapshotTTreeHelperMT{fNSlots ,
1913
+ finalName,
1914
+ fDirName ,
1915
+ fTreeName ,
1916
+ fInputBranchNames ,
1917
+ fOutputBranchNames ,
1918
+ fOptions ,
1919
+ std::vector<bool >(fIsDefine ),
1920
+ fOutputLoopManager ,
1921
+ fInputDataSource };
1883
1922
}
1884
1923
};
1885
1924
@@ -1907,7 +1946,7 @@ class R__CLING_PTRCHECK(off) SnapshotRNTupleHelper : public RActionImpl<Snapshot
1907
1946
std::unique_ptr<TFile> fOutputFile {nullptr };
1908
1947
1909
1948
RSnapshotOptions fOptions ;
1910
- ROOT::Detail::RDF::RLoopManager *fLoopManager ;
1949
+ ROOT::Detail::RDF::RLoopManager *fOutputLoopManager ;
1911
1950
ColumnNames_t fInputFieldNames ; // This contains the resolved aliases
1912
1951
ColumnNames_t fOutputFieldNames ;
1913
1952
std::unique_ptr<ROOT::Experimental::RNTupleWriter> fWriter {nullptr };
@@ -1925,7 +1964,7 @@ public:
1925
1964
fDirName (dirname),
1926
1965
fNTupleName (ntuplename),
1927
1966
fOptions (options),
1928
- fLoopManager (lm),
1967
+ fOutputLoopManager (lm),
1929
1968
fInputFieldNames (vfnames),
1930
1969
fOutputFieldNames (ReplaceDotWithUnderscore (fnames)),
1931
1970
fIsDefine (std::move (isDefine))
@@ -1939,7 +1978,7 @@ public:
1939
1978
SnapshotRNTupleHelper &operator =(SnapshotRNTupleHelper &&) = default ;
1940
1979
~SnapshotRNTupleHelper ()
1941
1980
{
1942
- if (!fNTupleName .empty () && !fLoopManager ->GetDataSource () && fOptions .fLazy )
1981
+ if (!fNTupleName .empty () && !fOutputLoopManager ->GetDataSource () && fOptions .fLazy )
1943
1982
Warning (" Snapshot" , " A lazy Snapshot action was booked but never triggered." );
1944
1983
}
1945
1984
@@ -1999,7 +2038,7 @@ public:
1999
2038
{
2000
2039
fWriter .reset ();
2001
2040
// We can now set the data source of the loop manager for the RDataFrame that is returned by the Snapshot call.
2002
- fLoopManager ->SetDataSource (
2041
+ fOutputLoopManager ->SetDataSource (
2003
2042
std::make_unique<ROOT::Experimental::RNTupleDS>(fDirName + " /" + fNTupleName , fFileName ));
2004
2043
}
2005
2044
@@ -2029,7 +2068,7 @@ public:
2029
2068
fInputFieldNames ,
2030
2069
fOutputFieldNames ,
2031
2070
fOptions ,
2032
- fLoopManager ,
2071
+ fOutputLoopManager ,
2033
2072
std::vector<bool >(fIsDefine )};
2034
2073
}
2035
2074
};
0 commit comments