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() override;
305
306 schema &getSchema() { return bankSchema;}
307
308 int getRows() const noexcept{ return bankRows;}
309 void setRows( int rows);
310 int getInt( int item, int index) const noexcept;
311 int getShort( int item, int index) const noexcept;
312 int getByte( int item, int index) const noexcept;
313 float getFloat( int item, int index) const noexcept;
314 double getDouble( int item, int index) const noexcept;
315 long getLong( int item, int index) const noexcept;
316
317 std::vector<int> getInt( int item) const noexcept;
318 std::vector<float> getFloat( int item) const noexcept;
319 std::vector<double> getDouble( int item) const noexcept;
320
321 template<typename T = double> T get(int item, int index) const noexcept {
322 auto type = bankSchema.getEntryType(item);
323 auto offset = bankSchema.getOffset(item, index, bankRows);
324 switch(type) {
325 case kByte: return (int) getByteAt(offset);
326 case kShort: return (int) getShortAt(offset);
327 case kInt: return getIntAt(offset);
328 case kFloat: return getFloatAt(offset);
329 case kDouble: return getDoubleAt(offset);
330 case kLong: return getLongAt(offset);
331 default:
332 printf("---> error(get) : unknown type for [%s] type = %d\n", bankSchema.getEntryName(item).c_str(), type);
333 }
334 return 0;
335 }
336
337 int getInt( const char *name, int index) const noexcept;
338
339 int getShort( const char *name, int index) const noexcept;
340 int getByte( const char *name, int index) const noexcept;
341 float getFloat( const char *name, int index) const noexcept;
342 double getDouble( const char *name, int index) const noexcept;
343 long getLong( const char *name, int index) const noexcept;
344
345 std::vector<int> getInt( const char *name) const noexcept;
346 std::vector<float> getFloat( const char *name) const noexcept;
347 std::vector<double> getDouble( const char *name) const noexcept;
348
349 template<typename T = double> T get(const char *name, int index) const noexcept {
350 return get<T>(bankSchema.getEntryOrder(name), index);
351 }
352
353 void putInt( const char *name, int index, int32_t value);
354 void putShort( const char *name, int index, int16_t value);
355 void putByte( const char *name, int index, int8_t value);
356 void putFloat( const char *name, int index, float value);
357 void putDouble( const char *name, int index, double value);
358 void putLong( const char *name, int index, int64_t value);
359 template<typename T> void put(const char *name, int index, T value) {
360 put(bankSchema.getEntryOrder(name), index, value);
361 }
362
363 void putInt(int item, int index, int32_t value);
364 void putShort(int item, int index, int16_t value);
365 void putByte(int item, int index, int8_t value);
366 void putFloat(int item, int index, float value);
367 void putDouble(int item, int index, double value);
368 void putLong(int item, int index, int64_t value);
369 template<typename T> void put(int item, int index, T value) {
370 auto type = bankSchema.getEntryType(item);
371 switch(type) {
372 case kByte: putByte(item, index, static_cast<int8_t>(value)); break;
373 case kShort: putShort(item, index, static_cast<int16_t>(value)); break;
374 case kInt: putInt(item, index, static_cast<int32_t>(value)); break;
375 case kFloat: putFloat(item, index, static_cast<float>(value)); break;
376 case kDouble: putDouble(item, index, static_cast<double>(value)); break;
377 case kLong: putLong(item, index, static_cast<int64_t>(value)); break;
378 default:
379 printf("---> error(put) : unknown type for [%s] type = %d\n", bankSchema.getEntryName(item).c_str(), type);
380 }
381 }
382
385 rowlist::list_t const& getRowList() const;
386
389 rowlist::list_t const getFullRowList() const;
390
393 rowlist& getMutableRowList();
394
398 rowlist::list_t const getRowListLinked(int const row, int const column) const;
399
401 void show() const override;
402
406 void show(bool const showAllRows) const;
407
411 void printValue(int schemaEntry, int row) const;
412
416 std::size_t checksum(bool checkAllRows=false) const;
417
418 void reset();
419
420 void notify() override;
421
422 };
423
425 // compile-time check that a `filter` callable takes its `bank` argument by lvalue reference
426 //
427 // `std::is_invocable` alone cannot tell `bank` (by value) from `bank const&` -- both accept every
428 // argument category. So two complementary detections are used, see `bank_takes_bank_by_ref` below.
429 namespace detail {
430 struct sealed_bank : bank {
431 sealed_bank(sealed_bank const&) = delete;
432 sealed_bank(sealed_bank&&) = delete;
433 };
434
435 // the first parameter type of a callable's signature, recovered directly from its type. We
436 // avoid `std::function` CTAD here: deducing a signature via `decltype(std::function{...})` in
437 // an unevaluated context is rejected by GCC for block-scope lambdas ("local type ... used but
438 // never defined"), so we introspect the signature without ever forming a `std::function`.
439 template <typename Sig> struct sig_first_param; // primary: undefined
440 template <typename R, typename A0, typename... As> // plain function type
441 struct sig_first_param<R(A0, As...)> { using type = A0; };
442 template <typename R, typename A0, typename... As> // function pointer
443 struct sig_first_param<R(*)(A0, As...)> { using type = A0; };
444 template <typename C, typename R, typename A0, typename... As> // member operator() (mutable)
445 struct sig_first_param<R(C::*)(A0, As...)> { using type = A0; };
446 template <typename C, typename R, typename A0, typename... As> // member operator() (const)
447 struct sig_first_param<R(C::*)(A0, As...) const> { using type = A0; };
448
449 // a class with a *non-generic* operator() (concrete lambda, functor, or `std::function`) exposes a
450 // single `&F::operator()`; a generic lambda's operator() is templated, so taking its address is ill-formed
451 template <typename F, typename = void> struct call_signature { using type = F; }; // fn ptr / fn type
452 template <typename F>
453 struct call_signature<F, std::void_t<decltype(&F::operator())>> { using type = decltype(&F::operator()); };
454
455 // the bank parameter type of F, if F has an inspectable single signature (else ill-formed -> SFINAE)
456 template <typename F>
457 using bank_param_t = typename sig_first_param<typename call_signature<F>::type>::type;
458
459 // primary template: a generic lambda has a *templated* operator() and thus no single signature,
460 // so `bank_param_t` is ill-formed -> probe with the non-copyable `sealed_bank`
461 template <typename F, typename = void>
462 struct bank_takes_bank_by_ref
463 : std::bool_constant<std::is_invocable_r<bool, F&, sealed_bank&, int>::value> {};
464
465 // inspectable callable (concrete lambda/functor, std::function, or function pointer): we recover its
466 // signature -- including the bank parameter's reference-ness -- and check it directly. This catches
467 // by-value `bank`/`bank const` (which copying could never reveal).
468 template <typename F>
469 struct bank_takes_bank_by_ref<F, std::void_t<bank_param_t<F>>>
470 : std::is_lvalue_reference<bank_param_t<F>> {};
471
472 template <typename F>
473 inline constexpr bool bank_takes_bank_by_ref_v = bank_takes_bank_by_ref<std::decay_t<F>>::value;
474
475 } // namespace detail
476
477 // out-of-line definition of the constrained `filter`, now that `bank` is a complete type
478 template <typename F, std::enable_if_t<std::is_invocable_r_v<bool, F&, bank&, int>, int>>
479 void bank::rowlist::filter(F&& func) {
480 static_assert(detail::bank_takes_bank_by_ref_v<F>,
481 "hipo::bank::rowlist::filter: the callable's bank parameter must be an lvalue reference "
482 "(bank& / bank const& / auto& / auto const&), never by value -- a by-value bank is copied "
483 "per row and the copy shallow-aliases the original's buffer, which can cause a data race "
484 "under multithreaded RDataFrame use.");
485 filterByFunction(std::forward<F>(func));
486 }
487
489 //inlined getters
490
491 inline float bank::getFloat(int item, int index) const noexcept{
492 if(bankSchema.getEntryType(item)==kFloat){
493 int offset = bankSchema.getOffset(item, index, bankRows);
494 return getFloatAt(offset);
495 }
496 return 0.0;
497 }
498
499 inline double bank::getDouble(int item, int index) const noexcept{
500 if(bankSchema.getEntryType(item)==kDouble){
501 int offset = bankSchema.getOffset(item, index, bankRows);
502 return getDoubleAt(offset);
503 }
504 if(bankSchema.getEntryType(item)==kFloat){
505 int offset = bankSchema.getOffset(item, index, bankRows);
506 return getFloatAt(offset);
507 }
508 return 0.0;
509 }
510
511 inline long bank::getLong(int item, int index) const noexcept{
512 if(bankSchema.getEntryType(item)==kLong){
513 int offset = bankSchema.getOffset(item, index, bankRows);
514 return getLongAt(offset);
515 }
516 return 0;
517 }
518
519 inline int bank::getInt(int item, int index) const noexcept{
520 int type = bankSchema.getEntryType(item);
521 int offset = bankSchema.getOffset(item, index, bankRows);
522 switch(type){
523 case kByte: return (int) getByteAt(offset);
524 case kShort: return (int) getShortAt(offset);
525 case kInt: return getIntAt(offset);
526 default: printf("---> error : requested INT for [%s] type = %d\n",
527 bankSchema.getEntryName(item).c_str(),type); break;
528 }
529 return 0;
530 }
531
532 inline std::vector<int> bank::getInt(int item) const noexcept{
533 int type = bankSchema.getEntryType(item);
534
535 std::vector<int> row;
536 int nrows = getRows();
537
538 for(int j = 0; j < nrows; j++){
539 int offset = bankSchema.getOffset(item, j, bankRows);
540 switch(type){
541 case kByte: row.push_back((int) getByteAt(offset)); break;
542 case kShort: row.push_back((int) getShortAt(offset)); break;
543 case kInt: row.push_back((int) getIntAt(offset)); break;
544 default: printf("---> error : requested INT for [%s] type = %d\n",
545 bankSchema.getEntryName(item).c_str(),type); break;
546 }
547 }
548 return row;
549 }
550
551 inline int bank::getShort(int item, int index) const noexcept{
552 int type = bankSchema.getEntryType(item);
553 int offset = bankSchema.getOffset(item, index, bankRows);
554 switch(type){
555 case kByte: return (int) getByteAt(offset);
556 case kShort: return (int) getShortAt(offset);
557 default: printf("---> error : requested SHORT for [%s] type = %d\n",
558 bankSchema.getEntryName(item).c_str(),type); break;
559 }
560 return 0;
561 }
562
563 inline int bank::getByte(int item, int index) const noexcept{
564 int type = bankSchema.getEntryType(item);
565 int offset = bankSchema.getOffset(item, index, bankRows);
566 switch(type){
567 case kByte: return (int) getByteAt(offset);
568 default: printf("---> error : requested BYTE for [%s] type = %d\n",
569 bankSchema.getEntryName(item).c_str(),type); break;
570 }
571 return 0;
572 }
573 inline int bank::getInt(const char *name, int index) const noexcept{
574 int item = bankSchema.getEntryOrder(name);
575 int type = bankSchema.getEntryType(item);
576 int offset = bankSchema.getOffset(item, index, bankRows);
577 switch(type){
578 case kByte: return (int) getByteAt(offset);
579 case kShort: return (int) getShortAt(offset);
580 case kInt: return getIntAt(offset);
581 default: printf("---> error : requested INT for [%s] type = %d\n",name,type); break;
582 }
583 return 0;
584 }
585
586 inline std::vector<int> bank::getInt(const char *name) const noexcept{
587 int item = bankSchema.getEntryOrder(name);
588 int type = bankSchema.getEntryType(item);
589 std::vector<int> row;
590
591 int nrows = getRows();
592 for(int j = 0; j < nrows; j++){
593 int offset = bankSchema.getOffset(item, j, bankRows);
594 switch(type){
595 case kByte: row.push_back((int) getByteAt(offset)); break;
596 case kShort: row.push_back((int) getShortAt(offset)); break;
597 case kInt: row.push_back((int) getIntAt(offset)); break;
598 default: printf("---> error : requested INT for [%s] type = %d\n",name,type); break;
599 }
600 }
601 return row;
602 }
603
604 inline int bank::getShort(const char *name, int index) const noexcept{
605 int item = bankSchema.getEntryOrder(name);
606 int type = bankSchema.getEntryType(item);
607 int offset = bankSchema.getOffset(item, index, bankRows);
608 switch(type){
609 case kByte: return (int) getByteAt(offset);
610 case kShort: return (int) getShortAt(offset);
611 default: printf("---> error : requested SHORT for [%s] type = %d\n",
612 bankSchema.getEntryName(item).c_str(),type); break;
613 }
614 return 0;
615 }
616 inline int bank::getByte(const char *name, int index) const noexcept{
617 int item = bankSchema.getEntryOrder(name);
618 int type = bankSchema.getEntryType(item);
619 int offset = bankSchema.getOffset(item, index, bankRows);
620 switch(type){
621 case kByte: return (int) getByteAt(offset);
622 default: printf("---> error : requested BYTE for [%s] type = %d\n",
623 bankSchema.getEntryName(item).c_str(),type); break;
624 }
625 return 0;
626 }
627
628 inline float bank::getFloat(const char *name, int index) const noexcept{
629 int item = bankSchema.getEntryOrder(name);
630 if(bankSchema.getEntryType(item)==kFloat){
631 int offset = bankSchema.getOffset(item, index, bankRows);
632 return getFloatAt(offset);
633 }
634 return 0.0;
635 }
636
637 inline std::vector<float> bank::getFloat(const char *name) const noexcept{
638 int item = bankSchema.getEntryOrder(name);
639 std::vector<float> row;
640 int nrows = getRows();
641 if(bankSchema.getEntryType(item)==kFloat){
642 for(int j = 0; j < nrows; j++){
643 int offset = bankSchema.getOffset(item, j, bankRows);
644 row.push_back( getFloatAt(offset));
645 }
646 }
647 return row;
648 }
649
650 inline std::vector<float> bank::getFloat(int item) const noexcept{
651 std::vector<float> row;
652 int nrows = getRows();
653 if(bankSchema.getEntryType(item)==kFloat){
654 for(int j = 0; j < nrows; j++){
655 int offset = bankSchema.getOffset(item, j, bankRows);
656 row.push_back( getFloatAt(offset));
657 }
658 }
659 return row;
660 }
661 inline double bank::getDouble(const char *name, int index) const noexcept{
662 int item = bankSchema.getEntryOrder(name);
663 if(bankSchema.getEntryType(item)==kDouble){
664 int offset = bankSchema.getOffset(item, index, bankRows);
665 return getDoubleAt(offset);
666 }
667 if(bankSchema.getEntryType(item)==kFloat){
668 int offset = bankSchema.getOffset(item, index, bankRows);
669 return (double) getFloatAt(offset);
670 }
671 return 0.0;
672 }
673
674 inline std::vector<double> bank::getDouble(int item) const noexcept{
675 std::vector<double> row;
676 int nrows = getRows();
677
678 if(bankSchema.getEntryType(item)==kDouble){
679 for(int j = 0; j < nrows; j++){
680 int offset = bankSchema.getOffset(item, j, bankRows);
681 row.push_back(getDoubleAt(offset));
682 }
683 }
684 if(bankSchema.getEntryType(item)==kFloat){
685 for(int j = 0; j < nrows; j++){
686 int offset = bankSchema.getOffset(item, j, bankRows);
687 row.push_back((double) getFloatAt(offset));
688 }
689 }
690 return row;
691 }
692
693 inline std::vector<double> bank::getDouble(const char *name) const noexcept{
694 std::vector<double> row;
695 int nrows = getRows();
696 int item = bankSchema.getEntryOrder(name);
697
698 if(bankSchema.getEntryType(item)==kDouble){
699 for(int j = 0; j < nrows; j++){
700 int offset = bankSchema.getOffset(item, j, bankRows);
701 row.push_back(getDoubleAt(offset));
702 }
703 }
704 if(bankSchema.getEntryType(item)==kFloat){
705 for(int j = 0; j < nrows; j++){
706 int offset = bankSchema.getOffset(item, j, bankRows);
707 row.push_back((double) getFloatAt(offset));
708 }
709 }
710 return row;
711 }
712
713 inline long bank::getLong(const char *name, int index) const noexcept{
714 int item = bankSchema.getEntryOrder(name);
715 if(bankSchema.getEntryType(item)==kLong){
716 int offset = bankSchema.getOffset(item, index, bankRows);
717 return getLongAt(offset);
718 }
719 return 0;
720 }
721 inline void bank::putInt(int item, int index, int32_t value){
722 //int type = bankSchema.getEntryType(item);
723 int offset = bankSchema.getOffset(item, index, bankRows);
724 putIntAt(offset,value);
725 }
726 inline void bank::putShort(int item, int index, int16_t value){
727 //int type = bankSchema.getEntryType(item);
728 int offset = bankSchema.getOffset(item, index, bankRows);
729 putShortAt(offset,value);
730 }
731 inline void bank::putByte(int item, int index, int8_t value){
732 //int type = bankSchema.getEntryType(item);
733 int offset = bankSchema.getOffset(item, index, bankRows);
734 putByteAt(offset,value);
735 }
736 inline void bank::putFloat(int item, int index, float value){
737 //int type = bankSchema.getEntryType(item);
738 int offset = bankSchema.getOffset(item, index, bankRows);
739 //printf("---- put float %f at position = %d\n",value,offset);
740 putFloatAt(offset,value);
741 }
742 inline void bank::putDouble(int item, int index, double value){
743 //int type = bankSchema.getEntryType(item);
744 int offset = bankSchema.getOffset(item, index, bankRows);
745 putDoubleAt(offset,value);
746 }
747 inline void bank::putLong(int item, int index, int64_t value){
748 //int type = bankSchema.getEntryType(item);
749 int offset = bankSchema.getOffset(item, index, bankRows);
750 putLongAt(offset,value);
751 }
752
753 using banklist=std::vector<bank>;
754
755 // @returns the index of the bank in `banklist` `banks` which has the name `bankName`; if there is more
756 // than one, only the index of the first such bank will be returned. A runtime exception is thrown
757 // if the bank is not found
758 // @param banks the `banklist` to search
759 // @param bankName the bank name
760 banklist::size_type getBanklistIndex(banklist& banks, std::string const& bankName) noexcept(false);
761
762}
763#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:479
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
void reset()
Definition bank.cpp:437
void put(const char *name, int index, T value)
Definition bank.h:359
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:321
rowlist & getMutableRowList()
Definition bank.cpp:492
int getInt(int item, int index) const noexcept
Definition bank.h:519
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:511
void printValue(int schemaEntry, int row) const
print a stored value
Definition bank.cpp:530
int getRows() const noexcept
Definition bank.h:308
void put(int item, int index, T value)
Definition bank.h:369
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:306
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:349
int getShort(int item, int index) const noexcept
Definition bank.h:551
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:491
int getByte(int item, int index) const noexcept
Definition bank.h:563
~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:499
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:753
constexpr uint32_t STRUCT_SIZE_MASK
Definition constants.h:127