ATLAS Offline Software
DiskListLocal.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 <memory>
21 #include <TSystem.h>
22 #include <RootCoreUtils/Assert.h>
23 #include <RootCoreUtils/ThrowMsg.h>
24 
25 //
26 // method implementations
27 //
28 
29 namespace SH
30 {
32  testInvariant () const
33  {
34  }
35 
36 
37 
39  DiskListLocal (const std::string& val_dir)
40  : m_dir (val_dir), m_prefix (val_dir), m_dirp (0)
41  {
42  RCU_NEW_INVARIANT (this);
43  }
44 
45 
46 
48  DiskListLocal (const std::string& val_dir, const std::string& val_prefix)
49  : m_dir (val_dir), m_prefix (val_prefix), m_dirp (0)
50  {
51  RCU_NEW_INVARIANT (this);
52  }
53 
54 
55 
58  {
59  RCU_DESTROY_INVARIANT (this);
60 
61  if (m_dirp)
62  {
63  gSystem->FreeDirectory (m_dirp);
64  m_dirp = 0;
65  }
66  }
67 
68 
69 
71  getNext ()
72  {
73  RCU_CHANGE_INVARIANT (this);
74 
75  if (!m_dirp)
76  {
77  m_dirp = gSystem->OpenDirectory (m_dir.c_str());
78  if (!m_dirp)
79  RCU_THROW_MSG ("could not open directory " + m_dir);
80  }
81 
82  const char *subresult = 0;
83  do
84  {
85  subresult = gSystem->GetDirEntry (m_dirp);
86  if (subresult == 0)
87  {
88  gSystem->FreeDirectory (m_dirp);
89  m_dirp = 0;
90  m_file.clear ();
91  return false;
92  }
93  } while (strcmp (subresult, ".") == 0 || strcmp (subresult, "..") == 0);
94  m_file = subresult;
95  return subresult;
96  }
97 
98 
99 
100  std::string DiskListLocal ::
101  getPath () const
102  {
103  RCU_READ_INVARIANT (this);
104  return m_prefix + "/" + m_file;
105  }
106 
107 
108 
110  doOpenDir () const
111  {
112  RCU_READ_INVARIANT (this);
113 
114  std::unique_ptr<DiskListLocal> result
115  (new DiskListLocal (m_dir + "/" + m_file, m_prefix + "/" + m_file));
116  result->m_dirp = gSystem->OpenDirectory (result->m_dir.c_str());
117  if (result->m_dirp)
118  return result.release();
119  return 0;
120  }
121 
122 
123 
124  std::string DiskListLocal ::
125  getDirname () const
126  {
127  RCU_READ_INVARIANT (this);
128  return m_dir;
129  }
130 }
SH::DiskListLocal::m_dirp
void * m_dirp
the directory pointer used
Definition: DiskListLocal.h:117
DiskListLocal.h
m_dir
TDirectory & m_dir
The directory we need to return to.
Definition: OutputStreamData.cxx:41
get_generator_info.result
result
Definition: get_generator_info.py:21
SH::DiskListLocal::m_file
std::string m_file
the file we last fetched
Definition: DiskListLocal.h:121
SH::DiskListLocal::m_prefix
std::string m_prefix
the directory from with to read actual files
Definition: DiskListLocal.h:113
SH::DiskListLocal::doOpenDir
virtual DiskList * doOpenDir() const
make a new list object for the sub-directory
Definition: DiskListLocal.cxx:110
Assert.h
SH::DiskListLocal::testInvariant
void testInvariant() const
test the invariant of this object
Definition: DiskListLocal.cxx:32
SH::DiskList
an interface for listing directory contents, locally or on a file server
Definition: DiskList.h:32
SH::DiskListLocal::DiskListLocal
DiskListLocal(const std::string &val_dir)
make the listing for the given directory
Definition: DiskListLocal.cxx:39
SH::DiskListLocal::~DiskListLocal
virtual ~DiskListLocal()
standard destructor
Definition: DiskListLocal.cxx:57
SH::DiskListLocal::getDirname
virtual std::string getDirname() const
the base path for the directory listed
Definition: DiskListLocal.cxx:125
SH::DiskListLocal::getPath
virtual std::string getPath() const
the path for the current entry.
Definition: DiskListLocal.cxx:101
ThrowMsg.h
SH::DiskListLocal
a DiskList implementation for local directories
Definition: DiskListLocal.h:27
SH::DiskListLocal::getNext
virtual bool getNext()
get the next list entry
Definition: DiskListLocal.cxx:71
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
SH::DiskListLocal::m_dir
std::string m_dir
the directory we are reading
Definition: DiskListLocal.h:109
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
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
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233