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)
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;
37  std::string output;
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 Storage *open (const std::string &proto,
59  const std::string &surl,
60  int mode)
61  {
63  StorageFactory::ReadHint readHint = f->readHint();
64  StorageFactory::CacheHint cacheHint = f->cacheHint();
65 
67  || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
68  mode &= ~IOFlags::OpenUnbuffered;
69  else
71 
72  std::string path = getTURL(surl);
73  File *file = new File (path, mode);
74  return f->wrapNonLocalFile (file, proto, path, mode);
75  }
76 
77  virtual bool check (const std::string &/*proto*/,
78  const std::string &path,
79  IOOffset *size = 0)
80  {
81  struct stat st;
82  if (stat (getTURL(path).c_str(), &st) != 0)
83  return false;
84 
85  if (size)
86  *size = st.st_size;
87 
88  return true;
89  }
90 };
91 
#define LogDebug(id)
CacheHint cacheHint(void) const
def pipe
Definition: pipe.py:5
Definition: Storage.h:8
Storage * wrapNonLocalFile(Storage *s, const std::string &proto, const std::string &path, int mode)
static StorageFactory * get(void)
list path
Definition: scaleCards.py:51
double f[11][100]
std::string getTURL(const std::string &surl)
ReadHint readHint(void) const
int64_t IOOffset
Definition: IOTypes.h:19
virtual bool check(const std::string &, const std::string &path, IOOffset *size=0)
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: File.h:11
tuple size
Write out results.
virtual Storage * open(const std::string &proto, const std::string &surl, int mode)