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