HIPO  4.3.0
High Performance Output data format for experimental physics
writer.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 sowftware was developed at Jefferson National Laboratory.
32  */
90 /*
91  * File: writer.h
92  * Author: gavalian
93  *
94  * Created on April 11, 2017, 2:07 PM
95  */
96 
102 
103 #ifndef HIPOWRITER_H
104 #define HIPOWRITER_H
105 
106 
107 #include <iostream>
108 #include <vector>
109 #include <fstream>
110 #include <stdio.h>
111 #include <stdlib.h>
112 #include <memory>
113 #include <climits>
114 #include "recordbuilder.h"
115 #include "reader.h"
116 
117 namespace hipo {
118 
122  typedef struct {
123  int uniqueid;
136 
156 class writer {
157 
158  private:
159  std::ofstream outputStream;
160  hipo::recordbuilder recordBuilder;
161  hipo::dictionary writerDictionary;
162  std::vector<hipo::recordInfo_t> writerRecordInfo;
163  std::map<std::string,std::string> userConfig;
164 
165  std::map<int,hipo::recordbuilder> extendedBuilder;
166 
167  void writeIndexTable();
168  int verbose = 0;
169 
170  public:
171 
172  writer(){};
173  virtual ~writer(){};
174 
177  void addEvent(hipo::event &hevent);
181  void addEvent(std::vector<char> &vec, int size = -1);
183  void addUserConfig(std::string key, std::string value){ userConfig[key] = value;}
185  void addUserConfig(const char *key, const char *value){ userConfig[std::string(key)] = std::string(value);}
188  void writeRecord(recordbuilder &builder);
191  void open(const char *filename);
193  void close();
195  void showSummary();
198  void addDictionary(hipo::dictionary &dict);
200  hipo::dictionary &getDictionary(){ return writerDictionary;}
202  void setUserIntegerOne(long userIntOne);
204  void setUserIntegerTwo(long userIntTwo);
206  void flush();
209  void setVerbose(int level){ verbose = level;}
210 };
211 
212 };
213 #endif /* HIPOFILE_H */
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
Builds HIPO records by accumulating events and compressing them.
Definition: recordbuilder.h:45
Writer for creating HIPO files.
Definition: writer.h:156
void addUserConfig(const char *key, const char *value)
Add a user configuration key-value pair to the file header (C-string overload).
Definition: writer.h:185
void open(const char *filename)
Open a file for writing.
Definition: writer.cpp:45
void writeRecord(recordbuilder &builder)
Write a completed record to the output file.
Definition: writer.cpp:158
void flush()
Flush the current record buffer to disk.
Definition: writer.cpp:246
virtual ~writer()
Definition: writer.h:173
void setUserIntegerTwo(long userIntTwo)
Set the second user-defined integer in the file header.
Definition: writer.cpp:239
void setUserIntegerOne(long userIntOne)
Set the first user-defined integer in the file header.
Definition: writer.cpp:232
void addDictionary(hipo::dictionary &dict)
Set the dictionary to be written into the file header.
Definition: writer.cpp:123
void addEvent(hipo::event &hevent)
Add an event to the current record buffer.
Definition: writer.cpp:130
void addUserConfig(std::string key, std::string value)
Add a user configuration key-value pair to the file header.
Definition: writer.h:183
void setVerbose(int level)
Set the verbosity level for output messages.
Definition: writer.h:209
void showSummary()
Print a summary of records written to stdout.
Definition: writer.cpp:178
void close()
Close the file, flushing remaining events and writing the trailer.
Definition: writer.cpp:216
hipo::dictionary & getDictionary()
Definition: writer.h:200
Definition: bank.cpp:47
Sequential and random-access reader for HIPO files with event filtering and dictionary support.
HIPO record builder for accumulating and compressing events.
HIPO file header structure used by the writer.
Definition: writer.h:122
int userHeaderLength
User header length in bytes.
Definition: writer.h:129
int userIntegerTwo
Second user-defined integer.
Definition: writer.h:134
int userIntegerOne
First user-defined integer.
Definition: writer.h:133
int magicNumber
Magic number for endianness (0xc0da0100)
Definition: writer.h:130
long trailerPosition
File offset to trailer.
Definition: writer.h:132
int bitInfoVersion
Bit info and version packed word.
Definition: writer.h:128
int indexArrayLength
Index array length in bytes.
Definition: writer.h:127
int uniqueid
File format identifier.
Definition: writer.h:123
int recordCount
Number of records written.
Definition: writer.h:126
long userRegister
User-defined register.
Definition: writer.h:131
int filenumber
Split file number.
Definition: writer.h:124
int headerLength
Header length in words (usually 14)
Definition: writer.h:125