ATLAS Offline Software
Loading...
Searching...
No Matches
interpretSeeds.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <charconv>
6#include <iostream>
7#include <vector>
8#include <ranges>
9#include <string_view>
10
11#include "interpretSeeds.h"
12
13//get the luxury level, if specified. In that case moves token past it
14inline
15void getLuxury(std::vector<std::string>::iterator& token, short& luxLevel) {
16 if ((*token) == "LUXURY") {
17 ++token;
18 uint32_t parsedValue = 0;
19 auto result = std::from_chars(token->data(), token->data() + token->size(), parsedValue);
20 if (result.ec != std::errc()) {
21 std::cerr << "Parsing error in function getLuxury." << std::endl;
22 }
23 luxLevel = parsedValue;
24 ++token;
25 }
26}
27
28//get the luxury level, if specified. In that case moves token past it
29inline
30void getOffset(std::vector<std::string>::iterator& token, uint32_t& offset) {
31 if ((*token) == "OFFSET") {
32 ++token;
33 uint32_t parsedValue = 0;
34 auto result = std::from_chars(token->data(), token->data() + token->size(), parsedValue);
35 if (result.ec != std::errc()) {
36 std::cerr << "Parsing error in function getOffset." << std::endl;
37 }
38 offset = parsedValue;
39 ++token;
40 }
41}
42
43bool interpretSeeds(const std::string& buffer,
44 std::string& stream, uint32_t& seed1, uint32_t& seed2, short& luxury, uint32_t& offset)
45{
46 //split the space-separated string in 3 or 5 or 7 words:
47 std::vector<std::string> tokens;
48 for (auto&& range : std::string_view{buffer} | std::views::split(' ')) if (!range.empty()) tokens.emplace_back(range.begin(), range.end());
49 int nToks = static_cast<int>(tokens.size());
50 bool status = (nToks == 3 || nToks == 5 || nToks == 7);
51 if (status) {
52 auto token = tokens.begin();
53 stream = *token++;
54 //FIXME, try permutations by hand. With more than two we'd need a parser
55 getOffset(token, offset);
56 getLuxury(token, luxury);
57 getOffset(token, offset);
58 auto [ptr1, ec1] = std::from_chars(token->data(), token->data() + token->size(), seed1);
59 ++token;
60 auto [ptr2, ec2] = std::from_chars(token->data(), token->data() + token->size(), seed2);
61 ++token;
62 if (ec1 != std::errc() || ec2 != std::errc()) {
63 status = false;
64 }
65 }
66 return status;
67}
68
69bool interpretSeeds(const std::string& buffer,
70 std::string& stream, std::vector<uint32_t>& seeds)
71{
72 //split the space-separated string in 31 or 33 words:
73 std::vector<std::string> tokens;
74 for (auto&& range : std::string_view{buffer} | std::views::split(' ')) if (!range.empty()) tokens.emplace_back(range.begin(), range.end());
75 int nToks = static_cast<int>(tokens.size());
76 bool status = (nToks == 31 || nToks == 33 || nToks == 771);
77 if (status) {
78 auto token = tokens.begin();
79 stream = *token++;
80 --nToks;
81 if (nToks == 32) nToks=30; //ranlux (FIXME NEEDED?)
82 for (int i=0; i<nToks; i++) {
83 uint32_t value = 0;
84 auto [ptr, ec] = std::from_chars(token->data(), token->data() + token->size(), value);
85 if (ec != std::errc()) {
86 status = false;
87 break;
88 }
89 seeds.push_back(value);
90 ++token;
91 }
92 }
93 return status;
94}
bool interpretSeeds(const std::string &buffer, std::string &stream, uint32_t &seed1, uint32_t &seed2, short &luxury, uint32_t &offset)
void getLuxury(std::vector< std::string >::iterator &token, short &luxLevel)
void getOffset(std::vector< std::string >::iterator &token, uint32_t &offset)