File indexing completed on 2026-04-09 07:49:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "SPath.hh"
0015 #include "SSys.hh"
0016 #include "NP.hh"
0017 #include "SName.h"
0018
0019 struct SNameTest
0020 {
0021 SName* id ;
0022 char qt ;
0023
0024 SNameTest(int argc, char** argv);
0025 void desc();
0026 void detail();
0027 void findIndex(int argc, char** argv);
0028 void findIndices(int argc, char** argv);
0029 void getIDXListFromContaining();
0030 void getIDXListFromNames();
0031 void hasNames();
0032 };
0033
0034
0035 SNameTest::SNameTest(int argc, char** argv)
0036 :
0037 id(SName::Load("$CFBase/CSGFoundry/meshname.txt")),
0038 qt(SSys::getenvchar("QTYPE", 'S'))
0039 {
0040 assert( qt == 'S' || qt == 'E' || qt == 'C' );
0041 desc();
0042
0043 findIndex(argc, argv);
0044 findIndices(argc, argv);
0045 getIDXListFromContaining();
0046
0047 hasNames();
0048 }
0049
0050 void SNameTest::desc()
0051 {
0052 std::cout << "id.desc()" << std::endl << id->desc() << std::endl ;
0053 }
0054 void SNameTest::detail()
0055 {
0056 std::cout << "id.detail()" << std::endl << id->detail() << std::endl ;
0057 }
0058
0059 void SNameTest::findIndex( int argc, char** argv )
0060 {
0061 for(int i=1 ; i < argc ; i++)
0062 {
0063 const char* arg = argv[i] ;
0064 unsigned count = 0 ;
0065 int max_count = -1 ;
0066 int idx = id->findIndex(arg, count, max_count);
0067 std::cout
0068 << " findIndex " << std::setw(80) << arg
0069 << " count " << std::setw(3) << count
0070 << " idx " << std::setw(3) << idx
0071 << std::endl
0072 ;
0073 }
0074 }
0075
0076 void SNameTest::findIndices( int argc, char** argv )
0077 {
0078 for(int i=1 ; i < argc ; i++)
0079 {
0080 const char* arg = argv[i] ;
0081
0082 std::vector<unsigned> idxs ;
0083 id->findIndicesMatch(idxs, arg, qt);
0084
0085 const char* elv = SName::IDXList(idxs);
0086 std::cout
0087 << " findIndices " << std::setw(80) << arg
0088 << " idxs.size " << std::setw(3) << idxs.size()
0089 << " SName::QTypeLabel " << SName::QTypeLabel(qt)
0090 << std::endl
0091 << "descIndices"
0092 << std::endl
0093 << id->descIndices(idxs)
0094 << std::endl
0095 << "SName::ELVString:[" << elv << "]"
0096 << std::endl
0097 ;
0098 }
0099 }
0100
0101 void SNameTest::getIDXListFromContaining()
0102 {
0103 const char* contain = "_virtual" ;
0104 const char* elv = id->getIDXListFromContaining(contain);
0105 std::cout
0106 << "getIDXListFromContaining"
0107 << " contain [" << contain << "]"
0108 << " elv [" << elv << "]"
0109 << std::endl
0110 ;
0111 }
0112
0113
0114 void SNameTest::getIDXListFromNames()
0115 {
0116 const char* x_elv = "t110,117,134" ;
0117 const char* names = "NNVTMCPPMTsMask_virtual0x,HamamatsuR12860sMask_virtual0x,mask_PMT_20inch_vetosMask_virtual0x" ;
0118 char delim = ',' ;
0119 const char* prefix = "t" ;
0120 const char* elv = id->getIDXListFromNames(names, delim, prefix);
0121 bool match = strcmp( elv, x_elv) == 0 ;
0122
0123 std::cout
0124 << "test_getIDXListFromNames"
0125 << " names [" << names << "]"
0126 << " elv [" << elv << "]"
0127 << " x_elv [" << x_elv << "]"
0128 << " match " << match
0129 << std::endl
0130 ;
0131
0132
0133 }
0134
0135 void SNameTest::hasNames()
0136 {
0137 const char* names = "NNVTMCPPMTsMask_virtual0x,HamamatsuR12860sMask_virtual0x,mask_PMT_20inch_vetosMask_virtual0x" ;
0138 bool has = id->hasNames(names);
0139 std::cout
0140 << "test_hasNames"
0141 << " names [" << names << "]"
0142 << " has " << has
0143 << std::endl
0144 ;
0145 }
0146
0147 int main(int argc, char** argv)
0148 {
0149 SNameTest t(argc, argv);
0150 return 0 ;
0151 }