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

# GFALStageBlock Class Reference

`#include <GaudiGridSvc/GFALStageBlock.h>`

Collaboration diagram for GFALStageBlock:

[legend]

List of all members.

## Detailed Description

Author:
  Andres Felipe OSORIO OLIVEROS

  Greig COWAN

Date:
  2006-11-11

Definition at line 24 of file GFALStageBlock.h.

## Public Types
enum | Status { UNKNOWN = 0, STGING, STGED, FAILED }
enum | FillStatus { EMPTY = 0, FREE, FULL }
## Public Member Functions
| GFALStageBlock ()
| Standard constructor.
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
IMessageSvc * | msgSvc () const
## Public Attributes
std::vector< GFALStageFile * > | m_files
## Private Member Functions
void | updateFillStatus ()
## Private Attributes
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
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
IMessageSvc * | m_MS

## Member Enumeration Documentation

enum GFALStageBlock::Status

Enumerator:

  UNKNOWN |
  STGING |
  STGED |
  FAILED |

Definition at line 27 of file GFALStageBlock.h.

    00027 {UNKNOWN=0,STGING,STGED,FAILED} ;

enum GFALStageBlock::FillStatus

Enumerator:

  EMPTY |
  FREE |
  FULL |

Definition at line 28 of file GFALStageBlock.h.

    00028 {EMPTY=0,FREE,FULL} ;

## Constructor & Destructor Documentation

GFALStageBlock::GFALStageBlock | ( |  | ) |

Standard constructor.

Definition at line 21 of file GFALStageBlock.cpp.

    00021                                  {
    00022
    00023 }

GFALStageBlock::~GFALStageBlock | ( |  | ) | `[virtual]`

Destructor.

Definition at line 42 of file GFALStageBlock.cpp.

    00042                                 {
    00043
    00044   std::vector<GFALStageFile*>::iterator itr = m_files.begin() ;
    00045   while( (itr != m_files.end()) ) {
    00046     if ( (*itr) ) delete (*itr);
    00047     ++itr;
    00048   }
    00049
    00050 }

GFALStageBlock::GFALStageBlock | ( | size_t | nmaxfiles,
|  | IMessageSvc * | ms |
| ) |  |  |

Definition at line 25 of file GFALStageBlock.cpp.

    00026 {
    00027
    00028   m_MS = ms ;
    00029   m_status = UNKNOWN ;
    00030   m_nmaxfiles = nmaxfiles ;
    00031   m_nfiles = 0 ;
    00032   updateFillStatus();
    00033   m_protocols.push_back(std::string("rfio"));
    00034   m_protocols.push_back(std::string("gsidcap"));
    00035   m_protocols.push_back(std::string("gridftp"));
    00036
    00037 }

## Member Function Documentation

StatusCode GFALStageBlock::Stage | ( |  | ) |

Definition at line 116 of file GFALStageBlock.cpp.

    00117 {
    00118
    00119   StatusCode stc = StatusCode::SUCCESS ;
    00120
    00121   MsgStream log( msgSvc(), name() );
    00122
    00123   log << MSG::DEBUG << "Stage> starts here." << endreq;
    00124
    00125   if ( stageInitialize()==StatusCode::FAILURE) {
    00126     stc = StatusCode::FAILURE ;
    00127     return stc ;
    00128   }
    00129
    00130   if ( stageFinalize()==StatusCode::FAILURE) {
    00131     stc = StatusCode::FAILURE ;
    00132   }
    00133
    00134   log << MSG::DEBUG << "invoking srm_getx()" << endreq;
    00135
    00136   int ret = srm_getx( m_nmaxfiles, const_cast<const char **>(ptr_surls),
    00137                       m_nprotocols, ptr_protocols, &m_reqid,
    00138                       &m_filestatuses, m_errbuf, m_errbufsz, m_timeout);
    00139
    00140   log << MSG::DEBUG << "srm_getx() returned: " << ret << endreq;
    00141   log << MSG::DEBUG << "checking now filestatus: " << endreq;
    00142
    00143   if ( ret == -1 ) return StatusCode::FAILURE;
    00144
    00145   struct srm_filestatus *fs = m_filestatuses;
    00146
    00147   std::vector<GFALStageFile*>::iterator itr = m_files.begin();
    00148
    00149   int pos = 0;
    00150   int nstaging = 0;
    00151   int nstaged = 0;
    00152
    00153   for( int i = 0; i < (int)m_nmaxfiles; ++i) {
    00154
    00155     log << MSG::DEBUG << "file status: " << fs->status << endreq;
    00156     (*itr)->setStatus( fs->status );
    00157
    00158     if( fs->status == -1 ) {
    00159       log << MSG::DEBUG << "File is FAILED" << endreq;
    00160       m_failedAt.push_back( pos );
    00161     }
    00162     else if ( fs->status == 0 ) {
    00163       log << MSG::DEBUG << "File is STGING" << endreq;
    00164       (*itr)->setTurl(std::string("PENDING"));
    00165       (*itr)->setRequestID( fs->fileid );
    00166       ++nstaging;
    00167     }
    00168     else if ( fs->status == 1 ) {
    00169       log << MSG::DEBUG << "File is STGED" << endreq;
    00170       (*itr)->setTurl(std::string( fs->turl ));
    00171       (*itr)->setRequestID( fs->fileid );
    00172       log << MSG::DEBUG << "turl: \n"
    00173           << std::string( fs->turl ) << endreq;
    00174       ++nstaged;
    00175     }
    00176     else {
    00177       log << MSG::DEBUG << "status UNKNOWN" << endreq;
    00178     }
    00179
    00180     ++itr;
    00181     fs++;
    00182   }
    00183
    00184   if ( nstaging > 0 ) m_status = STGING;
    00185   else if (nstaged == (int)m_nmaxfiles) {
    00186     log << MSG::DEBUG << "block set to STGED" << endreq;
    00187     m_status = STGED;
    00188   }
    00189   else {
    00190     log << MSG::DEBUG << "block set to FAILED" << endreq;
    00191     m_status = FAILED;
    00192   }
    00193
    00194   log << MSG::DEBUG << " Stage> done" << endreq;
    00195
    00196   return stc ;
    00197
    00198 }

StatusCode GFALStageBlock::stageInitialize | ( |  | ) |

Definition at line 53 of file GFALStageBlock.cpp.

    00054 {
    00055
    00056   StatusCode stc = StatusCode::SUCCESS ;
    00057
    00058   MsgStream log( msgSvc(), name() );
    00059   log << MSG::DEBUG << "stageInitialize> preparing files for stage process" << endreq;
    00060
    00061   if (m_nfiles == 0) {
    00062     return StatusCode::FAILURE;
    00063   }
    00064
    00065   //get for each GFALStageFile its surl
    00066   int k=0;
    00067
    00068   m_nmaxfiles = m_files.size();
    00069
    00070   for(std::vector<GFALStageFile*>::iterator itr = m_files.begin();
    00071       itr != m_files.end();
    00072       ++itr)
    00073   {
    00074
    00075     if( (*itr)->isValid() ) {
    00076       std::string fsurl = (*itr)->getSurl();
    00077       m_surls.push_back(fsurl);
    00078       ptr_surls[k] = (char*) fsurl.c_str();
    00079       ++k;
    00080     }
    00081     else {
    00082       //GFALStageFile set to status=unknown
    00083       log << MSG::DEBUG << "stageInitialize> could not get surl from file"  << endreq;
    00084       stc = StatusCode::FAILURE;
    00085     }
    00086   }
    00087
    00088   //protocols
    00089   k = 0;
    00090   for(std::vector<std::string>::iterator itr = m_protocols.begin();
    00091       itr != m_protocols.end();
    00092       ++itr) {
    00093     std::string protocol = (*itr);
    00094     ptr_protocols[k] = (char*) protocol.c_str();
    00095     ++k;
    00096   }
    00097
    00098   m_nprotocols = m_protocols.size();
    00099
    00100   //Not fully implemented (in gfal)
    00101   m_reqid    = 0;
    00102   //m_tokens   = 0;
    00103   m_errbuf   = NULL;
    00104   m_errbufsz = 0;
    00105
    00106   //Timeout default value
    00107   m_timeout  = 100;
    00108
    00109   log << MSG::DEBUG << "stageInitialize> done" << endreq;
    00110
    00111   return stc;
    00112
    00113 }

StatusCode GFALStageBlock::stageFinalize | ( |  | ) |

Definition at line 201 of file GFALStageBlock.cpp.

    00202 {
    00203
    00204   StatusCode stc = StatusCode::SUCCESS ;
    00205   return stc ;
    00206
    00207 }

StatusCode GFALStageBlock::addFile | ( | GFALStageFile * | stgfile | ) |

Definition at line 210 of file GFALStageBlock.cpp.

    00211 {
    00212
    00213   MsgStream log( msgSvc(), name() );
    00214
    00215   if (getFillStatus()==FULL) {
    00216     log << MSG::DEBUG << "addFile> Failed. block is full" << endreq;
    00217     return StatusCode::FAILURE;
    00218   }
    00219
    00220   m_files.push_back(stgfile);
    00221   m_nfiles++;
    00222   updateFillStatus();
    00223
    00224   return StatusCode::SUCCESS;
    00225
    00226 }

void GFALStageBlock::updateStatus | ( |  | ) |

Definition at line 246 of file GFALStageBlock.cpp.

    00247 {
    00248
    00249   MsgStream log( msgSvc(), name() );
    00250
    00251   int ret = srm_get( m_nmaxfiles,const_cast<const char**>(ptr_surls),
    00252                      m_nprotocols, ptr_protocols, &m_reqid, m_tokens,
    00253                      &m_filestatuses, m_timeout);
    00254
    00255   log << MSG::DEBUG << "srm_get() returned: " << ret << endreq;
    00256   log << MSG::DEBUG << "checking now filestatus: " << endreq;
    00257
    00258   if ( ret == -1 ) return;
    00259
    00260   struct srm_filestatus *fs = m_filestatuses;
    00261
    00262   std::vector<GFALStageFile*>::iterator itr = m_files.begin();
    00263
    00264   int pos = 0;
    00265   int nstaged = 0;
    00266   int nfailed = 0;
    00267
    00268   for( int i = 0; i < (int)m_nmaxfiles; ++i) {
    00269
    00270     log << MSG::DEBUG << "file status: " << fs->status << endreq;
    00271     (*itr)->setStatus( fs->status );
    00272
    00273     if( fs->status == -1 ) {
    00274       log << MSG::DEBUG << "File is FAILED" << endreq;
    00275       m_failedAt.push_back( pos );
    00276       ++nfailed;
    00277     }
    00278     else if ( fs->status == 0 ) {
    00279       log << MSG::DEBUG << "File is STGING" << endreq;
    00280       (*itr)->setTurl(std::string("PENDING"));
    00281       (*itr)->setRequestID( fs->fileid );
    00282     }
    00283     else if ( fs->status == 1 ) {
    00284       log << MSG::DEBUG << "File is STGED" << endreq;
    00285       log << MSG::DEBUG << "turl:"
    00286           << std::string( fs->turl ) << endreq;
    00287       (*itr)->setTurl(std::string( fs->turl ));
    00288       (*itr)->setRequestID( fs->fileid );
    00289       ++nstaged;
    00290     }
    00291     else {
    00292       log << MSG::DEBUG << "UNKNOWN status" << endreq;
    00293     }
    00294
    00295     ++itr;
    00296     fs++;
    00297     ++pos;
    00298   }
    00299
    00300   if (nstaged == ( (int) m_nmaxfiles - nfailed) && nstaged != 0 ) m_status = STGED ;
    00301   else if ( nfailed == (int) m_nmaxfiles ) m_status = FAILED;
    00302   else  m_status = STGING;
    00303
    00304   return ;
    00305
    00306 }

GFALStageBlock::Status GFALStageBlock::getStatus | ( |  | ) | const

Definition at line 308 of file GFALStageBlock.cpp.

    00309 {
    00310   return m_status ;
    00311 }

GFALStageBlock::FillStatus GFALStageBlock::getFillStatus | ( |  | ) | const

Definition at line 314 of file GFALStageBlock.cpp.

    00315 {
    00316   return m_fillstatus ;
    00317 }

const std::string GFALStageBlock::name | ( |  | ) | const`[inline]`

Definition at line 51 of file GFALStageBlock.h.

    00051 { return std::string("StageBlock") ; }

IMessageSvc* GFALStageBlock::msgSvc | ( |  | ) | const`[inline]`

Definition at line 53 of file GFALStageBlock.h.

    00053 { return m_MS ; }

void GFALStageBlock::updateFillStatus | ( |  | ) | `[private]`

Definition at line 228 of file GFALStageBlock.cpp.

    00229 {
    00230   if(m_nfiles == 0) {
    00231     m_fillstatus = EMPTY ;
    00232   }
    00233   else if(m_nfiles != 0){
    00234     m_fillstatus = FREE ;
    00235   }
    00236   else if(m_nfiles == (m_nmaxfiles-1)) {
    00237     m_fillstatus = FULL ;
    00238   }
    00239
    00240   else {}
    00241
    00242   return ;
    00243
    00244 }

## Member Data Documentation

std::vector<GFALStageFile*> GFALStageBlock::m_files

Definition at line 55 of file GFALStageBlock.h.

size_t GFALStageBlock::m_nfiles`[private]`

Definition at line 64 of file GFALStageBlock.h.

size_t GFALStageBlock::m_nmaxfiles`[private]`

Definition at line 65 of file GFALStageBlock.h.

int GFALStageBlock::m_nprotocols`[private]`

Definition at line 66 of file GFALStageBlock.h.

std::vector<std::string> GFALStageBlock::m_surls`[private]`

Definition at line 68 of file GFALStageBlock.h.

std::vector<std::string> GFALStageBlock::m_protocols`[private]`

Definition at line 69 of file GFALStageBlock.h.

std::vector<int> GFALStageBlock::m_failedAt`[private]`

Definition at line 71 of file GFALStageBlock.h.

char* GFALStageBlock::ptr_surls[10000]`[private]`

Definition at line 75 of file GFALStageBlock.h.

char* GFALStageBlock::ptr_protocols[100]`[private]`

Definition at line 76 of file GFALStageBlock.h.

char** GFALStageBlock::m_tokens`[private]`

Definition at line 77 of file GFALStageBlock.h.

int GFALStageBlock::m_reqid`[private]`

Definition at line 78 of file GFALStageBlock.h.

char* GFALStageBlock::m_errbuf`[private]`

Definition at line 79 of file GFALStageBlock.h.

int GFALStageBlock::m_errbufsz`[private]`

Definition at line 80 of file GFALStageBlock.h.

int GFALStageBlock::m_timeout`[private]`

Definition at line 81 of file GFALStageBlock.h.

struct srm_filestatus* GFALStageBlock::m_filestatuses`[read, private]`

Definition at line 83 of file GFALStageBlock.h.

Status GFALStageBlock::m_status`[private]`

Definition at line 85 of file GFALStageBlock.h.

FillStatus GFALStageBlock::m_fillstatus`[private]`

Definition at line 87 of file GFALStageBlock.h.

IMessageSvc* GFALStageBlock::m_MS`[mutable, private]`

Definition at line 89 of file GFALStageBlock.h.

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r3/GaudiGridSvc/src/GFALDataStreamTool/GFALStageBlock.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r3/GaudiGridSvc/src/GFALDataStreamTool/GFALStageBlock.cpp