17 #include "cetlib_except/exception.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
23 #include <string_view>
25 #include <type_traits>
48 static constexpr
const char* TestDirName =
" PlotSandbox invalid name! ";
52 TDirectory* testDir = dir.make<TDirectory>(TestDirName, TestDirName);
54 throw cet::exception(
"PlotSandbox") <<
"TFileDirectoryHelper::create() "
55 "failed to figure out the ROOT directory!\n";
57 TDirectory* pROOTdir = testDir->GetMotherDir();
58 MF_LOG_DEBUG(
"TFileDirectoryHelper")
59 <<
"icarus::trigger::PlotSandbox::TFileDirectoryHelper::create(): "
60 <<
"found parent directory: '" << pROOTdir->GetName() <<
"'";
65 return {
dir, pROOTdir };
75 for (
auto& subbox:
util::values(subBoxes)) subbox->setParent(newParent);
81 art::TFileDirectory parentDir,
82 std::string
name, std::string desc
84 : fData(
std::move(name),
std::move(desc),
102 {
return fData.parent? (fData.parent->ID() +
'/' +
name()):
name(); }
107 (std::string
const&
name)
const
109 std::string
const sandboxName = processedSandboxName();
110 return sandboxName.empty()? name: name +
'_' + sandboxName;
116 (std::string
const& title)
const
118 std::string
const sandboxDesc = processedSandboxDesc();
119 return sandboxDesc.empty()? title: title +
' ' + sandboxDesc;
126 std::vector<TDirectory const*> subDirectories;
129 for (
auto& subbox: subSandboxes()) {
130 if (!subbox.empty())
return false;
131 subDirectories.push_back(subbox.getDirectory());
134 auto const isSubDirectory = [b=subDirectories.begin(),
e=subDirectories.end()]
137 auto dir =
dynamic_cast<TDirectory
const*
>(obj);
138 return dir && std::find(b,
e, dir) !=
e;
143 for (TObject
const* obj: *(getDirectory()->GetList()))
144 if (!isSubDirectory(obj))
return false;
147 if (getDirectory()->GetListOfKeys()->GetSize())
return false;
156 {
return findSandbox(*
this, name); }
160 {
return findSandbox(*
this, name); }
166 {
return demandSandbox(*
this, name); }
170 {
return demandSandbox(*
this, name); }
176 auto const it = fData.subBoxes.find(name);
177 if (it == fData.subBoxes.end())
return false;
180 auto&& subbox = std::move(it->second);
181 if (subbox->getDirectory())
delete subbox->getDirectory();
182 if (getDirectory()) getDirectory()->Delete((name +
";*").c_str());
185 fData.subBoxes.erase(it);
200 (std::string
const& title)
const
212 auto const tbegin = title.begin();
213 auto const tend = title.end();
215 while (atend != tend) {
216 if ((*atend ==
';') && ((atend == tbegin) || (*std::prev(atend) !=
'\\')))
221 return processTitle({ tbegin, atend }).append(atend, tend);
229 std::string processed;
232 if (!hasName())
return processed;
235 if (fData.parent) processed +=
'_' + fData.parent->processedSandboxName();
244 std::string processed;
247 if (hasDescription()) processed += description();
249 if (fData.parent) processed +=
' ' + fData.parent->processedSandboxDesc();
257 (std::string
const&
path,
char sep )
260 auto const iSep = path.rfind(sep);
261 if (iSep == std::string::npos)
return { {}, path };
262 else return { path.substr(0U, iSep), path.substr(iSep + 1) };
269 (std::initializer_list<std::string> pathElements,
char sep )
273 auto stripSep = [sep](std::string
const&
s) -> std::string_view {
276 ((
s.length() > 1) && (
s.back() == sep))?
s.length() - 1:
s.length()
280 auto iElem = pathElements.begin();
281 auto const eend = pathElements.end();
282 auto const&
first = stripSep(*iElem);
284 while (++iElem != eend) {
285 auto const& elem = stripSep(*iElem);
286 if (elem.empty())
continue;
287 if (elem.front() != sep)
s.push_back(sep);
std::string ID() const
Returns a string ID for this sandbox.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
TFileDirectoryHelper outputDir
Output ROOT directory of the sandbox.
static std::string joinPath(std::initializer_list< std::string > pathElements, char sep= '/')
static TFileDirectoryHelper create(art::TFileDirectory parentDir, std::string const &subdir, std::string const &dirTitle="")
Creates a helper managing a subdirectory of parentDir.
struct icarus::trigger::PlotSandbox::Data_t fData
static std::pair< std::string, std::string > splitPath(std::string const &path, char sep= '/')
bool deleteSubSandbox(std::string const &name)
Deletes the subbox with the specified name and its directory.
static auto * findSandbox(SandboxType &sandbox, std::string const &name)
Helper function for findSandbox() implementations.
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
virtual std::string processName(std::string const &name) const
Processes the specified string as it were a name.
bool empty() const
Returns if the sandbox is empty (neither it nor subboxes hold objects).
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
virtual std::string processedSandboxName() const
virtual std::string processedSandboxDesc() const
PlotSandbox(art::TFileDirectory parentDir, std::string name, std::string desc)
Constructor: specifies all sandbox characteristics.
void resetSubboxParents(PlotSandbox const *newParent)
std::string processPlotTitle(std::string const &title) const
Applies title processing only at the title part of the string.
then echo File list $list not found else cat $list while read file do echo $file sed s
static auto & demandSandbox(SandboxType &sandbox, std::string const &name)
Helper function for demandSandbox() implementations.
Definition of util::values() and util::const_values().
bool empty(FixedBins< T, C > const &) noexcept
A helper to manage ROOT objects in a art::TFileDirectory.
virtual std::string processTitle(std::string const &title) const
Processes the specified string as it were a description or title.
A helper to manage ROOT objects with consistent naming.
Contains both a art::TFileDirectory and the TDirectory it manages.