CMS 3D CMS Logo

StormStorageMaker.cc
Go to the documentation of this file.
1 #define ML_DEBUG 1
8 #include <cstdlib>
9 #include <cstdio>
10 #include <sys/stat.h>
11 
12 namespace edm::storage {
14  /* getTURL: Executes a prepare to get script and extracts the physical file path */
15  std::string getTURL(const std::string &surl) const {
17  if (char *p = std::getenv("CMS_STORM_PTG_CLIENT"))
18  client = p;
19  else
20  throw cms::Exception("StormStorageMaker") << "$CMS_STORM_PTG_CLIENT has no value";
21 
22  // Command
23  std::string comm(client + " srm:" + surl + " 2>&1");
24  LogDebug("StormStorageMaker") << "command: " << comm << std::endl;
25 
26  FILE *pipe = popen(comm.c_str(), "r");
27  if (!pipe)
28  throw cms::Exception("StormStorageMaker") << "failed to execute PtG command: " << comm;
29 
30  // Get output
31  int ch;
33  while ((ch = getc(pipe)) != EOF)
34  output.push_back(ch);
35  pclose(pipe);
36 
37  LogDebug("StormStorageMaker") << "output: " << output << std::endl;
38 
39  // Extract TURL if possible.
40  size_t start = output.find("FilePath:", 0);
41  if (start == std::string::npos)
42  throw cms::Exception("StormStorageMaker") << "no turl found in command '" << comm << "' output:\n" << output;
43 
44  start += 9;
45  std::string turl(output, start, output.find_first_of('\n', start) - start);
46  LogDebug("StormStorageMaker") << "file to open: " << turl << std::endl;
47  return turl;
48  }
49 
50  public:
51  std::unique_ptr<Storage> open(const std::string &proto,
52  const std::string &surl,
53  int mode,
54  const AuxSettings &) const override {
56  StorageFactory::ReadHint readHint = f->readHint();
57  StorageFactory::CacheHint cacheHint = f->cacheHint();
58 
60  mode &= ~IOFlags::OpenUnbuffered;
61  else
63 
64  std::string path = getTURL(surl);
65  auto file = std::make_unique<File>(path, mode);
66  return f->wrapNonLocalFile(std::move(file), proto, path, mode);
67  }
68 
69  bool check(const std::string & /*proto*/,
70  const std::string &path,
71  const AuxSettings &,
72  IOOffset *size = nullptr) const override {
73  struct stat st;
74  if (stat(getTURL(path).c_str(), &st) != 0)
75  return false;
76 
77  if (size)
78  *size = st.st_size;
79 
80  return true;
81  }
82  };
83 } // namespace edm::storage
84 
85 using namespace edm::storage;
size
Write out results.
Definition: start.py:1
int64_t IOOffset
Definition: IOTypes.h:20
std::unique_ptr< Storage > open(const std::string &proto, const std::string &surl, int mode, const AuxSettings &) const override
double f[11][100]
bool check(const std::string &, const std::string &path, const AuxSettings &, IOOffset *size=nullptr) const override
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: output.py:1
static const StorageFactory * get(void)
Definition: pipe.py:1
def move(src, dest)
Definition: eostools.py:511
std::string getTURL(const std::string &surl) const
#define LogDebug(id)