64 result <<
"SampleHandler with " <<
obj.size() <<
" files";
79 void swap (SampleHandler&
a, SampleHandler&
b)
81 swap (
a.m_samples,
b.m_samples);
82 swap (
a.m_named,
b.m_named);
88 testInvariant ()
const
104 SampleHandler (
const SampleHandler& that)
105 : TObject (that), m_samples (that.m_samples), m_named (that.m_named)
120 SampleHandler& SampleHandler ::
121 operator = (
const SampleHandler& that)
124 SampleHandler
tmp (that);
134 SamplePtr mysample (
sample);
160 if (!
sample->name().empty() && m_named.find (
sample->name()) != m_named.end())
161 RCU_THROW_MSG (
"can't add sample of name " +
sample->name() +
"\na sample with that name already exists\nold sample:\n" +
dbg (*m_named.find (
sample->name())->second, 9999) +
"\nnew sample:\n" +
dbg (*
sample, 9999));
165 m_samples.push_back (
sample.get());
166 if (!
sample->name().empty())
170 if (m_samples.back() ==
sample.get())
171 m_samples.pop_back();
186 add (
const SampleHandler&
sh)
192 iter != end2; ++ iter)
200 void SampleHandler ::
201 addWithPrefix (
const SampleHandler&
sh,
const std::string&
prefix)
207 iter != end2; ++ iter)
209 std::unique_ptr<Sample>
sample (
dynamic_cast<Sample*
>((*iter)->Clone ()));
236 NamedMIter nameIter = m_named.find (
sample->name());
237 if (nameIter == m_named.end())
239 if (nameIter->second.get() !=
sample)
241 SamplesMIter sampleIter = m_samples.end();
242 for (SamplesMIter iter = m_samples.begin(), end2 = m_samples.end();
243 iter != end2; ++ iter)
248 m_samples.erase (sampleIter);
249 m_named.erase (nameIter);
259 NamedIter iter = m_named.find (
name);
260 if (iter != m_named.end())
261 return iter->second.get();
267 get (
const std::string&
name)
const
271 auto iter = m_named.find (
name);
272 if (iter != m_named.end())
273 return iter->second.get();
280 find (
const std::string&
tags)
const
295 for (SamplesIter
sample = m_samples.begin(),
300 end =
tags.end(); !use && iter !=
end; ++ iter)
301 use = (*sample)->tags().has (*iter);
310 Sample *SampleHandler ::
311 findBySource (
const std::string&
name)
const
315 std::vector<Sample*>
result;
319 if (
name == (*sample)->meta()->castString (MetaFields::sourceSample, (*sample)->name()))
325 message <<
"multiple samples have " <<
name <<
" as a source:";
326 for (std::vector<Sample*>::const_iterator
sample =
result.begin(),
328 message <<
" " << (*sample)->name();
338 SampleHandler SampleHandler ::
339 findByName (
const std::string&
pattern)
const
358 std::cout <<
dbg (*
this, 9999) << std::endl;
363 void SampleHandler ::
364 printContent ()
const
379 gSystem->MakeDirectory (
directory.c_str());
383 TFile
file ((
directory +
"/" + (*iter)->name() +
".root").c_str(),
"RECREATE");
384 (*iter)->Write (
"sample");
398 const std::string
file =
mydir.fileName();
400 if (
file.size() > 5 &&
401 file.rfind (
".root") ==
file.size() - 5)
403 TFile myfile (
mydir.path().c_str(),
"READ");
404 Sample *
const sample =
dynamic_cast<Sample*
>(myfile.Get (
"sample"));
413 void SampleHandler ::
414 updateLocation (
const std::string& from,
const std::string&
to)
421 (*sample)->updateLocation (from,
to);
426 void SampleHandler ::
427 fetch (
const SampleHandler&
source)
434 const std::string
name
435 = (*sample)->meta()->castString (MetaFields::sourceSample, (*sample)->name());
436 const Sample *
const mysource =
source.get (
name);
438 (*sample)->meta()->fetch (*mysource->meta());
444 void SampleHandler ::
445 fetchDefaults (
const SampleHandler&
source)
452 const std::string
name
453 = (*sample)->meta()->castString (MetaFields::sourceSample, (*sample)->name());
454 const Sample *
const mysource =
source.get (
name);
456 (*sample)->meta()->fetchDefaults (*mysource->meta());
462 bool SampleHandler ::
463 check_complete (
const SampleHandler&
source)
const
467 std::set<std::string>
names;
471 names.insert ((*sample)->meta()->castString (MetaFields::sourceSample, (*sample)->name()));
477 if (
names.find ((*sample)->name()) ==
names.end())
485 void SampleHandler ::
486 setMetaDouble (
const std::string&
name,
double value)
493 (*sample)->meta()->setDouble (
name,
value);
499 void SampleHandler ::
500 setMetaString (
const std::string&
name,
const std::string&
value)
507 (*sample)->meta()->setString (
name,
value);
513 void SampleHandler ::
514 setMetaDouble (
const std::string&
pattern,
const std::string&
name,
525 (*sample)->meta()->setDouble (
name,
value);
531 void SampleHandler ::
532 setMetaString (
const std::string&
pattern,
const std::string&
name,
533 const std::string&
value)
543 (*sample)->meta()->setString (
name,
value);
553 return m_samples.begin();
562 return m_samples.end();
571 return m_samples.size();
576 Sample *SampleHandler ::
577 operator [] (std::size_t
index)
const
585 Sample *SampleHandler ::
586 at (std::size_t
index)
const
590 return m_samples[
index];
595 void SampleHandler ::
596 Streamer (TBuffer&
b)
604 for (ULong_t iter = 0; iter !=
count; ++ iter)
614 ULong_t
count = m_samples.size(), count2 = 0;
616 for (SamplesIter iter = m_samples.begin(),
617 end = m_samples.end(); iter !=
end; ++ iter, ++ count2)