Skip to content
Snippets Groups Projects
Commit 2f23898e authored by cvs2svn's avatar cvs2svn
Browse files

This commit was manufactured by cvs2svn to create tag

'GAUDI_v19r3pre'.

git-svn-id: svn+ssh://svn.cern.ch/reps/gaudi/distribution/tags/GAUDI/GAUDI_v19r3pre@3745 53ecefc3-a64d-0410-9bdf-b8581fa3287e
parents
No related branches found
No related tags found
No related merge requests found
#============================================================================
# Created : 2006-11-17
# Maintainer : Andres Felipe OSORIO OLIVEROS
#============================================================================
package GaudiGridSvc
version v1r0
#============================================================================
# Structure, i.e. directories to process.
#============================================================================
branches cmt doc src
#============================================================================
# Used packages. Specify the version, * at the end specifies 'any revision'
# Put as many lines as needed, with all packages, without the '#'
#============================================================================
use GaudiKernel v*
#-------------------------------------------------------
#GFAL libraries and dependencies (needed by GFALDataStreamSvc)
use gfal v* LCG_Interfaces -no_auto_imports
use cgsigsoap v* LCG_Interfaces -no_auto_imports
use globusrls v* LCG_Interfaces -no_auto_imports
include_dirs ${gfal_home}/include
macro_append GaudiGridSvc_use_linkopts " ${gfal_linkopts} "
#-------------------------------------------------------
#============================================================================
# Component library building rule
library GaudiGridSvc \
GFALDataStreamTool/*.cpp \
Dll/GaudiGridSvc*.cpp
#============================================================================
# define component library link options
#============================================================================
apply_pattern component_library library=GaudiGridSvc
######################################################################
private
macro_remove constituents "GaudiGridSvc" \
slc3 ""
macro_remove constituents "GaudiGridSvcRootMap" \
slc3 ""
macro_remove constituents "GaudiGridSvcConf" \
slc3 ""
macro_append cppflags "" \
Linux " -pedantic -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-long-long " \
Darwin "" \
WIN32 ""
Package: GaudiGridSvc
Package manager : Hubert Degaudenzi
================ GaudiGridSvc v1r0 ==========================================
! 2007-01-15 - Hubert Degaudenzi
New package.
!============================================================================
// Include Files
#include "GaudiKernel/LoadFactoryEntries.h"
LOAD_FACTORY_ENTRIES(GaudiGridSvc)
// Include Files
#include "GaudiKernel/DeclareFactoryEntries.h"
// Using the MACROS in the previous include file declare all "components" of
// the library.
DECLARE_FACTORY_ENTRIES(GaudiGridSvc) {
DECLARE_TOOL( GFALDataStreamTool );
}
// $Id: GFALDataStreamTool.cpp,v 1.2 2007/01/15 16:49:47 hmd Exp $
// Include files
// from Gaudi
#include "GaudiKernel/DeclareFactoryEntries.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/xtoa.h"
#include "GaudiKernel/SmartIF.h"
#include "GaudiKernel/Incident.h"
#include "GaudiKernel/SvcFactory.h"
#include "GaudiKernel/Tokenizer.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/ISvcManager.h"
#include "GaudiKernel/IAddressCreator.h"
// local
#include "GFALDataStreamTool.h"
//-----------------------------------------------------------------------------
// Implementation file for class : GFALDataStreamTool
//
// 2006-09-29 : Andres Osorio
// : Greig Cowan
//-----------------------------------------------------------------------------
// Declaration of the Tool Factory
DECLARE_TOOL_FACTORY( GFALDataStreamTool );
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
GFALDataStreamTool::GFALDataStreamTool( const std::string& type,
const std::string& name,
const IInterface* parent )
: DataStreamTool ( type, name , parent )
{
declareProperty("BlockSize",m_blocksize = 1 );
declareProperty("InitialStage",m_initstage = 1);
}
//=============================================================================
// Destructor
//=============================================================================
GFALDataStreamTool::~GFALDataStreamTool()
{
std::vector<GFALStageBlock*>::iterator itr = m_blocks.begin() ;
while( (itr != m_blocks.end()) ) {
if ( (*itr) ) delete (*itr);
++itr;
}
}
StatusCode GFALDataStreamTool::initialize() {
MsgStream logger(msgSvc(), name());
StatusCode status = DataStreamTool::initialize();
if( !status.isSuccess() ) {
logger << MSG::FATAL << "Error. Cannot initialize base class." << endreq;
return status;
}
m_streamCount = 1;
m_turlCount = 0;
m_atblock = 0;
m_pos = 0;
m_task = UNKNOWN;
if (m_blocksize < 1) {
logger << MSG::ERROR << "Wrong Block size" << endreq;
logger << MSG::ERROR << "Prestaging disable" << endreq;
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
//=============================================================================
StatusCode GFALDataStreamTool::addStreams(const StreamSpecs & inputs) {
MsgStream logger(msgSvc(), name());
StatusCode status = DataStreamTool::addStreams(inputs);
///////////////////////////
///initialize Stage
m_ntotblocks = 0;
status = setBlocks();
if ( ! status.isSuccess() ){
logger << MSG::ERROR << "Unable to set Blocks" << endreq;
return StatusCode::FAILURE;
}
status = firstBlockStage();
if ( ! status.isSuccess() ) {
logger << MSG::ERROR << "Unable stage first Block" << endreq;
return StatusCode::FAILURE;
}
//Stage first block of files until all files in the block are STAGED
m_task = STGING;
m_blockitr=m_blocks.begin();
while ( ((*m_blockitr)->getStatus() != GFALStageBlock::STGED) && ((*m_blockitr)->getStatus() != GFALStageBlock::FAILED) ) {
status = updateBlockStatus();
}
/////////////////////////////
m_streamTurls = m_streamSpecs;
if( status.isFailure() ){
return status;
}
m_streamCount = 1;
return updateStreamTurls();
}
StatusCode GFALDataStreamTool::finalize() {
StatusCode iret, status = StatusCode::SUCCESS;
iret.ignore();
MsgStream log(msgSvc(), name());
log << MSG::DEBUG << "finalise() starts now!" << endmsg;
for ( StreamSpecs::const_iterator i = m_streamTurls.begin(); i != m_streamTurls.end(); i++ ) {
EventSelectorDataStream * s = DataStreamTool::getStream(*i);
if ( NULL == s ) {
if ( s->isInitialized() ) {
iret = finalizeStream(s);
if ( !iret.isSuccess() ) {
log << MSG::ERROR << "Failed to finalize stream " << *i << endmsg;
status = iret;
}
}
}
iret = eraseStream( *i );
if ( !iret.isSuccess() ) {
log << MSG::ERROR << "Failed to disconnect stream " << *i << endmsg;
status = iret;
}
}
m_streamSpecs.clear(); //The input specification are not needed anymore
log << MSG::DEBUG << "finalise() total files processed " << m_streamID << endmsg;
status = DataStreamTool::finalize();
return status;
}
StatusCode GFALDataStreamTool::getNextStream( const EventSelectorDataStream * & esds, size_type & dsid )
{
EventSelectorDataStream * nextStream = getStream(dsid);
if ( NULL == nextStream ) return StatusCode::FAILURE; //<-end of streams reached
esds = nextStream;
//Stage blocks request
if ( m_task != DONE ) {
if ( (*m_blockitr)->getStatus() == GFALStageBlock::STGED ) {
nextBlockStage().ignore();
updateStreamTurls().ignore();
}
updateBlockStatus().ignore();
}
//
++m_streamID;
return StatusCode::SUCCESS;
}
/////////////////////////////
// Stage files functionality
StatusCode GFALDataStreamTool::setBlocks()
{
MsgStream log (msgSvc(),name());
GFALStageBlock * btmp = new GFALStageBlock(m_blocksize,msgSvc());
log << MSG::DEBUG << "Setting up the blocks of files to stage. Total files: "
<< m_streamSpecs.size()
<< endreq;
log << MSG::DEBUG << "Each block is set to have "
<< m_blocksize << " files."
<< endreq;
StatusCode fstatus = StatusCode::SUCCESS;
int addedfiles(0);
for(StreamSpecs::const_iterator i = m_streamSpecs.begin() ;
i != m_streamSpecs.end(); ++i) {
GFALStageFile * ftmp = new GFALStageFile(*i,msgSvc());
ftmp->initialize().ignore();
if (ftmp->isValid()) {
if ( addedfiles != (int) m_blocksize ) {
fstatus = btmp->addFile(ftmp);
++addedfiles;
}
if ( addedfiles == (int) m_blocksize && (&(*i)!= &m_streamSpecs.back()) ) {
addBlock(btmp);
log << MSG::DEBUG << "adding block" << endreq;
btmp = new GFALStageBlock(m_blocksize,msgSvc());
addedfiles = 0;
}
if (&(*i)==&m_streamSpecs.back()) {
log << MSG::DEBUG << "adding last block" << endreq;
addBlock(btmp);
}
}
else {
log << MSG::DEBUG <<" The file: "
<< ftmp->rawFileName()
<< "] does not exist."
<< endreq;
fstatus = StatusCode::FAILURE;
}
}
log << MSG::DEBUG << "setBlocks done." << endreq;
return fstatus;
}
StatusCode GFALDataStreamTool::firstBlockStage() {
MsgStream log (msgSvc(),name());
if (m_initstage==0) {
log << MSG::DEBUG <<"No initial stage" << endreq;
m_blockindex = 0 ;
} else {
log << MSG::DEBUG <<"Performing initial stage. Total number of blocks: "
<< m_blocks.size() << endreq;
m_blockitr = m_blocks.begin();
log << MSG::DEBUG << "staging first block of files" << endreq;
if ( m_blocks.size() > 0 ) {
StatusCode status = (*m_blockitr)->Stage();
if ( status.isFailure() ){
log << MSG::ERROR << "firstBlockStage> unable to stage first block" << endreq;
return status;
}
}
else {
log << MSG::DEBUG << "Block is empty: check input file format or grid certificate" << endreq;
return StatusCode::FAILURE;
}
}
log << MSG::DEBUG << "firstBlockStage> done." << endreq;
return StatusCode::SUCCESS;
}
StatusCode GFALDataStreamTool::nextBlockStage() {
//Initial stage for each block.
MsgStream log (msgSvc(),name());
if ( (*m_blockitr)->getStatus() != GFALStageBlock::STGED )
return StatusCode::SUCCESS;
++m_blockitr;
if (m_blockitr == m_blocks.end() ) {
log << MSG::DEBUG << "nextBlockStage> Last block reached" << endreq;
m_task = DONE;
return StatusCode::SUCCESS;
}
StatusCode status = (*m_blockitr)->Stage();
if ( status.isFailure() ){
log << MSG::ERROR << "nextBlockStage> unable to stage block" << endreq;
return status;
}
++m_blockindex;
log << MSG::DEBUG << "nextBlockStage> done." << endreq;
return StatusCode::SUCCESS;
}
StatusCode GFALDataStreamTool::updateBlockStatus( )
{
MsgStream log (msgSvc(),name());
if ( m_task == DONE ) return StatusCode::SUCCESS;
log << MSG::DEBUG << "updateStatus> block" << endreq;
(*m_blockitr)->updateStatus();
return StatusCode::SUCCESS;
}
StatusCode GFALDataStreamTool::updateBlockStatus( GFALStageBlock * ablock )
{
MsgStream log (msgSvc(),name());
if ( m_task == DONE ) return StatusCode::SUCCESS;
log << MSG::DEBUG << "updateStatus> block" << endreq;
ablock->updateStatus();
return StatusCode::SUCCESS;
}
void GFALDataStreamTool::addBlock(GFALStageBlock * b)
{
m_blocks.push_back(b);
m_ntotblocks++;
return ;
}
StatusCode GFALDataStreamTool::updateStreamTurls()
{
MsgStream log (msgSvc(),name());
StatusCode status;
log << MSG::DEBUG << "updateStreamTurls>" << endreq;
if ( m_task == DONE ) return StatusCode::SUCCESS;
if ( (*m_blockitr)->getStatus() == GFALStageBlock::STGED) {
std::vector<GFALStageFile*>::iterator stgfile = (*m_blockitr)->m_files.begin() ;
while( (stgfile != (*m_blockitr)->m_files.end() ) ) {
std::string turl = (*stgfile)->getTurl();
if ( (*stgfile)->getStatus() == GFALStageFile::STGED ) {
int pos = m_streamTurls[m_turlCount].find("'",10);
std::string tail = m_streamTurls[m_turlCount].erase(0,pos+1);
std::string head;
if ( ! (*stgfile)->isPFN() ) head = std::string("DATAFILE='gfal:") + turl + std::string("'");
else {
std::string pfnturl = turl.erase(0,8);
head = std::string("DATAFILE='rfio:") + pfnturl + std::string("'");
}
m_streamTurls[m_turlCount] = head + tail;
log << MSG::DEBUG << "Adding to m_streamTurl_" << m_turlCount << "\n"
<< m_streamTurls[m_turlCount] << endmsg;
////////////////////////////////////////////
//Update the data stream list with the turl
StatusCode fts = updateStreams( (*stgfile)->rawFileName(), m_streamTurls[m_turlCount] );
if ( ! fts.isSuccess() ) log << MSG::DEBUG << "Failed to update Stream!" << endmsg;
++m_turlCount;
}
++stgfile;
}
}
return status;
}
StatusCode GFALDataStreamTool::updateStreams( const std::string & oldinfo, const std::string & uptinfo )
{
Streams::iterator i = DataStreamTool::getStreamIterator(oldinfo);
if ( i != m_streams.end() ) {
(*i)->release();
Streams::iterator p = m_streams.erase(i);
char txt[32];
std::string nam = name() + "_" + ::_itoa( ++m_streamCount, txt, 10);
EventSelectorDataStream* s = 0;
StatusCode status = DataStreamTool::createStream(nam, uptinfo, s);
if ( status.isSuccess() ) {
if ( 0 != s ) {
s->addRef();
m_streams.insert(p, s);
return StatusCode::SUCCESS;
}
}
}
return StatusCode::FAILURE;
}
// $Id: GFALDataStreamTool.h,v 1.1.1.1 2007/01/15 12:22:56 hmd Exp $
#ifndef GAUDIGRIDSVC_GFALDATASTREAMTOOL_H
#define GAUDIGRIDSVC_GFALDATASTREAMTOOL_H 1
// Include files
#include <vector>
// Local
#include "GFALStageBlock.h"
// from Gaudi
#include "GaudiKernel/Service.h"
#include "GaudiKernel/IEvtSelector.h"
#include "GaudiKernel/EventSelectorDataStream.h"
#include "GaudiKernel/DataStreamTool.h"
/** @class GFALDataStreamTool GFALDataStreamTool.h GaudiGridSvc/GFALDataStreamTool.h
*
*
* @author Andres Osorio
* @author Greig Cowan
* @date 2006-09-29
*
* Implementation of DataStreamTool using GFAL
*
*
*/
//class DataStreamTool;
class GFALDataStreamTool : virtual public DataStreamTool {
public:
enum Status {UNKNOWN=0,STGING,DONE};
/// Standard constructor
GFALDataStreamTool( const std::string& type,
const std::string& name,
const IInterface* parent);
virtual ~GFALDataStreamTool( ); ///< Destructor
virtual StatusCode initialize();
virtual StatusCode finalize();
virtual StatusCode addStreams(const StreamSpecs &);
virtual StatusCode getNextStream( const EventSelectorDataStream* &, size_type & );
protected:
StatusCode updateStreams( const std::string & , const std::string & );
private:
size_type m_turlCount;
StreamSpecs m_streamTurls;
StatusCode setBlocks();
StatusCode firstBlockStage();
StatusCode nextBlockStage();
StatusCode updateBlockStatus();
StatusCode updateBlockStatus(GFALStageBlock *);
StatusCode updateStreamTurls();
void addBlock(GFALStageBlock *);
std::vector<GFALStageBlock*> m_blocks ;
std::vector<GFALStageBlock*>::iterator m_blockitr;
long int m_pos;
size_t m_blockindex ;
///< index of the last staged block
size_t m_ntotblocks ;
///< total number of blocks
size_t m_blocksize ;
///< number of files in one stage block
size_t m_initstage ;
///< number of blocks for the initial prestage
size_t m_readfile ;
///< number of files (streams) read.
int m_atblock ;
Status m_task;
};
#endif // GAUDIGRIDSVC_GFALDATASTREAMTOOL_H
// $Id: GFALStageBlock.cpp,v 1.1.1.1 2007/01/15 12:22:56 hmd Exp $
// Include files
// local
#include "GFALStageBlock.h"
//From Gaudi
#include "GaudiKernel/GaudiException.h"
#include "GaudiKernel/System.h"
//-----------------------------------------------------------------------------
// Implementation file for class : GFALStageBlock
//
// 2006-11-11 : Andres Felipe OSORIO OLIVEROS
// Greig COWAN
//-----------------------------------------------------------------------------
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
GFALStageBlock::GFALStageBlock( ) {
}
GFALStageBlock::GFALStageBlock(size_t nmaxfiles,IMessageSvc* ms)
{
m_MS = ms ;
m_status = UNKNOWN ;
m_nmaxfiles = nmaxfiles ;
m_nfiles = 0 ;
updateFillStatus();
m_protocols.push_back(std::string("rfio"));
m_protocols.push_back(std::string("gsidcap"));
m_protocols.push_back(std::string("gridftp"));
}
//=============================================================================
// Destructor
//=============================================================================
GFALStageBlock::~GFALStageBlock() {
std::vector<GFALStageFile*>::iterator itr = m_files.begin() ;
while( (itr != m_files.end()) ) {
if ( (*itr) ) delete (*itr);
++itr;
}
}
//=============================================================================
StatusCode GFALStageBlock::stageInitialize()
{
StatusCode stc = StatusCode::SUCCESS ;
MsgStream log( msgSvc(), name() );
log << MSG::DEBUG << "stageInitialize> preparing files for stage process" << endreq;
if (m_nfiles == 0) {
return StatusCode::FAILURE;
}
//get for each GFALStageFile its surl
int k=0;
m_nmaxfiles = m_files.size();
for(std::vector<GFALStageFile*>::iterator itr = m_files.begin();
itr != m_files.end();
++itr)
{
if( (*itr)->isValid() ) {
std::string fsurl = (*itr)->getSurl();
m_surls.push_back(fsurl);
ptr_surls[k] = (char*) fsurl.c_str();
++k;
}
else {
//GFALStageFile set to status=unknown
log << MSG::DEBUG << "stageInitialize> could not get surl from file" << endreq;
stc = StatusCode::FAILURE;
}
}
//protocols
k = 0;
for(std::vector<std::string>::iterator itr = m_protocols.begin();
itr != m_protocols.end();
++itr) {
std::string protocol = (*itr);
ptr_protocols[k] = (char*) protocol.c_str();
++k;
}
m_nprotocols = m_protocols.size();
//Not fully implemented (in gfal)
m_reqid = 0;
m_tokens = 0;
m_errbuf = NULL;
m_errbufsz = 0;
//Timeout default value
m_timeout = 100;
log << MSG::DEBUG << "stageInitialize> done" << endreq;
return stc;
}
StatusCode GFALStageBlock::Stage()
{
StatusCode stc = StatusCode::SUCCESS ;
MsgStream log( msgSvc(), name() );
log << MSG::DEBUG << "Stage> starts here." << endreq;
if ( stageInitialize()==StatusCode::FAILURE) {
stc = StatusCode::FAILURE ;
return stc ;
}
if ( stageFinalize()==StatusCode::FAILURE) {
stc = StatusCode::FAILURE ;
}
char ** p_surls = &ptr_surls[0];
p_surls = &ptr_surls[0];
log << MSG::DEBUG << "invoking srm_getx()" << endreq;
int ret = srm_getx( m_nmaxfiles, p_surls, m_nprotocols,
ptr_protocols, &m_reqid, m_tokens,
&m_filestatuses, m_errbuf, m_errbufsz, m_timeout);
log << MSG::DEBUG << "srm_getx() returned: " << ret << endreq;
log << MSG::DEBUG << "checking now filestatus: " << endreq;
if ( ret == -1 ) return StatusCode::FAILURE;
struct srm_filestatus *fs = m_filestatuses;
std::vector<GFALStageFile*>::iterator itr = m_files.begin();
int pos = 0;
int nstaging = 0;
int nstaged = 0;
for( int i = 0; i < (int)m_nmaxfiles; ++i) {
log << MSG::DEBUG << "file status: " << fs->status << endreq;
(*itr)->setStatus( fs->status );
if( fs->status == -1 ) {
log << MSG::DEBUG << "File is FAILED" << endreq;
m_failedAt.push_back( pos );
}
else if ( fs->status == 0 ) {
log << MSG::DEBUG << "File is STGING" << endreq;
(*itr)->setTurl(std::string("PENDING"));
(*itr)->setRequestID( fs->fileid );
++nstaging;
}
else if ( fs->status == 1 ) {
log << MSG::DEBUG << "File is STGED" << endreq;
(*itr)->setTurl(std::string( fs->turl ));
(*itr)->setRequestID( fs->fileid );
log << MSG::DEBUG << "turl: \n"
<< std::string( fs->turl ) << endreq;
++nstaged;
}
else {
log << MSG::DEBUG << "status UNKNOWN" << endreq;
}
++itr;
fs++;
}
if ( nstaging > 0 ) m_status = STGING;
else if (nstaged == (int)m_nmaxfiles) {
log << MSG::DEBUG << "block set to STGED" << endreq;
m_status = STGED;
}
else {
log << MSG::DEBUG << "block set to FAILED" << endreq;
m_status = FAILED;
}
log << MSG::DEBUG << " Stage> done" << endreq;
return stc ;
}
StatusCode GFALStageBlock::stageFinalize()
{
StatusCode stc = StatusCode::SUCCESS ;
return stc ;
}
StatusCode GFALStageBlock::addFile(GFALStageFile * stgfile)
{
MsgStream log( msgSvc(), name() );
if (getFillStatus()==FULL) {
log << MSG::DEBUG << "addFile> Failed. block is full" << endreq;
return StatusCode::FAILURE;
}
m_files.push_back(stgfile);
m_nfiles++;
updateFillStatus();
return StatusCode::SUCCESS;
}
void GFALStageBlock::updateFillStatus()
{
if(m_nfiles == 0) {
m_fillstatus = EMPTY ;
}
else if(m_nfiles != 0){
m_fillstatus = FREE ;
}
else if(m_nfiles == (m_nmaxfiles-1)) {
m_fillstatus = FULL ;
}
else {}
return ;
}
void GFALStageBlock::updateStatus()
{
MsgStream log( msgSvc(), name() );
char ** p_surls = &ptr_surls[0];
p_surls = &ptr_surls[0];
int ret = srm_get( m_nmaxfiles, p_surls, m_nprotocols, ptr_protocols, &m_reqid, m_tokens,
&m_filestatuses, m_timeout);
log << MSG::DEBUG << "srm_get() returned: " << ret << endreq;
log << MSG::DEBUG << "checking now filestatus: " << endreq;
if ( ret == -1 ) return;
struct srm_filestatus *fs = m_filestatuses;
std::vector<GFALStageFile*>::iterator itr = m_files.begin();
int pos = 0;
int nstaged = 0;
int nfailed = 0;
for( int i = 0; i < (int)m_nmaxfiles; ++i) {
log << MSG::DEBUG << "file status: " << fs->status << endreq;
(*itr)->setStatus( fs->status );
if( fs->status == -1 ) {
log << MSG::DEBUG << "File is FAILED" << endreq;
m_failedAt.push_back( pos );
++nfailed;
}
else if ( fs->status == 0 ) {
log << MSG::DEBUG << "File is STGING" << endreq;
(*itr)->setTurl(std::string("PENDING"));
(*itr)->setRequestID( fs->fileid );
}
else if ( fs->status == 1 ) {
log << MSG::DEBUG << "File is STGED" << endreq;
log << MSG::DEBUG << "turl:"
<< std::string( fs->turl ) << endreq;
(*itr)->setTurl(std::string( fs->turl ));
(*itr)->setRequestID( fs->fileid );
++nstaged;
}
else {
log << MSG::DEBUG << "UNKNOWN status" << endreq;
}
++itr;
fs++;
++pos;
}
if (nstaged == ( (int) m_nmaxfiles - nfailed) && nstaged != 0 ) m_status = STGED ;
else if ( nfailed == (int) m_nmaxfiles ) m_status = FAILED;
else m_status = STGING;
return ;
}
GFALStageBlock::Status GFALStageBlock::getStatus() const
{
return m_status ;
}
GFALStageBlock::FillStatus GFALStageBlock::getFillStatus() const
{
return m_fillstatus ;
}
// $Id: GFALStageBlock.h,v 1.1.1.1 2007/01/15 12:22:56 hmd Exp $
#ifndef GAUDIGRIDSVC_GFALSTAGEBLOCK_H
#define GAUDIGRIDSVC_GFALSTAGEBLOCK_H 1
// Include files
#include <string>
#include <vector>
#include <iterator>
#include "GFALStageFile.h"
/** @class GFALStageBlock GFALStageBlock.h GaudiGridSvc/GFALStageBlock.h
*
*
* @author Andres Felipe OSORIO OLIVEROS
* @author Greig COWAN
* @date 2006-11-11
*
*
*
*/
class GFALStageBlock {
public:
enum Status {UNKNOWN=0,STGING,STGED,FAILED} ;
enum FillStatus {EMPTY=0,FREE,FULL} ;
/// Standard constructor
GFALStageBlock( );
virtual ~GFALStageBlock( ); ///< Destructor
GFALStageBlock(size_t nmaxfiles,IMessageSvc* ms) ;
StatusCode Stage() ;
StatusCode stageInitialize() ;
StatusCode stageFinalize() ;
StatusCode addFile(GFALStageFile *) ;
void updateStatus() ;
Status getStatus() const;
FillStatus getFillStatus() const ;
const std::string name() const { return std::string("StageBlock") ; }
IMessageSvc* msgSvc() const { return m_MS ; }
std::vector<GFALStageFile*> m_files ;
protected:
private:
void updateFillStatus() ;
size_t m_nfiles ;
size_t m_nmaxfiles;
int m_nprotocols;
std::vector<std::string> m_surls;
std::vector<std::string> m_protocols;
std::vector<int> m_failedAt;
//gfal srm_getx arguments:
char *ptr_surls[10000];
char *ptr_protocols[100];
char **m_tokens;
int m_reqid;
char *m_errbuf;
int m_errbufsz;
int m_timeout;
struct srm_filestatus *m_filestatuses;
Status m_status ;
FillStatus m_fillstatus ;
mutable IMessageSvc* m_MS ;
};
#endif // GAUDIGRIDSVC_GFALSTAGEBLOCK_H
// $Id: GFALStageFile.cpp,v 1.1.1.1 2007/01/15 12:22:56 hmd Exp $
// Include files
// local
#include "GFALStageFile.h"
// From Gaudi
#include "GaudiKernel/Tokenizer.h"
#include "GaudiKernel/GaudiException.h"
#include "GaudiKernel/MsgStream.h"
//-----------------------------------------------------------------------------
// Implementation file for class : GFALStageFile
//
// 2006-11-11 : Andres Felipe Osorio Oliveros
// Greig COWAN
//
//
//-----------------------------------------------------------------------------
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
GFALStageFile::GFALStageFile( ) {
}
GFALStageFile::GFALStageFile(std::string name,IMessageSvc* ms)
{
Tokenizer tok(true);
m_MS=ms;
m_rawfilename = name ;
tok.analyse(m_rawfilename, " ", "", "", "=", "'", "'");
for ( Tokenizer::Items::iterator i = tok.items().begin();
i != tok.items().end();
i++ ) {
const std::string& tag = (*i).tag();
const std::string& val = (*i).value();
if (::toupper(tag[0])=='D') {
name = val ;
}
}
std::vector<std::string> prefixname;
prefixname.push_back("PFN:");
prefixname.push_back("LFN:");
prefixname.push_back("lfn:");
prefixname.push_back("guid:");
prefixname.push_back("surl:");
prefixname.push_back("srm:");
prefixname.push_back("gfal:");
prefixname.push_back("rfio:");
//prefixname.push_back("castor:");
m_isvalid = true;
is_pfn = false;
is_guid = false;
is_lfn = false;
is_surl = false;
for(std::vector<std::string>::iterator i = prefixname.begin() ;
i != prefixname.end();
++i) {
size_t begpos = name.find(*i) ;
if ( begpos != name.npos ) {
size_t ntmp = i->length();
name.erase(begpos,ntmp);
if ((*i) == prefixname[0] ) {
is_pfn = true;
} else if ((*i) == prefixname[1] || (*i) == prefixname[2]) {
is_lfn = true;
} else if ((*i) == prefixname[3] ) {
is_guid = true;
} else if ((*i) == prefixname[4] || (*i) == prefixname[5]) {
is_surl = true;
}
else { }
}
}
m_filename = name ;
m_status = UNKNOWN;
m_MS=ms;
}
GFALStageFile::GFALStageFile(const GFALStageFile& rhs)
{
m_filename = rhs.m_filename;
m_rawfilename = rhs.m_rawfilename;
m_status = rhs.m_status;
m_reqid = rhs.m_reqid;
m_surl = rhs.m_surl;
m_turl = rhs.m_turl;
is_pfn = rhs.is_pfn;
is_lfn = rhs.is_lfn;
is_guid = rhs.is_guid;
is_surl = rhs.is_surl;
m_isvalid = rhs.m_isvalid;
m_MS = rhs.m_MS;
}
GFALStageFile& GFALStageFile::operator=(const GFALStageFile& rhs)
{
if (this != &rhs) {
m_filename = rhs.m_filename;
m_rawfilename = rhs.m_rawfilename;
m_status = rhs.m_status;
m_reqid = rhs.m_reqid;
m_surl = rhs.m_surl;
m_turl = rhs.m_turl;
is_pfn = rhs.is_pfn;
is_lfn = rhs.is_lfn;
is_guid = rhs.is_guid;
is_surl = rhs.is_surl;
m_isvalid = rhs.m_isvalid;
m_MS = rhs.m_MS;
}
return *this ;
}
//=============================================================================
// Destructor
//=============================================================================
GFALStageFile::~GFALStageFile() {}
//=============================================================================
StatusCode GFALStageFile::initialize()
{
MsgStream log( msgSvc(), name() );
log << MSG::DEBUG << "initialise()" << endreq;
char errbuf[512];
int errbufsz = 512;
char * ptr_errbuf = errbuf;
char * ptr_guid;
char * ptr_surl;
if ( is_pfn ) {
log << MSG::DEBUG << "File is PFN" << endreq;
m_surl = std::string("srm://castorgridsc.cern.ch") + m_filename;
m_status = EXIST;
}
else if ( is_lfn ) {
m_filename = std::string("/grid") + m_filename;
log << MSG::DEBUG << "filename: " << m_filename << endreq;
ptr_guid = guidfromlfn( m_filename.c_str(), ptr_errbuf, errbufsz );
if (ptr_guid != NULL ) {
ptr_surl = surlfromguid( ptr_guid, ptr_errbuf, errbufsz );
if (ptr_surl == NULL ) {
log << MSG::DEBUG << "Failed to get surl from guid" << endreq;
log << MSG::ERROR << "surlfromguid> " << std::string(errbuf) << endreq;
m_isvalid = false;
return StatusCode::FAILURE;
}
}
else {
log << MSG::DEBUG << "Failed to get surl from lfn" << endreq;
m_isvalid = false;
return StatusCode::FAILURE;
}
m_surl = std::string(ptr_surl);
m_status = EXIST;
}
else if ( is_guid ) {
ptr_surl = surlfromguid( m_filename.c_str(), ptr_errbuf, errbufsz );
if (ptr_surl == NULL ) {
log << MSG::DEBUG << "Failed to get surl from guid" << endreq;
log << MSG::ERROR << "surlfromguid> " << std::string(errbuf) << endreq;
m_isvalid = false;
return StatusCode::FAILURE;
}
m_surl = std::string(ptr_surl);
m_status = EXIST;
}
else if ( is_surl ) {
m_surl = std::string("srm:") + m_filename;
m_status = EXIST;
}
else {
log << MSG::DEBUG << "initiliaze> failed to get SURL" << endreq;
log << MSG::DEBUG << "initialize> type of input unknown" << endreq;
m_isvalid = false;
}
log << MSG::DEBUG << "initiliaze> done." << endreq;
return StatusCode::SUCCESS;
}
void GFALStageFile::setStatus(int status)
{
if ( status == -1 ) {
m_status = FAILED;
}
else if ( status == 0 ) {
m_status = STGING;
}
else if ( status == 1 ) {
m_status = STGED;
}
else m_status = UNKNOWN;
}
void GFALStageFile::setSurl(const std::string &surl)
{
m_surl = surl;
}
void GFALStageFile::setTurl(const std::string &turl)
{
m_turl = turl;
}
void GFALStageFile::setRequestID( int reqid )
{
m_reqid = reqid;
}
GFALStageFile::Status GFALStageFile::getStatus() const
{
return m_status ;
}
bool GFALStageFile::isValid() const
{
return m_isvalid ;
}
bool GFALStageFile::isPFN() const
{
return is_pfn;
}
int GFALStageFile::getRequestID() const
{
return m_reqid ;
}
std::string GFALStageFile::getSurl() const
{
return m_surl ;
}
std::string GFALStageFile::getTurl() const
{
return m_turl ;
}
IMessageSvc* GFALStageFile::msgSvc() const
{
return m_MS;
}
// $Id: GFALStageFile.h,v 1.1.1.1 2007/01/15 12:22:56 hmd Exp $
#ifndef GAUDIGRIDSVC_GFALSTAGEFILE_H
#define GAUDIGRIDSVC_GFALSTAGEFILE_H 1
// Include files
#include <string>
#include <vector>
#include <iterator>
//From Gaudi
#include <GaudiKernel/StatusCode.h>
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/IMessageSvc.h"
//GFAL_API utilities
#include <fcntl.h>
extern "C" {
#include "gfal_api.h"
}
/** @class GFALStageFile GFALStageFile.h GaudiGridSvc/GFALStageFile.h
*
*
* @author Andres Felipe Osorio Oliveros
* @author Greig Cowan
*
*
* @date 2006-11-11
*/
class GFALStageFile {
public:
enum Status {FAILED=-1,STGING,STGED,EXIST,UNKNOWN};
/// Standard constructor
GFALStageFile( );
GFALStageFile(std::string name,IMessageSvc* ms);
GFALStageFile(const GFALStageFile&);
GFALStageFile& operator=(const GFALStageFile&);
virtual ~GFALStageFile( );
StatusCode initialize();
Status getStatus() const ;
int getRequestID() const;
std::string getSurl() const ;
std::string getTurl() const ;
bool isPFN() const;
void setStatus(int );
void setSurl( const std::string &);
void setTurl( const std::string &);
void setRequestID( int );
static const std::string name() { return "StageFile" ; }
const std::string fileName() const { return m_filename ; }
const std::string rawFileName() const { return m_rawfilename ; }
bool isValid() const;
IMessageSvc* msgSvc() const ;
protected:
private:
std::string m_filename ;
std::string m_rawfilename ;
Status m_status;
int m_reqid ;
std::string m_surl ;
std::string m_turl ;
bool is_pfn ;
bool is_lfn ;
bool is_guid ;
bool is_surl ;
bool m_isvalid;
mutable IMessageSvc* m_MS ;
};
#endif // GAUDIGRIDSVC_GFALSTAGEFILE_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment