HIPO  4.3.0
High Performance Output data format for experimental physics
node.cpp
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: bank.cc
32  * Author: gavalian
33  *
34  * Created on April 12, 2017, 10:14 AM
35  */
36 
41 #include "node.h"
42 #include "utils.h"
43 
44 namespace hipo {
45 
46  //==============================================================
47  // Definition of class structure, this will class will be extended
48  // to represent different objects that will be appended to the event
49  //==============================================================
50 
51  void node::create(int group, int item, int type, int size){
52  allocate(size);
53  char *__a = const_cast<char*> (nodePointer);
54  *reinterpret_cast<uint16_t *>(__a) = (uint16_t) group;
55  *reinterpret_cast<uint8_t *>(__a+2) = (uint8_t) item;
56  *reinterpret_cast<uint8_t *>(__a+3) = (uint8_t) type;
57  *reinterpret_cast<uint32_t *>(__a+4) = 0x00000000;
58  }
59 
60  void node::setSize(int size){
61  char *__a = const_cast<char*> (nodePointer);
62  *reinterpret_cast<uint32_t *>(__a+4) = size;
63  }
64 
65  void node::assign(std::tuple<int,int,int,int> params ){
66  int size = std::get<3>(params);
67  int group = std::get<0>(params);
68  int item = std::get<1>(params);
69  int type = std::get<2>(params);
70  //std::get<0>(params),std::get<1>(params), std::get<2>(params), std::get<3>(params)
71  allocate(size);
72  char *__a = const_cast<char*> (nodePointer);
73  *reinterpret_cast<uint16_t *>(__a) = (uint16_t) group;
74  *reinterpret_cast<uint8_t *>(__a+2) = (uint8_t) item;
75  *reinterpret_cast<uint8_t *>(__a+3) = (uint8_t) type;
76  *reinterpret_cast<uint32_t *>(__a+4) = 0x00000000;
77 
78  }
80  char *__a = const_cast<char*> (nodePointer);
81  *reinterpret_cast<uint16_t *>(__a) = (uint16_t) 0;
82  *reinterpret_cast<uint8_t *>(__a+2) = (uint8_t) 0;
83  *reinterpret_cast<uint8_t *>(__a+3) = (uint8_t) 0;
84  *reinterpret_cast<uint8_t *>(__a+4) = 0x00000000;
85  }
86 
87  void node::show(){
88  printf("hipo::node : [%5d,%5d] type = %4d, node length = %5d, format length = %6d, data length = %8d, offset = %5d, capacity = %8d\n",
89  group(),item(),type(), size(), formatLength(), dataLength(), dataOffset(), (int) capacity());
90  }
91 
92 //====================================================================
93 //-=- END of hipo::node class - starting composite class -=-
94 //====================================================================
95 
96 }
int formatLength() const noexcept
Definition: node.h:151
int group()
Definition: node.h:212
int item()
Definition: node.h:214
int size() const noexcept
Definition: node.h:138
virtual void show()
Print a summary of this node to stdout.
Definition: node.cpp:87
void assign(std::tuple< int, int, int, int > params)
Re-initialize this node from a parameter tuple.
Definition: node.cpp:65
int capacity() const noexcept
Definition: node.h:145
int dataOffset() const noexcept
Definition: node.h:323
int dataLength() const noexcept
Definition: node.h:183
void initEmpty()
Initialize the node to an empty state.
Definition: node.cpp:79
void create(int group, int item, int type, int size)
Create a node with the given header fields and allocate storage.
Definition: node.cpp:51
int type()
Definition: node.h:216
void setSize(int size)
Set the total size of the node.
Definition: node.cpp:60
bool allocate(int size)
Ensure the internal buffer can hold at least size bytes.
Definition: node.h:128
Definition: bank.cpp:47
Low-level node class for handling tagged binary data elements in HIPO structures.
Utility functions and benchmark timer for HIPO library operations.