File indexing completed on 2026-04-09 07:49:14
0001
0002
0003 #include "sprof.h"
0004 #include "sstr.h"
0005 #include "sstamp.h"
0006
0007 #include "NPFold.h"
0008
0009 struct NP_delete_test
0010 {
0011 static constexpr const int M = 1000000 ;
0012 static constexpr const int K = 1000 ;
0013
0014 static void t0();
0015 static void t1();
0016 static void t2();
0017
0018 static void main();
0019 };
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 void NP_delete_test::t0()
0040 {
0041 sprof p0, p1, p2 ;
0042
0043 sprof::Stamp(p0);
0044
0045 NP* a = NP::Make<float>( 1*M, 4, 4 ) ;
0046 std::cout << a->descSize() << std::endl ;
0047
0048 sprof::Stamp(p1);
0049
0050
0051
0052 a->data.clear() ;
0053 a->data.shrink_to_fit();
0054
0055
0056
0057 sprof::Stamp(p2);
0058
0059 std::cout << sprof::Desc(p0,p1) << std::endl ;
0060 std::cout << sprof::Desc(p1,p2) << std::endl ;
0061 }
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 void NP_delete_test::t1()
0076 {
0077 const char* NumPhotonSpec = "M1,1,1,1,1" ;
0078 std::vector<int>* nums = sstr::ParseIntSpecList<int>( NumPhotonSpec, ',' ) ;
0079 int num_event = nums ? nums->size() : 0 ;
0080
0081 NP* run = NP::Make<int>(num_event);
0082 int* rr = run->values<int>();
0083
0084 run->set_meta<std::string>("TEST", "t1") ;
0085
0086 bool CLEAR = getenv("CLEAR") != nullptr ;
0087 bool DELETE = getenv("DELETE") != nullptr ;
0088 run->set_meta<std::string>("CLEAR", CLEAR ? "YES" : "NO" ) ;
0089 run->set_meta<std::string>("DELETE", DELETE ? "YES" : "NO" ) ;
0090
0091
0092 for(int idx=0 ; idx < 10 ; idx++)
0093 {
0094 std::string head = U::FormName_("head_", idx, nullptr, 3 ) ;
0095 run->set_meta<std::string>(head.c_str(), sprof::Now() );
0096
0097 int num = (*nums)[idx] ;
0098 rr[idx] = num ;
0099
0100 NP* a = NP::Make<float>( num, 4, 4 ) ;
0101
0102 std::string body = U::FormName_("body_", idx, nullptr, 3 ) ;
0103 run->set_meta<std::string>(body.c_str(), sprof::Now() );
0104
0105 if(CLEAR) a->clear() ;
0106 if(DELETE) delete a ;
0107
0108 std::string tail = U::FormName_("tail_", idx, nullptr, 3 ) ;
0109 run->set_meta<std::string>(tail.c_str(), sprof::Now() );
0110
0111 sstamp::sleep_us(100000);
0112 }
0113
0114 NPFold* fold = new NPFold ;
0115 fold->add( "run", run );
0116 fold->add( "runprof", run->makeMetaKVProfileArray() );
0117 fold->save("$FOLD");
0118 }
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 void NP_delete_test::t2()
0140 {
0141
0142 const char* NumPhotonSpec = "M1,2,3,4,3,2,1" ;
0143 std::vector<int>* nums = sstr::ParseIntSpecList<int>( NumPhotonSpec, ',' ) ;
0144
0145 int num_event = nums ? nums->size() : 0 ;
0146
0147 NP* run = NP::Make<int>(num_event);
0148 int* rr = run->values<int>();
0149
0150 run->set_meta<std::string>("TEST", "t2" ) ;
0151
0152 bool CLEAR = getenv("CLEAR") != nullptr ;
0153 bool DELETE = getenv("DELETE") != nullptr ;
0154 run->set_meta<std::string>("CLEAR", CLEAR ? "YES" : "NO" ) ;
0155 run->set_meta<std::string>("DELETE", DELETE ? "YES" : "NO" ) ;
0156
0157
0158 for(int idx=0 ; idx < num_event ; idx++)
0159 {
0160 int num = (*nums)[idx] ;
0161 rr[idx] = num ;
0162 std::cout << std::setw(4) << idx << " : " << num << std::endl ;
0163
0164 std::string head = U::FormName_("head_", idx, nullptr, 3 ) ;
0165 sstamp::sleep_us(100000);
0166 run->set_meta<std::string>(head.c_str(), sprof::Now() );
0167
0168 NP* a = NP::Make<float>( num, 4, 4 ) ;
0169
0170
0171 std::string body = U::FormName_("body_", idx, nullptr, 3 ) ;
0172 sstamp::sleep_us(100000);
0173 run->set_meta<std::string>(body.c_str(), sprof::Now() );
0174
0175 if(CLEAR) a->clear() ;
0176 if(DELETE) delete a ;
0177
0178
0179 std::string tail = U::FormName_("tail_", idx, nullptr, 3 ) ;
0180 sstamp::sleep_us(100000);
0181 run->set_meta<std::string>(tail.c_str(), sprof::Now() );
0182 }
0183
0184 NPFold* fold = new NPFold ;
0185 fold->add( "run", run );
0186 fold->add( "runprof", run->makeMetaKVProfileArray() );
0187 fold->save("$FOLD");
0188
0189 }
0190
0191
0192
0193
0194
0195 void NP_delete_test::main()
0196 {
0197 char* TEST = getenv("TEST") ;
0198 int test = TEST && strlen(TEST) > 0 && TEST[0] == 't' ? strtol(TEST+1, nullptr, 10) : -1 ;
0199 switch(test)
0200 {
0201 case 0: t0() ; break ;
0202 case 1: t1() ; break ;
0203 case 2: t2() ; break ;
0204 case 3: t3() ; break ;
0205 }
0206 }
0207
0208 int main()
0209 {
0210 NP_delete_test::main();
0211 return 0 ;
0212 }
0213
0214
0215