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

Snapshot uses existing TDirectory when MT enabled #4649

Merged
merged 14 commits into from Dec 3, 2019
Merged
2 changes: 1 addition & 1 deletion core/base/inc/TDirectory.h
Expand Up @@ -172,7 +172,7 @@ class TDirectory : public TNamed {
virtual Bool_t IsModified() const { return kFALSE; }
virtual Bool_t IsWritable() const { return kFALSE; }
void ls(Option_t *option="") const override;
virtual TDirectory *mkdir(const char *name, const char *title="");
virtual TDirectory *mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory = kFALSE);
virtual TFile *OpenFile(const char * /*name*/, Option_t * /*option*/ = "",
const char * /*ftitle*/ = "", Int_t /*compress*/ = 1,
Int_t /*netopt*/ = 0) {return nullptr;}
Expand Down
16 changes: 15 additions & 1 deletion core/base/src/TDirectory.cxx
Expand Up @@ -1015,6 +1015,7 @@ void TDirectory::FillFullPath(TString& buf) const
///
/// Returns 0 in case of error or if a sub-directory (hierarchy) with the requested
/// name already exists.
/// returnExistingDirectory returns a pointer to an already existing sub-directory with the same name.
/// Returns a pointer to the created sub-directory or to the top sub-directory of
/// the hierarchy (in the above example, the returned TDirectory * always points
/// to "a").
Expand All @@ -1028,9 +1029,22 @@ void TDirectory::FillFullPath(TString& buf) const
/// gDirectory->cd("b");
/// gDirectory->mkdir("d");
/// ~~~
/// or
/// ~~~ {.cpp}
/// TFile * file = new TFile("afile","RECREATE");
/// file->mkdir("a");
/// file->cd("a");
/// gDirectory->mkdir("b/c");
/// gDirectory->mkdir("b/d", "", true);
/// ~~~

TDirectory *TDirectory::mkdir(const char *name, const char *title)
TDirectory *TDirectory::mkdir(const char *name, const char *title, Bool_t returnExistingDirectory)
{
if (returnExistingDirectory) {
auto existingdir = GetDirectory(name);
if (existingdir)
return existingdir;
}
if (!name || !title || !name[0]) return nullptr;
if (!title[0]) title = name;
TDirectory *newdir = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion io/io/inc/TDirectoryFile.h
Expand Up @@ -103,7 +103,7 @@ class TDirectoryFile : public TDirectory {
Bool_t IsModified() const override { return fModified; }
Bool_t IsWritable() const override { return fWritable; }
void ls(Option_t *option="") const override;
TDirectory *mkdir(const char *name, const char *title="") override;
TDirectory *mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory = kFALSE) override;
TFile *OpenFile(const char *name, Option_t *option= "",
const char *ftitle = "", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose,
Int_t netopt = 0) override;
Expand Down
11 changes: 8 additions & 3 deletions io/io/src/TDirectoryFile.cxx
Expand Up @@ -1186,17 +1186,22 @@ TFile *TDirectoryFile::OpenFile(const char *name, Option_t *option,const char *f
///
/// Returns 0 in case of error or if a sub-directory (hierarchy) with the requested
/// name already exists.
/// returnExistingDirectory returns a pointer to an already existing sub-directory instead of 0.
/// Returns a pointer to the created sub-directory or to the top sub-directory of
/// the hierarchy (in the above example, the returned TDirectory * always points
/// to "a").

TDirectory *TDirectoryFile::mkdir(const char *name, const char *title)
TDirectory *TDirectoryFile::mkdir(const char *name, const char *title, Bool_t returnExistingDirectory)
{
if (!name || !title || !name[0]) return nullptr;
if (!title[0]) title = name;
if (GetKey(name)) {
Error("mkdir","An object with name %s exists already",name);
return nullptr;
if (returnExistingDirectory)
return (TDirectoryFile*) GetKey(name)->ReadObj();
else {
Error("mkdir","An object with name %s exists already",name);
return nullptr;
}
}
TDirectoryFile *newdir = nullptr;
if (const char *slash = strchr(name,'/')) {
Expand Down
3 changes: 2 additions & 1 deletion tree/dataframe/inc/ROOT/RDF/ActionHelpers.hxx
Expand Up @@ -1293,7 +1293,8 @@ public:
}
TDirectory *treeDirectory = fOutputFiles[slot].get();
if (!fDirName.empty()) {
treeDirectory = fOutputFiles[slot]->mkdir(fDirName.c_str());
// call returnExistingDirectory=true since MT can end up making this call multiple times
treeDirectory = fOutputFiles[slot]->mkdir(fDirName.c_str(), "", true);
eguiraud marked this conversation as resolved.
Show resolved Hide resolved
}
// re-create output tree as we need to create its branches again, with new input variables
// TODO we could instead create the output tree and its branches, change addresses of input variables in each task
Expand Down
2 changes: 1 addition & 1 deletion tree/dataframe/inc/ROOT/RDF/InterfaceUtils.hxx
Expand Up @@ -67,7 +67,7 @@ namespace TTraits = ROOT::TypeTraits;
namespace RDFInternal = ROOT::Internal::RDF;

using HeadNode_t = ::ROOT::RDF::RResultPtr<RInterface<RLoopManager, void>>;
HeadNode_t CreateSnaphotRDF(const ColumnNames_t &validCols,
HeadNode_t CreateSnapshotRDF(const ColumnNames_t &validCols,
std::string_view treeName,
std::string_view fileName,
bool isLazy,
Expand Down
2 changes: 1 addition & 1 deletion tree/dataframe/inc/ROOT/RDF/RInterface.hxx
Expand Up @@ -2451,7 +2451,7 @@ private:

fLoopManager->Book(actionPtr.get());

return RDFInternal::CreateSnaphotRDF(validCols, fullTreename, filename, options.fLazy, *fLoopManager,
return RDFInternal::CreateSnapshotRDF(validCols, fullTreename, filename, options.fLazy, *fLoopManager,
std::move(actionPtr));
}

Expand Down
2 changes: 1 addition & 1 deletion tree/dataframe/src/RDFInterfaceUtils.cxx
Expand Up @@ -118,7 +118,7 @@ std::set<std::string> GetPotentialColumnNames(const std::string &expr)
// the one in the vector
class RActionBase;

HeadNode_t CreateSnaphotRDF(const ColumnNames_t &validCols,
HeadNode_t CreateSnapshotRDF(const ColumnNames_t &validCols,
std::string_view treeName,
std::string_view fileName,
bool isLazy,
Expand Down