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 "R3BReader.h"
16#include "R3BUcesbDecl.h"
17#include "R3BUcesbMappingFlag.h"
18#include <R3BException.h>
19#include <R3BLogger.h>
20#include <R3BUcesbSource2.h>
21#include <ext_data_client.h>
22#include <fairlogger/Logger.h>
23#include <fmt/core.h>
24#include <string_view>
25
26namespace R3B
27{
28 // return pointer of the reader if it requires the item. If not required, return nullptr
29 inline auto check_struct_item_requried(std::string_view item_name, UcesbSource* source) -> R3BReader*
30 {
31 return source->FindReaderIf([item_name](R3BReader* reader)
32 { return reader->MismappedItemRequired(item_name); });
33 }
34
36 {
37 auto map_flag = static_cast<UcesbMap>(item->_map_success);
38 auto is_match_ok = ((map_flag & ~(map_success_conditions_)) == UcesbMap::zero);
39 if (is_match_ok)
40 {
41 return true;
42 }
43 auto* required_reader = check_struct_item_requried(item->_var_name, source);
44 R3BLOG(debug2, fmt::format("Checking ucesb struct item {:?}.", item->_var_name));
45 if (required_reader == nullptr || required_reader->AllowExtraCondition(map_flag, map_success_conditions_))
46 {
47 // no reader requries this item or reader accepts extra flag
48 return true;
49 }
50
51 R3BLOG(error,
52 fmt::format("Failed to map the item {} required from {} due to the map flag: {}",
53 item->_var_name,
54 required_reader->GetName(),
55 map_flag));
56 return false;
57 }
58
60 {
61 R3BLOG(debug, "Checking struct mapping.");
62 auto* struct_info = static_cast<ext_data_structure_info*>(struct_info_);
63 auto is_checking_ok = true;
64 // ext_data_struct_info_print_map_success(struct_info, stderr, EXT_DATA_ITEM_MAP_NO_DEST);
65 // ext_data_struct_info_print_map_success(struct_info, stderr, 0);
66 for (auto* item = struct_info->_items; item != nullptr; item = item->_next_off_item)
67 {
68 is_checking_ok &= check_struct_item(item, source);
69 }
70
71 if (not is_checking_ok)
72 {
73 terminate();
74 }
75 }
76
78 {
79 R3BLOG(error, "ext_data_clnt::setup() failed to map all items:");
80
81 if (fair::Logger::GetConsoleSeverity() < fair::Severity::info)
82 {
83 ext_data_struct_info_print_map_success(static_cast<ext_data_structure_info*>(struct_info_),
84 stderr,
86 }
87 throw R3B::runtime_error("ext_data_clnt::setup() mapping failure may cause unexpected analysis results "
88 "due to missing data members. Unpacker needs fixing.\n\n\n");
89 }
90
91 // void UcesbStructInfo::check_struct_info_mapping_old(const UcesbMap& is_map_success)
92 // {
93 // if ((is_map_success & ~(map_success_conditions_)) != UcesbMap::zero)
94 // {
95 // R3BLOG(error, "ext_data_clnt::setup() failed to map all items:");
96 // ext_data_struct_info_print_map_success(static_cast<ext_data_structure_info*>(ucesb_client_struct_info_),
97 // stderr,
98 // static_cast<UcesbMapUType>(map_success_conditions_));
99 // throw R3B::runtime_error("ext_data_clnt::setup() mapping failure may cause unexpected analysis results "
100 // "due to missing data members. Unpacker needs fixing.");
101 // }
102 // }
103} // namespace R3B
#define R3BLOG(severity, x)
Definition R3BLogger.h:32
bool check_struct_item(ext_data_structure_item *item, UcesbSource *source)
void CheckStructMapping(UcesbSource *source)
ext_data_struct_info struct_info_
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