HIPO4 C++ Library 4.4.1
Columnar I/O library for CLAS12 physics data
Loading...
Searching...
No Matches
bank.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: bank.h
32 * Author: gavalian
33 *
34 * Created on April 12, 2017, 10:14 AM
35 */
36
37#ifndef HIPO_BANK_H
38#define HIPO_BANK_H
39#include <iostream>
40#include <vector>
41#include <cstring>
42#include <cstdint>
43#include <cstdio>
44#include <cstdlib>
45#include <map>
46#include <functional>
47#include <type_traits>
48#include "dictionary.h"
49#include "node.h"
50
51namespace hipo {
52
53 class Parser;
54
55 class structure {
56
57 private:
58
59 std::vector<char> structureBuffer;
60 char *structureAddress{};
61 void setAddress(const char *address);
62
63 protected:
64
65 void initStructureBySize(int __group, int __item, int __type, int __size);
66 std::vector<char> &getStructureBuffer(){ return structureBuffer;}
67 int getStructureBufferSize(){ return 8+getSize();}
68 int dataOffset = 8;
69 //std::vector<char> structureBuffer;
70 friend class tuple;
71
72 public:
73
74 structure(){ structureAddress = nullptr;}
75 structure(int size){ allocate(size);}
76 structure(int __group, int __item, std::string &str);
77
78 virtual ~structure()= default;
79 bool allocate(int size);
80
81 int getSize() const noexcept{
82 int length = *reinterpret_cast<uint32_t *>(structureAddress+4);
83 return length&STRUCT_SIZE_MASK;
84 //return getHeaderSize()+getDataSize();
85 }
86
87 int getHeaderSize() const noexcept {
88 int length = *reinterpret_cast<uint32_t *>(structureAddress+4);
90 }
91
92 int getDataSize() const noexcept {
93 return getSize()-getHeaderSize();
94 }
95
96 int getType() const;
97 int getGroup() const;
98 int getItem() const;
99 void init(const char *buffer, int size);
100 void initNoCopy(const char *buffer, int size);
101
102 const char *getAddress();
103 virtual void show() const;
104 void setSize(int size);
105 void setHeaderSize(int size);
106 void setDataSize(int size);
107
108 int getIntAt ( int index) const noexcept {
109 return *reinterpret_cast<int32_t*>(&structureAddress[index+dataOffset]);
110 }
111
112 int16_t getShortAt ( int index) const noexcept {
113 return *reinterpret_cast<int16_t*>(&structureAddress[index+dataOffset]);
114 }
115 int8_t getByteAt ( int index) const noexcept {
116 return *reinterpret_cast<int8_t*>(&structureAddress[index+dataOffset]);
117 }
118 float getFloatAt ( int index) const noexcept {
119 return *reinterpret_cast<float*>(&structureAddress[index+dataOffset]);
120 }
121 double getDoubleAt( int index) const noexcept {
122 return *reinterpret_cast<double*>(&structureAddress[index+dataOffset]);
123 }
124 long getLongAt ( int index) const noexcept {
125 return *reinterpret_cast<int64_t*>(&structureAddress[index+dataOffset]);
126 }
127
128 std::string getStringAt(int index);
129
130 void putIntAt(int index, int value){
131 *reinterpret_cast<int32_t*>(&structureAddress[index+dataOffset]) = value;
132 }
133
134 void putShortAt(int index, int16_t value){
135 *reinterpret_cast<int16_t*>(&structureAddress[index+dataOffset]) = value;
136 }
137
138 void putByteAt(int index, int8_t value){
139 *reinterpret_cast<int8_t*>(&structureAddress[index+dataOffset]) = value;
140 }
141
142 void putFloatAt(int index, float value){
143 *reinterpret_cast<float*>(&structureAddress[index+dataOffset]) = value;
144 }
145
146 void putDoubleAt(int index, double value){
147 *reinterpret_cast<double*>(&structureAddress[index+dataOffset]) = value;
148 }
149
150 void putLongAt(int index, int64_t value){
151 *reinterpret_cast<int64_t*>(&structureAddress[index+dataOffset]) = value;
152 }
153
154 void putStringAt(int index, std::string &str);
155
156 virtual void notify(){}
157 friend class event;
158 };
159
160 class composite : public node {
166 private:
167
168 std::vector<char> typeChars;
169 std::vector<int> offsets;
170 std::vector<int> types;
171 int rowOffset = 0;
172
173 // void parse(std::string format);
174 int getTypeSize(int type);
175
176 public:
177
180 composite(int group, int item, int size){ /*initStructureBySize(group, item, 10, size);*/};
181 composite(const char *format){}
182 composite(int group, int item, const char *format, int capacity);
183
184 void parse(std::string format);
185 void parse(int group, int item, std::string format, int maxrows);
186 virtual ~composite(){}
187
191 int getRows() const noexcept { return dataLength()/rowOffset;}
192
193 int getEntries() const noexcept { return offsets.size();}
194 int getEntryType(int index) const noexcept { return types[index];}
195 void setRows(int rows);// { setDataLength(rows*rowOffset);}
196
197 int getRowSize() const noexcept { return rowOffset;}
198
199 int getInt ( int element, int row) const noexcept;
200 int64_t getLong ( int element, int row) const noexcept;
201 float getFloat ( int element, int row) const noexcept;
202 void putInt ( int element, int row, int value);
203 void putLong ( int element, int row, int64_t value);
204 void putFloat ( int element, int row, float value);
205 virtual void notify();
206 void print();
207 void reset();
208 };
209 //typedef std::auto_ptr<hipo::generic_node> node_pointer;
210
211 class bank : public structure {
212
213 public:
214
216 class rowlist {
217
218 public:
219 using list_t = std::vector<int>;
220
221 rowlist() = default;
222 ~rowlist() = default;
223
226 void reset(int numRows = -1);
227 bool isInitialized() const { return m_init; }
228
230 list_t const& getList() const;
232 void setList(list_t const& list);
233
249 template <typename F,
250 std::enable_if_t<std::is_invocable_r_v<bool, F&, bank&, int>, int> = 0>
251 void filter(F&& func);
254 void filter(char const* expression);
257 void filter(Parser& p);
258
261 static list_t createFullList(int num);
262
264 void setOwnerBank(bank* const ownerBank) { m_owner_bank = ownerBank; }
265
266 private:
267 bool m_init{false};
268 list_t m_list{};
269 bank* m_owner_bank{nullptr};
270
271 bool ownerBankIsUnknown(std::string_view caller = "");
272
275 void filterByFunction(std::function<bool(bank&, int)> func);
276
277 };
278
279 private:
280
281 schema bankSchema;
282 int bankRows{-1};
283 rowlist bankRowList;
284
285 public:
286
288 // constructor initializes the nodes in the bank
289 // and they will be filled automatically by reader.next()
290 // method.
291 bank(const schema& __schema){
292 bankSchema = __schema;
293 bankRows = -1;
294 }
295
296 bank(const schema& __schema, int __rows){
297 bankSchema = __schema;
298 bankRows = __rows;
299 int size = bankSchema.getSizeForRows(__rows);
300 initStructureBySize(bankSchema.getGroup(),bankSchema.getItem(), 11, size);
301 bankRowList.reset(bankRows);
302 }
303
304 bank(const bank& other) : structure(){
305 bankSchema = other.copySchema();
306 setRows(0);
307 }
308
309 bank& operator=(const bank& other) {
310 if (this != &other) {
311 bankSchema = other.copySchema();
312 setRows(0);
313 }
314 return *this;
315 }
316
317 ~bank() override;
318
319 schema &getSchema() { return bankSchema;}
320 schema copySchema() const { return bankSchema;}
321
322 int getRows() const noexcept{ return bankRows;}
323 void setRows( int rows);
324 int getInt( int item, int index) const noexcept;
325 int getShort( int item, int index) const noexcept;
326 int getByte( int item, int index) const noexcept;
327 float getFloat( int item, int index) const noexcept;
328 double getDouble( int item, int index) const noexcept;
329 long getLong( int item, int index) const noexcept;
330
331 std::vector<int> getInt( int item) const noexcept;
332 std::vector<float> getFloat( int item) const noexcept;
333 std::vector<double> getDouble( int item) const noexcept;
334
335 template<typename T = double> T get(int item, int index) const noexcept {
336 auto type = bankSchema.getEntryType(item);
337 auto offset = bankSchema.getOffset(item, index, bankRows);
338 switch(type) {
339 case kByte: return (int) getByteAt(offset);
340 case kShort: return (int) getShortAt(offset);
341 case kInt: return getIntAt(offset);
342 case kFloat: return getFloatAt(offset);
343 case kDouble: return getDoubleAt(offset);
344 case kLong: return getLongAt(offset);
345 default:
346 printf("---> error(get) : unknown type for [%s] type = %d\n", bankSchema.getEntryName(item).c_str(), type);
347 }
348 return 0;
349 }
350
351 int getInt( const char *name, int index) const noexcept;
352
353 int getShort( const char *name, int index) const noexcept;
354 int getByte( const char *name, int index) const noexcept;
355 float getFloat( const char *name, int index) const noexcept;
356 double getDouble( const char *name, int index) const noexcept;
357 long getLong( const char *name, int index) const noexcept;
358
359 std::vector<int> getInt( const char *name) const noexcept;
360 std::vector<float> getFloat( const char *name) const noexcept;
361 std::vector<double> getDouble( const char *name) const noexcept;
362
363 template<typename T = double> T get(const char *name, int index) const noexcept {
364 return get<T>(bankSchema.getEntryOrder(name), index);
365 }
366
367 void putInt( const char *name, int index, int32_t value);
368 void putShort( const char *name, int index, int16_t value);
369 void putByte( const char *name, int index, int8_t value);
370 void putFloat( const char *name, int index, float value);
371 void putDouble( const char *name, int index, double value);
372 void putLong( const char *name, int index, int64_t value);
373 template<typename T> void put(const char *name, int index, T value) {
374 put(bankSchema.getEntryOrder(name), index, value);
375 }
376
377 void putInt(int item, int index, int32_t value);
378 void putShort(int item, int index, int16_t value);
379 void putByte(int item, int index, int8_t value);
380 void putFloat(int item, int index, float value);
381 void putDouble(int item, int index, double value);
382 void putLong(int item, int index, int64_t value);
383 template<typename T> void put(int item, int index, T value) {
384 auto type = bankSchema.getEntryType(item);
385 switch(type) {
386 case kByte: putByte(item, index, static_cast<int8_t>(value)); break;
387 case kShort: putShort(item, index, static_cast<int16_t>(value)); break;
388 case kInt: putInt(item, index, static_cast<int32_t>(value)); break;
389 case kFloat: putFloat(item, index, static_cast<float>(value)); break;
390 case kDouble: putDouble(item, index, static_cast<double>(value)); break;
391 case kLong: putLong(item, index, static_cast<int64_t>(value)); break;
392 default:
393 printf("---> error(put) : unknown type for [%s] type = %d\n", bankSchema.getEntryName(item).c_str(), type);
394 }
395 }
396
399 rowlist::list_t const& getRowList() const;
400
403 rowlist::list_t const getFullRowList() const;
404
407 rowlist& getMutableRowList();
408
412 rowlist::list_t const getRowListLinked(int const row, int const column) const;
413
415 void show() const override;
416
420 void show(bool const showAllRows) const;
421
425 void printValue(int schemaEntry, int row) const;
426
430 std::size_t checksum(bool checkAllRows=false) const;
431
432 void reset();
433
434 void notify() override;
435
436 };
437
439 // compile-time check that a `filter` callable takes its `bank` argument by lvalue reference
440 //
441 // `std::is_invocable` alone cannot tell `bank` (by value) from `bank const&` -- both accept every
442 // argument category. So two complementary detections are used, see `bank_takes_bank_by_ref` below.
443 namespace detail {
444 struct sealed_bank : bank {
445 sealed_bank(sealed_bank const&) = delete;
446 sealed_bank(sealed_bank&&) = delete;
447 };
448
449 // the first parameter type of a callable's signature, recovered directly from its type. We
450 // avoid `std::function` CTAD here: deducing a signature via `decltype(std::function{...})` in
451 // an unevaluated context is rejected by GCC for block-scope lambdas ("local type ... used but
452 // never defined"), so we introspect the signature without ever forming a `std::function`.
453 template <typename Sig> struct sig_first_param; // primary: undefined
454 template <typename R, typename A0, typename... As> // plain function type
455 struct sig_first_param<R(A0, As...)> { using type = A0; };
456 template <typename R, typename A0, typename... As> // function pointer
457 struct sig_first_param<R(*)(A0, As...)> { using type = A0; };
458 template <typename C, typename R, typename A0, typename... As> // member operator() (mutable)
459 struct sig_first_param<R(C::*)(A0, As...)> { using type = A0; };
460 template <typename C, typename R, typename A0, typename... As> // member operator() (const)
461 struct sig_first_param<R(C::*)(A0, As...) const> { using type = A0; };
462
463 // a class with a *non-generic* operator() (concrete lambda, functor, or `std::function`) exposes a
464 // single `&F::operator()`; a generic lambda's operator() is templated, so taking its address is ill-formed
465 template <typename F, typename = void> struct call_signature { using type = F; }; // fn ptr / fn type
466 template <typename F>
467 struct call_signature<F, std::void_t<decltype(&F::operator())>> { using type = decltype(&F::operator()); };
468
469 // the bank parameter type of F, if F has an inspectable single signature (else ill-formed -> SFINAE)
470 template <typename F>
471 using bank_param_t = typename sig_first_param<typename call_signature<F>::type>::type;
472
473 // primary template: a generic lambda has a *templated* operator() and thus no single signature,
474 // so `bank_param_t` is ill-formed -> probe with the non-copyable `sealed_bank`
475 template <typename F, typename = void>
476 struct bank_takes_bank_by_ref
477 : std::bool_constant<std::is_invocable_r<bool, F&, sealed_bank&, int>::value> {};
478
479 // inspectable callable (concrete lambda/functor, std::function, or function pointer): we recover its
480 // signature -- including the bank parameter's reference-ness -- and check it directly. This catches
481 // by-value `bank`/`bank const` (which copying could never reveal).
482 template <typename F>
483 struct bank_takes_bank_by_ref<F, std::void_t<bank_param_t<F>>>
484 : std::is_lvalue_reference<bank_param_t<F>> {};
485
486 template <typename F>
487 inline constexpr bool bank_takes_bank_by_ref_v = bank_takes_bank_by_ref<std::decay_t<F>>::value;
488
489 } // namespace detail
490
491 // out-of-line definition of the constrained `filter`, now that `bank` is a complete type
492 template <typename F, std::enable_if_t<std::is_invocable_r_v<bool, F&, bank&, int>, int>>
493 void bank::rowlist::filter(F&& func) {
494 static_assert(detail::bank_takes_bank_by_ref_v<F>,
495 "hipo::bank::rowlist::filter: the callable's bank parameter must be an lvalue reference "
496 "(bank& / bank const& / auto& / auto const&), never by value -- a by-value bank is copied "
497 "per row and the copy shallow-aliases the original's buffer, which can cause a data race "
498 "under multithreaded RDataFrame use.");
499 filterByFunction(std::forward<F>(func));
500 }
501
503 //inlined getters
504
505 inline float bank::getFloat(int item, int index) const noexcept{
506 if(bankSchema.getEntryType(item)==kFloat){
507 int offset = bankSchema.getOffset(item, index, bankRows);
508 return getFloatAt(offset);
509 }
510 return 0.0;
511 }
512
513 inline double bank::getDouble(int item, int index) const noexcept{
514 if(bankSchema.getEntryType(item)==kDouble){
515 int offset = bankSchema.getOffset(item, index, bankRows);
516 return getDoubleAt(offset);
517 }
518 if(bankSchema.getEntryType(item)==kFloat){
519 int offset = bankSchema.getOffset(item, index, bankRows);
520 return getFloatAt(offset);
521 }
522 return 0.0;
523 }
524
525 inline long bank::getLong(int item, int index) const noexcept{
526 if(bankSchema.getEntryType(item)==kLong){
527 int offset = bankSchema.getOffset(item, index, bankRows);
528 return getLongAt(offset);
529 }
530 return 0;
531 }
532
533 inline int bank::getInt(int item, int index) const noexcept{
534 int type = bankSchema.getEntryType(item);
535 int offset = bankSchema.getOffset(item, index, bankRows);
536 switch(type){
537 case kByte: return (int) getByteAt(offset);
538 case kShort: return (int) getShortAt(offset);
539 case kInt: return getIntAt(offset);
540 default: printf("---> error : requested INT for [%s] type = %d\n",
541 bankSchema.getEntryName(item).c_str(),type); break;
542 }
543 return 0;
544 }
545
546 inline std::vector<int> bank::getInt(int item) const noexcept{
547 int type = bankSchema.getEntryType(item);
548
549 std::vector<int> row;
550 int nrows = getRows();
551
552 for(int j = 0; j < nrows; j++){
553 int offset = bankSchema.getOffset(item, j, bankRows);
554 switch(type){
555 case kByte: row.push_back((int) getByteAt(offset)); break;
556 case kShort: row.push_back((int) getShortAt(offset)); break;
557 case kInt: row.push_back((int) getIntAt(offset)); break;
558 default: printf("---> error : requested INT for [%s] type = %d\n",
559 bankSchema.getEntryName(item).c_str(),type); break;
560 }
561 }
562 return row;
563 }
564
565 inline int bank::getShort(int item, int index) const noexcept{
566 int type = bankSchema.getEntryType(item);
567 int offset = bankSchema.getOffset(item, index, bankRows);
568 switch(type){
569 case kByte: return (int) getByteAt(offset);
570 case kShort: return (int) getShortAt(offset);
571 default: printf("---> error : requested SHORT for [%s] type = %d\n",
572 bankSchema.getEntryName(item).c_str(),type); break;
573 }
574 return 0;
575 }
576
577 inline int bank::getByte(int item, int index) const noexcept{
578 int type = bankSchema.getEntryType(item);
579 int offset = bankSchema.getOffset(item, index, bankRows);
580 switch(type){
581 case kByte: return (int) getByteAt(offset);
582 default: printf("---> error : requested BYTE for [%s] type = %d\n",
583 bankSchema.getEntryName(item).c_str(),type); break;
584 }
585 return 0;
586 }
587 inline int bank::getInt(const char *name, int index) const noexcept{
588 int item = bankSchema.getEntryOrder(name);
589 int type = bankSchema.getEntryType(item);
590 int offset = bankSchema.getOffset(item, index, bankRows);
591 switch(type){
592 case kByte: return (int) getByteAt(offset);
593 case kShort: return (int) getShortAt(offset);
594 case kInt: return getIntAt(offset);
595 default: printf("---> error : requested INT for [%s] type = %d\n",name,type); break;
596 }
597 return 0;
598 }
599
600 inline std::vector<int> bank::getInt(const char *name) const noexcept{
601 int item = bankSchema.getEntryOrder(name);
602 int type = bankSchema.getEntryType(item);
603 std::vector<int> row;
604
605 int nrows = getRows();
606 for(int j = 0; j < nrows; j++){
607 int offset = bankSchema.getOffset(item, j, bankRows);
608 switch(type){
609 case kByte: row.push_back((int) getByteAt(offset)); break;
610 case kShort: row.push_back((int) getShortAt(offset)); break;
611 case kInt: row.push_back((int) getIntAt(offset)); break;
612 default: printf("---> error : requested INT for [%s] type = %d\n",name,type); break;
613 }
614 }
615 return row;
616 }
617
618 inline int bank::getShort(const char *name, int index) const noexcept{
619 int item = bankSchema.getEntryOrder(name);
620 int type = bankSchema.getEntryType(item);
621 int offset = bankSchema.getOffset(item, index, bankRows);
622 switch(type){
623 case kByte: return (int) getByteAt(offset);
624 case kShort: return (int) getShortAt(offset);
625 default: printf("---> error : requested SHORT for [%s] type = %d\n",
626 bankSchema.getEntryName(item).c_str(),type); break;
627 }
628 return 0;
629 }
630 inline int bank::getByte(const char *name, int index) const noexcept{
631 int item = bankSchema.getEntryOrder(name);
632 int type = bankSchema.getEntryType(item);
633 int offset = bankSchema.getOffset(item, index, bankRows);
634 switch(type){
635 case kByte: return (int) getByteAt(offset);
636 default: printf("---> error : requested BYTE for [%s] type = %d\n",
637 bankSchema.getEntryName(item).c_str(),type); break;
638 }
639 return 0;
640 }
641
642 inline float bank::getFloat(const char *name, int index) const noexcept{
643 int item = bankSchema.getEntryOrder(name);
644 if(bankSchema.getEntryType(item)==kFloat){
645 int offset = bankSchema.getOffset(item, index, bankRows);
646 return getFloatAt(offset);
647 }
648 return 0.0;
649 }
650
651 inline std::vector<float> bank::getFloat(const char *name) const noexcept{
652 int item = bankSchema.getEntryOrder(name);
653 std::vector<float> row;
654 int nrows = getRows();
655 if(bankSchema.getEntryType(item)==kFloat){
656 for(int j = 0; j < nrows; j++){
657 int offset = bankSchema.getOffset(item, j, bankRows);
658 row.push_back( getFloatAt(offset));
659 }
660 }
661 return row;
662 }
663
664 inline std::vector<float> bank::getFloat(int item) const noexcept{
665 std::vector<float> row;
666 int nrows = getRows();
667 if(bankSchema.getEntryType(item)==kFloat){
668 for(int j = 0; j < nrows; j++){
669 int offset = bankSchema.getOffset(item, j, bankRows);
670 row.push_back( getFloatAt(offset));
671 }
672 }
673 return row;
674 }
675 inline double bank::getDouble(const char *name, int index) const noexcept{
676 int item = bankSchema.getEntryOrder(name);
677 if(bankSchema.getEntryType(item)==kDouble){
678 int offset = bankSchema.getOffset(item, index, bankRows);
679 return getDoubleAt(offset);
680 }
681 if(bankSchema.getEntryType(item)==kFloat){
682 int offset = bankSchema.getOffset(item, index, bankRows);
683 return (double) getFloatAt(offset);
684 }
685 return 0.0;
686 }
687
688 inline std::vector<double> bank::getDouble(int item) const noexcept{
689 std::vector<double> row;
690 int nrows = getRows();
691
692 if(bankSchema.getEntryType(item)==kDouble){
693 for(int j = 0; j < nrows; j++){
694 int offset = bankSchema.getOffset(item, j, bankRows);
695 row.push_back(getDoubleAt(offset));
696 }
697 }
698 if(bankSchema.getEntryType(item)==kFloat){
699 for(int j = 0; j < nrows; j++){
700 int offset = bankSchema.getOffset(item, j, bankRows);
701 row.push_back((double) getFloatAt(offset));
702 }
703 }
704 return row;
705 }
706
707 inline std::vector<double> bank::getDouble(const char *name) const noexcept{
708 std::vector<double> row;
709 int nrows = getRows();
710 int item = bankSchema.getEntryOrder(name);
711
712 if(bankSchema.getEntryType(item)==kDouble){
713 for(int j = 0; j < nrows; j++){
714 int offset = bankSchema.getOffset(item, j, bankRows);
715 row.push_back(getDoubleAt(offset));
716 }
717 }
718 if(bankSchema.getEntryType(item)==kFloat){
719 for(int j = 0; j < nrows; j++){
720 int offset = bankSchema.getOffset(item, j, bankRows);
721 row.push_back((double) getFloatAt(offset));
722 }
723 }
724 return row;
725 }
726
727 inline long bank::getLong(const char *name, int index) const noexcept{
728 int item = bankSchema.getEntryOrder(name);
729 if(bankSchema.getEntryType(item)==kLong){
730 int offset = bankSchema.getOffset(item, index, bankRows);
731 return getLongAt(offset);
732 }
733 return 0;
734 }
735 inline void bank::putInt(int item, int index, int32_t value){
736 //int type = bankSchema.getEntryType(item);
737 int offset = bankSchema.getOffset(item, index, bankRows);
738 putIntAt(offset,value);
739 }
740 inline void bank::putShort(int item, int index, int16_t value){
741 //int type = bankSchema.getEntryType(item);
742 int offset = bankSchema.getOffset(item, index, bankRows);
743 putShortAt(offset,value);
744 }
745 inline void bank::putByte(int item, int index, int8_t value){
746 //int type = bankSchema.getEntryType(item);
747 int offset = bankSchema.getOffset(item, index, bankRows);
748 putByteAt(offset,value);
749 }
750 inline void bank::putFloat(int item, int index, float value){
751 //int type = bankSchema.getEntryType(item);
752 int offset = bankSchema.getOffset(item, index, bankRows);
753 //printf("---- put float %f at position = %d\n",value,offset);
754 putFloatAt(offset,value);
755 }
756 inline void bank::putDouble(int item, int index, double value){
757 //int type = bankSchema.getEntryType(item);
758 int offset = bankSchema.getOffset(item, index, bankRows);
759 putDoubleAt(offset,value);
760 }
761 inline void bank::putLong(int item, int index, int64_t value){
762 //int type = bankSchema.getEntryType(item);
763 int offset = bankSchema.getOffset(item, index, bankRows);
764 putLongAt(offset,value);
765 }
766
767 using banklist=std::vector<bank>;
768
769 // @returns the index of the bank in `banklist` `banks` which has the name `bankName`; if there is more
770 // than one, only the index of the first such bank will be returned. A runtime exception is thrown
771 // if the bank is not found
772 // @param banks the `banklist` to search
773 // @param bankName the bank name
774 banklist::size_type getBanklistIndex(banklist& banks, std::string const& bankName) noexcept(false);
775
776}
777#endif /* BANK_H */
Definition parser.h:25
rowlist encapsulates a list of rows for this bank, providing a way to iterate over them
Definition bank.h:216
list_t const & getList() const
Definition bank.cpp:355
void setOwnerBank(bank *const ownerBank)
Definition bank.h:264
void setList(list_t const &list)
Definition bank.cpp:361
bool isInitialized() const
Definition bank.h:227
std::vector< int > list_t
Definition bank.h:219
static list_t createFullList(int num)
Definition bank.cpp:398
void filter(F &&func)
filter the list according to a function
Definition bank.h:493
Definition bank.h:211
void setRows(int rows)
Definition bank.cpp:429
void putByte(const char *name, int index, int8_t value)
Definition bank.cpp:462
schema copySchema() const
Definition bank.h:320
void reset()
Definition bank.cpp:437
void put(const char *name, int index, T value)
Definition bank.h:373
bank & operator=(const bank &other)
Definition bank.h:309
bank(const bank &other)
Definition bank.h:304
rowlist::list_t const & getRowList() const
Definition bank.cpp:484
void putFloat(const char *name, int index, float value)
Definition bank.cpp:467
bank(const schema &__schema, int __rows)
Definition bank.h:296
T get(int item, int index) const noexcept
Definition bank.h:335
rowlist & getMutableRowList()
Definition bank.cpp:492
int getInt(int item, int index) const noexcept
Definition bank.h:533
void putShort(const char *name, int index, int16_t value)
Definition bank.cpp:457
void notify() override
Definition bank.cpp:443
void putLong(const char *name, int index, int64_t value)
Definition bank.cpp:478
long getLong(int item, int index) const noexcept
Definition bank.h:525
void printValue(int schemaEntry, int row) const
print a stored value
Definition bank.cpp:530
int getRows() const noexcept
Definition bank.h:322
void put(int item, int index, T value)
Definition bank.h:383
std::size_t checksum(bool checkAllRows=false) const
calculate a checksum for this bank; useful for comparing two banks' equality
Definition bank.cpp:549
schema & getSchema()
Definition bank.h:319
void putDouble(const char *name, int index, double value)
Definition bank.cpp:472
T get(const char *name, int index) const noexcept
Definition bank.h:363
int getShort(int item, int index) const noexcept
Definition bank.h:565
void show() const override
show this bank's contents; only the rows in its current rowlist instance are shown
Definition bank.cpp:506
bank(const schema &__schema)
Definition bank.h:291
float getFloat(int item, int index) const noexcept
Definition bank.h:505
int getByte(int item, int index) const noexcept
Definition bank.h:577
~bank() override
rowlist::list_t const getFullRowList() const
Definition bank.cpp:488
void putInt(const char *name, int index, int32_t value)
Definition bank.cpp:452
double getDouble(int item, int index) const noexcept
Definition bank.h:513
rowlist::list_t const getRowListLinked(int const row, int const column) const
Definition bank.cpp:497
Definition bank.h:160
int getRows() const noexcept
Definition bank.h:191
int getInt(int element, int row) const noexcept
Definition bank.cpp:214
composite(const char *format)
Definition bank.h:181
virtual void notify()
Definition bank.cpp:282
int getEntries() const noexcept
Definition bank.h:193
composite(int group, int item, int size)
Definition bank.h:180
void print()
Definition bank.cpp:307
void putLong(int element, int row, int64_t value)
Definition bank.cpp:265
float getFloat(int element, int row) const noexcept
Definition bank.cpp:241
void putInt(int element, int row, int value)
Definition bank.cpp:251
int getEntryType(int index) const noexcept
Definition bank.h:194
void parse(std::string format)
Definition bank.cpp:160
void reset()
Definition bank.cpp:148
int getRowSize() const noexcept
Definition bank.h:197
int64_t getLong(int element, int row) const noexcept
Definition bank.cpp:231
void putFloat(int element, int row, float value)
Definition bank.cpp:273
virtual ~composite()
Definition bank.h:186
composite(int size)
Definition bank.h:179
composite()
Definition bank.h:178
void setRows(int rows)
Definition bank.cpp:164
Definition event.h:62
Definition node.h:51
int group()
Definition node.h:148
int item()
Definition node.h:149
int size() const noexcept
Definition node.h:92
int capacity() const noexcept
Definition node.h:98
int dataLength() const noexcept
Definition node.h:126
int type()
Definition node.h:150
bool allocate(int size)
Definition node.h:84
Schema definition for a HIPO bank.
Definition dictionary.h:56
int getEntryOrder(const char *name) const
Definition dictionary.h:146
std::string getEntryName(int item) const noexcept
Definition dictionary.h:130
int getOffset(int item, int order, int rows) const
Definition dictionary.h:109
int getEntryType(int item) const noexcept
Definition dictionary.h:119
Definition bank.h:55
float getFloatAt(int index) const noexcept
Definition bank.h:118
void initStructureBySize(int __group, int __item, int __type, int __size)
Definition bank.cpp:65
void putShortAt(int index, int16_t value)
Definition bank.h:134
int getItem() const
Definition bank.cpp:106
int getSize() const noexcept
Definition bank.h:81
void putIntAt(int index, int value)
Definition bank.h:130
int getDataSize() const noexcept
Definition bank.h:92
void putByteAt(int index, int8_t value)
Definition bank.h:138
std::vector< char > & getStructureBuffer()
Definition bank.h:66
bool allocate(int size)
Definition bank.cpp:58
int getGroup() const
Definition bank.cpp:101
virtual ~structure()=default
void putStringAt(int index, std::string &str)
Definition bank.cpp:135
structure()
Definition bank.h:74
int getStructureBufferSize()
Definition bank.h:67
void setSize(int size)
Definition bank.cpp:74
int16_t getShortAt(int index) const noexcept
Definition bank.h:112
virtual void show() const
Definition bank.cpp:120
int dataOffset
Definition bank.h:68
void putLongAt(int index, int64_t value)
Definition bank.h:150
long getLongAt(int index) const noexcept
Definition bank.h:124
int getType() const
Definition bank.cpp:96
void initNoCopy(const char *buffer, int size)
Definition bank.cpp:110
int8_t getByteAt(int index) const noexcept
Definition bank.h:115
int getIntAt(int index) const noexcept
Definition bank.h:108
structure(int size)
Definition bank.h:75
void setDataSize(int size)
Definition bank.cpp:80
void putDoubleAt(int index, double value)
Definition bank.h:146
virtual void notify()
Definition bank.h:156
void putFloatAt(int index, float value)
Definition bank.h:142
int getHeaderSize() const noexcept
Definition bank.h:87
void init(const char *buffer, int size)
Definition bank.cpp:114
double getDoubleAt(int index) const noexcept
Definition bank.h:121
std::string getStringAt(int index)
Definition bank.cpp:125
void setHeaderSize(int size)
Definition bank.cpp:89
const char * getAddress()
Definition bank.cpp:140
Definition tuple.h:61
Definition progresstracker.hpp:16
HIPO namespace is used for the classes that read/write files and records.
Definition bank.cpp:45
@ kLong
Definition dictionary.h:41
@ kInt
Definition dictionary.h:38
@ kFloat
Definition dictionary.h:39
@ kShort
Definition dictionary.h:37
@ kByte
Definition dictionary.h:36
@ kDouble
Definition dictionary.h:40
constexpr uint32_t STRUCT_FORMAT_BYTE
Definition constants.h:130
banklist::size_type getBanklistIndex(banklist &banks, std::string const &bankName) noexcept(false)
Definition bank.cpp:585
constexpr int STRUCT_FORMAT_SHIFT
Definition constants.h:129
std::vector< bank > banklist
Definition bank.h:767
constexpr uint32_t STRUCT_SIZE_MASK
Definition constants.h:127