ATLAS Offline Software
SampleHist.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 
14 //
15 // includes
16 //
17 
19 
20 #include <RootCoreUtils/Assert.h>
22 #include <RootCoreUtils/ThrowMsg.h>
24 #include <TFile.h>
25 #include <memory>
26 
27 //
28 // method implementations
29 //
30 
32 
33 namespace SH
34 {
35  void SampleHist ::
36  testInvariant () const
37  {
38  RCU_INVARIANT (!m_file.empty() || name() == "unnamed");
39  }
40 
41 
42 
44  SampleHist ()
45  : Sample ("unnamed")
46  {
47  RCU_NEW_INVARIANT (this);
48  }
49 
50 
51 
53  SampleHist (const std::string& name, const std::string& file)
54  : Sample (name), m_file (file)
55  {
56  RCU_NEW_INVARIANT (this);
57  }
58 
59 
60 
61  std::size_t SampleHist ::
62  getNumFiles () const
63  {
64  RCU_READ_INVARIANT (this);
65  return 1;
66  }
67 
68 
69 
70  std::string SampleHist ::
71  getFileName (const std::size_t
72 #ifndef NDEBUG
73  index
74 #endif
75  ) const
76  {
77  RCU_READ_INVARIANT (this);
78 
79  RCU_INVARIANT (index == static_cast<std::size_t>(0));
80  return m_file;
81  }
82 
83 
84 
85  SamplePtr SampleHist ::
86  doMakeLocal () const
87  {
88  RCU_READ_INVARIANT (this);
89  RCU_THROW_MSG ("Sample::makeLocal not supported for SampleHist");
90  return SamplePtr (); // compiler dummy
91  }
92 
93 
94 
95  std::vector<std::string> SampleHist ::
96  doMakeFileList () const
97  {
98  RCU_READ_INVARIANT (this);
99 
100  std::vector<std::string> result;
101  result.push_back (m_file);
102  return result;
103  }
104 
105 
106 
107  void SampleHist ::
108  doUpdateLocation (const std::string& from, const std::string& to)
109  {
110  RCU_READ_INVARIANT (this);
111  if (strncmp (m_file.c_str(), from.c_str(), from.size()) == 0)
112  m_file = to + "/" + m_file.substr (from.size());
113  }
114 
115 
116 
117  TObject *SampleHist ::
118  doReadHist (const std::string& name) const
119  {
120  RCU_READ_INVARIANT (this);
121 
122  std::unique_ptr<TFile> file (TFile::Open (m_file.c_str(), "READ"));
123  if (file.get() == 0)
124  RCU_THROW_MSG ("could not open file " + m_file);
125  TObject *object = file->Get (name.c_str());
126  if (object != 0)
127  RCU::SetDirectory (object, 0);
128  return object;
129  }
130 }
SH::Sample::SamplePtr
friend class SamplePtr
Definition: Sample.h:448
get_generator_info.result
result
Definition: get_generator_info.py:21
RootUtils.h
index
Definition: index.py:1
SH::SampleHist
A sample that represents a single histogram file.
Definition: SampleHist.h:31
Assert.h
SH::SampleHist::doUpdateLocation
virtual void doUpdateLocation(const std::string &from, const std::string &to)
update all file references starting with from to to
m_file
std::unique_ptr< TFile > m_file
description: this is a custom writer for the old-school drivers that don't use an actual writer
Definition: OutputStreamData.cxx:52
SamplePtr.h
SH::SampleHist::getFileName
virtual std::string getFileName(std::size_t index) const
the name of the file with the given index
SH::SampleHist::getNumFiles
virtual std::size_t getNumFiles() const
the number of files in the sample
SH::SampleHist::SampleHist
SampleHist()
standard constructor
SH::SampleHist::doReadHist
virtual TObject * doReadHist(const std::string &name) const
read an object from a histogram file
SH::SampleHist::testInvariant
void testInvariant() const
test the invariant of this object
ClassImp
ClassImp(SH::SampleHist) namespace SH
Definition: SampleHist.cxx:31
file
TFile * file
Definition: tile_monitor.h:29
SH::SampleHist::doMakeLocal
virtual SamplePtr doMakeLocal() const
Make this a local sample, i.e.
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
SH::Sample::name
const std::string & name() const
the name of the sample we are using
SH::SampleHist::m_file
std::string m_file
the path to the file we use
Definition: SampleHist.h:105
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
RCU::SetDirectory
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
Definition: RootUtils.cxx:28
ThrowMsg.h
SH::SampleHist::doMakeFileList
virtual std::vector< std::string > doMakeFileList() const
make a list of all files, prestaging them if necessary
CxxUtils::to
CONT to(RANGE &&r)
Definition: ranges.h:32
pickleTool.object
object
Definition: pickleTool.py:30
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
SampleHist.h
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233