CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Alignment/Geners/src/uriUtils.cc

Go to the documentation of this file.
00001 #include <cstring>
00002 #include <cassert>
00003 #include "Alignment/Geners/interface/IOException.hh"
00004 
00005 #include "Alignment/Geners/interface/uriUtils.hh"
00006 
00007 namespace gs {
00008     std::string localFileURI(const char* filename)
00009     {
00010         assert(filename);
00011         if (strlen(filename) == 0) throw gs::IOInvalidArgument(
00012             "In gs::localFileURI: empty file name");
00013         std::string uri("file://");
00014         if (filename[0] != '/')
00015             uri += "./";
00016         uri += filename;
00017         return uri;
00018     }
00019 
00020     std::string fileTail(const char* filename)
00021     {
00022         assert(filename);
00023         const char *progname = std::strrchr(filename, '/');
00024         if (progname)
00025             ++progname;
00026         else
00027             progname = filename;
00028         return std::string(progname);
00029     }
00030 
00031     std::string fileDirname(const char* filename)
00032     {
00033         assert(filename);
00034         const char *progname = std::strrchr(filename, '/');
00035         if (progname)
00036             return std::string(filename, progname - filename);
00037         else
00038             return std::string(".");
00039     }
00040 
00041     std::string joinDir1WithName2(const char* fname1, const char* fname2)
00042     {
00043         std::string res(fileDirname(fname1));
00044         res += '/';
00045         res += fileTail(fname2);
00046         return res;
00047     }
00048 }