Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:23

0001 // ./stree_sensor_test.sh 
0002 
0003 #include <cstdlib>
0004 #include <iostream>
0005 #include "stree.h"
0006 
0007 
0008 void test_lookup_sensor_identifier( const stree& st )
0009 {
0010     std::vector<int> s_ident ; 
0011     const std::vector<int> s_index = {{ 
0012           -4,-3,-2,-1,0,1,2,3,4, 
0013           1000, 
0014           10000, 
0015           17610, 17611, 17612, 17613, 17614, 17615, 17616, 
0016           20000, 
0017           30000, 
0018           40000, 
0019           43210, 43211, 43212, 43213, 43214, 43215, 43216, 
0020           45610, 45611, 45612, 45613, 45614, 45615, 45616, 
0021           50000, 50001, 50002 }} ;  
0022 
0023     bool one_based_index = true ; 
0024     bool verbose = true ; 
0025     unsigned edge = 50 ; 
0026 
0027     st.lookup_sensor_identifier( s_ident, s_index, one_based_index,  verbose, edge );  
0028  
0029     std::cout 
0030         << " test_lookup_sensor_identifier " 
0031         << " st.sensor_id.size " << st.sensor_id.size()
0032         << " s_index.size " << s_index.size()    
0033         << " s_ident.size " << s_ident.size()    
0034         << std::endl
0035         ;
0036 
0037     assert( s_index.size()  == s_ident.size() ); 
0038 
0039     for(unsigned i=0 ; i < s_index.size() ; i++ )
0040     {
0041          std::cout 
0042              << " i " << std::setw(6) << i 
0043              << " s_index[i] " << std::setw(6) << s_index[i]
0044              << " s_ident[i] " << std::setw(6) << s_ident[i]
0045              << std::endl 
0046              ;
0047     } 
0048 }
0049 
0050 void test_sensor_id( const stree& st )
0051 {
0052     std::cout << " st.sensor_id.size " << st.sensor_id.size() << std::endl ; 
0053     std::cout << " st.sensor_id[st.sensor_id.size()-1] " << st.sensor_id[st.sensor_id.size()-1] << std::endl ; 
0054 
0055     std::cout << " std::vector [] does not range check and does not give any error, returning \"garbage\" values " << std::endl ; 
0056     std::cout << " st.sensor_id[st.sensor_id.size()] " << st.sensor_id[st.sensor_id.size()] << std::endl ; 
0057     std::cout << " st.sensor_id[st.sensor_id.size()+1] " << st.sensor_id[st.sensor_id.size()+1] << std::endl ; 
0058     std::cout << " st.sensor_id[st.sensor_id.size()+1000] " << st.sensor_id[st.sensor_id.size()+1000] << std::endl ; 
0059     std::cout << " st.sensor_id[st.sensor_id.size()+1001] " << st.sensor_id[st.sensor_id.size()+1001] << std::endl ; 
0060 
0061     // std::vector ".at" range checks and throws 
0062     //      : libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: vector
0063     //std::cout << " st.sensor_id.at(st.sensor_id.size()) " << st.sensor_id.at(st.sensor_id.size()) << std::endl ; 
0064 }
0065 
0066 
0067 
0068 void test_desc_repeat_nodes( const stree& st )
0069 {
0070     std::cout << st.desc_repeat_nodes(); 
0071 }
0072 
0073 int main(int argc, char** argv)
0074 {
0075     stree st ; 
0076     st.level = 2 ; 
0077     st.load("$HOME/.opticks/GEOM/$GEOM/CSGFoundry/SSim") ; 
0078 
0079     std::cout << "st.desc_sub(false)" << std::endl << st.desc_sub(false) << std::endl ;
0080     std::cout << "st.desc_sensor_id()" << std::endl << st.desc_sensor_id() << std::endl ; 
0081 
0082     /*
0083     test_sensor_id( st ); 
0084     test_desc_repeat_nodes(st); 
0085     */
0086 
0087     test_lookup_sensor_identifier( st );  
0088 
0089 
0090     return 0 ; 
0091 }