<commit_before>// @(#)root/rfio:$Name:  $:$Id: TRFIOFile.cxx,v 1.46 2007/07/02 18:02:36 rdm Exp $
// Author: <NAME>   20/01/99 + <NAME> 29/06/2006

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

///////////////////////////////////////////////////////////////////////////
//                                                                       //
// TRFIOFile                                                             //
//                                                                       //
// A TRFIOFile is like a normal TFile except that it reads and writes    //
// its data via a rfiod server (for more on the rfiod daemon see         //
// http://wwwinfo.cern.ch/pdp/serv/shift.html). TRFIOFile file names     //
// are in standard URL format with protocol "rfio". The following are    //
// valid TRFIOFile URL's:                                                //
//                                                                       //
//    rfio:/afs/cern.ch/user/r/rdm/galice.root                           //
//         where galice.root is a symlink of the type /shift/.../...     //
//    rfio:na49db1:/data1/raw.root                                       //
//    rfio:/castor/cern.ch/user/r/rdm/test.root                          //
//                                                                       //
// If Castor 2.1 is used the file names can be given also in the         //
// following ways:                                                       //
//                                                                       //
//  rfio://host:port/?path=FILEPATH                                      //
//  rfio://host/?path=FILEPATH                                           //
//  rfio:///castor?path=FILEPATH                                         //
//  rfio://stager_host:stager_port/?path=/castor/cern.ch/user/r/         //
//    rdm/bla.root&svcClass=MYSVCLASS&castorVersion=MYCASTORVERSION      //
//  rfio://stager_host/?path=/castor/cern.ch/user/r/                     //
//    rdm/bla.root&svcClass=MYSVCLASS&castorVersion=MYCASTORVERSION      //
//  rfio:///castor?path=/castor/cern.ch/user/r/                          //
//    rdm/bla.root&svcClass=MYSVCLASS&castorVersion=MYCASTORVERSION      //
//                                                                       //
// path is mandatory as parameter but all the other ones are optional.   //
//                                                                       //
// For the ultimate description of supported urls see:                   //
//    https://twiki.cern.ch/twiki/bin/view/FIOgroup/RfioRootTurl         //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

#include "TRFIOFile.h"
#include "TROOT.h"
#include <sys/stat.h>
#include <sys/types.h>
#ifndef R__WIN32
#include <unistd.h>
#if defined(R__SUN) || defined(R__SGI) || defined(R__HPUX) ||         \
defined(R__AIX) || defined(R__LINUX) || defined(R__SOLARIS) ||        \
defined(R__ALPHA) || defined(R__HIUX) || defined(R__FBSD) ||          \
defined(R__MACOSX) || defined(R__HURD) || defined(R__OBSD)
#define HAS_DIRENT
#endif
#else
#define off64_t __int64
#define fstat64 _fstati64
#define lseek64 _lseeki64
#define open64 open
#define stat64 _stati64
#endif

#ifdef HAS_DIRENT
#include <dirent.h>
#else

struct dirent {
   ino_t d_ino;
   off_t d_reclen;
   unsigned short d_namlen;
   char d_name[232];  // from Castor_limits.h
};
#endif

//#include <rfio_api.h>    // prototypes don't have "const char*" ?!?

extern "C" {
   int     rfio_open(const char *path, int flags, int mode);
   int     rfio_open64(const char *path, int flags, int mode);
   int     rfio_close(int s);
   int     rfio_read(int s, void *ptr, int size);
   int     rfio_write(int s, const void *ptr, int size);
   off_t   rfio_lseek(int s, off_t offset, int how);
   off64_t rfio_lseek64(int s, off64_t offset, int how);
   int     rfio_access(const char *path, int mode);
   int     rfio_unlink(const char *path);
   int     rfio_parse(const char *name, char **host, char **path);
   int     rfio_stat(const char *path, struct stat *statbuf);
   int     rfio_stat64(const char *path, struct stat64 *statbuf);
   int     rfio_fstat(int s, struct stat *statbuf);
   int     rfio_fstat64(int s, struct stat64 *statbuf);
   void    rfio_perror(const char *msg);
   char   *rfio_serror();
   int     rfiosetopt(int opt, int *pval, int len);
   int     rfio_mkdir(const char *path, int mode);
   int     rfio_rmdir (const char *path);
   void   *rfio_opendir(const char *dirpath);
   int     rfio_closedir(void *dirp);
   void   *rfio_readdir(void *dirp);
#ifdef R__WIN32
   int    *C__serrno(void);
   int    *C__rfio_errno (void);
#endif
};

#ifndef RFIO_READOPT
#define RFIO_READOPT 1
#endif

#ifdef R__WIN32

// Thread safe rfio_errno. Note, C__rfio_errno is defined in Cglobals.c rather
// than rfio/error.c.
#define rfio_errno (*C__rfio_errno())

// Thread safe serrno. Note, C__serrno is defined in Cglobals.c rather
// rather than serror.c.
#define serrno (*C__serrno())

#else

extern int rfio_errno;
extern int serrno;

#endif


ClassImp(TRFIOFile)
ClassImp(TRFIOSystem)

//______________________________________________________________________________
TRFIOFile::TRFIOFile(const char *url, Option_t *option, const char *ftitle,
                     Int_t compress)
   : TFile(url, "NET", ftitle, compress)
{
   // Create a RFIO file object. A RFIO file is the same as a TFile
   // except that it is being accessed via a rfiod server. The url
   // argument must be of the form: rfio:/path/file.root (where file.root
   // is a symlink of type /shift/aaa/bbb/ccc) or rfio:server:/path/file.root.
   // If the file specified in the URL does not exist, is not accessable
   // or can not be created the kZombie bit will be set in the TRFIOFile
   // object. Use IsZombie() to see if the file is accessable.
   // For a description of the option and other arguments see the TFile ctor.
   // The preferred interface to this constructor is via TFile::Open().

   fOption = option;
   fOption.ToUpper();

   // tell RFIO to not read large buffers, ROOT does own buffering
   Int_t readopt = 0;
   ::rfiosetopt(RFIO_READOPT, &readopt, 4);

   if (fOption == "NEW")
      fOption = "CREATE";

   Bool_t create   = (fOption == "CREATE") ? kTRUE : kFALSE;
   Bool_t recreate = (fOption == "RECREATE") ? kTRUE : kFALSE;
   Bool_t update   = (fOption == "UPDATE") ? kTRUE : kFALSE;
   Bool_t read     = (fOption == "READ") ? kTRUE : kFALSE;
   if (!create && !recreate && !update && !read) {
      read    = kTRUE;
      fOption = "READ";
   }

   // to be able to use the turl starting with castor:
   if (!strcmp(fUrl.GetProtocol(), "castor"))
      fUrl.SetProtocol("rfio");

   // old RFIO client lib does not support :///, need to change to :////
   Bool_t addSlash = kFALSE;<commit_msg>remove filetpye=raw option from the url as the old libshift is doing that not correctly.<commit_after>// @(#)root/rfio:$Name:  $:$Id: TRFIOFile.cxx,v 1.47 2007/07/03 11:09:57 rdm Exp $
// Author: <NAME>   20/01/99 + <NAME> 29/06/2006

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

///////////////////////////////////////////////////////////////////////////
//                                                                       //
// TRFIOFile                                                             //
//                                                                       //
// A TRFIOFile is like a normal TFile except that it reads and writes    //
// its data via a rfiod server (for more on the rfiod daemon see         //
// http://wwwinfo.cern.ch/pdp/serv/shift.html). TRFIOFile file names     //
// are in standard URL format with protocol "rfio". The following are    //
// valid TRFIOFile URL's:                                                //
//                                                                       //
//    rfio:/afs/cern.ch/user/r/rdm/galice.root                           //
//         where galice.root is a symlink of the type /shift/.../...     //
//    rfio:na49db1:/data1/raw.root                                       //
//    rfio:/castor/cern.ch/user/r/rdm/test.root                          //
//                                                                       //
// If Castor 2.1 is used the file names can be given also in the         //
// following ways:                                                       //
//                                                                       //
//  rfio://host:port/?path=FILEPATH                                      //
//  rfio://host/?path=FILEPATH                                           //
//  rfio:///castor?path=FILEPATH                                         //
//  rfio://stager_host:stager_port/?path=/castor/cern.ch/user/r/         //
//    rdm/bla.root&svcClass=MYSVCLASS&castorVersion=MYCASTORVERSION      //
//  rfio://stager_host/?path=/castor/cern.ch/user/r/                     //
//    rdm/bla.root&svcClass=MYSVCLASS&castorVersion=MYCASTORVERSION      //
//  rfio:///castor?path=/castor/cern.ch/user/r/                          //
//    rdm/bla.root&svcClass=MYSVCLASS&castorVersion=MYCASTORVERSION      //
//                                                                       //
// path is mandatory as parameter but all the other ones are optional.   //
//                                                                       //
// For the ultimate description of supported urls see:                   //
//    https://twiki.cern.ch/twiki/bin/view/FIOgroup/RfioRootTurl         //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

#include "TRFIOFile.h"
#include "TROOT.h"
#include <sys/stat.h>
#include <sys/types.h>
#ifndef R__WIN32
#include <unistd.h>
#if defined(R__SUN) || defined(R__SGI) || defined(R__HPUX) ||         \
defined(R__AIX) || defined(R__LINUX) || defined(R__SOLARIS) ||        \
defined(R__ALPHA) || defined(R__HIUX) || defined(R__FBSD) ||          \
defined(R__MACOSX) || defined(R__HURD) || defined(R__OBSD)
#define HAS_DIRENT
#endif
#else
#define off64_t __int64
#define fstat64 _fstati64
#define lseek64 _lseeki64
#define open64 open
#define stat64 _stati64
#endif

#ifdef HAS_DIRENT
#include <dirent.h>
#else

struct dirent {
   ino_t d_ino;
   off_t d_reclen;
   unsigned short d_namlen;
   char d_name[232];  // from Castor_limits.h
};
#endif

//#include <rfio_api.h>    // prototypes don't have "const char*" ?!?

extern "C" {
   int     rfio_open(const char *path, int flags, int mode);
   int     rfio_open64(const char *path, int flags, int mode);
   int     rfio_close(int s);
   int     rfio_read(int s, void *ptr, int size);
   int     rfio_write(int s, const void *ptr, int size);
   off_t   rfio_lseek(int s, off_t offset, int how);
   off64_t rfio_lseek64(int s, off64_t offset, int how);
   int     rfio_access(const char *path, int mode);
   int     rfio_unlink(const char *path);
   int     rfio_parse(const char *name, char **host, char **path);
   int     rfio_stat(const char *path, struct stat *statbuf);
   int     rfio_stat64(const char *path, struct stat64 *statbuf);
   int     rfio_fstat(int s, struct stat *statbuf);
   int     rfio_fstat64(int s, struct stat64 *statbuf);
   void    rfio_perror(const char *msg);
   char   *rfio_serror();
   int     rfiosetopt(int opt, int *pval, int len);
   int     rfio_mkdir(const char *path, int mode);
   int     rfio_rmdir (const char *path);
   void   *rfio_opendir(const char *dirpath);
   int     rfio_closedir(void *dirp);
   void   *rfio_readdir(void *dirp);
#ifdef R__WIN32
   int    *C__serrno(void);
   int    *C__rfio_errno (void);
#endif
};

#ifndef RFIO_READOPT
#define RFIO_READOPT 1
#endif

#ifdef R__WIN32

// Thread safe rfio_errno. Note, C__rfio_errno is defined in Cglobals.c rather
// than rfio/error.c.
#define rfio_errno (*C__rfio_errno())

// Thread safe serrno. Note, C__serrno is defined in Cglobals.c rather
// rather than serror.c.
#define serrno (*C__serrno())

#else

extern int rfio_errno;
extern int serrno;

#endif


ClassImp(TRFIOFile)
ClassImp(TRFIOSystem)

//______________________________________________________________________________
TRFIOFile::TRFIOFile(const char *url, Option_t *option, const char *ftitle,
                     Int_t compress)
   : TFile(url, "NET", ftitle, compress)
{
   // Create a RFIO file object. A RFIO file is the same as a TFile
   // except that it is being accessed via a rfiod server. The url
   // argument must be of the form: rfio:/path/file.root (where file.root
   // is a symlink of type /shift/aaa/bbb/ccc) or rfio:server:/path/file.root.
   // If the file specified in the URL does not exist, is not accessable
   // or can not be created the kZombie bit will be set in the TRFIOFile
   // object. Use IsZombie() to see if the file is accessable.
   // For a description of the option and other arguments see the TFile ctor.
   // The preferred interface to this constructor is via TFile::Open().

   fOption = option;
   fOption.ToUpper();

   // tell RFIO to not read large buffers, ROOT does own buffering
   Int_t readopt = 0;
   ::rfiosetopt(RFIO_READOPT, &readopt, 4);

   if (fOption == "NEW")
      fOption = "CREATE";

   Bool_t create   = (fOption == "CREATE") ? kTRUE : kFALSE;
   Bool_t recreate = (fOption == "RECREATE") ? kTRUE : kFALSE;
   Bool_t update   = (fOption == "UPDATE") ? kTRUE : kFALSE;
   Bool_t read     = (fOption == "READ") ? kTRUE : kFALSE;
   if (!create && !recreate && !update && !read) {
      read    = kTRUE;
      fOption = "READ";
   }

   // to be able to use the turl starting with castor:
   if (!strcmp(fUrl.GetProtocol(), "castor"))
      fUrl.SetProtocol("rfio");

   // old RFIO client does not ignore ?filetpye=raw, remove it
   TString opt = fUrl.GetOptions();
   if (opt.Contains("&filetype=raw")) {
      opt.ReplaceAll("&filetype=raw", "");
      fUrl.SetOptions(opt);
   } else if (opt.Contains("filetype=raw")) {
      opt.ReplaceAll("filetype=raw", "");
      fUrl.SetOptions(opt);
   }

   // old RFIO client lib does not support :///, need to change to :////
   Bool_t addSlash = kFALSE;
{'fraction_non_alphanumeric': 0.14988505747126438, 'fraction_numerical': 0.011954022988505748, 'mean_word_length': 1.629706390328152, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 80, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7211670', 'n_tokens_mistral': 4782, 'n_tokens_neox': 4476, 'n_words': 1228}