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 {
52
53
54
55 try
56 {
58 for (std::size_t iter = 0, end =
obj.numFiles();
59 iter != end; ++ iter)
61 } catch (std::exception& e)
62 {
63 result +=
"\n <file listing not available: " + std::string (
e.what()) +
">\n";
64 }
65 };
66 };
68 }
69
70
71
72 void Sample ::
73 testInvariant () const
74 {
76 }
77
78
79
80 Sample ::
81 ~Sample ()
82 {
84
85 delete m_meta;
86 }
87
88
89
90 const std::string& Sample ::
91 name () const
92 {
95 }
96
97
98
99 void Sample ::
100 name (std::string val_name)
101 {
103 if (m_lockedName)
104 throw std::logic_error
105 ("SH::Sample::name: cannot change name of sample \""
106 + m_name + "\" after it has been registered in a SampleHandler"
107 " (or otherwise locked via lockName)");
108 m_meta->setString (MetaNames::sampleName(), val_name);
109 m_name = std::move (val_name);
110
111 }
112
113
114
115 void Sample ::
116 lockName ()
117 {
119 m_lockedName = true;
120 }
121
122
123
124 std::size_t Sample ::
125 numFiles () const
126 {
128 return getNumFiles();
129 }
130
131
132
133 std::string Sample ::
134 fileName (
const std::size_t
index)
const
135 {
138
140
143 }
144
145
146
147 std::unique_ptr<SampleLocal> Sample ::
148 makeLocal () const
149 {
151 return doMakeLocal ();
152 }
153
154
155
156 const TagList& Sample ::
157 tags () const
158 {
160 return m_tags;
161 }
162
163
164
165 void Sample ::
166 tags (
const TagList&
tags)
167 {
170 }
171
172
173
174 void Sample ::
175 addTag (const std::string& tag)
176 {
178 m_tags.add (tag);
179 }
180
181
182
183 void Sample ::
184 updateLocation (const std::string& from, const std::string& to)
185 {
187 doUpdateLocation (from, to);
188 }
189
190
191
192 MetaObject *Sample ::
193 meta ()
194 {
196 return m_meta;
197 }
198
199
200
201 const MetaObject *Sample ::
202 meta () const
203 {
205 return m_meta;
206 }
207
208
209
210 std::vector<std::string> Sample ::
211 makeFileList () const
212 {
214 return doMakeFileList ();
215 }
216
217
218
219 TChain *Sample ::
220 makeTChain () const
221 {
222
223
224 std::vector<std::string>
files = makeFileList ();
225
226 const std::string
treeName (
meta()->castString (MetaFields::treeName, MetaFields::treeName_default));
228 throw std::runtime_error (
"sample " +
name() +
" does not have a tree name associated");
233 }
234
235
236
237 void Sample ::
238 doUpdateLocation (const std::string& , const std::string& )
239 {
241 }
242
243
244
245 TObject *Sample ::
246 readHist (const std::string& name) const
247 {
249 return doReadHist (name);
250 }
251
252
253
254 bool Sample ::
255 contains (const std::string& name) const
256 {
258
259
261 }
262
263
264
265 void Sample ::
266 addSamples (SampleHandler& result, const std::shared_ptr<Sample>& self)
267 {
270 doAddSamples (result, self);
271 }
272
273
274
275 void Sample ::
276 print () const
277 {
279 std::cout <<
dbg (*
this, 9999) << std::endl;
280 }
281
282
283
284 void Sample ::
285 printContent () const
286 {
287
289 }
290
291
292
293 Long64_t Sample ::
294 getNumEntries () const
295 {
297
299 =
meta()->castString (MetaFields::treeName, MetaFields::treeName_default);
301 std::vector<std::string>
fileList = makeFileList();
302 for (const auto& fileName : fileList)
303 {
304 std::unique_ptr<TFile>
file (TFile::Open (
fileName.c_str(),
"READ"));
305 if (
file.get() ==
nullptr)
306 throw std::runtime_error ("failed to open file: " + fileName);
310 }
312 }
313
314
315
316 TCollection *Sample ::
317 metaDataList ()
318 {
319
321 }
322
323
324
325 const TCollection *Sample ::
326 metaDataList () const
327 {
328
330 }
331
332
333
334 void Sample ::
335 removeMeta (const std::string& name)
336 {
337
338 meta()->remove (name);
339 }
340
341
342
343 void Sample ::
344 addReplaceMeta (TNamed *meta_swallow)
345 {
346 std::unique_ptr<TNamed> mymeta (meta_swallow);
347
348
350
351 meta()->addReplace (mymeta.release());
352 }
353
354
355
356 TObject *Sample ::
357 getMeta (const std::string& name)
358 {
359
360 return meta()->get (name);
361 }
362
363
364
365 const TObject *Sample ::
366 getMeta (const std::string& name) const
367 {
368
369 return meta()->get (name);
370 }
371
372
373
374 double Sample ::
375 getMetaDouble (const std::string& name, double def_val) const
376 {
377
378 return meta()->castDouble (name, def_val, MetaObject::CAST_NOCAST_DEFAULT);
379 }
380
381
382
383 std::string Sample ::
384 getMetaString (const std::string& name, const std::string& def_val) const
385 {
386
387 return meta()->castString (name, def_val, MetaObject::CAST_NOCAST_DEFAULT);
388 }
389
390
391
392 void Sample ::
393 setMetaDouble (const std::string& name, double value)
394 {
395
396 meta()->setDouble (name, value);
397 }
398
399
400
401 void Sample ::
402 setMetaString (const std::string& name, const std::string& value)
403 {
404
405 meta()->setString (name, value);
406 }
407
408
409
410 void Sample ::
411 fetchMeta (const Sample& source)
412 {
413
415 }
416
417
418
419 Sample ::
420 Sample (const std::string& name)
422 {
423 m_meta->setString (MetaNames::sampleName(), name);
424
426 }
427
428
429
430 Sample ::
431 Sample (const Sample& that)
433 m_tags (that.m_tags), m_meta (
new MetaObject (*that.m_meta))
434 {
436 }
437
438
439
440 TObject *Sample ::
441 doReadHist (const std::string& name) const
442 {
444 std::vector<std::string>
fileList (makeFileList());
446 throw std::runtime_error ("reading histgrams from samples with multiple files is not (yet) implemented");
448 return nullptr;
449 std::unique_ptr<TFile>
file (TFile::Open (fileList[0].c_str(),
"READ"));
451 throw std::runtime_error ("could not open file " + fileList[0]);
452
453 TObject *
object =
file->Get (
name.c_str());
454 if (object != nullptr)
457 }
458
459
460
461 bool Sample ::
462 getContains (const std::string& ) const
463 {
465 return false;
466 }
467
468
469
470 void Sample ::
471 doAddSamples (SampleHandler& result, const std::shared_ptr<Sample>& self)
472 {
475 }
476}
#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='#')