34{
35 std::string
dbg (
const Sample& obj,
unsigned verbosity)
36 {
39 if (dynamic_cast<const SampleGrid*>(&obj))
40 {
41 if (verbosity % 10 > 0)
42 {
43 result +=
"\n " + MetaFields::gridName +
"="+
obj.meta()->castString(MetaFields::gridName);
44 result +=
"\n " + MetaFields::gridFilter +
"="+
obj.meta()->castString(MetaFields::gridFilter);
45 };
46 } else
47 {
48 if (verbosity % 10 > 0)
50 if (verbosity % 10 > 1)
51 {
53 for (std::size_t iter = 0, end =
obj.numFiles();
54 iter != end; ++ iter)
56 };
57 };
59 }
60
61
62
63 void Sample ::
64 testInvariant () const
65 {
67 }
68
69
70
71 Sample ::
72 ~Sample ()
73 {
75
76 delete m_meta;
77 }
78
79
80
81 const std::string& Sample ::
82 name () const
83 {
86 }
87
88
89
90 void Sample ::
91 name (std::string val_name)
92 {
94 if (m_lockedName)
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)");
99 m_meta->setString (MetaNames::sampleName(), val_name);
100 m_name = std::move (val_name);
101
102 }
103
104
105
106 void Sample ::
107 lockName ()
108 {
110 m_lockedName = true;
111 }
112
113
114
115 std::size_t Sample ::
116 numFiles () const
117 {
119 return getNumFiles();
120 }
121
122
123
124 std::string Sample ::
125 fileName (
const std::size_t
index)
const
126 {
129
131
134 }
135
136
137
138 std::unique_ptr<SampleLocal> Sample ::
139 makeLocal () const
140 {
142 return doMakeLocal ();
143 }
144
145
146
147 const TagList& Sample ::
148 tags () const
149 {
151 return m_tags;
152 }
153
154
155
156 void Sample ::
157 tags (
const TagList&
tags)
158 {
161 }
162
163
164
165 void Sample ::
166 addTag (const std::string& tag)
167 {
169 m_tags.add (tag);
170 }
171
172
173
174 void Sample ::
175 updateLocation (const std::string& from, const std::string& to)
176 {
178 doUpdateLocation (from, to);
179 }
180
181
182
183 MetaObject *Sample ::
184 meta ()
185 {
187 return m_meta;
188 }
189
190
191
192 const MetaObject *Sample ::
193 meta () const
194 {
196 return m_meta;
197 }
198
199
200
201 std::vector<std::string> Sample ::
202 makeFileList () const
203 {
205 return doMakeFileList ();
206 }
207
208
209
210 TChain *Sample ::
211 makeTChain () const
212 {
213
214
215 std::vector<std::string>
files = makeFileList ();
216
217 const std::string
treeName (
meta()->castString (MetaFields::treeName, MetaFields::treeName_default));
219 throw std::runtime_error (
"sample " +
name() +
" does not have a tree name associated");
221 for (std::vector<std::string>::const_iterator
file =
files.begin(),
225 }
226
227
228
229 void Sample ::
230 doUpdateLocation (const std::string& , const std::string& )
231 {
233 }
234
235
236
237 TObject *Sample ::
238 readHist (const std::string& name) const
239 {
241 return doReadHist (name);
242 }
243
244
245
246 bool Sample ::
247 contains (const std::string& name) const
248 {
250 if (m_name == name)
251 return true;
252 return false;
253 }
254
255
256
257 void Sample ::
258 addSamples (SampleHandler& result, const std::shared_ptr<Sample>& self)
259 {
262 doAddSamples (result, self);
263 }
264
265
266
267 void Sample ::
268 print () const
269 {
271 std::cout <<
dbg (*
this, 9999) << std::endl;
272 }
273
274
275
276 void Sample ::
277 printContent () const
278 {
279
281 }
282
283
284
285 Long64_t Sample ::
286 getNumEntries () const
287 {
289
291 =
meta()->castString (MetaFields::treeName, MetaFields::treeName_default);
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)
296 {
297 std::unique_ptr<TFile>
file (TFile::Open (
fileName->c_str(),
"READ"));
299 throw std::runtime_error ("failed to open file: " + *fileName);
303 }
305 }
306
307
308
309 TCollection *Sample ::
310 metaDataList ()
311 {
312
314 }
315
316
317
318 const TCollection *Sample ::
319 metaDataList () const
320 {
321
323 }
324
325
326
327 void Sample ::
328 removeMeta (const std::string& name)
329 {
330
331 meta()->remove (name);
332 }
333
334
335
336 void Sample ::
337 addReplaceMeta (TNamed *meta_swallow)
338 {
339 std::unique_ptr<TNamed> mymeta (meta_swallow);
340
341
343
344 meta()->addReplace (mymeta.release());
345 }
346
347
348
349 TObject *Sample ::
350 getMeta (const std::string& name)
351 {
352
353 return meta()->get (name);
354 }
355
356
357
358 const TObject *Sample ::
359 getMeta (const std::string& name) const
360 {
361
362 return meta()->get (name);
363 }
364
365
366
367 double Sample ::
368 getMetaDouble (const std::string& name, double def_val) const
369 {
370
371 return meta()->castDouble (name, def_val, MetaObject::CAST_NOCAST_DEFAULT);
372 }
373
374
375
376 std::string Sample ::
377 getMetaString (const std::string& name, const std::string& def_val) const
378 {
379
380 return meta()->castString (name, def_val, MetaObject::CAST_NOCAST_DEFAULT);
381 }
382
383
384
385 void Sample ::
386 setMetaDouble (const std::string& name, double value)
387 {
388
389 meta()->setDouble (name, value);
390 }
391
392
393
394 void Sample ::
395 setMetaString (const std::string& name, const std::string& value)
396 {
397
398 meta()->setString (name, value);
399 }
400
401
402
403 void Sample ::
404 fetchMeta (const Sample& source)
405 {
406
408 }
409
410
411
412 Sample ::
413 Sample (const std::string& name)
415 {
416 m_meta->setString (MetaNames::sampleName(), name);
417
419 }
420
421
422
423 Sample ::
424 Sample (const Sample& that)
426 m_tags (that.m_tags), m_meta (
new MetaObject (*that.m_meta))
427 {
429 }
430
431
432
433 TObject *Sample ::
434 doReadHist (const std::string& name) const
435 {
437 std::vector<std::string>
fileList (makeFileList());
439 throw std::runtime_error ("reading histgrams from samples with multiple files is not (yet) implemented");
441 return nullptr;
442 std::unique_ptr<TFile>
file (TFile::Open (fileList[0].c_str(),
"READ"));
444 throw std::runtime_error ("could not open file " + fileList[0]);
445
446 TObject *
object =
file->Get (
name.c_str());
447 if (object != nullptr)
450 }
451
452
453
454 bool Sample ::
455 getContains (const std::string& ) const
456 {
458 return false;
459 }
460
461
462
463 void Sample ::
464 doAddSamples (SampleHandler& result, const std::shared_ptr<Sample>& self)
465 {
468 }
469}
#define RCU_DESTROY_INVARIANT(x)
#define RCU_CHANGE_INVARIANT(x)
#define RCU_NEW_INVARIANT(x)
#define RCU_REQUIRE_SOFT(x)
#define RCU_READ_INVARIANT(x)
void print(char *figname, TCanvas *c1)
std::vector< std::string > files
file names and file pointers
std::vector< std::string > tags
std::string m_name
The primary name part of this expression.
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
getFileName(name, sep='#')