CMS 3D CMS Logo

StormLCGStorageMaker.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 
13  /* getTURL: Executes lcg-gt and extracts the physical file path */
14  std::string getTURL(const std::string &surl) const {
15  // PrepareToGet timeout
16  std::string timeout("300");
17  if (char *p = std::getenv("CMS_STORM_LCG_GT_TIMEOUT"))
18  timeout = p;
19 
20  /* Build the command line:
21  -b => no BDII contacted
22  -T srmv2 => necessary with -b
23  -t timeout */
24  std::string comm("lcg-gt -b -T srmv2 -t " + timeout + " srm:" + surl + " file 2>&1");
25  LogDebug("StormLCGStorageMaker") << "command: " << comm << std::endl;
26 
27  FILE *pipe = popen(comm.c_str(), "r");
28  if (!pipe)
29  throw cms::Exception("StormLCGStorageMaker") << "failed to execute lcg-gt command: " << comm;
30 
31  // Get output
32  int ch;
34  while ((ch = getc(pipe)) != EOF)
35  output.push_back(ch);
36  pclose(pipe);
37 
38  LogDebug("StormLCGStorageMaker") << "output: " << output << std::endl;
39 
40  // Extract TURL if possible.
41  size_t start = output.find("file:", 0);
42  if (start == std::string::npos)
43  throw cms::Exception("StormLCGStorageMaker") << "no turl found in command '" << comm << "' output:\n" << output;
44 
45  start += 5;
46  std::string turl(output, start, output.find_first_of("\n", start) - start);
47  LogDebug("StormLCGStorageMaker") << "file to open: " << turl << std::endl;
48  return turl;
49  }
50 
51 public:
52  std::unique_ptr<Storage> open(const std::string &proto,
53  const std::string &surl,
54  int mode,
55  const AuxSettings &) const override {
57  StorageFactory::ReadHint readHint = f->readHint();
58  StorageFactory::CacheHint cacheHint = f->cacheHint();
59 
61  mode &= ~IOFlags::OpenUnbuffered;
62  else
64 
65  std::string path = getTURL(surl);
66  auto file = std::make_unique<File>(path, mode);
67  return f->wrapNonLocalFile(std::move(file), proto, path, mode);
68  }
69 
70  bool check(const std::string & /*proto*/,
71  const std::string &path,
72  const AuxSettings &,
73  IOOffset *size = nullptr) const override {
74  struct stat st;
75  if (stat(getTURL(path).c_str(), &st) != 0)
76  return false;
77 
78  if (size)
79  *size = st.st_size;
80 
81  return true;
82  }
83 };
84 
#define LogDebug(id)
size
Write out results.
Definition: start.py:1
CacheHint cacheHint(void) const
std::unique_ptr< Storage > wrapNonLocalFile(std::unique_ptr< Storage > s, const std::string &proto, const std::string &path, int mode) const
Definition: IOFlags.h:4
int timeout
Definition: mps_check.py:53
static const StorageFactory * get(void)
bool check(const std::string &, const std::string &path, const AuxSettings &, IOOffset *size=0) const override
std::unique_ptr< Storage > open(const std::string &proto, const std::string &surl, int mode, const AuxSettings &) const override
double f[11][100]
ReadHint readHint(void) const
int64_t IOOffset
Definition: IOTypes.h:19
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: pipe.py:1
def move(src, dest)
Definition: eostools.py:511
std::string getTURL(const std::string &surl) const