35 std::string
dbg (
const Sample& obj,
unsigned verbosity)
38 result +=
"Sample:name=" + obj.name();
39 if (
dynamic_cast<const SampleGrid*
>(&obj))
41 if (verbosity % 10 > 0)
48 if (verbosity % 10 > 0)
49 result +=
",tags=" +
dbg (obj.tags(), verbosity / 10);
50 if (verbosity % 10 > 1)
53 for (std::size_t iter = 0, end = obj.numFiles();
55 result += obj.fileName (iter) +
"\n";
64 testInvariant ()
const
81 const std::string& Sample ::
91 name (std::string val_name)
95 throw std::logic_error
96 (
"SH::Sample::name: cannot change name of sample \""
97 + m_name +
"\" after it has been registered in a SampleHandler"
98 " (or otherwise locked via lockName)");
100 m_name = std::move (val_name);
115 std::size_t Sample ::
119 return getNumFiles();
124 std::string Sample ::
125 fileName (
const std::size_t
index)
const
130 std::string result = getFileName (
index);
138 std::unique_ptr<SampleLocal> Sample ::
142 return doMakeLocal ();
147 const TagList& Sample ::
157 tags (
const TagList&
tags)
166 addTag (
const std::string& tag)
175 updateLocation (
const std::string& from,
const std::string& to)
178 doUpdateLocation (from, to);
183 MetaObject *Sample ::
192 const MetaObject *Sample ::
201 std::vector<std::string> Sample ::
202 makeFileList ()
const
205 return doMakeFileList ();
215 std::vector<std::string>
files = makeFileList ();
218 if (treeName.empty())
219 throw std::runtime_error (
"sample " + name() +
" does not have a tree name associated");
220 std::unique_ptr<TChain> result (
new TChain (treeName.c_str()));
221 for (std::vector<std::string>::const_iterator
file =
files.begin(),
223 result->AddFile (
file->c_str());
224 return result.release();
230 doUpdateLocation (
const std::string& ,
const std::string& )
238 readHist (
const std::string& name)
const
241 return doReadHist (name);
247 contains (
const std::string& name)
const
258 addSamples (SampleHandler& result,
const std::shared_ptr<Sample>& self)
262 doAddSamples (result, self);
271 std::cout <<
dbg (*
this, 9999) << std::endl;
277 printContent ()
const
286 getNumEntries ()
const
293 std::vector<std::string> fileList = makeFileList();
294 for (std::vector<std::string>::const_iterator fileName = fileList.begin(),
295 end = fileList.end(); fileName != end; ++ fileName)
297 std::unique_ptr<TFile>
file (TFile::Open (fileName->c_str(),
"READ"));
299 throw std::runtime_error (
"failed to open file: " + *fileName);
300 TTree *
tree =
dynamic_cast<TTree*
>(
file->Get (treeName.c_str()));
302 result +=
tree->GetEntries();
309 TCollection *Sample ::
318 const TCollection *Sample ::
319 metaDataList ()
const
328 removeMeta (
const std::string& name)
331 meta()->remove (name);
337 addReplaceMeta (TNamed *meta_swallow)
339 std::unique_ptr<TNamed> mymeta (meta_swallow);
344 meta()->addReplace (mymeta.release());
350 getMeta (
const std::string& name)
353 return meta()->get (name);
358 const TObject *Sample ::
359 getMeta (
const std::string& name)
const
362 return meta()->get (name);
368 getMetaDouble (
const std::string& name,
double def_val)
const
376 std::string Sample ::
377 getMetaString (
const std::string& name,
const std::string& def_val)
const
386 setMetaDouble (
const std::string& name,
double value)
389 meta()->setDouble (name, value);
395 setMetaString (
const std::string& name,
const std::string& value)
398 meta()->setString (name, value);
404 fetchMeta (
const Sample& source)
407 meta()->fetch (*source.meta());
413 Sample (
const std::string& name)
414 : m_name (name), m_meta (
new MetaObject)
424 Sample (
const Sample& that)
425 : TObject (that), m_name (that.m_name),
426 m_tags (that.m_tags), m_meta (
new MetaObject (*that.m_meta))
434 doReadHist (
const std::string& name)
const
437 std::vector<std::string> fileList (makeFileList());
438 if (fileList.size() > 1)
439 throw std::runtime_error (
"reading histgrams from samples with multiple files is not (yet) implemented");
440 if (fileList.size() == 0)
442 std::unique_ptr<TFile>
file (TFile::Open (fileList[0].c_str(),
"READ"));
444 throw std::runtime_error (
"could not open file " + fileList[0]);
446 TObject *
object =
file->Get (name.c_str());
447 if (
object !=
nullptr)
455 getContains (
const std::string& )
const
464 doAddSamples (SampleHandler& result,
const std::shared_ptr<Sample>& self)