HIPO4 C++ Library 4.4.1
Columnar I/O library for CLAS12 physics data
Loading...
Searching...
No Matches
record.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/*
32 * File: record.h
33 * Author: gavalian
34 *
35 * Created on April 11, 2017, 4:47 PM
36 */
37
38#ifndef HIPORECORD_H
39#define HIPORECORD_H
40
41#include <iostream>
42#include <vector>
43#include <string>
44#include <cstdint>
45#include <cstdio>
46#include <cstdlib>
47#include <fstream>
48
49#include "event.h"
50#include "utils.h"
51
52namespace hipo {
53
54 typedef struct recordHeader_t {
55 int signatureString{}; // 1) identifier string is HREC (int = 0x43455248
56 int recordLength{}; // 2) TOTAL Length of the RECORD, includes INDEX array
57 int recordDataLength{}; // 3) Length of the DATA uncompressed
58 int recordDataLengthCompressed{}; // 4) compressed length of the DATA buffer
59 int numberOfEvents{} ; // 5) number of event, data buckets in DATA buffer
60 int headerLength{} ; // 6) Length of the buffer represengin HEADER for the record
61 int indexDataLength{} ; // 7) Length of the index buffer (in bytes)
62 int userHeaderLength{}; // user header length in bytes
63 int userHeaderLengthPadding{}; // the padding added to user header Length
64 int bitInfo{};
68 } recordHeader_t;
69
70 class data {
71 private:
72 const char *data_ptr{};
73 int data_size{};
74 int data_endianness{};
75 int data_offset{};
76 int data_type;
77
78 public:
79 data(){ data_ptr = nullptr; data_size = 0;}
80 ~data()= default;
81
82 void setDataPtr(const char *__ptr){ data_ptr = __ptr;}
83 void setDataSize(int __size){ data_size = __size;}
84 void setDataOffset(int __offset) { data_offset = __offset;}
85 void setDataEndianness(int __endianness) { data_endianness = __endianness;}
86 void setDataType(int __type){ data_type = __type;}
87 const uint32_t *getEvioPtr(){ return reinterpret_cast<const uint32_t *>(data_ptr);}
88 int getEvioSize(){ return (int) data_size/4 ;}
89 const char *getDataPtr(){ return data_ptr;}
90 int getDataSize(){ return data_size;}
91 int getDataType(){ return data_type;}
92 int getDataEndianness(){ return data_endianness;}
93 int getDataOffset(){ return data_offset;}
94 };
95
96 class dataframe {
97 private:
98 std::vector<char> dataBuffer;
99 recordHeader_t recordHeader{};
100 int maxEvents = 50;
101 int maxSize = 512*1024;
102
103 public:
105 dataframe(int max_events, int max_size);
107
108 void init(const char *ptr);
110 int getEventAt(int pos, hipo::event &event);
111 int count();
112 int size();
113 void reset();
114 const char *buffer(){ return &dataBuffer[0];}
115
116 void summary();
117 };
118
119 class record {
120
121 private:
122
123 //std::vector< std::vector<char> > eventBuffer;
124 std::vector<char> recordHeaderBuffer;
125 recordHeader_t recordHeader{};
126
127 std::vector<char> recordBuffer;
128 std::vector<char> recordCompressedBuffer;
129
130 hipo::benchmark readBenchmark;
131 hipo::benchmark unzipBenchmark;
132 hipo::benchmark indexBenchmark;
133
134 char *getUncompressed(const char *data, int dataLength, int dataLengthUncompressed);
135 int getUncompressed(const char *data, char *dest, int dataLength, int dataLengthUncompressed);
136 void showBuffer(const char *data, int wrapping, int maxsize);
137
138 public:
139
142
143 void read(hipo::bank &b, int event);
144 void readRecord(std::ifstream &stream, long position, int dataOffset);
145 void readRecord__(std::ifstream &stream, long position, long recordLength);
146 bool readRecord(std::ifstream &stream, long position, int dataOffset, long inputSize);
147 int getEventCount();
149
150 void getColumn(hipo::data &data,int column, hipo::bank &bank, int event);
151 void getColumn(hipo::data &data,const char* column, hipo::bank &bank, int event);
152
153 void readEvent( std::vector<char> &vec, int index);
154 void readHipoEvent(hipo::event &event, int index);
155
156 void getData( hipo::data &data, int index);
157 //void getBank( hipo::bank &bank, int index);
158
159 void getEventsMap(std::vector<std::pair<int,int>> &emap);
160
161 hipo::benchmark &getReadBenchmark(){ return readBenchmark;}
162 hipo::benchmark &getUnzipBenchmark(){ return unzipBenchmark;}
163 hipo::benchmark &getIndexBenchmark(){ return indexBenchmark;}
164 };
165}
166#endif /* HIPORECORD_H */
Definition bank.h:210
Definition utils.h:65
Definition record.h:70
void setDataSize(int __size)
Definition record.h:83
const uint32_t * getEvioPtr()
Definition record.h:87
void setDataOffset(int __offset)
Definition record.h:84
void setDataPtr(const char *__ptr)
Definition record.h:82
int getDataEndianness()
Definition record.h:92
int getEvioSize()
Definition record.h:88
data()
Definition record.h:79
int getDataOffset()
Definition record.h:93
int getDataType()
Definition record.h:91
void setDataType(int __type)
Definition record.h:86
int getDataSize()
Definition record.h:90
~data()=default
const char * getDataPtr()
Definition record.h:89
void setDataEndianness(int __endianness)
Definition record.h:85
Definition record.h:96
bool addEvent(hipo::event &event)
Definition record.cpp:565
void reset()
Definition record.cpp:552
int getEventAt(int pos, hipo::event &event)
Definition record.cpp:579
void init(const char *ptr)
Definition record.cpp:585
int count()
Definition record.cpp:591
dataframe()
Definition record.h:104
void summary()
Definition record.cpp:594
int size()
Definition record.cpp:592
~dataframe()
Definition record.h:106
const char * buffer()
Definition record.h:114
Definition event.h:62
Definition record.h:119
void readEvent(std::vector< char > &vec, int index)
reads content of the event with given index into a vector vector will be resized to fit the data.
Definition record.cpp:397
int getEventCount()
returns number of events in the record.
Definition record.cpp:389
hipo::benchmark & getUnzipBenchmark()
Definition record.h:162
hipo::benchmark & getIndexBenchmark()
Definition record.h:163
void read(hipo::bank &b, int event)
Definition record.cpp:420
int getRecordSizeCompressed()
Definition record.cpp:275
void getEventsMap(std::vector< std::pair< int, int > > &emap)
Definition record.cpp:459
void readRecord(std::ifstream &stream, long position, int dataOffset)
Read.
Definition record.cpp:57
void readHipoEvent(hipo::event &event, int index)
Definition record.cpp:481
void getData(hipo::data &data, int index)
returns a data object that points to the event inside of the record.
Definition record.cpp:407
void getColumn(hipo::data &data, int column, hipo::bank &bank, int event)
Definition record.cpp:431
hipo::benchmark & getReadBenchmark()
Definition record.h:161
void readRecord__(std::ifstream &stream, long position, long recordLength)
Definition record.cpp:279
HIPO namespace is used for the classes that read/write files and records.
Definition bank.cpp:45
Definition record.h:54
int dataEndianness
Definition record.h:67
int bitInfo
Definition record.h:64
int userHeaderLengthPadding
Definition record.h:63
int userHeaderLength
Definition record.h:62
int compressedLengthPadding
Definition record.h:66
int compressionType
Definition record.h:65
int indexDataLength
Definition record.h:61
int recordDataLength
Definition record.h:57
int headerLength
Definition record.h:60
int numberOfEvents
Definition record.h:59
int signatureString
Definition record.h:55
int recordLength
Definition record.h:56
int recordDataLengthCompressed
Definition record.h:58