Go to the documentation of this file.00001 #define ML_DEBUG 1
00002 #include "Utilities/StorageFactory/interface/StorageMaker.h"
00003 #include "Utilities/StorageFactory/interface/StorageMakerFactory.h"
00004 #include "Utilities/StorageFactory/interface/StorageFactory.h"
00005 #include "Utilities/StorageFactory/interface/File.h"
00006 #include "FWCore/Utilities/interface/EDMException.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include <cstdlib>
00009 #include <cstdio>
00010 #include <sys/stat.h>
00011
00012 class StormLcgGtStorageMaker : public StorageMaker
00013 {
00014
00015 std::string getTURL (const std::string &surl)
00016 {
00017
00018 std::string timeout("300");
00019 if(char *p = getenv("CMS_STORM_LCG_GT_TIMEOUT"))
00020 timeout = p;
00021
00022
00023
00024
00025
00026 std::string comm("lcg-gt -b -T srmv2 -t " + timeout + " srm:" + surl + " file 2>&1");
00027 LogDebug("StormLCGStorageMaker") << "command: " << comm << std::endl;
00028
00029 FILE *pipe = popen(comm.c_str(), "r");
00030 if(! pipe)
00031 throw cms::Exception("StormLCGStorageMaker")
00032 << "failed to execute lcg-gt command: "
00033 << comm;
00034
00035
00036 int ch;
00037 std::string output;
00038 while ((ch = getc(pipe)) != EOF)
00039 output.push_back(ch);
00040 pclose(pipe);
00041
00042 LogDebug("StormLCGStorageMaker") << "output: " << output << std::endl;
00043
00044
00045 size_t start = output.find("file:", 0);
00046 if (start == std::string::npos)
00047 throw cms::Exception("StormLCGStorageMaker")
00048 << "no turl found in command '" << comm << "' output:\n" << output;
00049
00050 start += 5;
00051 std::string turl(output, start, output.find_first_of("\n", start) - start);
00052 LogDebug("StormLCGStorageMaker") << "file to open: " << turl << std::endl;
00053 return turl;
00054 }
00055
00056
00057 public:
00058 virtual Storage *open (const std::string &proto,
00059 const std::string &surl,
00060 int mode)
00061 {
00062 StorageFactory *f = StorageFactory::get();
00063 StorageFactory::ReadHint readHint = f->readHint();
00064 StorageFactory::CacheHint cacheHint = f->cacheHint();
00065
00066 if (readHint != StorageFactory::READ_HINT_UNBUFFERED
00067 || cacheHint == StorageFactory::CACHE_HINT_STORAGE)
00068 mode &= ~IOFlags::OpenUnbuffered;
00069 else
00070 mode |= IOFlags::OpenUnbuffered;
00071
00072 std::string path = getTURL(surl);
00073 File *file = new File (path, mode);
00074 return f->wrapNonLocalFile (file, proto, path, mode);
00075 }
00076
00077 virtual bool check (const std::string &proto,
00078 const std::string &path,
00079 IOOffset *size = 0)
00080 {
00081 struct stat st;
00082 if (stat (getTURL(path).c_str(), &st) != 0)
00083 return false;
00084
00085 if (size)
00086 *size = st.st_size;
00087
00088 return true;
00089 }
00090 };
00091
00092 DEFINE_EDM_PLUGIN (StorageMakerFactory, StormLcgGtStorageMaker, "storm-lcg");