HIPO4 C++ Library 4.4.1
Columnar I/O library for CLAS12 physics data
Loading...
Searching...
No Matches
datastream.h
Go to the documentation of this file.
1//******************************************************************************
2//* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ *
3//* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ *
4//* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ *
5//* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ *
6//* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ *
7//* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ *
8//************************ Jefferson National Lab (2017) ***********************
9/*
10 * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission
11 * to use, copy, modify, and distribute this software and its documentation
12 * for educational, research, and not-for-profit purposes, without fee and
13 * without a signed licensing agreement.
14 *
15 * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL
16 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
17 * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS
18 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 *
20 * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
23 * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 *
26 * This software was developed under the United States Government license.
27 * For more information contact author at gavalian@jlab.org
28 * Department of Experimental Nuclear Physics, Jefferson Lab.
29 */
30/*
31 * This class is generic class that is suppose to provide a data stream.
32 * it is implemented as a test case for xrootd, functionality to switch
33 * between the regular file and files provided by xrootd server.
34 * File: datastream.h
35 * Author: gavalian
36 *
37 * Created on May 5, 2020, 9:18 PM
38 */
39
40#ifndef DATASTREAM_H
41#define DATASTREAM_H
42
43#include <iostream>
44#include <utility>
45#include <vector>
46#include <fstream>
47#include <cstdio>
48#include <cstdlib>
49#include <memory>
50#include <climits>
51
52#ifdef __XROOTD__
53#include <XrdClient/XrdClient.hh>
54#include "XrdClient/XrdClientEnv.hh"
55#include "XrdSys/XrdSysHeaders.hh"
56#endif
57
58namespace hipo {
59
60
62
63 private:
64
65 std::ifstream inputStream;
66 std::string remoteAddress;
67 int streamType = 1;
68
69
70 public:
71
73 //datastream(const char *address);
74 virtual ~datastream();
75
76 virtual long size(){ return 0;}
77 virtual long position(){ return 0;}
78 virtual long position(long pos){ return 0;}
79 //virtual void setAdress(const char *address){}
80 virtual void open(const char *filename){}
81 virtual int read(char *s, int size){return 0;}
82 };
83
85
86 private:
87 std::ifstream inputStream;
88
89 public:
90
93 if(inputStream.is_open()==true){
94 inputStream.close();
95 }
96 }
97
98 long size(){
99 long pos = inputStream.tellg();
100 inputStream.seekg(0,std::ios_base::end);
101 long lastpos = inputStream.tellg();
102 inputStream.seekg(pos,std::ios_base::beg);
103 return lastpos;
104 }
105
106 void open(const char *filename){
107 inputStream.open(filename, std::ios::binary);
108 }
109 long position(){ return inputStream.tellg();}
110 long position(long pos){ inputStream.seekg(pos,std::ios_base::beg); return pos; }
111 int read(char *s, int size){inputStream.read(s,size); return size;}
112};
113
115
116private:
117 #ifdef __XROOTD__
118 kXR_unt16 open_mode = (kXR_ur);
119 kXR_unt16 open_opts = (1);
120 XrdClient *cli = NULL;
121 #endif
122 long streamPosition = 0;
123
124public:
127
128
129 long size();
130 long position();
131 long position(long pos);
132 //virtual void setAdress(const char *address){}
133 void open(const char *filename);
134 int read(char *s, int size);
135};
136}
137#endif /* DATASTREAM_H */
Definition datastream.h:84
void open(const char *filename)
Definition datastream.h:106
long position()
Definition datastream.h:109
long size()
Definition datastream.h:98
int read(char *s, int size)
Definition datastream.h:111
long position(long pos)
Definition datastream.h:110
~datastreamLocalFile()
Definition datastream.h:92
Definition datastream.h:114
long position()
Definition datastream.cpp:83
~datastreamXrootd()
Default destructor.
Definition datastream.cpp:57
void open(const char *filename)
Definition datastream.cpp:64
datastreamXrootd()
The constructor for reader, printWarning routine will printout a warning message if the library was n...
Definition datastream.cpp:47
long size()
Definition datastream.cpp:72
int read(char *s, int size)
Definition datastream.cpp:85
Definition datastream.h:61
virtual int read(char *s, int size)
Definition datastream.h:81
virtual void open(const char *filename)
Definition datastream.h:80
virtual long position(long pos)
Definition datastream.h:78
virtual long size()
Definition datastream.h:76
virtual ~datastream()
virtual long position()
Definition datastream.h:77
HIPO namespace is used for the classes that read/write files and records.
Definition bank.cpp:45