File indexing completed on 2025-01-18 10:17:37
0001
0002
0003
0004
0005 #pragma once
0006 #include <sstream>
0007
0008 #include <JANA/JVersion.h>
0009
0010 #if JANA2_HAVE_ROOT
0011 #include <TObject.h>
0012 #include <TClass.h>
0013 #include <TDataMember.h>
0014 #include <TMethodCall.h>
0015 #include <TList.h>
0016 #endif
0017
0018 #include <JANA/JObject.h>
0019 #include <JANA/JEvent.h>
0020
0021 class JStringification {
0022
0023 public:
0024
0025 JStringification() = default;
0026 virtual ~JStringification() = default;
0027
0028
0029 void GetObjectSummaries(std::map<std::string, JObjectSummary> &objects, std::shared_ptr<const JEvent> &jevent, const std::string &object_name, const std::string factory_tag="") const;
0030 void GetObjectSummariesAsJSON(std::vector<std::string> &json_vec, std::shared_ptr<const JEvent> &jevent, const std::string &object_name, const std::string factory_tag="") const;
0031 std::string ObjectToJSON( const std::string &hexaddr, const JObjectSummary &summary ) const;
0032
0033
0034
0035
0036
0037
0038
0039 template <typename T> void ConvertInt(std::stringstream &ss, T val, std::true_type) const {ss << (int)val;}
0040 template <typename T> void ConvertInt(std::stringstream &ss, T , std::false_type) const {ss << "unknown";}
0041 template <typename T> void ConvertUInt(std::stringstream &ss, T val, std::true_type) const {ss << "0x" << std::hex << (unsigned int)val << std::dec;}
0042 template <typename T> void ConvertUInt(std::stringstream &ss, T , std::false_type) const {ss << "unknown";}
0043
0044 template <typename T> std::string GetAddrAsString(void *addr) const;
0045
0046 #if JANA2_HAVE_ROOT
0047 std::string GetRootObjectMemberAsString(const TObject *tobj, const TDataMember *memitem, std::string type) const;
0048 #endif
0049
0050 private:
0051
0052
0053 };
0054
0055
0056
0057
0058
0059
0060
0061 template <typename T>
0062 std::string JStringification::GetAddrAsString(void *addr) const {
0063 auto val = *(T *)addr;
0064 std::stringstream ss;
0065 if( std::is_same<T, char>::value ) {
0066 ConvertInt(ss, val, std::is_same<T, char>());
0067 }else if( std::is_same<T, unsigned char>::value ){
0068 ConvertUInt(ss, val, std::is_same<T, unsigned char>());
0069 }else if( std::is_same<T, std::string>::value ){
0070 ss << val;
0071 }else{
0072 ss << val;
0073 }
0074 return ss.str();
0075 }
0076