R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BUcesbStructInfo.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#include "R3BUcesbStructInfo.h"
15#include "R3BUcesbDecl.h"
16#include <R3BException.h>
17#include <R3BLogger.h>
18#include <R3BUcesbSource2.h>
19
20namespace R3B
21{
22 // return pointer of the reader if it requires the item. If not required, return nullptr
23 inline auto check_struct_item_requried(std::string_view item_name, UcesbSource* source) -> R3BReader*
24 {
25 return source->FindReaderIf([item_name](R3BReader* reader)
26 { return reader->MismappedItemRequired(item_name); });
27 }
28
29 bool UcesbStructInfo::check_struct_item(ext_data_structure_item* item, UcesbSource* source)
30 {
31 auto map_flag = static_cast<UcesbMap>(item->_map_success);
32 auto is_match_ok = ((map_flag & ~(map_success_conditions_)) == UcesbMap::zero);
33 if (is_match_ok)
34 {
35 return true;
36 }
37 auto* required_reader = check_struct_item_requried(item->_var_name, source);
38 R3BLOG(debug2, fmt::format("Checking ucesb struct item {:?}.", item->_var_name));
39 if (required_reader == nullptr || required_reader->AllowExtraCondition(map_flag, map_success_conditions_))
40 {
41 // no reader requries this item or reader accepts extra flag
42 return true;
43 }
44
45 R3BLOG(error,
46 fmt::format("Failed to map the item {} required from {} due to the map flag: {}",
47 item->_var_name,
48 required_reader->GetName(),
49 map_flag));
50 return false;
51 }
52
54 {
55 R3BLOG(debug, "Checking struct mapping.");
56 auto* struct_info = static_cast<ext_data_structure_info*>(struct_info_);
57 auto is_checking_ok = true;
58 // ext_data_struct_info_print_map_success(struct_info, stderr, EXT_DATA_ITEM_MAP_NO_DEST);
59 // ext_data_struct_info_print_map_success(struct_info, stderr, 0);
60 for (auto* item = struct_info->_items; item != nullptr; item = item->_next_off_item)
61 {
62 is_checking_ok &= check_struct_item(item, source);
63 }
64
65 if (not is_checking_ok)
66 {
67 terminate();
68 }
69 }
70
71 void UcesbStructInfo::terminate()
72 {
73 R3BLOG(error, "ext_data_clnt::setup() failed to map all items:");
74
75 if (fair::Logger::GetConsoleSeverity() < fair::Severity::info)
76 {
77 ext_data_struct_info_print_map_success(static_cast<ext_data_structure_info*>(struct_info_),
78 stderr,
79 static_cast<UcesbMapUType>(map_success_conditions_));
80 }
81 throw R3B::runtime_error("ext_data_clnt::setup() mapping failure may cause unexpected analysis results "
82 "due to missing data members. Unpacker needs fixing.\n\n\n");
83 }
84
85 // void UcesbStructInfo::check_struct_info_mapping_old(const UcesbMap& is_map_success)
86 // {
87 // if ((is_map_success & ~(map_success_conditions_)) != UcesbMap::zero)
88 // {
89 // R3BLOG(error, "ext_data_clnt::setup() failed to map all items:");
90 // ext_data_struct_info_print_map_success(static_cast<ext_data_structure_info*>(ucesb_client_struct_info_),
91 // stderr,
92 // static_cast<UcesbMapUType>(map_success_conditions_));
93 // throw R3B::runtime_error("ext_data_clnt::setup() mapping failure may cause unexpected analysis results "
94 // "due to missing data members. Unpacker needs fixing.");
95 // }
96 // }
97} // namespace R3B
#define R3BLOG(severity, x)
Definition R3BLogger.h:35
void CheckStructMapping(UcesbSource *source)
virtual bool MismappedItemRequired(std::string_view) const
Definition R3BReader.h:30
auto check_struct_item_requried(std::string_view item_name, UcesbSource *source) -> R3BReader *
std::underlying_type< UcesbMap >::type UcesbMapUType
struct ext_data_structure_item * _next_off_item