CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StormStorageMaker.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 a prepare to get script and extracts the physical file path */
15  std::string getTURL (const std::string &surl)
16  {
17  std::string client;
18  if (char *p = getenv("CMS_STORM_PTG_CLIENT"))
19  client = p;
20  else
21  throw cms::Exception("StormStorageMaker")
22  << "$CMS_STORM_PTG_CLIENT has no value";
23 
24  // Command
25  std::string comm(client + " srm:" + surl + " 2>&1");
26  LogDebug("StormStorageMaker") << "command: " << comm << std::endl;
27 
28  FILE *pipe = popen(comm.c_str(), "r");
29  if(! pipe)
30  throw cms::Exception("StormStorageMaker")
31  << "failed to execute PtG command: "
32  << comm;
33 
34  // Get output
35  int ch;
36  std::string output;
37  while ((ch = getc(pipe)) != EOF)
38  output.push_back(ch);
39  pclose(pipe);
40 
41  LogDebug("StormStorageMaker") << "output: " << output << std::endl;
42 
43  // Extract TURL if possible.
44  size_t start = output.find("FilePath:", 0);
45  if (start == std::string::npos)
46  throw cms::Exception("StormStorageMaker")
47  << "no turl found in command '" << comm << "' output:\n" << output;
48 
49  start += 9;
50  std::string turl(output, start, output.find_first_of("\n", start) - start);
51  LogDebug("StormStorageMaker") << "file to open: " << turl << std::endl;
52  return turl;
53  }
54 
55 
56 public:
57  virtual Storage *open (const std::string &proto,
58  const std::string &surl,
59  int mode)
60  {
62  StorageFactory::ReadHint readHint = f->readHint();
63  StorageFactory::CacheHint cacheHint = f->cacheHint();
64 
66  || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
67  mode &= ~IOFlags::OpenUnbuffered;
68  else
70 
71  std::string path = getTURL(surl);
72  File *file = new File (path, mode);
73  return f->wrapNonLocalFile (file, proto, path, mode);
74  }
75 
76  virtual bool check (const std::string &/*proto*/,
77  const std::string &path,
78  IOOffset *size = 0)
79  {
80  struct stat st;
81  if (stat (getTURL(path).c_str(), &st) != 0)
82  return false;
83 
84  if (size)
85  *size = st.st_size;
86 
87  return true;
88  }
89 };
90 
#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
std::string getTURL(const std::string &surl)
double f[11][100]
ReadHint readHint(void) const
int64_t IOOffset
Definition: IOTypes.h:19
virtual bool check(const std::string &, const std::string &path, IOOffset *size=0)
virtual Storage * open(const std::string &proto, const std::string &surl, int mode)
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: File.h:11
tuple size
Write out results.