6 #include <unordered_map> 17 const std::vector<std::vector<l1t::demo::Frame>>& dataRows) {
21 std::vector<l1t::demo::Frame> channelData(dataRows.size());
22 for (
size_t j = 0;
j < dataRows.size();
j++)
23 channelData.at(
j) = dataRows.at(
j).at(
i);
24 boardData.add(
channels.at(
i), channelData);
30 std::vector<std::string> searchAndTokenize(std::istream&
file,
const std::string& linePrefix) {
35 size_t startIndex =
line.find_first_not_of(
" \t");
36 if (startIndex != std::string::npos)
44 if (
line.rfind(linePrefix, 0) != std::string::npos) {
45 std::vector<std::string> tokens;
48 const std::regex delimiterRegex(
"\\s+");
49 std::sregex_token_iterator it(
line.begin() + linePrefix.size(),
line.end(), delimiterRegex, -1);
51 for (; it != std::sregex_token_iterator(); it++) {
55 tokens.push_back(
token);
60 throw std::logic_error(
"Found unexpected line found when searching for \"" + linePrefix +
"\": \"" +
line +
63 throw std::logic_error(
"Couldn't find any line starting with \"" + linePrefix +
"\"");
71 static const std::unordered_map<std::string, FileFormat> kFormatStringMap({{
"EMP",
FileFormat::EMP},
78 const auto it = kFormatStringMap.find(
s);
79 if (it == kFormatStringMap.end())
80 throw std::runtime_error(
"Could not convert '" +
s +
"' to FileFormat enum value");
94 if (not
file.is_open())
95 throw std::runtime_error(
"Could not open file '" +
filePath +
"'");
114 throw std::runtime_error(
"Specified file is empty!");
117 if (
line.find(
"#Sideband") == 0) {
119 throw std::runtime_error(
"APx file has incorrect format: Link labels and data missing!");
123 if (
line.find(
"#LinkLabel") != 0)
124 throw std::runtime_error(
125 "APx file has incorrect format: Link header does not start with '#LinkLabel' (line is '" +
line +
"')");
128 const std::regex delimiterRegex(
"\\s+");
129 std::sregex_token_iterator it(
line.begin() + 10,
line.end(), delimiterRegex, -1);
130 for (; it != std::sregex_token_iterator(); it++) {
135 if (
token.find(
"LINK_") != 0)
136 throw std::runtime_error(
"Link column name '" +
token +
"' (does not start with 'LINK_')");
137 if (
token.size() == 5)
138 throw std::runtime_error(
"Link column name '" +
token +
"' is too short");
139 if (not std::all_of(
token.begin() + 5,
token.end(), ::isdigit))
140 throw std::runtime_error(
"Link column name '" +
token +
"' does not end with a number");
147 throw std::runtime_error(
"APx file has incorrect format: Data missing!");
148 if (
line !=
"#BeginData")
149 throw std::runtime_error(
"APx file has incorrect format: '#BeginData' line missing (found '" +
line +
"')");
152 std::vector<std::vector<l1t::demo::Frame>> dataRows;
154 it = std::sregex_token_iterator(
line.begin(),
line.end(), delimiterRegex, -1);
156 for (; it != std::sregex_token_iterator(); it++,
count++) {
159 if ((
token.find(
"0x") != 0)
or (not std::all_of(
token.begin() + 2,
token.end(), ::isxdigit)))
160 throw std::runtime_error(
"APx file has incorrect format: Data token '" +
token +
161 "' is not hexadecimal number");
164 size_t rowIndex = std::stoul(
token,
nullptr, 16);
165 if (rowIndex != dataRows.size())
166 throw std::runtime_error(
"APx file has incorrect format: Expected data row " +
168 dataRows.push_back(std::vector<l1t::demo::Frame>(
indices.size()));
171 else if ((
count % 2) == 1) {
172 uint16_t sbValue = std::stoul(
token,
nullptr, 16);
173 dataRows.back().at((
count - 1) / 2).valid = (sbValue & 0x1);
174 dataRows.back().at((
count - 1) / 2).start = ((sbValue >> 1) & 0
x1);
175 dataRows.back().at((
count - 1) / 2).end = ((sbValue >> 3) & 0
x1);
179 dataRows.back().at((
count - 1) / 2).data = ap_uint<64>(std::stoull(
token,
nullptr, 16));
183 throw std::runtime_error(
"APx file has incorrect format: Line has incorrect number of tokens (expected " +
187 return createBoardDataFromRows(
"",
indices, dataRows);
199 if (
line.rfind(
"Board ", 0) != std::string::npos) {
203 throw std::logic_error(
"Found unexpected line found when searching for board ID: \"" +
line +
"\"");
207 searchAndTokenize(
file,
"Quad/Chan :");
208 const auto tokens = searchAndTokenize(
file,
"Link :");
211 return std::stoull(
s);
215 const std::regex delimiterRegex(
"\\s+");
216 static const std::regex frameRegex(
"([01]s)?([01]v)([0-9a-fA-F]{16})");
217 std::vector<std::vector<Frame>> dataRows;
222 std::ostringstream prefixStream;
223 prefixStream <<
"Frame ";
224 prefixStream << std::setw(4) << std::setfill(
'0') << dataRows.size();
225 prefixStream <<
" :";
228 if (
line.rfind(
prefix, 0) == std::string::npos)
229 throw std::logic_error(
"Found unexpected line found when searching for \"" +
prefix +
"\": \"" +
line +
"\"");
231 std::vector<l1t::demo::Frame> row;
232 std::sregex_token_iterator it(
line.begin() +
prefix.size(),
line.end(), delimiterRegex, -1);
233 for (; it != std::sregex_token_iterator(); it++) {
239 if (not std::regex_match(
token, what, frameRegex))
240 throw std::logic_error(
"Token '" +
token +
"' doesn't match the valid format");
245 value.strobe = (what[1] ==
"1s");
248 value.valid = (what[2] ==
"1v");
249 value.data = ap_uint<64>(std::stoull(what[3].
str(),
nullptr, 16));
251 row.push_back(
value);
254 dataRows.push_back(row);
257 return createBoardDataFromRows(
id,
channels, dataRows);
261 throw std::runtime_error(
"Reading X20 file format not yet implemented. Will be done ASAP.");
272 #ifdef CMSSW_GIT_HASH 278 <<
data.begin()->second.size() <<
" frames) to file '" <<
filePath <<
"' (format: " <<
format <<
")" 282 if (not
file.is_open())
283 throw std::runtime_error(
"Could not open file '" +
filePath +
"'");
290 const auto firstChannel =
data.begin();
292 for (
const auto& channel :
data) {
293 const auto i = channel.first;
294 const auto channelData = channel.second;
295 if (channelData.size() != firstChannel->second.size())
296 throw std::runtime_error(
"Cannot write board data to file - channels do not all have the same length (" +
298 ", but " +
std::to_string(firstChannel->second.size()) +
" words on channel " +
331 file << std::setfill(
'0');
332 file <<
"#Sideband ON" << std::endl;
335 file <<
"#LinkLabel";
336 for (
const auto& channel :
data) {
337 const auto i = channel.first;
338 file <<
" LINK_" << std::setw(2) <<
i <<
" ";
342 file <<
"#BeginData" << std::endl;
346 const auto firstChannel =
data.begin();
347 for (
size_t i = 0;
i < firstChannel->second.size();
i++) {
348 file <<
"0x" << std::setw(4) <<
i;
349 for (
const auto& channel :
data) {
351 const auto channelData = channel.second;
352 uint16_t sideband = channelData.at(
i).valid;
353 sideband |= channelData.at(
i).start << 1;
354 sideband |= channelData.at(
i).end << 3;
355 file <<
" 0x" << std::setw(2) << sideband;
356 file <<
" 0x" << std::setw(16) <<
uint64_t(channelData.at(
i).data);
363 file << std::setfill(
'0');
366 file <<
"Board CMSSW" << std::endl;
369 file <<
" Quad/Chan :";
370 for (
const auto& channel :
data) {
371 const auto i = channel.first;
372 file <<
" q" << std::setw(2) <<
i / 4 <<
'c' << std::setw(1) <<
i % 4 <<
" ";
378 for (
const auto& channel :
data) {
379 const auto i = channel.first;
380 file <<
" " << std::setw(3) <<
i <<
" ";
385 const auto firstChannel =
data.begin();
386 for (
size_t i = 0;
i < firstChannel->second.size();
i++) {
387 file <<
"Frame " << std::setw(4) <<
i <<
" :";
388 for (
const auto& channel :
data) {
390 const auto channelData = channel.second;
394 file << std::setw(1) << channelData.at(
i).valid <<
"v" << std::setw(16) << std::hex
402 throw std::runtime_error(
"Writing X20 file format not yet implemented. Will be done ASAP.");
BoardData readAPxFile(std::istream &, const FileFormat)
std::string to_string(const V &value)
BoardData readEMPFile(std::istream &, const FileFormat)
FileFormat parseFileFormat(const std::string &)
void write(const BoardData &, const std::string &filePath, const FileFormat)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
void writeAPxFile(const BoardData &, std::ostream &, const FileFormat)
filePath
CUSTOMIZE FOR ML.
Log< level::Info, false > LogInfo
unsigned long long uint64_t
char data[epos_bytes_allocation]
void writeX20File(const BoardData &, std::ostream &, const FileFormat)
BoardData read(const std::string &filePath, const FileFormat)
void writeEMPFile(const BoardData &, std::ostream &, const FileFormat)
BoardData readX20File(std::istream &, const FileFormat)
Class representing information that's stored in the input or output buffers on a phase-2 board...