File indexing completed on 2026-04-09 07:49:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 #include "NPFold.h"
0058
0059 #define WITH_SUBMETA 1
0060
0061 struct sreport
0062 {
0063 static constexpr const char* JUNCTURE = "SEvt__Init_RUN_META,SEvt__BeginOfRun,SEvt__EndOfRun,SEvt__Init_RUN_META" ;
0064 static constexpr const char* RANGES = R"(
0065 SEvt__Init_RUN_META:CSGFoundry__Load_HEAD ## init
0066 CSGFoundry__Load_HEAD:CSGFoundry__Load_TAIL ## load_geom
0067 CSGOptiX__Create_HEAD:CSGOptiX__Create_TAIL ## upload_geom
0068 A%0.3d_QSim__simulate_HEAD:A%0.3d_QSim__simulate_LBEG ## slice_genstep
0069 A%0.3d_QSim__simulate_PRUP:A%0.3d_QSim__simulate_PREL ## upload genstep slice
0070 A%0.3d_QSim__simulate_PREL:A%0.3d_QSim__simulate_POST ## simulate slice
0071 A%0.3d_QSim__simulate_POST:A%0.3d_QSim__simulate_DOWN ## download slice
0072 A%0.3d_QSim__simulate_LEND:A%0.3d_QSim__simulate_PCAT ## concat slices
0073 A%0.3d_QSim__simulate_BRES:A%0.3d_QSim__simulate_TAIL ## save arrays
0074 )" ;
0075
0076 bool VERBOSE ;
0077
0078 NP* run ;
0079 NP* runprof ;
0080 NP* ranges ;
0081
0082 NPFold* substamp ;
0083 NPFold* subprofile ;
0084 NPFold* submeta ;
0085 NPFold* submeta_NumPhotonCollected ;
0086 NPFold* subcount ;
0087
0088 sreport();
0089
0090 NPFold* serialize() const ;
0091 void import( const NPFold* fold );
0092 void save(const char* dir) const ;
0093 static sreport* Load(const char* dir) ;
0094
0095 std::string desc() const ;
0096 std::string desc_run() const ;
0097 std::string desc_runprof() const ;
0098 std::string desc_ranges() const ;
0099 std::string desc_substamp() const ;
0100 std::string desc_subprofile() const ;
0101 std::string desc_submeta() const ;
0102 std::string desc_subcount() const ;
0103 };
0104
0105 inline sreport::sreport()
0106 :
0107 VERBOSE(getenv("sreport__VERBOSE") != nullptr),
0108 run( nullptr ),
0109 runprof( nullptr ),
0110 ranges( nullptr ),
0111 substamp( nullptr),
0112 subprofile( nullptr ),
0113 submeta( nullptr ),
0114 submeta_NumPhotonCollected( nullptr ),
0115 subcount( nullptr )
0116 {
0117 }
0118 inline NPFold* sreport::serialize() const
0119 {
0120 NPFold* smry = new NPFold ;
0121 smry->add("run", run ) ;
0122 smry->add("runprof", runprof ) ;
0123 smry->add("ranges", ranges ) ;
0124 smry->add_subfold("substamp", substamp ) ;
0125 smry->add_subfold("subprofile", subprofile ) ;
0126 smry->add_subfold("submeta", submeta ) ;
0127 smry->add_subfold("submeta_NumPhotonCollected", submeta_NumPhotonCollected ) ;
0128 smry->add_subfold("subcount", subcount ) ;
0129 return smry ;
0130 }
0131 inline void sreport::import(const NPFold* smry)
0132 {
0133 run = smry->get("run")->copy() ;
0134 runprof = smry->get("runprof")->copy() ;
0135 ranges = smry->get("ranges")->copy() ;
0136 substamp = smry->get_subfold("substamp");
0137 subprofile = smry->get_subfold("subprofile");
0138 submeta = smry->get_subfold("submeta");
0139 submeta_NumPhotonCollected = smry->get_subfold("submeta_NumPhotonCollected");
0140 subcount = smry->get_subfold("subcount");
0141 }
0142 inline void sreport::save(const char* dir) const
0143 {
0144 NPFold* smry = serialize();
0145 smry->save_verbose(dir);
0146 }
0147 inline sreport* sreport::Load(const char* dir)
0148 {
0149 NPFold* smry = NPFold::Load(dir) ;
0150 sreport* report = new sreport ;
0151 report->import(smry) ;
0152 return report ;
0153 }
0154
0155 inline std::string sreport::desc() const
0156 {
0157 std::stringstream ss ;
0158 ss << "[sreport.desc" << std::endl
0159 << desc_run()
0160 << desc_runprof()
0161 << desc_ranges()
0162 << desc_substamp()
0163 << desc_submeta()
0164 << desc_subcount()
0165 << "]sreport.desc" << std::endl
0166 ;
0167 std::string str = ss.str() ;
0168 return str ;
0169 }
0170
0171 inline std::string sreport::desc_run() const
0172 {
0173 std::stringstream ss ;
0174 ss << "[sreport.desc_run (run is dummy small array used as somewhere to hang metadata) "
0175 << ( run ? run->sstr() : "-" )
0176 << "\n"
0177 << "[sreport.desc_run.descMetaKVS " << std::endl
0178 << ( run ? run->descMetaKVS(JUNCTURE, RANGES) : "-" ) << std::endl
0179 << "]sreport.desc_run.descMetaKVS " << std::endl
0180 << "]sreport.desc_run" << std::endl
0181 ;
0182 std::string str = ss.str() ;
0183 return str ;
0184 }
0185
0186
0187 inline std::string sreport::desc_runprof() const
0188 {
0189 std::stringstream ss ;
0190 ss << "[sreport.desc_runprof" << std::endl
0191 << ( runprof ? runprof->sstr() : "-" ) << std::endl
0192 << ".sreport.desc_runprof.descTable " << std::endl
0193 << ( runprof ? runprof->descTable<int64_t>(17) : "-" ) << std::endl
0194 << "]sreport.desc_runprof" << std::endl
0195 ;
0196 std::string str = ss.str() ;
0197 return str ;
0198 }
0199
0200 inline std::string sreport::desc_ranges() const
0201 {
0202 std::stringstream ss ;
0203 ss << "[sreport.desc_ranges"
0204 << " ranges : " << ( ranges ? ranges->sstr() : "-" ) << std::endl
0205 << ".sreport.desc_ranges.descTable "
0206 << " ( ta,tb : timestamps expressed as seconds from first timestamp, ab: (tb-ta) )"
0207 << "\n"
0208 << ( ranges ? ranges->descTable<int64_t>(17) : "-" ) << std::endl
0209 << "]sreport.desc_ranges" << std::endl
0210 ;
0211 std::string str = ss.str() ;
0212 return str ;
0213 }
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226 inline std::string sreport::desc_substamp() const
0227 {
0228 std::stringstream ss ;
0229 ss << "[sreport.desc_substamp" << std::endl
0230 ;
0231 if(VERBOSE) ss
0232 << "[sreport.desc_substamp.VERBOSE" << std::endl
0233 << ( substamp ? substamp->desc() : "-" )
0234 << "]sreport.desc_substamp.VERBOSE" << std::endl
0235 ;
0236
0237 ss << "[sreport.desc_substamp.compare_subarrays_report" << std::endl
0238 << ( substamp ? substamp->compare_subarrays_report<double, int64_t>( "delta_substamp", "a", "b" ) : "-" )
0239 << "]sreport.desc_substamp.compare_subarrays_report" << std::endl
0240 << "]sreport.desc_substamp" << std::endl
0241 ;
0242 std::string str = ss.str() ;
0243 return str ;
0244 }
0245
0246
0247 inline std::string sreport::desc_subprofile() const
0248 {
0249 std::stringstream ss ;
0250 ss << "[sreport.desc_subprofile" << std::endl
0251 ;
0252 if(VERBOSE) ss
0253 << "[sreport.desc_subprofile.VERBOSE" << std::endl
0254 << ( subprofile ? subprofile->desc() : "-" )
0255 << "]sreport.desc_subprofile.VERBOSE" << std::endl
0256 ;
0257
0258
0259
0260
0261
0262
0263
0264 ss
0265 << "]sreport.desc_subprofile" << std::endl
0266 ;
0267 std::string str = ss.str() ;
0268 return str ;
0269 }
0270
0271
0272 inline std::string sreport::desc_submeta() const
0273 {
0274 std::stringstream ss ;
0275 ss << "[sreport.desc_submeta" << std::endl
0276 << ( submeta ? submeta->desc() : "-" )
0277 << "]sreport.desc_submeta" << std::endl
0278 ;
0279 std::string str = ss.str() ;
0280 return str ;
0281 }
0282 inline std::string sreport::desc_subcount() const
0283 {
0284 std::stringstream ss ;
0285 ss << "[sreport.desc_subcount" << std::endl
0286 << ( subcount ? subcount->desc() : "-" )
0287 << "]sreport.desc_subcount" << std::endl
0288 ;
0289 std::string str = ss.str() ;
0290 return str ;
0291 }
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304 struct sreport_Creator
0305 {
0306 static constexpr const char* ASEL = "a://A" ;
0307 static constexpr const char* BSEL = "b://B" ;
0308
0309 bool VERBOSE ;
0310 const char* dirp ;
0311 NPFold* fold ;
0312 bool fold_valid ;
0313 const NP* run ;
0314 sreport* report ;
0315
0316 sreport_Creator( const char* dirp_ );
0317 void init();
0318 void init_SProf();
0319 void init_substamp();
0320 void init_subprofile();
0321 void init_submeta();
0322 void init_subcount();
0323
0324 std::string desc() const ;
0325 std::string desc_fold() const ;
0326 std::string desc_fold_detail() const ;
0327 std::string desc_run() const ;
0328 };
0329
0330 inline sreport_Creator::sreport_Creator( const char* dirp_ )
0331 :
0332 VERBOSE(getenv("sreport_Creator__VERBOSE") != nullptr),
0333 dirp(dirp_ ? strdup(dirp_) : nullptr),
0334 fold(NPFold::LoadNoData(dirp)),
0335 fold_valid(NPFold::IsValid(fold)),
0336 run(fold_valid ? fold->get("run") : nullptr),
0337 report(new sreport)
0338 {
0339 std::cout
0340 << "[sreport_Creator::sreport_Creator"
0341 << " fold_valid " << ( fold_valid ? "YES" : "NO " )
0342 << " run " << ( run ? "YES" : "NO " )
0343 << "\n"
0344 ;
0345 init();
0346 std::cout << "]sreport_Creator::sreport_Creator" << std::endl ;
0347 }
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360 inline void sreport_Creator::init()
0361 {
0362 std::cout << "[sreport_Creator::init\n" ;
0363
0364 init_SProf();
0365
0366 init_substamp();
0367 init_subprofile();
0368 init_submeta();
0369 init_subcount();
0370
0371 std::cout << "]sreport_Creator::init\n" ;
0372 }
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418 inline void sreport_Creator::init_SProf()
0419 {
0420 std::cout << "[sreport_Creator::init_SProf\n" ;
0421
0422 std::string meta = U::ReadString2_("SProf.txt");
0423
0424 report->runprof = NP::MakeMetaKVProfileArray(meta, "Index") ;
0425 std::cout << "-sreport_Creator::init.SProf:runprof :" << ( report->runprof ? report->runprof->sstr() : "-" ) << std::endl ;
0426
0427
0428 report->run = run ? run->copy() : nullptr ;
0429 std::cout << "-sreport_Creator::init_SProf.run :" << ( report->run ? report->run->sstr() : "-" ) << std::endl ;
0430
0431 report->ranges = run ? NP::MakeMetaKVS_ranges2( meta, sreport::RANGES ) : nullptr ;
0432 std::cout << "-sreport_Creator::init_SProf.ranges2 :" << ( report->ranges ? report->ranges->sstr() : "-" ) << std::endl ;
0433
0434 std::cout << "]sreport_Creator::init_SProf\n" ;
0435 }
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446 inline void sreport_Creator::init_substamp()
0447 {
0448 std::cout << "[sreport_Creator::init_substamp\n" ;
0449
0450 std::cout << "-sreport_Creator::init_substamp fold_valid " << ( fold_valid ? "Y" : "N" ) << std::endl ;
0451
0452 report->substamp = fold_valid ? fold->subfold_summary("substamp", ASEL, BSEL) : nullptr ;
0453 std::cout << "-sreport_Creator::init_substamp ((NPFold)report.substamp).stats [" << ( report->substamp ? report->substamp->stats() : "-" ) << "]\n" ;
0454
0455 std::cout << "]sreport_Creator::init_substamp\n" ;
0456 }
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466 inline void sreport_Creator::init_subprofile()
0467 {
0468 std::cout << "[sreport_Creator::init_subprofile\n" ;
0469 report->subprofile = fold_valid ? fold->subfold_summary("subprofile", ASEL, BSEL) : nullptr ;
0470 std::cout << "-sreport_Creator::init_subprofile :[" << ( report->subprofile ? report->subprofile->stats() : "-" ) << "]\n" ;
0471 std::cout << "]sreport_Creator::init_subprofile\n" ;
0472 }
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484 inline void sreport_Creator::init_submeta()
0485 {
0486 std::cout << "[sreport_Creator::init_submeta\n" ;
0487 #ifdef WITH_SUBMETA
0488 std::cout << "-sreport_Creator::init_submeta.WITH_SUBMETA\n" ;
0489
0490 report->submeta = fold_valid ? fold->subfold_summary("submeta", ASEL, BSEL) : nullptr ;
0491 std::cout << "-sreport_Creator::init_submeta :[" << ( report->submeta ? report->submeta->stats() : "-" ) << "]\n" ;
0492
0493 report->submeta_NumPhotonCollected = fold_valid ? fold->subfold_summary("submeta:NumPhotonCollected", ASEL, BSEL) : nullptr ;
0494 std::cout << "-sreport_Creator::init_submeta_NumPhotonCollected :[" << ( report->submeta_NumPhotonCollected ? report->submeta_NumPhotonCollected->stats() : "-" ) << "]\n" ;
0495
0496 #else
0497 std::cout << "-sreport_Creator::init_submeta.NOT:WITH_SUBMETA\n" ;
0498
0499 #endif
0500 std::cout << "]sreport_Creator::init_submeta\n" ;
0501 }
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511 inline void sreport_Creator::init_subcount()
0512 {
0513 std::cout << "[sreport_Creator::init_subcount\n" ;
0514 report->subcount = fold_valid ? fold->subfold_summary("subcount", ASEL, BSEL) : nullptr ;
0515 std::cout << "-sreport_Creator::init_subcount :[" << ( report->subcount ? report->subcount->stats() : "-" ) << "]\n" ;
0516 std::cout << "]sreport_Creator::init_subcount\n" ;
0517 }
0518
0519
0520 inline std::string sreport_Creator::desc() const
0521 {
0522 std::stringstream ss ;
0523 ss << "[sreport_Creator.desc" << std::endl
0524 << desc_fold()
0525 << ( VERBOSE ? desc_fold_detail() : "" )
0526 << ( VERBOSE ? desc_run() : "" )
0527 << "]sreport_Creator.desc" << std::endl
0528 ;
0529 std::string str = ss.str() ;
0530 return str ;
0531 }
0532
0533 inline std::string sreport_Creator::desc_fold() const
0534 {
0535 std::stringstream ss ;
0536 ss << "[sreport_Creator.desc_fold" << std::endl
0537 << "fold = NPFold::LoadNoData(\"" << dirp << "\")" << std::endl
0538 << "fold " << ( fold ? "YES" : "NO " ) << std::endl
0539 << "fold_valid " << ( fold_valid ? "YES" : "NO " ) << std::endl
0540 << "]sreport_Creator.desc_fold" << std::endl
0541 ;
0542 std::string str = ss.str() ;
0543 return str ;
0544 }
0545
0546 inline std::string sreport_Creator::desc_fold_detail() const
0547 {
0548 std::stringstream ss ;
0549 ss
0550 << "[sreport_Creator.desc_fold_detail " << std::endl
0551 << ( fold ? fold->desc() : "-" ) << std::endl
0552 << "]sreport_Creator.desc_fold_detail " << std::endl
0553 ;
0554 std::string str = ss.str() ;
0555 return str ;
0556 }
0557
0558 inline std::string sreport_Creator::desc_run() const
0559 {
0560 std::stringstream ss ;
0561 ss << "[sreport_Creator.desc_run" << std::endl
0562 << ( run ? run->sstr() : "-" ) << std::endl
0563 << ".sreport_Creator.desc_run.descMetaKVS " << std::endl
0564 << ( run ? run->descMetaKVS() : "-" ) << std::endl
0565 << "]sreport_Creator.desc_run" << std::endl
0566 ;
0567 std::string str = ss.str() ;
0568 return str ;
0569 }
0570
0571
0572
0573
0574 int main(int argc, char** argv)
0575 {
0576 char* argv0 = argv[0] ;
0577 const char* dirp = argc > 1 ? argv[1] : U::PWD() ;
0578 if(dirp == nullptr) return 0 ;
0579 bool is_executable_sibling_path = U::IsExecutableSiblingPath( argv0 , dirp ) ;
0580
0581 std::cout
0582 << "[sreport.main"
0583 << " argv0 " << ( argv0 ? argv0 : "-" )
0584 << " dirp " << ( dirp ? dirp : "-" )
0585 << " is_executable_sibling_path " << ( is_executable_sibling_path ? "YES" : "NO " )
0586 << std::endl
0587 ;
0588
0589 if( is_executable_sibling_path == false )
0590 {
0591 U::SetEnvDefaultExecutableSiblingPath("SREPORT_FOLD", argv0, dirp );
0592 std::cout << "[sreport.main : CREATING REPORT " << std::endl ;
0593
0594 std::cout << "[sreport.main : creator " << std::endl ;
0595 sreport_Creator creator(dirp);
0596 std::cout << "]sreport.main : creator " << std::endl ;
0597 std::cout << "[sreport.main : creator.desc " << std::endl ;
0598 std::cout << creator.desc() ;
0599 std::cout << "]sreport.main : creator.desc " << std::endl ;
0600 if(!creator.fold_valid) return 1 ;
0601
0602 sreport* report = creator.report ;
0603 std::cout << "[sreport.main : report.desc " << std::endl ;
0604 std::cout << report->desc() ;
0605 std::cout << "]sreport.main : report.desc " << std::endl ;
0606 report->save("$SREPORT_FOLD");
0607 std::cout << "]sreport.main : CREATED REPORT " << std::endl ;
0608
0609 if(getenv("CHECK") != nullptr )
0610 {
0611 std::cout << "[sreport.main : CHECK LOADED REPORT " << std::endl ;
0612 sreport* report2 = sreport::Load("$SREPORT_FOLD") ;
0613 std::cout << report2->desc() ;
0614 std::cout << "]sreport.main : CHECK LOADED REPORT " << std::endl ;
0615 }
0616
0617 }
0618 else
0619 {
0620 std::cout << "[sreport.main : LOADING REPORT " << std::endl ;
0621 sreport* report = sreport::Load(dirp) ;
0622 std::cout << report->desc() ;
0623 std::cout << "]sreport.main : LOADED REPORT " << std::endl ;
0624 }
0625
0626 std::cout
0627 << "]sreport.main"
0628 << std::endl
0629 ;
0630
0631 return 0 ;
0632 }
0633