6 #include <unordered_map> 7 #include <boost/iostreams/filter/gzip.hpp> 8 #include <boost/iostreams/filter/lzma.hpp> 9 #include <boost/iostreams/filtering_stream.hpp> 20 const std::vector<std::vector<l1t::demo::Frame>>& dataRows) {
24 std::vector<l1t::demo::Frame> channelData(dataRows.size());
25 for (
size_t j = 0;
j < dataRows.size();
j++)
26 channelData.at(
j) = dataRows.at(
j).at(
i);
27 boardData.add(
channels.at(
i), channelData);
33 std::vector<std::string> searchAndTokenize(std::istream&
file,
const std::string& linePrefix) {
38 size_t startIndex =
line.find_first_not_of(
" \t");
39 if (startIndex != std::string::npos)
47 if (
line.rfind(linePrefix, 0) != std::string::npos) {
48 std::vector<std::string> tokens;
51 const std::regex delimiterRegex(
"\\s+");
52 std::sregex_token_iterator
it(
line.begin() + linePrefix.size(),
line.end(), delimiterRegex, -1);
54 for (;
it != std::sregex_token_iterator();
it++) {
58 tokens.push_back(
token);
63 throw std::logic_error(
"Found unexpected line found when searching for \"" + linePrefix +
"\": \"" +
line +
66 throw std::logic_error(
"Couldn't find any line starting with \"" + linePrefix +
"\"");
74 static const std::unordered_map<std::string, FileFormat> kFormatStringMap({{
"EMP",
FileFormat::EMPv1},
83 const auto it = kFormatStringMap.find(
s);
84 if (
it == kFormatStringMap.end())
85 throw std::runtime_error(
"Could not convert '" +
s +
"' to FileFormat enum value");
101 if (not
file.is_open())
102 throw std::runtime_error(
"Could not open file '" +
filePath +
"'");
104 boost::iostreams::filtering_istream
stream;
106 stream.push(boost::iostreams::gzip_decompressor());
108 stream.push(boost::iostreams::lzma_decompressor());
127 std::ostringstream messageStream;
128 messageStream <<
"No read function registered for format " <<
format;
129 throw std::runtime_error(messageStream.str());
137 throw std::runtime_error(
"Specified file is empty!");
140 if (
line.find(
"#Sideband") == 0) {
142 throw std::runtime_error(
"APx file has incorrect format: Link labels and data missing!");
146 if (
line.find(
"#LinkLabel") != 0)
147 throw std::runtime_error(
148 "APx file has incorrect format: Link header does not start with '#LinkLabel' (line is '" +
line +
"')");
151 const std::regex delimiterRegex(
"\\s+");
152 std::sregex_token_iterator
it(
line.begin() + 10,
line.end(), delimiterRegex, -1);
153 for (;
it != std::sregex_token_iterator();
it++) {
158 if (
token.find(
"LINK_") != 0)
159 throw std::runtime_error(
"Link column name '" +
token +
"' (does not start with 'LINK_')");
160 if (
token.size() == 5)
161 throw std::runtime_error(
"Link column name '" +
token +
"' is too short");
162 if (not std::all_of(
token.begin() + 5,
token.end(), ::isdigit))
163 throw std::runtime_error(
"Link column name '" +
token +
"' does not end with a number");
170 throw std::runtime_error(
"APx file has incorrect format: Data missing!");
171 if (
line !=
"#BeginData")
172 throw std::runtime_error(
"APx file has incorrect format: '#BeginData' line missing (found '" +
line +
"')");
175 std::vector<std::vector<l1t::demo::Frame>> dataRows;
177 it = std::sregex_token_iterator(
line.begin(),
line.end(), delimiterRegex, -1);
179 for (;
it != std::sregex_token_iterator();
it++,
count++) {
182 if ((
token.find(
"0x") != 0)
or (not std::all_of(
token.begin() + 2,
token.end(), ::isxdigit)))
183 throw std::runtime_error(
"APx file has incorrect format: Data token '" +
token +
184 "' is not hexadecimal number");
187 size_t rowIndex = std::stoul(
token,
nullptr, 16);
188 if (rowIndex != dataRows.size())
189 throw std::runtime_error(
"APx file has incorrect format: Expected data row " +
191 dataRows.push_back(std::vector<l1t::demo::Frame>(
indices.size()));
194 else if ((
count % 2) == 1) {
195 uint16_t sbValue = std::stoul(
token,
nullptr, 16);
196 dataRows.back().at((
count - 1) / 2).valid = (sbValue & 0x1);
197 dataRows.back().at((
count - 1) / 2).startOfPacket = ((sbValue >> 1) & 0x1);
198 dataRows.back().at((
count - 1) / 2).endOfPacket = ((sbValue >> 3) & 0x1);
202 dataRows.back().at((
count - 1) / 2).data = ap_uint<64>(std::stoull(
token,
nullptr, 16));
206 throw std::runtime_error(
"APx file has incorrect format: Line has incorrect number of tokens (expected " +
210 return createBoardDataFromRows(
"",
indices, dataRows);
222 if (
line.rfind(
"Board ", 0) != std::string::npos) {
226 throw std::logic_error(
"Found unexpected line found when searching for board ID: \"" +
line +
"\"");
230 searchAndTokenize(
file,
"Quad/Chan :");
231 const auto tokens = searchAndTokenize(
file,
"Link :");
234 return std::stoull(
s);
238 const std::regex delimiterRegex(
"\\s+");
239 static const std::regex frameRegex(
"([01]s)?([01]v)([0-9a-fA-F]{16})");
240 std::vector<std::vector<Frame>> dataRows;
245 std::ostringstream prefixStream;
246 prefixStream <<
"Frame ";
247 prefixStream << std::setw(4) << std::setfill(
'0') << dataRows.size();
248 prefixStream <<
" :";
251 if (
line.rfind(
prefix, 0) == std::string::npos)
252 throw std::logic_error(
"Found unexpected line found when searching for \"" +
prefix +
"\": \"" +
line +
"\"");
254 std::vector<l1t::demo::Frame> row;
255 std::sregex_token_iterator
it(
line.begin() +
prefix.size(),
line.end(), delimiterRegex, -1);
256 for (;
it != std::sregex_token_iterator();
it++) {
262 if (not std::regex_match(
token, what, frameRegex))
263 throw std::logic_error(
"Token '" +
token +
"' doesn't match the valid format");
268 value.strobe = (what[1] ==
"1s");
271 value.valid = (what[2] ==
"1v");
272 value.data = ap_uint<64>(std::stoull(what[3].
str(),
nullptr, 16));
274 row.push_back(
value);
277 dataRows.push_back(row);
280 return createBoardDataFromRows(
id,
channels, dataRows);
292 if (
line.rfind(
"ID: ", 0) != std::string::npos) {
296 throw std::logic_error(
"Found unexpected line found when searching for board ID: \"" +
line +
"\"");
301 if (
line.find(
"Metadata: (strobe,) start of orbit, start of packet, end of packet, valid") != 0)
302 throw std::logic_error(
"Expected metadata line following 'ID' line. Instead found:" +
line);
305 const auto tokens = searchAndTokenize(
file,
"Link ");
308 return std::stoull(
s);
312 const std::regex delimiterRegex(
"\\s\\s+");
313 static const std::regex frameRegex(
"([01])?([01])([01])([01])([01]) ([0-9a-fA-F]{16})");
314 std::vector<std::vector<Frame>> dataRows;
319 std::ostringstream prefixStream;
320 prefixStream <<
"Frame ";
321 prefixStream << std::setw(4) << std::setfill(
'0') << dataRows.size();
325 if (
line.rfind(
prefix, 0) == std::string::npos)
326 throw std::logic_error(
"Found unexpected line found when searching for \"" +
prefix +
"\": \"" +
line +
"\"");
328 std::vector<l1t::demo::Frame> row;
329 std::sregex_token_iterator
it(
line.begin() +
prefix.size(),
line.end(), delimiterRegex, -1);
330 for (;
it != std::sregex_token_iterator();
it++) {
336 if (not std::regex_match(
token, what, frameRegex))
337 throw std::logic_error(
"Token '" +
token +
"' doesn't match the valid format");
342 value.strobe = (what[1] ==
"1");
345 value.startOfOrbit = (what[2] ==
"1");
346 value.startOfPacket = (what[3] ==
"1");
347 value.endOfPacket = (what[4] ==
"1");
348 value.valid = (what[5] ==
"1");
349 value.data = ap_uint<64>(std::stoull(what[6].
str(),
nullptr, 16));
351 row.push_back(
value);
354 dataRows.push_back(row);
357 return createBoardDataFromRows(
id,
channels, dataRows);
361 throw std::runtime_error(
"Reading X2O file format not yet implemented. Will be done ASAP.");
374 #ifdef CMSSW_GIT_HASH 380 <<
data.begin()->second.size() <<
" frames) to file '" <<
filePath <<
"' (format: " <<
format <<
")" 385 if (not
file.is_open())
386 throw std::runtime_error(
"Could not open file '" +
filePath +
"'");
388 boost::iostreams::filtering_ostream
stream;
390 stream.push(boost::iostreams::gzip_compressor());
392 stream.push(boost::iostreams::lzma_compressor());
399 const auto firstChannel =
data.begin();
401 for (
const auto& channel :
data) {
402 const auto i = channel.first;
403 const auto channelData = channel.second;
404 if (channelData.size() != firstChannel->second.size())
405 throw std::runtime_error(
"Cannot write board data to file - channels do not all have the same length (" +
407 ", but " +
std::to_string(firstChannel->second.size()) +
" words on channel " +
443 file << std::setfill(
'0');
444 file <<
"#Sideband ON" << std::endl;
447 file <<
"#LinkLabel";
448 for (
const auto& channel :
data) {
449 const auto i = channel.first;
450 file <<
" LINK_" << std::setw(2) <<
i <<
" ";
454 file <<
"#BeginData" << std::endl;
458 const auto firstChannel =
data.begin();
459 for (
size_t i = 0;
i < firstChannel->second.size();
i++) {
460 file <<
"0x" << std::setw(4) <<
i;
461 for (
const auto& channel :
data) {
463 const auto channelData = channel.second;
464 uint16_t sideband = channelData.at(
i).valid;
465 sideband |= channelData.at(
i).startOfPacket << 1;
466 sideband |= channelData.at(
i).endOfPacket << 3;
467 file <<
" 0x" << std::setw(2) << sideband;
468 file <<
" 0x" << std::setw(16) <<
uint64_t(channelData.at(
i).data);
475 file << std::setfill(
'0');
478 file <<
"Board CMSSW" << std::endl;
481 file <<
" Quad/Chan :";
482 for (
const auto& channel :
data) {
483 const auto i = channel.first;
484 file <<
" q" << std::setw(2) <<
i / 4 <<
'c' << std::setw(1) <<
i % 4 <<
" ";
490 for (
const auto& channel :
data) {
491 const auto i = channel.first;
492 file <<
" " << std::setw(3) <<
i <<
" ";
497 const auto firstChannel =
data.begin();
498 for (
size_t i = 0;
i < firstChannel->second.size();
i++) {
499 file <<
"Frame " << std::setw(4) <<
i <<
" :";
500 for (
const auto& channel :
data) {
502 const auto channelData = channel.second;
506 file << std::setw(1) << channelData.at(
i).valid <<
"v" << std::setw(16) << std::hex
514 file << std::setfill(
'0');
517 file <<
"ID: " <<
data.name() << std::endl;
518 file <<
"Metadata: (strobe,) start of orbit, start of packet, end of packet, valid" << std::endl;
523 std::map<size_t, bool> strobedLinkMap;
524 for (
const auto& channel :
data) {
525 const auto i = channel.first;
527 std::any_of(channel.second.begin(), channel.second.end(), [](
const Frame&
x) {
return not
x.strobe; });
528 if (strobedLinkMap.at(
i))
530 file <<
" " << std::setw(3) <<
i <<
" ";
535 const auto firstChannel =
data.begin();
536 for (
size_t i = 0;
i < firstChannel->second.size();
i++) {
537 file <<
"Frame " << std::setw(4) <<
i <<
" ";
538 for (
const auto& channel :
data) {
540 const auto channelData = channel.second;
542 if (strobedLinkMap.at(channel.first))
543 file << std::setw(1) << channelData.at(
i).strobe;
544 file << std::setw(1) << channelData.at(
i).startOfOrbit << channelData.at(
i).startOfPacket
545 << channelData.at(
i).endOfPacket << channelData.at(
i).valid;
546 file <<
" " << std::setw(16) << std::hex <<
uint64_t(channelData.at(
i).data);
553 throw std::runtime_error(
"Writing X2O file format not yet implemented. Will be done ASAP.");
BoardData readEMPFileV1(std::istream &)
void writeEMPFileV1(const BoardData &, std::ostream &)
FileFormat parseFileFormat(const std::string &)
void writeX2OFile(const BoardData &, std::ostream &)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
static std::string to_string(const XMLCh *ch)
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
BoardData readEMPFileV2(std::istream &)
BoardData readX2OFile(std::istream &)
filePath
CUSTOMIZE FOR ML.
void writeEMPFileV2(const BoardData &, std::ostream &)
Log< level::Info, false > LogInfo
unsigned long long uint64_t
void writeAPxFile(const BoardData &, std::ostream &)
char data[epos_bytes_allocation]
BoardData read(const std::string &filePath, const FileFormat)
Class representing information that's stored in the input or output buffers on a phase-2 board...
BoardData readAPxFile(std::istream &)