| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# GFALStageFile.cpp

Go to the documentation of this file.

    00001 // $Id: GFALStageFile.cpp,v 1.1.1.1 2007/01/15 12:22:56 hmd Exp $
    00002 // Include files
    00003
    00004 // local
    00005 #include "GFALStageFile.h"
    00006
    00007 // From Gaudi
    00008 #include "GaudiKernel/Tokenizer.h"
    00009 #include "GaudiKernel/GaudiException.h"
    00010 #include "GaudiKernel/MsgStream.h"
    00011
    00012
    00013
    00014 //-----------------------------------------------------------------------------
    00015 // Implementation file for class : GFALStageFile
    00016 //
    00017 // 2006-11-11 : Andres Felipe Osorio Oliveros
    00018 //              Greig COWAN
    00019 //
    00020 //
    00021 //-----------------------------------------------------------------------------
    00022
    00023 //=============================================================================
    00024 // Standard constructor, initializes variables
    00025 //=============================================================================
    00026 GFALStageFile::GFALStageFile(  ) {
    00027
    00028 }
    00029
    00030 GFALStageFile::GFALStageFile(std::string name,IMessageSvc* ms)
    00031 {
    00032
    00033   Tokenizer tok(true);
    00034
    00035   m_MS=ms;
    00036
    00037   m_rawfilename = name ;
    00038
    00039   tok.analyse(m_rawfilename, " ", "", "", "=", "'", "'");
    00040   for ( Tokenizer::Items::iterator i = tok.items().begin();
    00041         i != tok.items().end();
    00042         i++ )   {
    00043     const std::string& tag = (*i).tag();
    00044     const std::string& val = (*i).value();
    00045     if (::toupper(tag[0])=='D') {
    00046       name = val ;
    00047     }
    00048   }
    00049
    00050   std::vector<std::string> prefixname;
    00051
    00052   prefixname.push_back("PFN:");
    00053   prefixname.push_back("LFN:");
    00054   prefixname.push_back("lfn:");
    00055   prefixname.push_back("guid:");
    00056   prefixname.push_back("surl:");
    00057   prefixname.push_back("srm:");
    00058   prefixname.push_back("gfal:");
    00059   prefixname.push_back("rfio:");
    00060   //prefixname.push_back("castor:");
    00061
    00062   m_isvalid = true;
    00063
    00064   is_pfn  = false;
    00065   is_guid = false;
    00066   is_lfn  = false;
    00067   is_surl = false;
    00068
    00069   for(std::vector<std::string>::iterator i = prefixname.begin() ;
    00070       i != prefixname.end();
    00071       ++i) {
    00072     size_t begpos = name.find(*i) ;
    00073     if ( begpos != name.npos ) {
    00074       size_t ntmp = i->length();
    00075       name.erase(begpos,ntmp);
    00076       if ((*i)        == prefixname[0] ) {
    00077         is_pfn = true;
    00078       } else if ((*i) == prefixname[1] || (*i) == prefixname[2]) {
    00079         is_lfn = true;
    00080       } else if ((*i) == prefixname[3] ) {
    00081         is_guid = true;
    00082       } else if ((*i) == prefixname[4] || (*i) == prefixname[5]) {
    00083         is_surl = true;
    00084       }
    00085       else { }
    00086     }
    00087   }
    00088
    00089
    00090   m_filename = name ;
    00091   m_status = UNKNOWN;
    00092   m_MS=ms;
    00093
    00094
    00095 }
    00096
    00097 GFALStageFile::GFALStageFile(const GFALStageFile& rhs)
    00098 {
    00099   m_filename    = rhs.m_filename;
    00100   m_rawfilename = rhs.m_rawfilename;
    00101   m_status      = rhs.m_status;
    00102   m_reqid       = rhs.m_reqid;
    00103   m_surl        = rhs.m_surl;
    00104   m_turl        = rhs.m_turl;
    00105   is_pfn        = rhs.is_pfn;
    00106   is_lfn        = rhs.is_lfn;
    00107   is_guid       = rhs.is_guid;
    00108   is_surl       = rhs.is_surl;
    00109   m_isvalid     = rhs.m_isvalid;
    00110   m_MS          = rhs.m_MS;
    00111
    00112 }
    00113
    00114
    00115 GFALStageFile& GFALStageFile::operator=(const GFALStageFile& rhs)
    00116 {
    00117
    00118   if (this != &rhs) {
    00119     m_filename    = rhs.m_filename;
    00120     m_rawfilename = rhs.m_rawfilename;
    00121     m_status      = rhs.m_status;
    00122     m_reqid       = rhs.m_reqid;
    00123     m_surl        = rhs.m_surl;
    00124     m_turl        = rhs.m_turl;
    00125     is_pfn        = rhs.is_pfn;
    00126     is_lfn        = rhs.is_lfn;
    00127     is_guid       = rhs.is_guid;
    00128     is_surl       = rhs.is_surl;
    00129     m_isvalid     = rhs.m_isvalid;
    00130     m_MS          = rhs.m_MS;
    00131
    00132   }
    00133
    00134   return *this ;
    00135
    00136 }
    00137
    00138 //=============================================================================
    00139 // Destructor
    00140 //=============================================================================
    00141 GFALStageFile::~GFALStageFile() {}
    00142
    00143 //=============================================================================
    00144 StatusCode GFALStageFile::initialize()
    00145 {
    00146
    00147   MsgStream log( msgSvc(), name() );
    00148
    00149   log << MSG::DEBUG << "initialise()" << endreq;
    00150
    00151   char errbuf[512];
    00152   int errbufsz = 512;
    00153   char * ptr_errbuf = errbuf;
    00154   char * ptr_guid;
    00155   char * ptr_surl;
    00156
    00157   if ( is_pfn ) {
    00158     log << MSG::DEBUG << "File is PFN" << endreq;
    00159     m_surl = std::string("srm://castorgridsc.cern.ch") + m_filename;
    00160     m_status = EXIST;
    00161   }
    00162
    00163   else if ( is_lfn ) {
    00164     m_filename = std::string("/grid") + m_filename;
    00165     log << MSG::DEBUG << "filename: " << m_filename << endreq;
    00166     ptr_guid = guidfromlfn( m_filename.c_str(), ptr_errbuf, errbufsz );
    00167     if (ptr_guid != NULL ) {
    00168       ptr_surl = surlfromguid( ptr_guid, ptr_errbuf, errbufsz );
    00169       if (ptr_surl == NULL ) {
    00170         log << MSG::DEBUG << "Failed to get surl from guid" << endreq;
    00171         log << MSG::ERROR << "surlfromguid> " << std::string(errbuf) << endreq;
    00172         m_isvalid = false;
    00173         return StatusCode::FAILURE;
    00174       }
    00175     }
    00176     else {
    00177       log << MSG::DEBUG << "Failed to get surl from lfn" << endreq;
    00178       m_isvalid = false;
    00179       return StatusCode::FAILURE;
    00180     }
    00181     m_surl = std::string(ptr_surl);
    00182     m_status = EXIST;
    00183   }
    00184
    00185   else if ( is_guid ) {
    00186     ptr_surl = surlfromguid( m_filename.c_str(), ptr_errbuf, errbufsz );
    00187     if (ptr_surl == NULL ) {
    00188       log << MSG::DEBUG << "Failed to get surl from guid" << endreq;
    00189       log << MSG::ERROR << "surlfromguid> " << std::string(errbuf) << endreq;
    00190       m_isvalid = false;
    00191       return StatusCode::FAILURE;
    00192     }
    00193     m_surl = std::string(ptr_surl);
    00194     m_status = EXIST;
    00195   }
    00196
    00197   else if ( is_surl ) {
    00198     m_surl = std::string("srm:") + m_filename;
    00199     m_status = EXIST;
    00200   }
    00201
    00202   else {
    00203     log << MSG::DEBUG << "initiliaze> failed to get SURL" << endreq;
    00204     log << MSG::DEBUG << "initialize> type of input unknown" << endreq;
    00205     m_isvalid = false;
    00206   }
    00207
    00208   log << MSG::DEBUG << "initiliaze> done." << endreq;
    00209
    00210   return StatusCode::SUCCESS;
    00211
    00212 }
    00213
    00214 void GFALStageFile::setStatus(int status)
    00215 {
    00216   if ( status == -1 ) {
    00217     m_status = FAILED;
    00218   }
    00219   else if ( status == 0 ) {
    00220     m_status = STGING;
    00221   }
    00222   else if ( status == 1 ) {
    00223     m_status = STGED;
    00224   }
    00225   else m_status = UNKNOWN;
    00226
    00227 }
    00228
    00229 void GFALStageFile::setSurl(const std::string &surl)
    00230 {
    00231   m_surl = surl;
    00232 }
    00233
    00234 void GFALStageFile::setTurl(const std::string &turl)
    00235 {
    00236   m_turl = turl;
    00237 }
    00238
    00239 void GFALStageFile::setRequestID( int reqid )
    00240 {
    00241   m_reqid = reqid;
    00242 }
    00243
    00244 GFALStageFile::Status GFALStageFile::getStatus() const
    00245 {
    00246   return m_status ;
    00247 }
    00248
    00249
    00250 bool GFALStageFile::isValid() const
    00251 {
    00252   return m_isvalid ;
    00253 }
    00254
    00255 bool GFALStageFile::isPFN() const
    00256 {
    00257   return is_pfn;
    00258 }
    00259
    00260
    00261 int GFALStageFile::getRequestID() const
    00262 {
    00263   return m_reqid ;
    00264 }
    00265
    00266
    00267 std::string GFALStageFile::getSurl() const
    00268 {
    00269   return m_surl ;
    00270 }
    00271
    00272
    00273 std::string GFALStageFile::getTurl() const
    00274 {
    00275   return m_turl ;
    00276 }
    00277
    00278 IMessageSvc* GFALStageFile::msgSvc() const
    00279 {
    00280   return m_MS;
    00281 }
    00282