CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  virtual 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  virtual bool check (const std::string &/*proto*/,
79  const std::string &path,
80  const AuxSettings&,
81  IOOffset *size = 0) 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)
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
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
def pipe
Definition: pipe.py:5
static const StorageFactory * get(void)
def move
Definition: eostools.py:510
double f[11][100]
ReadHint readHint(void) const
int64_t IOOffset
Definition: IOTypes.h:19
virtual std::unique_ptr< Storage > open(const std::string &proto, const std::string &surl, int mode, const AuxSettings &) const override
virtual bool check(const std::string &, const std::string &path, const AuxSettings &, IOOffset *size=0) const override
#define DEFINE_EDM_PLUGIN(factory, type, name)
tuple size
Write out results.
std::string getTURL(const std::string &surl) const