12 #ifndef SST_CORE_SERIALIZATION_OBJECTMAP_H 13 #define SST_CORE_SERIALIZATION_OBJECTMAP_H 15 #include "sst/core/from_string.h" 16 #include "sst/core/warnmacros.h" 26 #include <type_traits> 88 enum class Op : std::uint8_t { LT, LTE, GT, GTE, EQ, NEQ, CHANGED, INVALID };
90 static Op getOperationFromString(
const std::string& op)
92 if ( op ==
"<" )
return Op::LT;
93 if ( op ==
"<=" )
return Op::LTE;
94 if ( op ==
">" )
return Op::GT;
95 if ( op ==
">=" )
return Op::GTE;
96 if ( op ==
"==" )
return Op::EQ;
97 if ( op ==
"!=" )
return Op::NEQ;
98 if ( op ==
"changed" )
return Op::CHANGED;
102 static std::string getStringFromOp(Op op)
139 virtual bool compare() = 0;
140 virtual std::string getCurrentValue() = 0;
141 virtual void print(std::ostream& stream) = 0;
142 std::string getName() {
return name_; }
144 virtual void* getVar() = 0;
147 std::string name_ =
"";
167 static const std::multimap<std::string, ObjectMap*>
emptyVars;
200 virtual void set_impl(
const std::string& UNUSED(value)) {}
221 int32_t refCount_ = 1;
252 virtual bool checkValue(
const std::string& UNUSED(value)) {
return false; }
283 virtual std::string
getType() = 0;
318 if ( !--refCount_ )
delete this;
334 const std::string& UNUSED(name), ObjectMapComparison::Op UNUSED(op),
const std::string& UNUSED(value))
339 virtual ObjectMapComparison* getComparisonVar(
const std::string& UNUSED(name), ObjectMapComparison::Op UNUSED(op),
340 const std::string& UNUSED(name2),
ObjectMap* UNUSED(var2))
342 printf(
"In virtual ObjectMapComparison\n");
346 virtual ObjectBuffer* getObjectBuffer(
const std::string& UNUSED(name),
size_t UNUSED(sz)) {
return nullptr; }
394 virtual std::string
get() {
return ""; }
408 void set(
const std::string& value)
424 virtual std::string
get(
const std::string& var);
444 virtual void set(
const std::string& var,
const std::string& value,
bool& found,
bool& read_only);
501 virtual std::string
listVariable(std::string name,
bool& found,
int recurse = 0);
514 virtual std::string
list(
int recurse = 0);
527 for (
auto [it, end] = variables.equal_range(name); it != end; ++it )
541 void activate(
ObjectMap* parent,
const std::string& name)
567 std::string listRecursive(
const std::string& name,
int level,
int recurse);
597 if ( obj.second !=
nullptr ) {
598 obj.second->decRefCount();
742 template <
typename T>
753 if ( op_ == Op::CHANGED ) {
759 comp_value_ = SST::Core::from_string<T>(value);
764 bool compare()
override 768 return *var_ < comp_value_;
771 return *var_ <= comp_value_;
774 return *var_ > comp_value_;
777 return *var_ >= comp_value_;
780 return *var_ == comp_value_;
783 return *var_ != comp_value_;
788 bool ret = *var_ != comp_value_;
799 std::string getCurrentValue()
override {
return SST::Core::to_string(*var_); }
801 void* getVar()
override {
return var_; }
803 void print(std::ostream& stream)
override 805 stream << name_ <<
" " << getStringFromOp(op_);
806 if ( op_ == Op::CHANGED )
809 stream <<
" " << SST::Core::to_string(comp_value_) <<
" ";
815 Op op_ = Op::INVALID;
822 template <
typename V1>
824 cmp(V1 v, ObjectMapComparison::Op op, V1 w)
827 case ObjectMapComparison::Op::LT:
830 case ObjectMapComparison::Op::LTE:
833 case ObjectMapComparison::Op::GT:
836 case ObjectMapComparison::Op::GTE:
839 case ObjectMapComparison::Op::EQ:
842 case ObjectMapComparison::Op::NEQ:
846 std::cout <<
"Invalid comparison operator\n";
853 template <
typename U1,
typename U2, std::enable_if_t<std::is_same_v<U1, U2>,
int> = true>
855 compareType(U1 v, ObjectMapComparison::Op op, U2 w)
859 return cmp(v, op, w);
863 template <
typename U1,
typename U2,
864 std::enable_if_t<!std::is_same_v<U1, U2> && std::is_arithmetic_v<U1> && std::is_arithmetic_v<U2>,
int> =
true>
866 compareType(U1 v, ObjectMapComparison::Op op, U2 w)
870 if ( std::is_integral_v<U1> && std::is_integral_v<U2> ) {
872 if ( std::is_unsigned_v<U1> && std::is_unsigned_v<U2> ) {
874 unsigned long long v1 =
static_cast<unsigned long long>(v);
875 unsigned long long w1 =
static_cast<unsigned long long>(w);
876 return cmp(v1, op, w1);
881 long long v1 =
static_cast<long long>(v);
882 long long w1 =
static_cast<long long>(w);
883 return cmp(v1, op, w1);
887 else if ( std::is_floating_point_v<U1> && std::is_floating_point_v<U2> ) {
889 long double v1 =
static_cast<long double>(v);
890 long double w1 =
static_cast<long double>(w);
891 return cmp(v1, op, w1);
895 if ( std::is_integral_v<U1> ) {
896 if ( std::is_same_v<U2, float> ) {
897 float v1 =
static_cast<float>(v);
898 float w1 =
static_cast<float>(w);
899 return cmp(v1, op, w1);
901 else if ( std::is_same_v<U2, double> ) {
902 double v1 =
static_cast<double>(v);
903 double w1 =
static_cast<double>(w);
904 return cmp(v1, op, w1);
907 long double v1 =
static_cast<long double>(v);
908 long double w1 =
static_cast<long double>(w);
909 return cmp(v1, op, w1);
913 if ( std::is_same_v<U1, float> ) {
914 float v1 =
static_cast<float>(v);
915 float w1 =
static_cast<float>(w);
916 return cmp(v1, op, w1);
918 else if ( std::is_same_v<U1, double> ) {
919 double v1 =
static_cast<double>(v);
920 double w1 =
static_cast<double>(w);
921 return cmp(v1, op, w1);
924 long double v1 =
static_cast<long double>(v);
925 long double w1 =
static_cast<long double>(w);
926 return cmp(v1, op, w1);
933 template <
typename U1,
typename U2,
934 std::enable_if_t<(!std::is_same_v<U1, U2> && (!std::is_arithmetic_v<U1> || !std::is_arithmetic_v<U2>)),
int> =
true>
936 compareType(U1 UNUSED(v), ObjectMapComparison::Op UNUSED(op), U2 UNUSED(w))
939 printf(
" ERROR: CMP: Does not support non-arithmetic types\n");
947 template <
typename T1,
typename T2>
959 bool compare()
override 963 return compareType(v1, op_, v2);
966 std::string getCurrentValue()
override {
return SST::Core::to_string(*var1_) +
" " + SST::Core::to_string(*var2_); }
968 void* getVar()
override {
return var1_; }
970 void print(std::ostream& stream)
override 972 stream << name_ <<
" " << getStringFromOp(op_);
973 if ( op_ == Op::CHANGED )
976 stream <<
" " << name2_ <<
" ";
980 std::string name2_ =
"";
982 Op op_ = Op::INVALID;
997 virtual void sample(
size_t index,
bool trigger) = 0;
998 virtual std::string
get(
size_t index) = 0;
999 virtual std::string getTriggerVal() = 0;
1001 std::string getName() {
return name_; }
1002 size_t getBufSize() {
return bufSize_; }
1010 template <
typename T>
1018 objectBuffer_.resize(sz);
1021 void sample(
size_t index,
bool trigger)
override 1023 objectBuffer_[index] = *varPtr_;
1024 if ( trigger ) triggerVal = *varPtr_;
1027 std::string
get(
size_t index)
override {
return SST::Core::to_string(objectBuffer_.at(index)); }
1029 std::string getTriggerVal()
override {
return SST::Core::to_string(triggerVal); }
1033 T* varPtr_ =
nullptr;
1034 std::vector<T> objectBuffer_;
1049 tagBuffer_.resize(bufSize_);
1050 cycleBuffer_.resize(bufSize_);
1051 handlerBuffer_.resize(bufSize_);
1056 void setBufferReset() { reset_ =
true; }
1058 void resetTraceBuffer()
1060 printf(
" Reset Trace Buffer\n");
1071 size_t getBufferSize() {
return bufSize_; }
1075 objBuffers_.push_back(vb);
1079 enum BufferState :
int {
1086 const std::map<BufferState, char> state2char { { CLEAR,
'-' }, { TRIGGER,
'!' }, { POSTTRIGGER,
'+' },
1090 bool sampleT(
bool trigger, uint64_t cycle,
const std::string& handler)
1092 size_t start_state = state_;
1093 bool invokeAction =
false;
1097 if ( start_state == CLEAR ) {
1104 if ( start_state == TRIGGER || start_state == POSTTRIGGER ) {
1105 state_ = POSTTRIGGER;
1110 #ifdef _OBJMAP_DEBUG_ 1111 std::cout <<
" Sample:" << handler <<
": numRecs:" << numRecs_ <<
" first:" << first_ <<
" cur:" << cur_
1112 <<
" state:" << state2char.at(state_) <<
" isOverrun:" << isOverrun_
1113 <<
" samplesLost:" << samplesLost_ << std::endl;
1115 cycleBuffer_[cur_] = cycle;
1116 handlerBuffer_[cur_] = handler;
1118 triggerCycle = cycle;
1123 for (
size_t obj = 0; obj < numObjects; obj++ ) {
1124 varBuffer_ = objBuffers_[obj];
1125 varBuffer_->sample(cur_, trigger);
1128 if ( numRecs_ < bufSize_ ) {
1129 tagBuffer_[cur_] = state_;
1131 cur_ = (cur_ + 1) % bufSize_;
1132 if ( cur_ == 0 ) first_ = 0;
1136 if ( tagBuffer_[cur_] == TRIGGER ) {
1140 tagBuffer_[cur_] = state_;
1142 cur_ = (cur_ + 1) % bufSize_;
1150 if ( (state_ == TRIGGER) && (postDelay_ == 0) ) {
1151 invokeAction =
true;
1152 std::cout <<
" Invoke Action\n";
1155 if ( state_ == POSTTRIGGER ) {
1157 if ( postCount_ >= postDelay_ ) {
1158 invokeAction =
true;
1159 std::cout <<
" Invoke Action\n";
1163 return invokeAction;
1166 void dumpTraceBufferT()
1168 if ( numRecs_ == 0 )
return;
1182 for (
int j = start;; j++ ) {
1183 size_t i = j % bufSize_;
1185 std::cout <<
"buf[" << i <<
"] " << handlerBuffer_.at(i) <<
" @" << cycleBuffer_.at(i) <<
" (" 1186 << state2char.at(tagBuffer_.at(i)) <<
") ";
1188 for (
size_t obj = 0; obj < numObjects; obj++ ) {
1190 std::cout << SST::Core::to_string(varBuffer_->getName()) <<
"=" << varBuffer_->get(i) <<
" ";
1192 std::cout << std::endl;
1200 void dumpTriggerRecord()
1202 if ( numRecs_ == 0 ) {
1203 std::cout <<
"No trace samples in current buffer" << std::endl;
1206 if ( state_ != CLEAR ) {
1207 std::cout <<
"TriggerRecord:@cycle" << triggerCycle <<
": samples lost = " << samplesLost_ <<
": ";
1208 for (
size_t obj = 0; obj < numObjects; obj++ ) {
1210 std::cout << SST::Core::to_string(varBuffer_->getName()) <<
"=" << varBuffer_->getTriggerVal() <<
" ";
1212 std::cout << std::endl;
1218 for (
size_t obj = 0; obj < numObjects; obj++ ) {
1220 std::cout << SST::Core::to_string(varBuffer_->getName()) <<
" ";
1226 std::cout <<
"bufsize = " << bufSize_ <<
" postDelay = " << postDelay_ <<
" : ";
1232 size_t bufSize_ = 64;
1233 size_t postDelay_ = 8;
1234 size_t postCount_ = 0;
1237 size_t numRecs_ = 0;
1238 bool isOverrun_ =
false;
1239 size_t samplesLost_ = 0;
1240 bool reset_ =
false;
1241 BufferState state_ = CLEAR;
1243 size_t numObjects = 0;
1244 std::vector<BufferState> tagBuffer_;
1245 std::vector<std::string> handlerBuffer_;
1246 std::vector<ObjectBuffer*> objBuffers_;
1247 std::vector<uint64_t> cycleBuffer_;
1248 uint64_t triggerCycle;
1263 template <
typename T>
1279 virtual void set_impl(
const std::string& value)
override { *
addr_ = SST::Core::from_string<T>(value); }
1281 virtual bool checkValue(
const std::string& value)
override 1285 T v = SST::Core::from_string<T>(value);
1286 ret =
static_cast<bool>(v);
1288 catch (
const std::invalid_argument& e ) {
1289 std::cerr <<
"Error: Invalid value: " << value << std::endl;
1292 catch (
const std::out_of_range& e ) {
1293 std::cerr <<
"Error: Value is out of range: " << value << std::endl;
1303 virtual std::string
get()
override {
return SST::Core::to_string(*
addr_); }
1347 const std::string& name, ObjectMapComparison::Op UNUSED(op),
const std::string& value)
override 1353 const std::string& name, ObjectMapComparison::Op op,
const std::string& name2,
ObjectMap* var2)
override 1357 printf(
"Triggers can only use fundamental types; %s is not " 1363 std::string type = var2->
getType();
1365 std::cout <<
"In ObjectMapComparison_var: " << name <<
" " << name2 << std::endl;
1367 std::string type1 =
getType();
1368 std::cout <<
"getType(v1): " << type1 << std::endl;
1369 std::cout <<
"getType(v2): " << type << std::endl;
1374 if ( std::is_arithmetic_v<T> ) {
1375 if ( type ==
"int" ) {
1376 int* addr2 =
static_cast<int*
>(var2->
getAddr());
1379 else if ( type ==
"unsigned int" ) {
1380 unsigned int* addr2 =
static_cast<unsigned int*
>(var2->
getAddr());
1381 return new ObjectMapComparison_var<T, unsigned int>(name,
addr_, op, name2, addr2);
1383 else if ( type ==
"long" ) {
1384 long* addr2 =
static_cast<long*
>(var2->
getAddr());
1385 return new ObjectMapComparison_var<T, long>(name,
addr_, op, name2, addr2);
1387 else if ( type ==
"unsigned long" ) {
1388 unsigned long* addr2 =
static_cast<unsigned long*
>(var2->
getAddr());
1389 return new ObjectMapComparison_var<T, unsigned long>(name,
addr_, op, name2, addr2);
1391 else if ( type ==
"char" ) {
1392 char* addr2 =
static_cast<char*
>(var2->
getAddr());
1393 return new ObjectMapComparison_var<T, char>(name,
addr_, op, name2, addr2);
1395 else if ( type ==
"signed char" ) {
1396 signed char* addr2 =
static_cast<signed char*
>(var2->
getAddr());
1397 return new ObjectMapComparison_var<T, signed char>(name,
addr_, op, name2, addr2);
1399 else if ( type ==
"unsigned char" ) {
1400 unsigned char* addr2 =
static_cast<unsigned char*
>(var2->
getAddr());
1401 return new ObjectMapComparison_var<T, unsigned char>(name,
addr_, op, name2, addr2);
1403 else if ( type ==
"short" ) {
1404 short* addr2 =
static_cast<short*
>(var2->
getAddr());
1405 return new ObjectMapComparison_var<T, short>(name,
addr_, op, name2, addr2);
1407 else if ( type ==
"unsigned short" ) {
1408 unsigned short* addr2 =
static_cast<unsigned short*
>(var2->
getAddr());
1409 return new ObjectMapComparison_var<T, unsigned short>(name,
addr_, op, name2, addr2);
1411 else if ( type ==
"long long" ) {
1412 long long* addr2 =
static_cast<long long*
>(var2->
getAddr());
1413 return new ObjectMapComparison_var<T, long long>(name,
addr_, op, name2, addr2);
1415 else if ( type ==
"unsigned long long" ) {
1416 unsigned long long* addr2 =
static_cast<unsigned long long*
>(var2->
getAddr());
1417 return new ObjectMapComparison_var<T, unsigned long long>(name,
addr_, op, name2, addr2);
1419 else if ( type ==
"bool" ) {
1420 bool* addr2 =
static_cast<bool*
>(var2->
getAddr());
1421 return new ObjectMapComparison_var<T, bool>(name,
addr_, op, name2, addr2);
1423 else if ( type ==
"float" ) {
1424 float* addr2 =
static_cast<float*
>(var2->
getAddr());
1425 return new ObjectMapComparison_var<T, float>(name,
addr_, op, name2, addr2);
1427 else if ( type ==
"double" ) {
1428 double* addr2 =
static_cast<double*
>(var2->
getAddr());
1429 return new ObjectMapComparison_var<T, double>(name,
addr_, op, name2, addr2);
1431 else if ( type ==
"long double" ) {
1432 long double* addr2 =
static_cast<long double*
>(var2->
getAddr());
1433 return new ObjectMapComparison_var<T, long double>(name,
addr_, op, name2, addr2);
1437 std::cout <<
"Invalid type for comparison: " << name2 <<
"(" << type <<
")\n";
1442 std::cout <<
"Invalid type for comparison: " << name2 <<
"(" << type <<
")\n";
1447 ObjectBuffer* getObjectBuffer(
const std::string& name,
size_t sz)
override 1449 return new ObjectBuffer_impl<T>(name,
addr_, sz);
1486 virtual size_t getSize() {
return size; }
1497 #endif // SST_CORE_SERIALIZATION_OBJECTMAP_H Template implementation of ObjectMapComparison for <op>
Definition: objectMap.h:948
bool isFundamental() override
Returns true as object is a fundamental.
Definition: objectMap.h:1310
Base class for interacting with data from ObjectMap.
Definition: objectMap.h:85
const std::multimap< std::string, ObjectMap * > & getVariables() override
Get the list of child variables contained in this ObjectMap.
Definition: objectMap.h:626
bool isContainer() override final
Check to see if this ObjectMap represents a container.
Definition: objectMap.h:1463
void * addr_
Address of the variable for reading and writing.
Definition: objectMap.h:687
virtual void deactivate_callback()
Function that will get called when this object is deactivated (i.e selectParent() is called) ...
Definition: objectMap.h:211
virtual bool isFundamental()
Check to see if this ObjectMap represents a fundamental or a class treated as a fundamental.
Definition: objectMap.h:453
Definition: objectMap.h:1011
ObjectMap object to create a level of hierarchy that doesn't represent a specific object...
Definition: objectMap.h:636
~ObjectMapFundamental() override=default
Destructor.
virtual ObjectMapComparison * getComparison(const std::string &UNUSED(name), ObjectMapComparison::Op UNUSED(op), const std::string &UNUSED(value))
Get a watch point for this object.
Definition: objectMap.h:333
~ObjectMapClass() override=default
Destructor.
bool read_only_
Indicates whether or not the variable is read-only.
Definition: objectMap.h:191
virtual std::string listVariable(std::string name, bool &found, int recurse=0)
Create a string that lists information for the specified variable.
Definition: objectMap.cc:177
Class used to map containers.
Definition: objectMap.h:1457
ObjectMap representing fundamental types, and classes treated as fundamental types.
Definition: objectMap.h:1264
virtual ~ObjectMap()=default
Destructor.
Template implementation of ObjectMapComparison for <op>
Definition: objectMap.h:743
T * addr_
Address of the variable for reading and writing.
Definition: objectMap.h:1270
virtual void set_impl(const std::string &UNUSED(value))
Function implemented by derived classes to implement set().
Definition: objectMap.h:200
virtual ObjectMap * findVariable(const std::string &name)
Find a variable in this object map.
Definition: objectMap.h:524
~ObjectMapHierarchyOnly() override=default
Destructor.
virtual void set_impl(const std::string &value) override
Set the value of the object represented as a string.
Definition: objectMap.h:1279
ObjectMapClass(void *addr, const std::string &type)
Constructor.
Definition: objectMap.h:709
void * getAddr() override
Get the address of the represented object.
Definition: objectMap.h:735
ObjectMapClass()=default
Default constructor.
void addVariable(const std::string &name, ObjectMap *obj) override
Adds a variable to this ObjectMap.
Definition: objectMap.h:617
Base class for objects created by the serializer mapping mode used to map the variables for objects...
Definition: objectMap.h:158
virtual bool isContainer()
Check to see if this ObjectMap represents a container.
Definition: objectMap.h:461
ObjectMapMetaData * mdata_
Metadata object for walking the object hierarchy.
Definition: objectMap.h:185
virtual void activate_callback()
Function that will get called when this object is selected.
Definition: objectMap.h:205
ObjectMap object for non-fundamental, non-container types.
Definition: objectMap.h:675
ObjectMap * selectParent()
Get the parent for this ObjectMap.
Definition: objectMap.cc:47
int32_t getRefCount()
Get the current reference count.
Definition: objectMap.h:326
bool isReadOnly()
Check to see if this object is read-only.
Definition: objectMap.h:235
virtual void * getAddr()=0
Get the address of the variable represented by the ObjectMap.
std::string getType() override
Get the type of the variable represented by the ObjectMap.
Definition: objectMap.h:1465
void * getAddr() override
Get the address of the variable represented by the ObjectMap.
Definition: objectMap.h:1317
std::string type_
Type of the variable as given by the demangled version of typeid(T).name() for the type...
Definition: objectMap.h:682
ObjectMap object for non-fundamental, non-container types.
Definition: objectMap.h:574
std::string getType() override
Returns empty string since there is no underlying object being represented.
Definition: objectMap.h:659
std::string getName()
Get the name of the variable represented by this ObjectMap.
Definition: objectMap.cc:26
static const std::multimap< std::string, ObjectMap * > emptyVars
Static empty variable map for use by versions that don't have variables (i.e.
Definition: objectMap.h:167
std::string getType() override
Get the type of the represented object.
Definition: objectMap.h:728
virtual const std::multimap< std::string, ObjectMap * > & getVariables()
Get the list of child variables contained in this ObjectMap.
Definition: objectMap.h:300
virtual std::string list(int recurse=0)
Create a string that lists information for the current object.
Definition: objectMap.cc:201
static std::string demangle_name(const char *name)
Static function to demangle type names returned from typeid(T).name()
Definition: objectMap.cc:161
void * getAddr() override
Returns nullptr since there is no underlying object being represented.
Definition: objectMap.h:667
std::string getFullName()
Get the full hierarchical name of the variable represented by this ObjectMap, based on the path taken...
Definition: objectMap.cc:32
virtual void addVariable(const std::string &UNUSED(name), ObjectMap *UNUSED(obj))
Adds a variable to this ObjectMap.
Definition: objectMap.h:381
~ObjectMapWithChildren() override
Destructor.
Definition: objectMap.h:594
Definition: objectMap.h:987
Class used to map arrays.
Definition: objectMap.h:1480
std::multimap< std::string, ObjectMap * > variables_
Map that child ObjectMaps are stored in.
Definition: objectMap.h:580
virtual bool checkValue(const std::string &UNUSED(value))
Check if value string is valid for this type
Definition: objectMap.h:252
ObjectMapWithChildren()=default
Default constructor.
void decRefCount()
Decrement the reference counter for this ObjectMap.
Definition: objectMap.h:316
void incRefCount()
Increment the reference counter for this ObjectMap.
Definition: objectMap.h:308
ObjectMap()=default
Default constructor primarily used for the "top" object in the hierarchy.
std::string getType() override
Return the type represented by this ObjectMap as given by the demangled version of typeid(T)...
Definition: objectMap.h:1344
ObjectMapHierarchyOnly()=default
Default constructor.
ObjectMap * selectVariable(std::string name, bool &loop_detected)
Get the ObjectMap for the specified variable.
Definition: objectMap.cc:59
virtual std::string getType()=0
Get the type of the variable represented by the ObjectMap.
void setReadOnly(bool state=true)
Set the read-only state of the object.
Definition: objectMap.h:245
void * getAddr() override
Get the address of the variable represented by the ObjectMap.
Definition: objectMap.h:1467
Definition: objectMap.h:1040