The link  below is the description about C - API to the dCache Access Protocol (dcap)


http://www-dcache.desy.de/manuals/libdcap.html
And the c++ code at bottom is to use the API for dcap library test.


It works on both SL5 and SL6, with the following packages installed.
dcap-2.47.7
dcap-libs-2.47.7
dcap-devel-2.47.7


#include <string>
#include <iostream>
#include </usr/include/unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "/usr/include/dcap.h"
#include "/usr/include/dcap_errno.h"

// This program tests reading a file from dCache
int usage()
{
    fprintf(stderr, "usage:  [ -d debug level ] [ -b read ahead buffer ] [ -B transfer buffer ] [ -r TCP receive buffer ] [ -t file open secs ] <durl> \n");
}

int main(int argc, char *argv[])
  {
  std::string fileName;
  int ClientActive=0;
  int opentime=0;
  int debuglevel=6;
  int tr_buffer_size=1048570;
  int ra_buffer_size=1048570;
  int tcp_buffer_size=262144;
  if ( argc < 2 )
    {
      usage();
      exit(1);
    }
  fileName = argv[argc-1];
  /**std::cout << "fileName: " << fileName << "\n";
  std::cout << "argc: " << argc << "\n"; **/
  for(int i = 1; i < argc-1 ; i++)
  {
    if( strcmp(argv[i],"-d") == 0 ) { debuglevel=atoi(argv[++i]); continue; }
    if( strcmp(argv[i],"-a") == 0 ) { ClientActive=1; continue; }
    if( strcmp(argv[i],"-b") == 0 ) { ra_buffer_size=atoi(argv[++i]); continue; }
    if( strcmp(argv[i],"-B") == 0 ) { tr_buffer_size=atoi(argv[++i]); std::cout << "tr_buffer:" <<tr_buffer_size << "\n"; continue; }
    if( strcmp(argv[i],"-r") == 0 ) { tcp_buffer_size=atoi(argv[++i]); continue; }
    if( strcmp(argv[i],"-t") == 0 ) { opentime=atoi(argv[++i]); continue; }
    if( strcmp(argv[i],"-h") == 0 ) { usage(); exit(1);}
    usage();
    exit(1);
  }
  std::cout << "ra_buffer: " << ra_buffer_size << "\n";
  std::cout << "tcp_buffer: " << tcp_buffer_size << "\n";
  std::cout << "tr_buffer: " << tr_buffer_size << "\n";
  dc_setDebugLevel(debuglevel);
  dc_setTCPReceiveBuffer( tcp_buffer_size );
  dc_setTCPSendBuffer( tcp_buffer_size );
  if( ClientActive ) dc_setClientActive();
  int fileDesc = dc_open( (fileName).c_str(), O_RDONLY );
  if( fileDesc == -1 )
  {
    std::cerr << "error opening file\n";
    return 1;
  }
  dc_setBufferSize( fileDesc, ra_buffer_size );
  std::string line;
  int Number=1;
  for( int count=1; ; ++count )
  {
    bool eof = false;
    char data_buffer[tr_buffer_size];
    int ret = dc_read( fileDesc, data_buffer, tr_buffer_size );
    switch (ret)
    {
      case 0:
        std::cout << "end of file reached, line #" << Number << "\n";
        eof = true;
        break;
      case -1:
        std::cerr << "error reading file, line #" << Number << "\n";
        return 1;
      default:
      {
        if( Number == 10 )
        {
          /*std::cout <<" number of buffer read: "<<  count << "\n";*/
          Number=1;
        }
        else {
          Number++;
        }
      }
    }
    if( eof )break;
  }
  if( opentime > 0 ) std::cout << "keep file open for " << opentime << "  seconds \n";
  sleep(opentime);
  int ret = dc_close( fileDesc );
  if( ret == -1 )
  {
    std::cerr << "error closing file\n";
    return 1;
  }
  return 0;
}


Compile it with the command:



g++ -o dcapio_read -L /usr/lib64/ -I /usr/include -ldcap dcapio_read.c