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