@@ -313,6 +313,20 @@ void ConfigurableParam::printAllKeyValuePairs()
313313
314314// ------------------------------------------------------------------
315315
316+ ConfigurableParam::EParamProvenance ConfigurableParam::getProvenance (const std::string& key)
317+ {
318+ if (!sIsFullyInitialized ) {
319+ initialize ();
320+ }
321+ auto iter = sValueProvenanceMap ->find (key);
322+ if (iter == sValueProvenanceMap ->end ()) {
323+ throw std::runtime_error (fmt::format (" provenace of unknown {:s} parameter is requested" , key));
324+ }
325+ return iter->second ;
326+ }
327+
328+ // ------------------------------------------------------------------
329+
316330// evidently this could be a local file or an OCDB server
317331// ... we need to generalize this ... but ok for demonstration purposes
318332void ConfigurableParam::toCCDB (std::string filename)
@@ -612,24 +626,24 @@ bool isMemblockDifferent(void const* block1, void const* block2)
612626// copies data from one place to other and returns
613627// true of data was actually changed
614628template <typename T>
615- bool Copy (void const * addr, void * targetaddr)
629+ ConfigurableParam::EParamUpdateStatus Copy (void const * addr, void * targetaddr)
616630{
617631 if (isMemblockDifferent<T>(addr, targetaddr)) {
618632 std::memcpy (targetaddr, addr, sizeof (T));
619- return true ;
633+ return ConfigurableParam::EParamUpdateStatus::Changed ;
620634 }
621- return false ;
635+ return ConfigurableParam::EParamUpdateStatus::Unchanged ;
622636}
623637
624- bool ConfigurableParam::updateThroughStorageMap (std::string mainkey, std::string subkey, std::type_info const & tinfo,
625- void * addr)
638+ ConfigurableParam::EParamUpdateStatus ConfigurableParam::updateThroughStorageMap (std::string mainkey, std::string subkey, std::type_info const & tinfo,
639+ void * addr)
626640{
627641 // check if key_exists
628642 auto key = mainkey + " ." + subkey;
629643 auto iter = sKeyToStorageMap ->find (key);
630644 if (iter == sKeyToStorageMap ->end ()) {
631645 LOG (WARN) << " Cannot update parameter " << key << " not found" ;
632- return false ;
646+ return ConfigurableParam::EParamUpdateStatus::Failed ;
633647 }
634648
635649 // the type we need to convert to
@@ -638,7 +652,7 @@ bool ConfigurableParam::updateThroughStorageMap(std::string mainkey, std::string
638652 // check that type matches
639653 if (iter->second .first != tinfo) {
640654 LOG (WARN) << " Types do not match; cannot update value" ;
641- return false ;
655+ return ConfigurableParam::EParamUpdateStatus::Failed ;
642656 }
643657
644658 auto targetaddress = iter->second .second ;
@@ -749,72 +763,74 @@ bool ConfigurableParam::updateThroughStorageMap(std::string mainkey, std::string
749763 break ;
750764 }
751765 }
752- return false ;
766+ return ConfigurableParam::EParamUpdateStatus::Failed ;
753767}
754768
755769template <typename T>
756- bool ConvertAndCopy (std::string const & valuestring, void * targetaddr)
770+ ConfigurableParam::EParamUpdateStatus ConvertAndCopy (std::string const & valuestring, void * targetaddr)
757771{
758772 auto addr = boost::lexical_cast<T>(valuestring);
759773 if (isMemblockDifferent<T>(targetaddr, (void *)&addr)) {
760774 std::memcpy (targetaddr, (void *)&addr, sizeof (T));
761- return true ;
775+ return ConfigurableParam::EParamUpdateStatus::Changed ;
762776 }
763- return false ;
777+ return ConfigurableParam::EParamUpdateStatus::Unchanged ;
764778}
779+
765780// special version for std::string
766781template <>
767- bool ConvertAndCopy<std::string>(std::string const & valuestring, void * targetaddr)
782+ ConfigurableParam::EParamUpdateStatus ConvertAndCopy<std::string>(std::string const & valuestring, void * targetaddr)
768783{
769784 std::string& target = *((std::string*)targetaddr);
770785 if (target.compare (valuestring) != 0 ) {
771786 // the targetaddr is a std::string to which we can simply assign
772787 // and all the magic will happen internally
773788 target = valuestring;
774- return true ;
789+ return ConfigurableParam::EParamUpdateStatus::Changed ;
775790 }
776- return false ;
791+ return ConfigurableParam::EParamUpdateStatus::Unchanged ;
777792}
778793// special version for char and unsigned char since we are interested in the numeric
779794// meaning of char as an 8-bit integer (boost lexical cast is assigning the string as a character i// nterpretation
780795template <>
781- bool ConvertAndCopy<char >(std::string const & valuestring, void * targetaddr)
796+ ConfigurableParam::EParamUpdateStatus ConvertAndCopy<char >(std::string const & valuestring, void * targetaddr)
782797{
783798 int intvalue = boost::lexical_cast<int >(valuestring);
784799 if (intvalue > std::numeric_limits<char >::max () || intvalue < std::numeric_limits<char >::min ()) {
785800 LOG (ERROR) << " Cannot assign " << valuestring << " to a char variable" ;
786- return false ;
801+ return ConfigurableParam::EParamUpdateStatus::Failed ;
787802 }
788803 char addr = intvalue;
789804 if (isMemblockDifferent<char >(targetaddr, (void *)&addr)) {
790805 std::memcpy (targetaddr, (void *)&addr, sizeof (char ));
791- return true ;
806+ return ConfigurableParam::EParamUpdateStatus::Changed ;
792807 }
793- return false ;
808+ return ConfigurableParam::EParamUpdateStatus::Unchanged ;
794809}
810+
795811template <>
796- bool ConvertAndCopy<unsigned char >(std::string const & valuestring, void * targetaddr)
812+ ConfigurableParam::EParamUpdateStatus ConvertAndCopy<unsigned char >(std::string const & valuestring, void * targetaddr)
797813{
798814 unsigned int intvalue = boost::lexical_cast<int >(valuestring);
799815 if (intvalue > std::numeric_limits<unsigned char >::max () || intvalue < std::numeric_limits<unsigned char >::min ()) {
800816 LOG (ERROR) << " Cannot assign " << valuestring << " to an unsigned char variable" ;
801- return false ;
817+ return ConfigurableParam::EParamUpdateStatus::Failed ;
802818 }
803819 unsigned char addr = intvalue;
804820 if (isMemblockDifferent<unsigned char >(targetaddr, (void *)&addr)) {
805821 std::memcpy (targetaddr, (void *)&addr, sizeof (unsigned char ));
806- return true ;
822+ return ConfigurableParam::EParamUpdateStatus::Changed ;
807823 }
808- return false ;
824+ return ConfigurableParam::EParamUpdateStatus::Unchanged ;
809825}
810826
811- bool ConfigurableParam::updateThroughStorageMapWithConversion (std::string const & key, std::string const & valuestring)
827+ ConfigurableParam::EParamUpdateStatus ConfigurableParam::updateThroughStorageMapWithConversion (std::string const & key, std::string const & valuestring)
812828{
813829 // check if key_exists
814830 auto iter = sKeyToStorageMap ->find (key);
815831 if (iter == sKeyToStorageMap ->end ()) {
816832 LOG (WARN) << " Cannot update parameter " << key << " (parameter not found) " ;
817- return false ;
833+ return ConfigurableParam::EParamUpdateStatus::Failed ;
818834 }
819835
820836 auto targetaddress = iter->second .second ;
@@ -936,7 +952,7 @@ bool ConfigurableParam::updateThroughStorageMapWithConversion(std::string const&
936952 break ;
937953 }
938954 }
939- return false ;
955+ return ConfigurableParam::EParamUpdateStatus::Failed ;
940956}
941957
942958} // namespace conf
0 commit comments