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) const
16  {
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;
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 std::unique_ptr<Storage> open (const std::string &proto,
58  const std::string &surl,
59  int mode,
60  const AuxSettings&) const override
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  auto file = std::make_unique<File> (path, mode);
74  return f->wrapNonLocalFile (std::move(file), proto, path, mode);
75  }
76 
77  virtual bool check (const std::string &/*proto*/,
78  const std::string &path,
79  const AuxSettings&,
80  IOOffset *size = 0) const override
81  {
82  struct stat st;
83  if (stat (getTURL(path).c_str(), &st) != 0)
84  return false;
85 
86  if (size)
87  *size = st.st_size;
88 
89  return true;
90  }
91 };
92 
#define LogDebug(id)
virtual std::unique_ptr< Storage > open(const std::string &proto, const std::string &surl, int mode, const AuxSettings &) const override
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
std::string getTURL(const std::string &surl) const
def pipe
Definition: pipe.py:5
static const StorageFactory * get(void)
def move
Definition: eostools.py:510
virtual bool check(const std::string &, const std::string &path, const AuxSettings &, IOOffset *size=0) const override
double f[11][100]
ReadHint readHint(void) const
int64_t IOOffset
Definition: IOTypes.h:19
#define DEFINE_EDM_PLUGIN(factory, type, name)
tuple size
Write out results.