Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:52

0001 /**
0002 SSimTest.cc
0003 ============
0004 
0005 TEST=Load ~/o/sysrap/tests/SSimTest.sh
0006 
0007 TEST=get_jpmt_nocopy  ~/o/sysrap/tests/SSimTest.sh
0008 TEST=get_jpmt         ~/o/sysrap/tests/SSimTest.sh
0009 TEST=get_spmt         ~/o/sysrap/tests/SSimTest.sh
0010 TEST=get_spmt_f       ~/o/sysrap/tests/SSimTest.sh
0011 
0012 **/
0013 
0014 
0015 #include "SSim.hh"
0016 #include "NPFold.h"
0017 #include "OPTICKS_LOG.hh"
0018 #include "SPMT.h"
0019 
0020 
0021 
0022 struct SSimTest
0023 {
0024     static const char* TEST ;
0025 
0026     static int Load();
0027     static int Load_get();
0028     static int Create();
0029     static int findName();
0030 
0031     static int addFake();
0032     static int addFake_ellipsis();
0033 
0034     static int get_bnd();
0035 
0036     static int get_jpmt_nocopy();
0037     static int get_jpmt();
0038     static int get_spmt();
0039     static int get_spmt_f();
0040 
0041     static int Main();
0042 };
0043 
0044 
0045 const char* SSimTest::TEST = U::GetEnv("TEST","ALL");
0046 
0047 
0048 int SSimTest::Load()
0049 {
0050     std::cout << "[Load\n" ;
0051     SSim* sim = SSim::Load();
0052     std::cout << ( sim ? sim->desc() : "-" ) ;
0053     std::cout << "]Load\n" ;
0054     return 0 ;
0055 }
0056 int SSimTest::Load_get()
0057 {
0058     std::cout << "[Load_get " << std::endl ;
0059     SSim* sim = SSim::Load();
0060     std::cout << " sim " << ( sim ? "YES" : "NO " ) << std::endl ;
0061     const NP* optical = sim ? sim->get(snam::OPTICAL) : nullptr ;
0062     std::cout << " optical " << ( optical ? optical->sstr() : "-" ) << std::endl ;
0063     std::cout << "]Load_get " << std::endl ;
0064     return 0 ;
0065 }
0066 int SSimTest::Create()
0067 {
0068     std::cout << "[Create\n" ;
0069     SSim* sim = SSim::Create();
0070     LOG(info) << " sim.desc " << sim->desc() ;
0071     std::cout << "]Create\n" ;
0072     return 0 ;
0073 }
0074 int SSimTest::findName()
0075 {
0076     std::cout << "[findName\n" ;
0077     std::vector<std::string> names = {
0078         "Air",
0079         "Rock",
0080         "Water",
0081         "Acrylic",
0082         "Cream",
0083         "vetoWater",
0084         "Cheese",
0085         "NextIsBlank",
0086         "",
0087         "Galactic",
0088         "Pyrex",
0089         "PMT_3inch_absorb_logsurf1",
0090         "Steel",
0091         "Steel_surface",
0092         "PE_PA",
0093         "Candy",
0094         "NextIsBlank",
0095         "",
0096         "Steel"
0097       } ;
0098 
0099 
0100     const SSim* sim = SSim::Load();
0101     const NP* bnd = sim->get(snam::BND);
0102     std::cout << " bnd " << ( bnd ? bnd->sstr() : "null-bnd" ) << " snam::BND " << snam::BND << std::endl ;
0103     std::cout << " bnd.names " << ( bnd ? bnd->names.size() : -1 ) << std::endl ;
0104 
0105 
0106     for(unsigned a=0 ; a < names.size() ; a++ )
0107     {
0108          const std::string& n = names[a] ;
0109          int i, j ;
0110          bool found = sim->findName(i,j,n.c_str() );
0111 
0112          std::cout << std::setw(30) << n << " " ;
0113          if(found)
0114          {
0115             std::cout
0116                 << "("
0117                 << std::setw(3) << i
0118                 << ","
0119                 << std::setw(3) << j
0120                 << ")"
0121                 << " "
0122                 << SSim::GetItemDigest(bnd, i, j, 8)
0123                 ;
0124          }
0125          else
0126          {
0127             std::cout << "-" ;
0128          }
0129          std::cout << std::endl ;
0130     }
0131     std::cout << "]findName\n" ;
0132     return 0 ;
0133 }
0134 
0135 
0136 int SSimTest::addFake()
0137 {
0138     std::cout << "[addFake\n" ;
0139     SSim* sim = SSim::Load();
0140     std::string bef = sim->desc();
0141 
0142     LOG(info) << "BEFORE " << std::endl << sim->descOptical() << std::endl ;
0143 
0144     std::vector<std::string> specs = { "Rock/perfectAbsorbSurface/perfectAbsorbSurface/Air", "Air///Water" } ;
0145     sim->addFake_(specs);
0146     std::string aft = sim->desc();
0147 
0148     LOG(info) << "AFTER " << std::endl << sim->descOptical() << std::endl ;
0149 
0150     std::cout << "bef" << std::endl << bef << std::endl ;
0151     std::cout << "aft" << std::endl << aft << std::endl ;
0152     std::cout << "]addFake\n" ;
0153     return 0 ;
0154 }
0155 
0156 int SSimTest::addFake_ellipsis()
0157 {
0158     std::cout << "[addFake_ellipsis\n" ;
0159     SSim* sim = SSim::Load();
0160     sim->addFake("Air///Water");
0161     sim->addFake("Air///Water", "Rock/perfectAbsorbSurface/perfectAbsorbSurface/Air");
0162     sim->addFake("Air///Water", "Rock/perfectAbsorbSurface/perfectAbsorbSurface/Air", "Water///Air" );
0163     std::cout << "]addFake_ellipsis\n" ;
0164     return 0 ;
0165 }
0166 
0167 
0168 
0169 int SSimTest::get_bnd()
0170 {
0171     std::cout << "[get_bnd\n" ;
0172     SSim* sim = SSim::Load();
0173     const NP* bnd = sim ? sim->get_bnd() : nullptr ;
0174     LOG(info) << ( bnd ? bnd->desc() : "get_bnd FAIL" ) ;
0175     assert( bnd );
0176     std::cout << "]get_bnd\n" ;
0177     return 0 ;
0178 }
0179 int SSimTest::get_jpmt_nocopy()
0180 {
0181     std::cout << "[get_jpmt_nocopy\n" ;
0182     SSim* sim = SSim::Load();
0183     const NPFold* f  = sim->get_jpmt_nocopy();
0184     LOG(info) << f->desc() ;
0185     std::cout << "]get_jpmt_nocopy\n" ;
0186     return 0 ;
0187 }
0188 int SSimTest::get_jpmt()
0189 {
0190     std::cout << "[get_jpmt\n" ;
0191     SSim* sim = SSim::Load();
0192     const NPFold* f  = sim->get_jpmt();
0193     LOG(info) << f->desc() ;
0194     std::cout << "]get_jpmt\n" ;
0195     return 0 ;
0196 }
0197 int SSimTest::get_spmt()
0198 {
0199     std::cout << "[get_spmt\n" ;
0200     SSim* sim = SSim::Load();
0201     const SPMT* spmt  = sim->get_spmt();
0202     LOG(info) << spmt->desc() ;
0203     std::cout << "]get_spmt\n" ;
0204     return 0 ;
0205 }
0206 int SSimTest::get_spmt_f()
0207 {
0208     std::cout << "[get_spmt_f\n" ;
0209     SSim* sim = SSim::Load();
0210     const NPFold* spmt_f  = sim->get_spmt_f();
0211     LOG(info) << spmt_f->desc() ;
0212     std::cout << "]get_spmt_f\n" ;
0213     return 0 ;
0214 }
0215 
0216 
0217 
0218 /**
0219 SSimTest::Main
0220 ----------------
0221 
0222 With TEST=ALL the ~10 SSim::Load took ~20s when loading 
0223 from slow /cvmfs which made this the slowest test. 
0224 So avoid leaving TEST=ALL as the default to 
0225 bring below 2.5s even with /cvmfs. 
0226 
0227 **/
0228 
0229 
0230 int SSimTest::Main()
0231 {
0232     bool ALL = strcmp(TEST, "findName") == 0 ;
0233     int rc = 0 ;
0234     if(ALL||0==strcmp(TEST,"Load"))      rc += Load();
0235     if(ALL||0==strcmp(TEST,"Load_get"))  rc += Load_get();
0236     if(ALL||0==strcmp(TEST,"Create"))    rc += Create();
0237     if(ALL||0==strcmp(TEST,"findName"))  rc += findName();
0238 
0239     // these two failing with consistencey assert
0240     if(0||0==strcmp(TEST,"addFake"))   rc += addFake();
0241     if(0||0==strcmp(TEST,"addFake_ellipsis")) rc += addFake_ellipsis();
0242 
0243     if(ALL||0==strcmp(TEST,"get_bnd"))         rc += get_bnd();
0244     if(ALL||0==strcmp(TEST,"get_jpmt_nocopy")) rc += get_jpmt_nocopy();
0245     if(ALL||0==strcmp(TEST,"get_jpmt"))        rc += get_jpmt();
0246     if(ALL||0==strcmp(TEST,"get_spmt"))        rc += get_spmt();
0247     if(ALL||0==strcmp(TEST,"get_spmt_f"))      rc += get_spmt_f();
0248 
0249     return rc ;
0250 }
0251 
0252 
0253 int main(int argc, char** argv)
0254 {
0255     OPTICKS_LOG(argc, argv);
0256     return SSimTest::Main();
0257 }
0258