CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
RemoteFile Class Reference

#include <RemoteFile.h>

Inheritance diagram for RemoteFile:
File IOChannel Storage IOInput IOOutput IOInput IOOutput

Public Member Functions

 ~RemoteFile (void) override
 

Static Public Member Functions

static std::unique_ptr< Storageget (int localfd, const std::string &name, char **cmd, int mode)
 
static int local (const std::string &tmpdir, std::string &temp)
 

Protected Member Functions

void abort (void) override
 
void close (void) override
 
- Protected Member Functions inherited from File
virtual void attach (IOFD fd)
 
virtual void create (const char *name, bool exclusive=false, int perms=0666)
 
virtual void create (const std::string &name, bool exclusive=false, int perms=0666)
 
 File (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
 File (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
 File (IOFD fd, bool autoclose=true)
 
 File (void)
 
void flush (void) override
 
virtual void open (const char *name, int flags=IOFlags::OpenRead, int perms=0666)
 
virtual void open (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666)
 
IOOffset position (IOOffset offset, Relative whence=SET) override
 
virtual IOOffset position (IOOffset offset, Relative whence=SET)=0
 
virtual IOOffset position (void) const
 
bool prefetch (const IOPosBuffer *what, IOSize n) override
 
IOSize read (IOBuffer into, IOOffset pos)
 
IOSize read (void *into, IOSize n) override
 
virtual IOSize read (void *into, IOSize n, IOOffset pos)
 
IOSize read (void *into, IOSize n, IOOffset pos) override
 
IOSize readv (IOBuffer *into, IOSize length) override
 
virtual IOSize readv (IOPosBuffer *into, IOSize buffers)
 
void resize (IOOffset size) override
 
virtual void setAutoClose (bool closeit)
 
IOOffset size (void) const override
 
IOSize write (const void *from, IOSize n) override
 
virtual IOSize write (const void *from, IOSize n, IOOffset pos)
 
IOSize write (const void *from, IOSize n, IOOffset pos) override
 
IOSize write (IOBuffer from, IOOffset pos)
 
IOSize writev (const IOBuffer *from, IOSize length) override
 
virtual IOSize writev (const IOPosBuffer *from, IOSize buffers)
 
 ~File (void) override
 
- Protected Member Functions inherited from IOChannel
bool sysclose (IOFD fd, int *error=nullptr)
 
virtual void fd (IOFD value)
 
virtual IOFD fd (void) const
 
 IOChannel (IOFD fd=-1)
 
virtual bool isBlocking (void) const
 
IOSize read (IOBuffer into)
 
IOSize read (void *into, IOSize n) override
 
virtual IOSize read (void *into, IOSize n)=0
 
int read (void)
 
IOSize readv (IOBuffer *into, IOSize buffers) override
 
virtual void setBlocking (bool value)
 
IOSize write (const void *from, IOSize n) override
 
virtual IOSize write (const void *from, IOSize n)=0
 
IOSize write (IOBuffer from)
 
IOSize write (unsigned char byte)
 
IOSize writev (const IOBuffer *from, IOSize buffers) override
 
 ~IOChannel (void) override
 
- Protected Member Functions inherited from IOInput
IOSize read (IOBuffer into)
 
int read (void)
 
IOSize xread (IOBuffer into)
 
IOSize xread (void *into, IOSize n)
 
IOSize xreadv (IOBuffer *into, IOSize buffers)
 
virtual ~IOInput (void)
 Destruct the stream. A no-op. More...
 
- Protected Member Functions inherited from IOOutput
IOSize write (IOBuffer from)
 
IOSize write (unsigned char byte)
 
IOSize xwrite (const void *from, IOSize n)
 
IOSize xwrite (IOBuffer from)
 
IOSize xwritev (const IOBuffer *from, IOSize buffers)
 
virtual ~IOOutput (void)
 Destruct the stream. A no-op. More...
 
- Protected Member Functions inherited from Storage
virtual bool eof (void) const
 
Storageoperator= (const Storage &)=delete
 
virtual IOOffset position (void) const
 
IOSize read (IOBuffer into)
 
IOSize read (IOBuffer into, IOOffset pos)
 
virtual IOSize read (void *into, IOSize n)=0
 
int read (void)
 
virtual IOSize readv (IOBuffer *into, IOSize buffers)
 
virtual IOSize readv (IOPosBuffer *into, IOSize buffers)
 
virtual void rewind (void)
 
 Storage (const Storage &)=delete
 
 Storage (void)
 
virtual IOSize write (const void *from, IOSize n)=0
 
IOSize write (IOBuffer from)
 
IOSize write (IOBuffer from, IOOffset pos)
 
IOSize write (unsigned char byte)
 
virtual IOSize writev (const IOBuffer *from, IOSize buffers)
 
virtual IOSize writev (const IOPosBuffer *from, IOSize buffers)
 
 ~Storage (void) override
 

Private Member Functions

 RemoteFile (IOFD fd, const std::string &name)
 
void remove (void)
 

Private Attributes

std::string name_
 

Detailed Description

Definition at line 8 of file RemoteFile.h.

Constructor & Destructor Documentation

◆ ~RemoteFile()

RemoteFile::~RemoteFile ( void  )
inlineoverride

Definition at line 10 of file RemoteFile.h.

10 { remove(); }

References remove().

◆ RemoteFile()

RemoteFile::RemoteFile ( IOFD  fd,
const std::string &  name 
)
private

Definition at line 34 of file RemoteFile.cc.

34 : File(fd), name_(name) {}

Referenced by get().

Member Function Documentation

◆ abort()

void RemoteFile::abort ( void  )
overrideprotectedvirtual

Close the file and ignore all errors.

Reimplemented from File.

Definition at line 43 of file RemoteFile.cc.

43  {
44  remove();
45  File::abort();
46 }

References File::abort(), and remove().

◆ close()

void RemoteFile::close ( void  )
overrideprotectedvirtual

Close the file.

Reimplemented from File.

Definition at line 38 of file RemoteFile.cc.

38  {
39  remove();
40  File::close();
41 }

References File::close(), and remove().

Referenced by get(), esMonitoring.AsyncLineReaderMixin::handle_close(), and esMonitoring.FDJsonServer::handle_close().

◆ get()

std::unique_ptr< Storage > RemoteFile::get ( int  localfd,
const std::string &  name,
char **  cmd,
int  mode 
)
static

Definition at line 78 of file RemoteFile.cc.

78  {
79  // FIXME: On write, create a temporary local file open for write;
80  // on close, trigger transfer to destination. If opening existing
81  // file for write, may need to first download.
83 
84  pid_t pid = -1;
85  int rc = posix_spawnp(&pid, cmd[0], nullptr, nullptr, cmd, environ);
86 
87  if (rc == -1) {
88  int errsave = errno;
89  ::close(localfd);
90  unlink(name.c_str());
91  throwStorageError("RemoteFile", "Calling RemoteFile::get()", "posix_spawnp()", errsave);
92  }
93 
94  pid_t rcpid;
95  do
96  rcpid = waitpid(pid, &rc, 0);
97  while (rcpid == (pid_t)-1 && errno == EINTR);
98 
99  if (rcpid == (pid_t)-1) {
100  int errsave = errno;
101  ::close(localfd);
102  unlink(name.c_str());
103  throwStorageError("RemoteFile", "Calling RemoteFile::get()", "waitpid()", errsave);
104  }
105 
106  if (WIFEXITED(rc) && WEXITSTATUS(rc) == 0)
107  return std::unique_ptr<Storage>(static_cast<Storage *>(new RemoteFile(localfd, name)));
108  else {
109  ::close(localfd);
110  unlink(name.c_str());
111  cms::Exception ex("RemoteFile");
112  ex << "'" << join(cmd) << "'"
113  << (WIFEXITED(rc) ? " exited with exit code "
114  : WIFSIGNALED(rc) ? " died from signal "
115  : " died for an obscure unknown reason with exit status ")
116  << (WIFEXITED(rc) ? WEXITSTATUS(rc)
117  : WIFSIGNALED(rc) ? WTERMSIG(rc)
118  : rc);
119  ex.addContext("Calling RemoteFile::get()");
120  throw ex;
121  }
122 }

References cms::cuda::assert(), close(), mps_setup::cmd, join(), ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, Skims_PA_cff::name, IOFlags::OpenCreate, IOFlags::OpenWrite, RemoteFile(), and throwStorageError().

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), submitPVValidationJobs.BetterConfigParser::__updateDict(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), betterConfigParser.BetterConfigParser::getResultingSection(), submitPVValidationJobs.BetterConfigParser::getResultingSection(), HttpStorageMaker::open(), and GsiFTPStorageMaker::open().

◆ local()

int RemoteFile::local ( const std::string &  tmpdir,
std::string &  temp 
)
static

Definition at line 48 of file RemoteFile.cc.

48  {
49  // Download temporary files to the current directory by default.
50  // This is better for grid jobs as the current directory is
51  // likely to have more space, and is more optimised for
52  // large files, and is cleaned up after the job.
53  if (tmpdir.empty() || tmpdir == ".") {
54  size_t len = pathconf(".", _PC_PATH_MAX);
55  char *buf = (char *)malloc(len);
56  getcwd(buf, len);
57 
58  temp.reserve(len + 32);
59  temp = buf;
60  free(buf);
61  } else {
62  temp.reserve(tmpdir.size() + 32);
63  temp = tmpdir;
64  }
65  if (temp[temp.size() - 1] != '/')
66  temp += '/';
67 
68  temp += "storage-factory-local-XXXXXX";
69  temp.c_str(); // null terminate for mkstemp
70 
71  int fd = mkstemp(&temp[0]);
72  if (fd == -1)
73  throwStorageError("RemoteFile", "Calling RemoteFile::local()", "mkstemp()", errno);
74 
75  return fd;
76 }

References visDQMUpload::buf, IOChannel::fd(), groupFilesInBlocks::temp, and throwStorageError().

Referenced by GsiFTPStorageMaker::open(), and HttpStorageMaker::open().

◆ remove()

void RemoteFile::remove ( void  )
private

Definition at line 36 of file RemoteFile.cc.

36 { unlink(name_.c_str()); }

References name_.

Referenced by abort(), close(), and ~RemoteFile().

Member Data Documentation

◆ name_

std::string RemoteFile::name_
private

Definition at line 22 of file RemoteFile.h.

Referenced by remove().

mps_setup.cmd
list cmd
Definition: mps_setup.py:244
File::close
void close(void) override
Definition: File.cc:241
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
cms::cuda::assert
assert(be >=bs)
IOFlags::OpenWrite
Definition: IOFlags.h:8
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
throwStorageError
void throwStorageError(const char *category, const char *context, const char *call, int error)
Definition: Throw.cc:6
IOFlags::OpenCreate
Definition: IOFlags.h:24
visDQMUpload.buf
buf
Definition: visDQMUpload.py:160
RemoteFile::RemoteFile
RemoteFile(IOFD fd, const std::string &name)
Definition: RemoteFile.cc:34
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
RemoteFile::remove
void remove(void)
Definition: RemoteFile.cc:36
IOChannel::fd
virtual IOFD fd(void) const
Definition: IOChannel.cc:69
cms::Exception
Definition: Exception.h:70
File::abort
virtual void abort(void)
Definition: File.cc:254
RemoteFile::close
void close(void) override
Definition: RemoteFile.cc:38
RemoteFile::name_
std::string name_
Definition: RemoteFile.h:22
File::File
File(void)
Definition: File.cc:57