HIPO  4.3.0
High Performance Output data format for experimental physics
fusion.h
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 
7 /*
8  * File: fusion.h
9  * Author: gavalian
10  *
11  * Created on April 27, 2017, 10:01 AM
12  */
13 
16 
17 #ifndef FUSION_H
18 #define FUSION_H
19 
20 #include <iostream>
21 #include <cstdlib>
22 #include <cstdio>
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include "reader.h"
27 #include <chrono>
28 
29 namespace hipo {
30 
32 
39 class inputSource {
40 
41  private:
42 
44  std::map<std::string,hipo::bank> banks;
45  hipo::dictionary factory;
47 
48  public:
49 
52  inputSource(const char *filename){ open(filename); }
54  inputSource(const char *filename, int tag) { open(filename, tag); }
56 
59  void open(const char *filename);
63  void open(const char *filename, int tag);
66  void define(const char *bank);
69  void describe(const char *bank);
72  bool next();
73 
75  std::string schema(const char *bank);
77  hipo::bank &get(const char *bank){ return banks[bank];}
79  int getSize(const char *bank);
80 
82  int getInt( const char *bank, const char *entry, int row);
84  int64_t getLong( const char *bank, const char *entry, int row);
86  float getFloat( const char *bank, const char *entry, int row);
88  double getDouble( const char *bank, const char *entry, int row);
89 
95  void getByteArray( const char *bank, int entry, int8_t *ptr, int length);
97  void getShortArray( const char *bank, int entry, int16_t *ptr, int length);
99  void getIntArray( const char *bank, int entry, int32_t *ptr, int length);
101  void getFloatArray( const char *bank, int entry, float *ptr, int length);
102 
104  int64_t getEntries() { return reader.getEntries(); }
105  };
106 
114 class fusion {
115 
116  private:
117 
118  std::map<int,inputSource*> sources;
119 
120  public:
121 
122  fusion(){}
124 
125 
129  int open(const char *filename);
131  int open(const char *filename, int tag);
134  bool next(int handle);
135 
137  void define(int fid, const char *bank);
139  void describe(int fid, const char *bank);
141  std::string schema(int fid, const char *bank);
142 
144  int getSize(int fid, const char *bank);
145 
147  void getByteArray( int handle, const char *bank, int entry, int8_t *ptr, int length){
148  sources[handle]->getByteArray(bank,entry,ptr,length);
149  }
151  void getShortArray( int handle, const char *bank, int entry, int16_t *ptr, int length){
152  sources[handle]->getShortArray(bank,entry,ptr,length);
153  }
155  void getIntArray( int handle, const char *bank, int entry, int32_t *ptr, int length){
156  sources[handle]->getIntArray(bank,entry,ptr,length);
157  }
159  void getFloatArray( int handle, const char *bank, int entry, float *ptr, int length){
160  sources[handle]->getFloatArray(bank,entry,ptr,length);
161  }
162 
164  int getInt( int handle, const char *bank, const char *entry, int row);
166  int64_t getLong( int handle, const char *bank, const char *entry, int row);
168  float getFloat( int handle, const char *bank, const char *entry, int row);
170  double getDouble( int handle, const char *bank, const char *entry, int row);
172  int getType( int handle, const char *bank, const char *entry);
173 
175  int64_t getEntries(int handle) { return sources[handle]->getEntries(); }
177  hipo::bank &getBank(int handle, const char *bank) {return sources[handle]->get(bank);}
178 };
179 }
180 
181 #endif /* FUSION_H */
Represents a HIPO bank, a tabular data structure with rows and typed columns.
Definition: bank.h:352
T get(int item, int index) const noexcept
Generic getter that returns the value at the given column and row.
Definition: bank.h:492
Collection of schema definitions, typically read from a HIPO file header.
Definition: dictionary.h:248
Represents a HIPO event, a container for multiple structures/banks.
Definition: event.h:77
Multi-file HIPO data access manager using integer handles.
Definition: fusion.h:114
void define(int fid, const char *bank)
Register a bank for reading in the given file.
Definition: fusion.cpp:106
int getInt(int handle, const char *bank, const char *entry, int row)
Definition: fusion.cpp:125
int getSize(int fid, const char *bank)
Definition: fusion.cpp:117
int getType(int handle, const char *bank, const char *entry)
Definition: fusion.cpp:143
int64_t getLong(int handle, const char *bank, const char *entry, int row)
Definition: fusion.cpp:129
double getDouble(int handle, const char *bank, const char *entry, int row)
Definition: fusion.cpp:139
void describe(int fid, const char *bank)
Print schema description for a bank in the given file.
Definition: fusion.cpp:113
void getShortArray(int handle, const char *bank, int entry, int16_t *ptr, int length)
Copy a short column into an array from the file identified by handle.
Definition: fusion.h:151
int open(const char *filename)
Open a HIPO file and return its handle.
Definition: fusion.cpp:94
float getFloat(int handle, const char *bank, const char *entry, int row)
Definition: fusion.cpp:133
void getByteArray(int handle, const char *bank, int entry, int8_t *ptr, int length)
Copy a byte column into an array from the file identified by handle.
Definition: fusion.h:147
std::string schema(int fid, const char *bank)
Definition: fusion.cpp:110
void getFloatArray(int handle, const char *bank, int entry, float *ptr, int length)
Copy a float column into an array from the file identified by handle.
Definition: fusion.h:159
int64_t getEntries(int handle)
Definition: fusion.h:175
hipo::bank & getBank(int handle, const char *bank)
Definition: fusion.h:177
void getIntArray(int handle, const char *bank, int entry, int32_t *ptr, int length)
Copy an integer column into an array from the file identified by handle.
Definition: fusion.h:155
bool next(int handle)
Advance to the next event in the given file.
Definition: fusion.cpp:121
Single HIPO file data source with named bank access.
Definition: fusion.h:39
void open(const char *filename)
Open a HIPO file and read its dictionary.
Definition: fusion.cpp:17
float getFloat(const char *bank, const char *entry, int row)
Definition: fusion.cpp:67
void describe(const char *bank)
Print the schema description for a bank.
Definition: fusion.cpp:36
bool next()
Advance to the next event and read all defined banks.
Definition: fusion.cpp:40
void getIntArray(const char *bank, int entry, int32_t *ptr, int length)
Copy an integer column into an array.
Definition: fusion.cpp:83
hipo::bank & get(const char *bank)
Definition: fusion.h:77
void getByteArray(const char *bank, int entry, int8_t *ptr, int length)
Copy a byte column into an array.
Definition: fusion.cpp:75
inputSource(const char *filename)
Open a HIPO file as input source.
Definition: fusion.h:52
std::string schema(const char *bank)
Definition: fusion.cpp:28
int64_t getLong(const char *bank, const char *entry, int row)
Definition: fusion.cpp:63
int64_t getEntries()
Definition: fusion.h:104
void define(const char *bank)
Register a bank name for reading from events.
Definition: fusion.cpp:32
int getSize(const char *bank)
Definition: fusion.cpp:54
void getShortArray(const char *bank, int entry, int16_t *ptr, int length)
Copy a short column into an array.
Definition: fusion.cpp:79
inputSource(const char *filename, int tag)
Open a HIPO file with a tag filter.
Definition: fusion.h:54
int getInt(const char *bank, const char *entry, int row)
Definition: fusion.cpp:59
void getFloatArray(const char *bank, int entry, float *ptr, int length)
Copy a float column into an array.
Definition: fusion.cpp:88
double getDouble(const char *bank, const char *entry, int row)
Definition: fusion.cpp:71
Sequential reader for HIPO files.
Definition: reader.h:250
int getEntries()
Definition: reader.h:379
Definition: bank.cpp:47
Sequential and random-access reader for HIPO files with event filtering and dictionary support.