ATLAS Offline Software
Sample.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef SAMPLE_HANDLER_SAMPLE_HH
6 #define SAMPLE_HANDLER_SAMPLE_HH
7 
8 //
9 // Distributed under the Boost Software License, Version 1.0.
10 // (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12 
13 // Please feel free to contact me (krumnack@iastate.edu) for bug
14 // reports, feature suggestions, praise and complaints.
15 
16 
17 
18 #include <SampleHandler/Global.h>
19 
20 #include <string>
21 #include <vector>
22 #include <atomic>
23 #include <TObject.h>
24 #include <SampleHandler/TagList.h>
25 
26 class TChain;
27 class TCollection;
28 
29 namespace SH
30 {
42  std::string dbg (const Sample& obj, unsigned verbosity = 0);
43 
44 
45 
53  class Sample : public TObject
54  {
55  //
56  // public interface
57  //
58 
63  public:
64  void testInvariant () const;
65 
66 
71  public:
72  virtual ~Sample ();
73 
74 
79  const std::string& name () const;
80 
96  public:
97  void name (std::string val_name);
98 
99 
104  public:
105  std::size_t numFiles () const;
106 
107 
118  public:
119  std::string fileName (std::size_t index) const;
120 
121 
133  public:
135 
136 
141  public:
142  const TagList& tags () const;
143 
144 
151  public:
152  void tags (const TagList& tags);
153 
154 
161  public:
162  void addTag (const std::string& tag);
163 
164 
178  public:
179  void updateLocation (const std::string& from, const std::string& to);
180 
181 
187  public:
189 
190 
192  public:
193  const MetaObject *meta () const;
194 
195 
203  public:
204  std::vector<std::string> makeFileList () const;
205 
206 
215  public:
216  TChain *makeTChain () const;
217 
218 
228  public:
229  TObject *readHist (const std::string& name) const;
230 
231 
244  public:
245  bool contains (const std::string& name) const;
246 
247 
257  public:
259 
260 
269  public:
270  void print () const;
271 
272 
276  public:
277  void printContent () const;
278 
279 
285  public:
286  Long64_t getNumEntries () const;
287 
288 
289 
290  //
291  // legacy interface
292  //
293 
301  public:
302  [[deprecated("use meta() instead, or (preferably) access of meta-data by name")]]
303  TCollection *metaDataList ();
304 
305 
307  public:
308  [[deprecated("use meta() instead, or (preferably) access of meta-data by name")]]
309  const TCollection *metaDataList () const;
310 
311 
313  public:
314  [[deprecated("use meta() instead")]]
315  void removeMeta (const std::string& name);
316 
317 
319  public:
320  [[deprecated("use meta() instead")]]
321  void addReplaceMeta (TNamed *meta_swallow);
322 
323 
325  public:
326  [[deprecated("use meta() instead")]]
327  TObject *getMeta (const std::string& name);
328 
329 
331  public:
332  [[deprecated("use meta() instead")]]
333  const TObject *getMeta (const std::string& name) const;
334 
335 
337  public:
338  [[deprecated("use meta() instead")]]
339  double getMetaDouble (const std::string& name, double def_val = 0) const;
340 
341 
343  public:
344  [[deprecated("use meta() instead")]]
345  std::string getMetaString (const std::string& name, const std::string& def_val = "") const;
346 
347 
349  public:
350  [[deprecated("use meta() instead")]]
351  void setMetaDouble (const std::string& name, double value);
352 
353 
355  public:
356  [[deprecated("use meta() instead")]]
357  void setMetaString (const std::string& name, const std::string& value);
358 
359 
361  public:
362  [[deprecated("use meta() instead")]]
363  void fetchMeta (const Sample& source);
364 
365 
366 
367  //
368  // protected interface
369  //
370 
377  protected:
378  Sample (const std::string& name);
379 
380 
381 
382  //
383  // virtual interface
384  //
385 
389  protected:
390  virtual std::size_t getNumFiles () const = 0;
391 
392 
396  protected:
397  virtual std::string getFileName (std::size_t index) const = 0;
398 
399 
403  protected:
404  virtual SamplePtr doMakeLocal () const = 0;
405 
406 
410  protected:
411  virtual std::vector<std::string> doMakeFileList () const = 0;
412 
413 
417  protected:
418  virtual void
419  doUpdateLocation (const std::string& from, const std::string& to);
420 
421 
425  protected:
426  virtual TObject *doReadHist (const std::string& name) const;
427 
428 
432  protected:
433  virtual bool getContains (const std::string& name) const;
434 
435 
439  protected:
441 
442 
443 
444  //
445  // friend interface for SamplePtr
446  //
447 
448  friend class SamplePtr;
449  private:
450 
455  void alloc () const;
456 
457 
465  void release () const;
466 
467 
468 
469  //
470  // private interface
471  //
472 
474  private:
475  std::string m_name;
476 
478  private:
480 
482  private:
484 
486  private:
487  mutable std::atomic<unsigned> m_references;
488 
491  private:
492  Sample (const Sample& that);
493 
496  private:
497  Sample& operator = (const Sample& that);
498 
500  };
501 }
502 
503 #endif
SH::Sample::numFiles
std::size_t numFiles() const
the number of files in the sample
SH::Sample::m_meta
MetaObject * m_meta
the meta-information for this sample
Definition: Sample.h:483
get_generator_info.result
result
Definition: get_generator_info.py:21
SH::Sample::m_tags
TagList m_tags
the tag list we are using
Definition: Sample.h:479
SH::Sample::updateLocation
void updateLocation(const std::string &from, const std::string &to)
update all file references starting with from to to
SH::Sample::doMakeLocal
virtual SamplePtr doMakeLocal() const =0
Make this a local sample, i.e.
SH::TagList
A class that manages a list of tags for identifying samples.
Definition: TagList.h:48
SH::Sample::getNumEntries
Long64_t getNumEntries() const
get the number of entries
SH::MetaObject
A class that manages meta-data to be associated with an object.
Definition: MetaObject.h:56
TagList.h
index
Definition: index.py:1
SH::Sample::Sample
Sample(const Sample &that)
SH::Sample::operator=
Sample & operator=(const Sample &that)
SH::Sample::doReadHist
virtual TObject * doReadHist(const std::string &name) const
read an object from a histogram file
SH::Sample::addTag
void addTag(const std::string &tag)
add a tag to the content of tags()
athena.value
value
Definition: athena.py:124
SH::Sample::readHist
TObject * readHist(const std::string &name) const
read an object from a histogram file
SH::Sample::getMeta
TObject * getMeta(const std::string &name)
the meta-data object with the given name
SH::Sample::print
void print() const
print the debugging output to the screen
SH::Sample::getMetaString
std::string getMetaString(const std::string &name, const std::string &def_val="") const
the meta-data string with the given name
SH::Sample::getMeta
const TObject * getMeta(const std::string &name) const
the meta-data object with the given name
SH::Sample::tags
void tags(const TagList &tags)
set the content of tags()
SH::Sample::metaDataList
TCollection * metaDataList()
get the meta-data list
SH::Sample::addReplaceMeta
void addReplaceMeta(TNamed *meta_swallow)
add a meta-data object and remove any existing meta-data with the same name
SH::Sample::setMetaDouble
void setMetaDouble(const std::string &name, double value)
set the meta-data double with the given name
SH::Sample::ClassDef
ClassDef(Sample, 2)
SH::Sample::fetchMeta
void fetchMeta(const Sample &source)
fetch the meta-data from the given sample.
SH::Sample::name
void name(std::string val_name)
set the value of name
SH::Sample::makeFileList
std::vector< std::string > makeFileList() const
make a list of all files, prestaging them if necessary
SH::Sample::getMetaDouble
double getMetaDouble(const std::string &name, double def_val=0) const
the meta-data double with the given name
SH::Sample::tags
const TagList & tags() const
the tag list we are using
SH::Sample::getContains
virtual bool getContains(const std::string &name) const
whether this sample contains a sample of the given name
SH::Sample::getFileName
virtual std::string getFileName(std::size_t index) const =0
the name of the file with the given index
SH::Sample::removeMeta
void removeMeta(const std::string &name)
remove all meta-information with the given name
SH::Sample::meta
MetaObject * meta()
the meta-information for this sample
SH::Sample::name
const std::string & name() const
the name of the sample we are using
SH::Sample::testInvariant
void testInvariant() const
test the invariant of this object
SH::Sample::meta
const MetaObject * meta() const
the meta-information for this sample
SH::Sample::release
void release() const
decrease the reference count by one
SH::Sample
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
Definition: Sample.h:54
SH::Sample::dbg
std::string dbg(const Sample &obj, unsigned verbosity=0)
the debugging info of this object
SH::Sample::~Sample
virtual ~Sample()
standard destructor
SH::Sample::contains
bool contains(const std::string &name) const
whether this sample contains a sample of the given name
SH::Sample::makeLocal
SamplePtr makeLocal() const
Make this a local sample, i.e.
covarianceTool.verbosity
verbosity
Definition: covarianceTool.py:513
SH::SamplePtr
A smart pointer class that holds a single Sample object.
Definition: SamplePtr.h:35
SH::Sample::printContent
void printContent() const
print the debugging output to the screen
SH::Sample::m_references
std::atomic< unsigned > m_references
the reference count
Definition: Sample.h:487
SH::Sample::fileName
std::string fileName(std::size_t index) const
the name of the file with the given index
CxxUtils::to
CONT to(RANGE &&r)
Definition: ranges.h:39
SH::Sample::doAddSamples
virtual void doAddSamples(SampleHandler &result)
add all samples this sample corresponds to to the given sample handler
runJobs.deprecated
deprecated
Definition: runJobs.py:191
SH::Sample::makeTChain
TChain * makeTChain() const
create a TChain object, containing all these files
SH::Sample::m_name
std::string m_name
the name of the sample we are using
Definition: Sample.h:475
SH::Sample::Sample
Sample(const std::string &name)
standard constructor
SH::Sample::doUpdateLocation
virtual void doUpdateLocation(const std::string &from, const std::string &to)
update all file references starting with from to to
SH::Sample::getNumFiles
virtual std::size_t getNumFiles() const =0
the number of files in the sample
copySelective.source
string source
Definition: copySelective.py:32
SH::SampleHandler
A class that manages a list of Sample objects.
Definition: SampleHandler.h:60
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
SH::Sample::setMetaString
void setMetaString(const std::string &name, const std::string &value)
set the meta-data string with the given name
SH::Sample::doMakeFileList
virtual std::vector< std::string > doMakeFileList() const =0
make a list of all files, prestaging them if necessary
SH::Sample::metaDataList
const TCollection * metaDataList() const
get the meta-data list
python.PyAthena.obj
obj
Definition: PyAthena.py:132
Global.h
SH::Sample::alloc
void alloc() const
increase the reference count by one
SH::Sample::addSamples
void addSamples(SampleHandler &result)
add all samples this sample corresponds to to the given sample handler