ATLAS Offline Software
DiskListEOS.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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 <sstream>
21 #include <vector>
22 #include <RootCoreUtils/Assert.h>
24 #include <RootCoreUtils/ThrowMsg.h>
25 
26 #include <iostream>
27 
28 //
29 // method implementations
30 //
31 
32 namespace SH
33 {
35  testInvariant () const
36  {
37  }
38 
39 
40 
42  DiskListEOS (const std::string& val_dir)
43  : m_dir (val_dir), m_prefix ("root://eosatlas.cern.ch/" + val_dir), m_isRead (false)
44  {
45  RCU_NEW_INVARIANT (this);
46  }
47 
48 
49 
51  DiskListEOS (const std::string& val_dir, const std::string& val_prefix)
52  : m_dir (val_dir), m_prefix (val_prefix), m_isRead (false)
53  {
54  RCU_NEW_INVARIANT (this);
55  }
56 
57 
58 
60  getNext ()
61  {
62  RCU_CHANGE_INVARIANT (this);
63 
64  if (!m_isRead)
65  {
66  m_list = RCU::Shell::exec_read ("eos ls -l " + m_dir);
67  m_isRead = true;
68  }
69 
70  while (!m_list.empty())
71  {
72  std::string::size_type split1 = m_list.find ('\n');
73  if (split1 == std::string::npos)
74  return false;
75 
76  std::string line (m_list.substr (0, split1));
77  m_list = m_list.substr (split1 + 1);
78 
79  // rationale: this should handle it correctly if there is a
80  // formatting escape sequence at the beginning of the line.
81  std::string::size_type split2 = line.find ("r");
82  m_isDir = line[split2-1] == 'd';
83  line = line.substr (split2);
84 
85  std::istringstream str (line);
86  std::string fields [9];
87  for (unsigned iter = 0, end = 9; iter != end; ++ iter)
88  {
89  if (!(str >> fields[iter]))
90  RCU_THROW_MSG ("failed to parse line: " + line);
91  }
92  if (fields[0].empty())
93  RCU_THROW_MSG ("failed to parse line: " + line);
94  m_file = fields[8];
95  return true;
96  }
97  return false;
98  }
99 
100 
101 
102  std::string DiskListEOS ::
103  getPath () const
104  {
105  RCU_READ_INVARIANT (this);
106  return m_prefix + "/" + m_file;
107  }
108 
109 
110 
112  doOpenDir () const
113  {
114  RCU_READ_INVARIANT (this);
115 
116  if (m_file.empty() || !m_isDir)
117  return 0;
118 
119  return new DiskListEOS (m_dir + "/" + m_file, m_prefix + "/" + m_file);
120  }
121 
122 
123 
124  std::string DiskListEOS ::
125  getDirname () const
126  {
127  RCU_READ_INVARIANT (this);
128  return m_dir;
129  }
130 }
checkFileSG.line
line
Definition: checkFileSG.py:75
SH::DiskListEOS::DiskListEOS
DiskListEOS(const std::string &val_dir)
make the listing for the given directory
Definition: DiskListEOS.cxx:42
m_dir
TDirectory & m_dir
The directory we need to return to.
Definition: OutputStreamData.cxx:41
SH::DiskListEOS::m_prefix
std::string m_prefix
the directory from with to read actual files
Definition: DiskListEOS.h:104
SH::DiskListEOS::getDirname
virtual std::string getDirname() const
the base path for the directory listed
Definition: DiskListEOS.cxx:125
DiskListEOS.h
SH::DiskListEOS::m_file
std::string m_file
the last file we read
Definition: DiskListEOS.h:112
ShellExec.h
Assert.h
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
SH::DiskListEOS::testInvariant
void testInvariant() const
test the invariant of this object
Definition: DiskListEOS.cxx:35
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SH::DiskListEOS::getPath
virtual std::string getPath() const
the path for the current entry.
Definition: DiskListEOS.cxx:103
SH::DiskListEOS::doOpenDir
virtual DiskList * doOpenDir() const
make a new list object for the sub-directory
Definition: DiskListEOS.cxx:112
SH::DiskList
an interface for listing directory contents, locally or on a file server
Definition: DiskList.h:32
SH::DiskListEOS::m_isRead
bool m_isRead
whether the directory has been read
Definition: DiskListEOS.h:120
SH::DiskListEOS::m_list
std::string m_list
the result of the directory listing
Definition: DiskListEOS.h:108
SH::DiskListEOS::m_isDir
bool m_isDir
whether this is a directory
Definition: DiskListEOS.h:116
ThrowMsg.h
RCU::Shell::exec_read
std::string exec_read(const std::string &cmd)
effects: execute the given command and return the output returns: the output of the command guarantee...
Definition: ShellExec.cxx:37
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
SH::DiskListEOS::getNext
virtual bool getNext()
get the next list entry
Definition: DiskListEOS.cxx:60
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
str
Definition: BTagTrackIpAccessor.cxx:11
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
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
SH::DiskListEOS::m_dir
std::string m_dir
the directory we are reading
Definition: DiskListEOS.h:100
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233