Functions
novadaq::HexUtils Namespace Reference

Functions

std::string format (const int32_t &value, const int &ndigits=8)
 
std::string format (const int64_t &value, const int &ndigits=16)
 
std::string format (const std::string &decimalString, const int &ndigits=8)
 
int64_t unsafeParse (const std::string &hexString)
 
bool isValidHex (const std::string &hexString)
 
bool parse (const std::string &hexString, int32_t &decimalValue)
 
bool parse (const std::string &hexString, int64_t &decimalValue)
 

Detailed Description

Utilities for parsing and formatting integers in hex.

Author
Kurt Biery
Version
Revision
1.1.24.1
Date
2019/09/27 00:07:20

Function Documentation

std::string novadaq::HexUtils::format ( const int32_t &  value,
const int ndigits 
)

Formats the specified 32-bit integer as a hex string with the specified number of hex digits.

Definition at line 14 of file HexUtils.cpp.

Referenced by run_unfold_ppfx_multiprocess.Task::__call__(), run_unfold_systs_multiprocess.Task::__call__(), run_unfold_genie_multiprocess.Task::__call__(), run_unfold_genie_multiprocess.Task::__str__(), dbutils::gui::ConfigDataTreeModel::_populateSubTree(), HTMLView.HTMLView::add_figure(), HTMLView.HTMLView::add_plot_information(), air::AirShower::analyze(), ViewHTML::assumptionsToTable(), ancestor.Ancestor::book_hists(), vdbl.Vdbl::book_hists(), nuray.Nuray::book_hists(), tgtexit.Tgtexit::book_hists(), decay.Decay::book_hists(), regression::callbacks(), plot_validation_datamc_2018::Caption(), check_jobs::check_dir(), getGoodRuns4SAM::consolidate(), ViewHTML::definitionListToExplorerData(), ViewHTML::directoryToTable(), bp_docdb.DocDB::DownloadArchive(), bp_docdb.DocDB::DownloadFile(), stan::lang::dump_program_line(), PandAna.reco_validation.prod5_pid_validation::event_count_report(), highe::HighEnergyFilt::filter(), PandAna.utils.misc::FindPandAnaDir(), format(), regression::generate_name(), PandAna.reco_validation.plot_pid_data_mc_cvn2020::get_all_files(), check_jobs::get_complete_jobs(), check_jobs::get_files(), PandAna.reco_validation.prod5_pid_validation_data_mc::get_files_nd(), plot_xsec_1d::get_genie_universes(), plot_xsec_2d::get_genie_universes(), plot_xsec_1d::get_ppfx_universes(), plot_xsec_2d::get_ppfx_universes(), POTPopulateData::get_runs(), POTGetData::get_runs(), POTSpillRate::get_spills(), POTPopulateData::get_spills(), POTGetData::get_spills(), canMan.Table::getLatex(), PandAna.core.filesource.listsource::getnextfile(), PandAna.core.filesource.globsource::getnextfile(), runNovaSAM::getOutputFileName(), runNovaSAM_cmake::getOutputFileName(), canMan.Table::getReadable(), dbutils::gui::BitmapEditor::getResult(), modify_metadata_with_upmu_sample_type::getSubRunType(), daqdataformats::VERSION_NAMESPACE::RawNanoSlice::getWordPointer(), PandAna.core.filesource.sourcewrapper::isproj(), isValidHex(), bp_utils::ListBlessedFilesInDir(), bp_utils::ListCaptionFilesInDir(), bp_utils::ListPlotsInDirForCaption(), dbutils::gui::ConfigDataTableModel::loadData(), art::TimeTracker::logToDestination_(), spectra_to_pyobj::main(), PandAna.utils.sadd_pandana::main(), main(), GetSpillData::main(), OnMonTriggerRateStudy::main(), garching_flux_to_genie_root::main(), PandAna.reco_validation.plot_pid_data_mc_cvn2020::main(), POTSpillRate::main(), PandAna.reco_validation.prod5_pid_validation::main(), run_unfold_genie_multiprocess::make_cmd(), run_unfold_ppfx_multiprocess::make_cmd(), run_unfold_systs_multiprocess::make_cmd(), runNovaSAM::makeDeCAF(), MCenterSpills::mc7_spills_between(), nova_uptime::mc7_spills_between(), build_tools::merge_all(), build_tools::merge_extraps(), build_tools::merge_jobs(), POTSpillRate::num_spills_between(), soup::old_soup_composition(), PandAna.reco_validation.prod5_pid_validation_data_mc::plot_data_mc(), PandAna.reco_validation.prod5_pid_validation::plot_ratio(), ddthelpers::print(), daqdataformats::VERSION_NAMESPACE::RawSummaryDCMData::print(), daqdataformats::VERSION_NAMESPACE::RawMicroBlock::print(), daqdataformats::VERSION_NAMESPACE::RawDataBlock::print(), daqdataformats::VERSION_NAMESPACE::RawEvent::print(), daqdataformats::VERSION_NAMESPACE::RawSummaryDCMDataHeader::print(), daqdataformats::RawDCMChan::print(), daqdataformats::VERSION_NAMESPACE::RawTriggerRange::print(), daqdataformats::VERSION_NAMESPACE::RawConfigurationName::print(), daqdataformats::VERSION_NAMESPACE::RawConfigurationSystemID::print(), daqdataformats::VERSION_NAMESPACE::RawMicroBlockHeader::print(), daqdataformats::VERSION_NAMESPACE::RawMicroSliceHeader::print(), daqdataformats::VERSION_NAMESPACE::RawSummaryDroppedMicroblock::print(), daqdataformats::VERSION_NAMESPACE::RawConfigurationTail::print(), daqdataformats::VERSION_NAMESPACE::RawSummaryDCMDataPoint::print(), daqdataformats::VERSION_NAMESPACE::RawTriggerTimingMarker::print(), daqdataformats::VERSION_NAMESPACE::RawEventTail::print(), daqdataformats::VERSION_NAMESPACE::RawTrigger::print(), daqdataformats::VERSION_NAMESPACE::RawTriggerMask::print(), daqdataformats::VERSION_NAMESPACE::RawTriggerTime::print(), daqdataformats::VERSION_NAMESPACE::RawDataBlockHeader::print(), daqdataformats::VERSION_NAMESPACE::RawTriggerHeader::print(), daqdataformats::VERSION_NAMESPACE::RawConfigurationHeader::print(), daqdataformats::VERSION_NAMESPACE::RawNanoSlice::print(), daqdataformats::VERSION_NAMESPACE::RawEventHeader::print(), daqdataformats::VERSION_NAMESPACE::RawNanoSliceHeader::print(), daqdataformats::VERSION_NAMESPACE::RawRunHeader::print(), util::print_composition(), daqdataformats::RawDAQData::printBuffer(), daqdataformats::RawTimingMarker::printStandard(), daqdataformats::RawMilliSlice::printStandard(), daqdataformats::RawMilliSliceHeader::printStandard(), evdb::PrintDialog::PrintToFile(), daqdataformats::RawDAQData::printWordHex(), PandAna.reco_validation.prod5_pid_validation_data_mc::prod5_pid_data_mc(), bp_utils::progressBar(), utilities::progressBar(), soup::radlength(), regression::regression(), rootgINukeVal(), run_unfold_ppfx_multiprocess.Consumer::run(), run_unfold_systs_multiprocess.Consumer::run(), run_unfold_genie_multiprocess.Consumer::run(), nova_uptime::run_at(), run_unfold_ppfx_multiprocess::RunMultiProcess(), run_unfold_systs_multiprocess::RunMultiProcess(), run_unfold_genie_multiprocess::RunMultiProcess(), MCenterSpills::runs_for_period(), nova_uptime::runs_for_period(), ViewHTML::samFileInfoSummaryTable(), APDHVSetting_M150::settings(), NDAPDHVSetting::settings(), APDHVSetting::settings(), soup::soup_composition(), hadd_reco_validation::source_script(), submit_reco_validation::source_script(), pot-for-runs::spills_between(), nova_uptime::spills_between(), HexUtilTests::testFormat(), ViewHTML::tierConfigurationsTables(), soup::totalstoppingpower(), pvc::totalstopppingpower(), and genie::Spline::YCanBeNegative().

15 {
16  std::ostringstream formatter;
17  formatter << "0x" << std::hex << std::setfill('0')
18  << std::setw(ndigits) << std::uppercase << value;
19  return formatter.str();
20 }
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::string novadaq::HexUtils::format ( const int64_t &  value,
const int ndigits 
)

Formats the specified 32-bit integer as a hex string with the specified number of hex digits.

Definition at line 26 of file HexUtils.cpp.

27 {
28  std::ostringstream formatter;
29  formatter << "0x" << std::hex << std::setfill('0')
30  << std::setw(ndigits) << std::uppercase << value;
31  return formatter.str();
32 }
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::string novadaq::HexUtils::format ( const std::string &  decimalString,
const int ndigits 
)

Reformats the specified decimal number string into a hex string with the specified number of hex digits. (The maximum number of supported hex digits is 16, corresponding to a 64-bit number.)

Exceptions
anexception of the parsing of the decimalString into an integer fails.

Definition at line 42 of file HexUtils.cpp.

References format().

43 {
44  if (ndigits > 8) {
45  int64_t value = boost::lexical_cast<int64_t>(decimalString);
46  return format(value, ndigits);
47  }
48  else {
49  int32_t value = boost::lexical_cast<int32_t>(decimalString);
50  return format(value, ndigits);
51  }
52 }
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
bool novadaq::HexUtils::isValidHex ( const std::string &  hexString)

Tests whether the specified string contains a valid number in hex format.

Definition at line 74 of file HexUtils.cpp.

References format(), cet::trim_copy(), and unsafeParse().

Referenced by parse(), dbutils::gui::ConfigDataTreeModel::saveChanges(), and HexUtilTests::testValidity().

75 {
76  // the logic used in this routine is to parse the input
77  // value, regenerate the hex string, and verify that the
78  // result matches what was input.
79 
80  std::string inputString = boost::trim_copy(hexString);
81  boost::to_upper(inputString);
82  if (inputString.find("0X") != 0) {return false;}
83 
84  int numberOfHexDigits = inputString.length() - 2;
85  int64_t value = unsafeParse(inputString);
86  std::string resultString = format(value, numberOfHexDigits);
87  boost::to_upper(resultString);
88 
89  return (resultString == inputString);
90 }
std::string trim_copy(std::string source, std::string const &t=" ")
Definition: trim.h:66
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
int64_t unsafeParse(const std::string &hexString)
Definition: HexUtils.cpp:62
bool novadaq::HexUtils::parse ( const std::string &  hexString,
int32_t &  decimalValue 
)

Parses the specified hex string into a 32-bit decimal value. Returns true if the parsing succeeded, and false if not.

Definition at line 96 of file HexUtils.cpp.

References isValidHex().

Referenced by dbutils::gui::BitmapEditor::BitmapEditor(), dbutils::gui::ConfigDataTreeModel::saveChanges(), and HexUtilTests::testParse().

97 {
98  if (! isValidHex(hexString)) {return false;}
99  if (hexString.length() > 10) {return false;}
100 
101  std::istringstream iss(hexString);
102  uint32_t u32Value;
103  iss >> std::hex >> u32Value;
104  decimalValue = (int32_t) u32Value;
105  return true;
106 }
bool isValidHex(const std::string &hexString)
Definition: HexUtils.cpp:74
bool novadaq::HexUtils::parse ( const std::string &  hexString,
int64_t &  decimalValue 
)

Parses the specified hex string into a 64-bit decimal value. Returns true if the parsing succeeded, and false if not.

Definition at line 112 of file HexUtils.cpp.

References isValidHex().

113 {
114  if (! isValidHex(hexString)) {return false;}
115  if (hexString.length() > 18) {return false;}
116 
117  std::istringstream iss(hexString);
118  uint64_t u64Value;
119  iss >> std::hex >> u64Value;
120  decimalValue = (int64_t) u64Value;
121  return true;
122 }
bool isValidHex(const std::string &hexString)
Definition: HexUtils.cpp:74
int64_t novadaq::HexUtils::unsafeParse ( const std::string &  hexString)

Parses the specified string into a 64-bit decimal value, assuming that the string contains a numeric value in hex, but does not do any checking that the hex string is valid.

NOTE that if the input string is not valid hex, the resulting integer value will essentially be a random number.

Definition at line 62 of file HexUtils.cpp.

Referenced by isValidHex().

63 {
64  std::istringstream iss(hexString);
65  uint64_t u64Value;
66  iss >> std::hex >> u64Value;
67  return (int64_t) u64Value;
68 }