HIPO  4.3.0
High Performance Output data format for experimental physics
event.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  * File: event.h
32  * Author: gavalian
33  *
34  * Created on April 12, 2017, 10:14 AM
35  */
36 
42 
43 #ifndef HIPO_EVENT_H
44 #define HIPO_EVENT_H
45 
46 #include <iostream>
47 #include <vector>
48 #include <cstring>
49 #include <cstdint>
50 #include <cstdio>
51 #include <cstdlib>
52 #include <map>
53 #include "bank.h"
54 #include "node.h"
55 
56 // if the library is compiled with C++11
57 // support we will use unordered map which
58 // is faster than standard map
59 #if __cplusplus > 199711L
60 #include <unordered_map>
61 #endif
62 
63 
64 namespace hipo {
65 
66  //typedef std::auto_ptr<hipo::generic_node> node_pointer;
67 
69 
77  class event {
78 
79  private:
80  std::vector<char> dataBuffer;
81  public:
82 
84  event();
89  event(int size);
91  virtual ~event();
92 
94  void show();
99  void init(std::vector<char> &buffer);
105  void init(const char *buffer, int size);
112  void getStructure(hipo::structure &str, int group, int item);
119  void getStructure4(hipo::structure &str, int group, int item);
120 
123  int getTag();
126  void setTag(int tag);
131  void getStructure(hipo::bank &b);
136  void read(hipo::bank &b);
141  void addStructure(hipo::structure &str);
149  void override(hipo::structure &str);
154  void remove(hipo::bank &str);
160  void remove(int group, int item);
165  void replace(hipo::bank &bank);
166 
171  void add(hipo::node &_n);
178  void get(hipo::node &_n, int group, int item);
179 
186  std::pair<int,int> getStructurePosition(int group, int item);
193  std::pair<int,int> getStructurePosition4(int group, int item);
194 
197  std::vector<char> &getEventBuffer();
200  int getSize();
202  void reset();
207  void write(hipo::node &node);
214  void read(hipo::node &node, int group, int item);
215 
230  static std::pair<int,int>
231  getStructurePosition(const char *buffer, int group, int item);
232  //static std::pair<int,int>
233  // getStructurePosition5(const char *buffer, int group, int item);
234  //static std::pair<int,int> getStructurePosition(const char *buffer, int group, int item);
242  static void
243  getStructure(const char *buffer, hipo::structure &str, int group, int item);
251  static void get(const char *buffer, hipo::node &_n, int group, int item);
261  static void
262  getStructureNoCopy(const char *buffer, hipo::structure &str, int group, int item);
263 
265  };
266 }
267 
268 #endif /* EVENT_H */
Core HIPO data structures: structure, composite, and bank classes for tabular data access.
Represents a HIPO bank, a tabular data structure with rows and typed columns.
Definition: bank.h:352
Represents a HIPO event, a container for multiple structures/banks.
Definition: event.h:77
std::vector< char > & getEventBuffer()
Definition: event.cpp:329
static void getStructureNoCopy(const char *buffer, hipo::structure &str, int group, int item)
Extract a structure from a raw buffer without copying the data.
Definition: event.cpp:97
event()
Default constructor. Creates an empty event.
Definition: event.cpp:47
void write(hipo::node &node)
Write a node into this event.
Definition: event.cpp:201
void addStructure(hipo::structure &str)
Add a structure to the event.
Definition: event.cpp:161
void get(hipo::node &_n, int group, int item)
Get a node from the event by group and item identifiers.
Definition: event.cpp:209
void setTag(int tag)
Definition: event.cpp:229
void read(hipo::bank &b)
Read a bank from this event (alias for getStructure).
Definition: event.cpp:67
void getStructure(hipo::structure &str, int group, int item)
Extract a structure from the event by group and item identifiers.
Definition: event.cpp:72
std::pair< int, int > getStructurePosition(int group, int item)
Find the position and length of a structure in the event buffer.
Definition: event.cpp:256
void init(std::vector< char > &buffer)
Initialize the event from an existing buffer.
Definition: event.cpp:234
void show()
Display the event contents to standard output.
Definition: event.cpp:336
void remove(hipo::bank &str)
Remove a bank from the event.
Definition: event.cpp:136
std::pair< int, int > getStructurePosition4(int group, int item)
Find the position and length of a structure using 4-byte header format.
Definition: event.cpp:274
int getSize()
Definition: event.cpp:315
int getTag()
Definition: event.cpp:223
void reset()
Reset the event to an empty state.
Definition: event.cpp:321
void add(hipo::node &_n)
Add a node to the event.
Definition: event.cpp:184
virtual ~event()
Destructor.
void replace(hipo::bank &bank)
Replace an existing bank in the event.
Definition: event.cpp:123
void getStructure4(hipo::structure &str, int group, int item)
Extract a structure using 4-byte header format.
Definition: event.cpp:84
Low-level node representing a tagged data element in a HIPO structure.
Definition: node.h:68
Low-level data structure representing a HIPO structure.
Definition: bank.h:64
Definition: bank.cpp:47
Low-level node class for handling tagged binary data elements in HIPO structures.