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 <sys/stat.h>
00010
00011 class StormLcgGtStorageMaker : public StorageMaker
00012 {
00013
00014 std::string getTURL (const std::string &surl)
00015 {
00016
00017 std::string timeout("300");
00018 if(char *p = getenv("CMS_STORM_LCG_GT_TIMEOUT"))
00019 timeout = p;
00020
00021
00022
00023
00024
00025 std::string comm("lcg-gt -b -T srmv2 -t " + timeout + " srm:" + surl + " file 2>&1");
00026 LogDebug("StormLCGStorageMaker") << "command: " << comm << std::endl;
00027
00028 FILE *pipe = popen(comm.c_str(), "r");
00029 if(! pipe)
00030 throw cms::Exception("StormLCGStorageMaker")
00031 << "failed to execute lcg-gt command: "
00032 << comm;
00033
00034
00035 int ch;
00036 std::string output;
00037 while ((ch = getc(pipe)) != EOF)
00038 output.push_back(ch);
00039 pclose(pipe);
00040
00041 LogDebug("StormLCGStorageMaker") << "output: " << output << std::endl;
00042
00043
00044 size_t start = output.find("file:", 0);
00045 if (start == std::string::npos)
00046 throw cms::Exception("StormLCGStorageMaker")
00047 << "no turl found in command '" << comm << "' output:\n" << output;
00048
00049 start += 5;
00050 std::string turl(output, start, output.find_first_of("\n", start) - start);
00051 LogDebug("StormLCGStorageMaker") << "file to open: " << turl << std::endl;
00052 return turl;
00053 }
00054
00055
00056 public:
00057 virtual Storage *open (const std::string &proto,
00058 const std::string &surl,
00059 int mode,
00060 const std::string &tmpdir)
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 return new File (getTURL(surl), mode);
00073 }
00074
00075 virtual bool check (const std::string &proto,
00076 const std::string &path,
00077 IOOffset *size = 0)
00078 {
00079 struct stat st;
00080 if (stat (getTURL(path).c_str(), &st) != 0)
00081 return false;
00082
00083 if (size)
00084 *size = st.st_size;
00085
00086 return true;
00087 }
00088 };
00089
00090 DEFINE_EDM_PLUGIN (StorageMakerFactory, StormLcgGtStorageMaker, "storm-lcg");