HIPO  4.3.0
High Performance Output data format for experimental physics
fusion.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2  * This is the implementation of fusion class which is used in
3  * interfacing HIPO library from python.
4  * author: G.Gavalian (June, 2022)
5  * ---------------------------------------------------------------------
6  */
7 
12 #include "fusion.h"
13 
14 
15 namespace hipo {
16 
17  void inputSource::open(const char *filename){
18  reader.open(filename);
19  reader.readDictionary(factory);
20  }
21 
22  void inputSource::open(const char *filename, int tag) {
23  reader.setTags(tag);
24  reader.open(filename);
25  reader.readDictionary(factory);
26  }
27 
28  std::string inputSource::schema(const char *bank){
29  return factory.getSchema(bank).getSchemaString();
30  }
31 
32  void inputSource::define(const char *bank){
33  banks[std::string(bank)] = hipo::bank(factory.getSchema(bank));
34  }
35 
36  void inputSource::describe(const char *bank){
37  banks[std::string(bank)].getSchema().show();
38  }
39 
41  bool status = reader.next();
42  if(status==true){
43  reader.read(event);
44  std::map<std::string, hipo::bank>::iterator it;
45  for (it = banks.begin(); it != banks.end(); it++)
46  {
47  event.getStructure(it->second);
48  //How do I access each element?
49  }
50  }
51  return status;
52  }
53 
54 int inputSource::getSize(const char *bank){
55  return banks[bank].getRows();
56 }
57 
58 
59 int inputSource::getInt( const char *bank, const char *entry, int row){
60  return banks[bank].getInt(entry,row);
61 }
62 
63 int64_t inputSource::getLong( const char *bank, const char *entry, int row){
64  return banks[bank].getLong(entry,row);
65 }
66 
67  float inputSource::getFloat( const char *bank, const char *entry, int row){
68  return banks[bank].getFloat(entry,row);
69 }
70 
71 double inputSource::getDouble( const char *bank, const char *entry, int row){
72  return banks[bank].getDouble(entry,row);
73 }
74 
75  void inputSource::getByteArray( const char *bank, int entry, int8_t *ptr, int length){
76  hipo::bank &b = banks[bank];
77  for(int i = 0; i < length; i++) ptr[i] = b.getByte(entry,i);
78  }
79  void inputSource::getShortArray( const char *bank, int entry, int16_t *ptr, int length){
80  hipo::bank &b = banks[bank];
81  for(int i = 0; i < length; i++) ptr[i] = b.getShort(entry,i);
82  }
83  void inputSource::getIntArray( const char *bank, int entry, int32_t *ptr, int length){
84  hipo::bank &b = banks[bank];
85  for(int i = 0; i < length; i++) ptr[i] = b.getInt(entry,i);
86  }
87 
88  void inputSource::getFloatArray( const char *bank, int entry, float *ptr, int length){
89  hipo::bank &b = banks[bank];
90  for(int i = 0; i < length; i++) ptr[i] = b.getFloat(entry,i);
91  }
92 
93 
94  int fusion::open(const char *filename){
95  int number = sources.size() + 1;
96  sources.insert(std::make_pair(number, new inputSource(filename)));
97  return number;
98  }
99 
100  int fusion::open(const char *filename, int tag) {
101  int number = sources.size() + 1;
102  sources.insert(std::make_pair(number, new inputSource(filename, tag)));
103  return number;
104  }
105 
106  void fusion::define(int fid, const char *bank){
107  sources[fid]->define(bank);
108  }
109 
110  std::string fusion::schema(int fid, const char *bank){
111  return sources[fid]->schema(bank);
112  }
113  void fusion::describe(int fid, const char *bank){
114  sources[fid]->describe(bank);
115  }
116 
117  int fusion::getSize(int fid, const char *bank){
118  return sources[fid]->getSize(bank);
119  }
120 
121 bool fusion::next(int handle){
122  return sources[handle]->next();
123 }
124 
125 int fusion::getInt( int handle, const char *bank, const char *entry, int row){
126  return sources[handle]->getInt(bank,entry,row);
127 }
128 
129  int64_t fusion::getLong( int handle, const char *bank, const char *entry, int row){
130  return sources[handle]->getLong(bank,entry,row);
131 }
132 
133  float fusion::getFloat( int handle, const char *bank, const char *entry, int row){
134  //double result = sources[handle]->getFloat(bank,entry,row);
135  //printf("reuslt = %f\n",result);
136  return sources[handle]->getFloat(bank,entry,row);
137 }
138 
139  double fusion::getDouble( int handle, const char *bank, const char *entry, int row){
140  return sources[handle]->getDouble(bank,entry,row);
141  }
142 
143 int fusion::getType( int handle, const char *bank, const char *entry){
144  hipo::bank b = sources[handle]->get(bank);
145  return b.getSchema().getEntryType(b.getSchema().getEntryOrder(entry));
146 }
147 }
Represents a HIPO bank, a tabular data structure with rows and typed columns.
Definition: bank.h:352
int getInt(int item, int index) const noexcept
Definition: bank.h:714
int getShort(int item, int index) const noexcept
Definition: bank.h:746
float getFloat(int item, int index) const noexcept
Definition: bank.h:686
int getByte(int item, int index) const noexcept
Definition: bank.h:758
schema & getSchema()
Definition: bank.h:443
schema & getSchema(const char *name)
Retrieve a schema by name.
Definition: dictionary.h:271
Represents a HIPO event, a container for multiple structures/banks.
Definition: event.h:77
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
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
std::string schema(int fid, const char *bank)
Definition: fusion.cpp:110
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
void getByteArray(const char *bank, int entry, int8_t *ptr, int length)
Copy a byte column into an array.
Definition: fusion.cpp:75
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
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
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
void read(hipo::event &dataevent)
Read the current event into the given event object.
Definition: reader.cpp:233
void readDictionary(hipo::dictionary &dict)
Read the schema dictionary from the file header.
Definition: reader.cpp:311
void setTags(int tag)
Add an event tag to the read filter.
Definition: reader.h:331
bool next()
Advance to the next event.
Definition: reader.cpp:334
void open(const char *filename)
Open a HIPO file for reading.
Definition: reader.cpp:81
std::string getSchemaString()
Serialize the schema to a definition string (e.g. "pid/I,px/F").
Definition: dictionary.cpp:86
int getEntryOrder(const char *name) const
Get the column index for a given column name.
Definition: dictionary.h:239
int getEntryType(int item) const noexcept
Get the type identifier of a column by index.
Definition: dictionary.h:193
Multi-file HIPO data source management with integer handle interface.
Definition: bank.cpp:47