Project
Loading...
Searching...
No Matches
DeviceConfigInfo.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_BIND_GLOBAL_PLACEHOLDERS
15#include <cstdlib>
16#include <string_view>
17#include <boost/property_tree/json_parser.hpp>
18
19namespace o2::framework
20{
21
22// Parses a config entry in the form
23//
24// [CONFIG] <key>=<vaue> <timestamp> <provenance>
25//
26// Now with backtracking to parse timestamp and provenance
28{
29 const char* cur = s.data();
30 const char* next = cur;
31 enum struct ParserState {
32 IN_PREAMBLE,
33 IN_KEY,
34 IN_VALUE,
36 IN_PROVENANCE,
38 DONE
39 };
40 char* err = nullptr;
41 // We need to keep track of the last and last but one space
42 // to be able to parse the timestamp and tags.
43 char const* lastSpace = nullptr;
44 char const* previousLastSpace = nullptr;
45 ParserState state = ParserState::IN_PREAMBLE;
46
47 while (true) {
48 auto previousState = state;
49 state = ParserState::IN_ERROR;
50 err = nullptr;
51 switch (previousState) {
52 case ParserState::IN_PREAMBLE:
53 if (s.data() + s.size() - cur < 9) {
54 } else if (strncmp("[CONFIG] ", cur, 9) == 0) {
55 next = cur + 8;
56 state = ParserState::IN_KEY;
57 }
58 break;
59 case ParserState::IN_KEY:
60 next = strpbrk(cur, "= ");
61 // Invalid key
62 if (next == nullptr || *next == ' ' || (next == cur)) {
63 } else if (*next == '=') {
64 match.beginKey = cur;
65 match.endKey = next;
66 match.beginValue = next + 1;
67 state = ParserState::IN_VALUE;
68 }
69 break;
70 case ParserState::IN_VALUE:
71 next = (char*)memchr(cur, ' ', s.data() + s.size() - cur);
72 if (next == nullptr) {
73 if (previousLastSpace == nullptr || lastSpace == nullptr) {
74 // We need at least two spaces to parse the timestamp and
75 // the provenance.
76 break;
77 }
78 match.endValue = previousLastSpace;
79 next = previousLastSpace;
80 state = ParserState::IN_TIMESTAMP;
81 } else {
82 previousLastSpace = lastSpace;
83 lastSpace = next;
84 state = ParserState::IN_VALUE;
85 }
86 break;
87 case ParserState::IN_TIMESTAMP:
88 match.timestamp = strtoll(cur, &err, 10);
89 next = err;
90 if (*next == ' ') {
91 state = ParserState::IN_PROVENANCE;
92 }
93 break;
94 case ParserState::IN_PROVENANCE:
95 match.beginProvenance = cur;
96 next = (char*)memchr(cur, '\n', s.data() + s.size() - cur);
97 if (next != nullptr) {
98 match.endProvenance = next;
99 state = ParserState::DONE;
100 } else {
101 match.endProvenance = s.data() + s.size();
102 state = ParserState::DONE;
103 }
104 break;
105 case ParserState::IN_ERROR:
106 return false;
107 case ParserState::DONE:
108 return true;
109 }
110 cur = next + 1;
111 }
112}
113
115 DeviceInfo& info)
116{
117 if (match.beginKey == nullptr || match.endKey == nullptr ||
118 match.beginValue == nullptr || match.endValue == nullptr ||
119 match.beginProvenance == nullptr || match.endProvenance == nullptr) {
120 return false;
121 }
122 auto keyString = std::string(match.beginKey, match.endKey - match.beginKey);
123 auto valueString = std::string(match.beginValue, match.endValue - match.beginValue);
124 auto provenanceString = std::string(match.beginProvenance, match.endProvenance - match.beginProvenance);
125 boost::property_tree::ptree branch;
126 std::stringstream ss{valueString};
127 try {
128 boost::property_tree::json_parser::read_json(ss, branch);
129 info.currentConfig.put_child(keyString, branch);
130 } catch (boost::exception&) {
131 // in case it is not a tree but a single value
132 info.currentConfig.put(keyString, valueString);
133 }
134
135 info.currentProvenance.put(keyString, provenanceString);
136 return true;
137}
138
139} // namespace o2::framework
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
SurfaceTrackState state
bool match(const std::vector< std::string > &queries, const char *pattern)
Definition dcs-ccdb.cxx:229
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
static bool processConfig(ParsedConfigMatch &results, DeviceInfo &info)
static bool parseConfig(std::string_view const s, ParsedConfigMatch &results)
Temporary struct to hold a configuration parameter.