Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 SEvt.hh
0004 =========
0005 
0006 TODO : prune useless/misleading statics,
0007        now that commonly have two active SEvt instances
0008        it is better to only use statics where really
0009        need to message all instances.
0010 
0011 
0012 TODO : lifecycle leak checking
0013 
0014 Q: Where is this instanciated canonically ?
0015 A: So far in G4CXOpticks::setGeometry and in the mains of lower level tests
0016 
0017 gather vs get
0018 -----------------
0019 
0020 Note the distinction in the names of accessors:
0021 
0022 *gather*
0023    resource intensive action done few times, that likely allocates memory,
0024    in the case of sibling class QEvt *gather* mostly includes downloading from device
0025    Care is needed in memory management of returned arrays to avoid leaking.
0026 
0027 *get*
0028    cheap action, done as many times as needed, returning a pointer to
0029    already allocated memory that is separately managed, eg within NPFold
0030 
0031 
0032 header-only INSTANCE problem
0033 ------------------------------
0034 
0035 Attempting to do this header only gives duplicate symbol for the SEvt::INSTANCE.
0036 It seems c++17 would allow "static inline SEvt* INSTANCE"  but c++17
0037 is problematic on laptop, so use separate header and implementation
0038 for simplicity.
0039 
0040 It is possible with c++11 but is non-intuitive
0041 
0042 * https://stackoverflow.com/questions/11709859/how-to-have-static-data-members-in-a-header-only-library
0043 
0044 HMM : Alt possibility for merging sgs label into genstep header
0045 ------------------------------------------------------------------
0046 
0047 gs vector of sgs provides summary of the full genstep,
0048 changing the first quad of the genstep to hold this summary info
0049 would avoid the need for the summary vector and mean the genstep
0050 index and photon offset info was available on device.
0051 Header of full genstep has plenty of spare bits to squeeze in
0052 index and photon offset in addition to  gentype/trackid/matline/numphotons
0053 
0054 **/
0055 
0056 #include <cassert>
0057 #include <vector>
0058 #include <string>
0059 #include <sstream>
0060 #include "plog/Severity.h"
0061 
0062 #include "scuda.h"
0063 #include "squad.h"
0064 #include "sphoton.h"
0065 #include "sphit.h"
0066 #include "sstate.h"
0067 #include "srec.h"
0068 #include "sseq.h"
0069 #include "stag.h"
0070 #include "sevent.h"
0071 #include "sctx.h"
0072 #include "sprof.h"
0073 
0074 #include "squad.h"
0075 
0076 
0077 
0078 //#define WITH_OLD_FRAME 1
0079 
0080 #ifdef WITH_OLD_FRAME
0081 #include "sframe.h"
0082 #else
0083 #include "sfr.h"
0084 #endif
0085 
0086 #include "sgs.h"
0087 #include "SComp.h"
0088 #include "SRandom.h"
0089 
0090 struct sphoton_selector ;
0091 struct sphotonlite_selector ;
0092 
0093 struct sdebug ;
0094 struct NP ;
0095 struct NPFold ;
0096 struct SGeo ;
0097 struct S4RandomArray ;
0098 struct stimer ;
0099 struct stree ;
0100 struct SSim ;
0101 
0102 #include "SYSRAP_API_EXPORT.hh"
0103 
0104 struct SYSRAP_API SEvt : public SCompProvider
0105 {
0106     friend struct SEvtTest ;
0107     static constexpr const int64_t M = 1000000 ;
0108     static constexpr const int64_t G = 1000000000 ;
0109     static constexpr const char* BLANK = "" ;
0110 
0111     static constexpr const char* SEvt__NPFOLD_VERBOSE = "SEvt__NPFOLD_VERBOSE" ;
0112     static bool NPFOLD_VERBOSE ;
0113 
0114     static constexpr const char* SEvt__GATHER = "SEvt__GATHER" ;
0115     static bool GATHER ;
0116 
0117     static constexpr const char* SEvt__SAVE = "SEvt__SAVE" ;
0118     static bool SAVE ;
0119 
0120     static constexpr const char* SEvt__INDEX = "SEvt__INDEX" ;
0121     static bool INDEX ;
0122 
0123     static constexpr const char* SEvt__LIFECYCLE = "SEvt__LIFECYCLE" ;
0124     static bool LIFECYCLE ;
0125 
0126     static constexpr const char* SEvt__FRAME = "SEvt__FRAME" ;
0127     static bool FRAME ;
0128 
0129     static constexpr const char* SEvt__MINIMAL = "SEvt__MINIMAL" ;
0130     static bool MINIMAL ;
0131 
0132     static constexpr const char* SEvt__MINTIME = "SEvt__MINTIME" ;
0133     static bool MINTIME ;
0134 
0135     static constexpr const char* SEvt__DIRECTORY = "SEvt__DIRECTORY" ;
0136     static bool DIRECTORY ;
0137 
0138 
0139 
0140     static constexpr const char* SEvt__CLEAR_SIGINT = "SEvt__CLEAR_SIGINT" ;
0141     static bool CLEAR_SIGINT ;
0142 
0143     static constexpr const char* SEvt__SIMTRACE = "SEvt__SIMTRACE" ;
0144     static bool SIMTRACE ;
0145 
0146     static constexpr const char* SEvt__EPH = "SEvt__EPH" ;
0147     static bool EPH_ ;
0148 
0149     static constexpr const char* SEvt__RUNMETA = "SEvt__RUNMETA" ;
0150     static bool RUNMETA ;
0151 
0152 
0153     static constexpr const char* SEvt__SAVE_NOTHING = "SEvt__SAVE_NOTHING" ;
0154     static bool SAVE_NOTHING ;
0155 
0156     static constexpr const char* SEvt__SAVE_RUNDIR = "SEvt__SAVE_RUNDIR" ;
0157     static bool SAVE_RUNDIR ;
0158 
0159 
0160 
0161 
0162     enum { SEvt__SEvt,
0163            SEvt__init,
0164            SEvt__beginOfEvent,
0165            SEvt__endOfEvent,
0166            SEvt__gather,
0167            SEvt__clear_output,
0168            SEvt__clear_genstep,
0169            SEvt__OTHER
0170            } ;
0171 
0172     static constexpr const char* SEvt__SEvt_ = "SEvt__SEvt" ;
0173     static constexpr const char* SEvt__init_ = "SEvt__init" ;
0174     static constexpr const char* SEvt__beginOfEvent_ = "SEvt__beginOfEvent" ;
0175     static constexpr const char* SEvt__endOfEvent_ = "SEvt__endOfEvent" ;
0176     static constexpr const char* SEvt__gather_ = "SEvt__gather" ;
0177     static constexpr const char* SEvt__clear_output_ = "SEvt__clear_output" ;
0178     static constexpr const char* SEvt__OTHER_ = "SEvt__OTHER" ;
0179 
0180     const char* descStage() const ;
0181     void setStage(int stage_);
0182     int  getStage() const ;
0183 
0184 
0185     void* async_handle = nullptr;
0186 
0187     int cfgrc ;
0188 
0189     int index ;
0190     int instance ;
0191     int stage ;
0192     int gather_metadata_notopfold ;
0193 
0194     sprof p_SEvt__beginOfEvent_0 ;
0195     sprof p_SEvt__beginOfEvent_1 ;
0196     sprof p_SEvt__endOfEvent_0 ;
0197     //sprof p_SEvt__endOfEvent_1 ;
0198 
0199     uint64_t t_BeginOfEvent ;
0200 #ifndef PRODUCTION
0201     uint64_t t_setGenstep_0 ;
0202     uint64_t t_setGenstep_1 ;
0203     uint64_t t_setGenstep_2 ;
0204     uint64_t t_setGenstep_3 ;
0205     uint64_t t_setGenstep_4 ;
0206     uint64_t t_setGenstep_5 ;
0207     uint64_t t_setGenstep_6 ;
0208     uint64_t t_setGenstep_7 ;
0209     uint64_t t_setGenstep_8 ;
0210 #endif
0211     uint64_t t_PreLaunch ;
0212     uint64_t t_PostLaunch ;
0213     uint64_t t_EndOfEvent ;
0214 
0215     uint64_t t_PenultimatePoint ;
0216     uint64_t t_LastPoint ;
0217 
0218     double   t_Launch ;
0219 
0220     sphoton_selector*     photon_selector ;
0221     sphotonlite_selector* photonlite_selector ;
0222 
0223     sevent* evt ;
0224     sdebug* dbg ;
0225     std::string meta ;
0226 
0227     NP* input_genstep ;
0228     NP* input_photon ;
0229     NP* input_photon_transformed ;
0230     NP* g4state ;    // populated by U4Engine::SaveStatus
0231 
0232     const SRandom*        random ;
0233     S4RandomArray*        random_array ;
0234     // random_array
0235     //      low-dep random consumption debug, usage needs Geant4
0236     //      but its useful to have somewhere to hang it
0237 
0238     const SCompProvider*  provider ;
0239     NPFold*               topfold ;
0240     NPFold*               fold ;
0241     NPFold*               extrafold ;
0242 
0243     const SGeo*           cf ;
0244     const SSim*           sim ;
0245     const stree*          tree ;
0246 
0247     bool              hostside_running_resize_done ; // only ever becomes true for non-GPU running
0248     bool              gather_done ;
0249     bool              is_loaded ;
0250     bool              is_loadfail ;
0251 
0252 #ifdef WITH_OLD_FRAME
0253     sframe            frame = {};
0254 #else
0255     sfr               fr = {} ;
0256 #endif
0257 
0258 
0259     // comp vectors are populated from SEventConfig in SEvt::init
0260     std::vector<unsigned> gather_comp ;
0261     std::vector<unsigned> save_comp ;
0262 
0263     int64_t           numgenstep_collected ;   // updated by addGenstep
0264     int64_t           numphoton_collected ;    // updated by addGenstep
0265     int64_t           numphoton_genstep_max ;  // maximum photons in a genstep since last SEvt::clear_genstep_vector
0266 
0267     int                clear_genstep_vector_count ;
0268     int                clear_output_vector_count ;
0269 
0270     // moved here from G4CXOpticks, updated in gather
0271     unsigned gather_total ;
0272     unsigned genstep_total ;
0273     unsigned photon_total ;
0274     unsigned hit_total ;
0275     unsigned addGenstep_array ;
0276 
0277 
0278     // [--- these vectors are cleared by SEvt::clear_genstep_vector
0279     std::vector<quad6>   genstep ;
0280     std::vector<sgs>     gs ;
0281     // ]
0282 
0283     // [--- these vectors are cleared by SEvt::clear_output_vector
0284     std::vector<spho>    pho ;   // spho are label structs holding 4*int
0285     std::vector<int>     slot ;
0286     std::vector<sphoton> photon ;
0287     std::vector<sphoton> record ;
0288     std::vector<srec>    rec ;
0289     std::vector<sseq>    seq ;
0290     std::vector<quad2>   prd ;
0291     std::vector<stag>    tag ;
0292     std::vector<sflat>   flat ;
0293     std::vector<quad4>   simtrace ;
0294     std::vector<quad4>   aux ;
0295     std::vector<quad6>   sup ;
0296     // ]---- these vectors are cleared by SEvt::clear_output_vector
0297 
0298 
0299     // current_* are saved into the vectors on calling SEvt::pointPhoton
0300     spho    current_pho = {} ;
0301     quad2   current_prd = {} ;
0302     sctx    current_ctx = {};
0303 
0304 
0305     static constexpr const int64_t UNDEF = ~0u ;
0306     static bool IsDefined(unsigned val);
0307 
0308     static stimer* TIMER ;
0309     static void   TimerStart();
0310     static double TimerDone();
0311     static uint64_t TimerStartCount();
0312     static std::string TimerDesc();
0313 
0314 
0315     static NP* Init_RUN_META();
0316     static NP* RUN_META ;
0317     static std::string* RunMetaString();
0318 
0319 
0320     static NP* UU ;
0321     static NP* UU_BURN ;
0322     static const plog::Severity LEVEL ;
0323     static const int GIDX ;
0324     static const int PIDX ;
0325     static const int MISSING_INDEX ;
0326     static const int MISSING_INSTANCE ;
0327     static const int DEBUG_CLEAR ;
0328 
0329     //static SEvt* INSTANCE ;
0330     enum { MAX_INSTANCE = 2 } ;
0331     enum { EGPU, ECPU };
0332     static std::array<SEvt*, MAX_INSTANCE> INSTANCES ;
0333     static std::string DescINSTANCE();
0334 
0335 private:
0336 
0337     SEvt();
0338     void init();
0339 public:
0340     void setFoldVerbose(bool v);
0341 
0342     static const char* GetSaveDir(int idx) ;
0343     const char* getSaveDir() const ;
0344     const char* getLoadDir() const ;
0345     int getTotalItems() const ;
0346 
0347     static constexpr const char* SearchCFBase_RELF = "CSGFoundry/solid.npy" ;
0348     const char* getSearchCFBase() const ;
0349 
0350 
0351     static const char* INPUT_GENSTEP_DIR ;
0352     static const char* INPUT_PHOTON_DIR ;
0353     static const char* ResolveInputArray(const char* spec, const char* dir) ;
0354     static NP* LoadInputArray(const char* path) ;
0355 
0356     static NP* LoadInputGenstep_array(int idx);
0357     static NP* LoadInputGenstep_array(const char* spec);
0358 
0359     static NP* LoadInputPhoton();
0360     static NP* LoadInputPhoton(const char* spec);
0361     static bool IsInputPhotonRecord(   const char* spec );
0362     static NP* LoadInputPhoton_photon( const char* spec);
0363     static NP* LoadInputPhoton_record( const char* spec);
0364 
0365 
0366     // NB these _array methods are lower level than createInputGenstep_configured
0367     void initInputGenstep_array();
0368     void setInputGenstep_array(NP* g);
0369     NP* getInputGenstep_array() const ;
0370     bool hasInputGenstep_array() const ;
0371     bool hasInputGenstep_arrayPath() const ;
0372 
0373 
0374     void initInputPhoton();
0375     void setInputPhoton(NP* p);
0376 
0377     NP* getInputPhoton_() const ;
0378     bool hasInputPhoton() const ;
0379     NP* getInputPhoton() const ;    // returns input_photon_transformed when exists
0380     bool hasInputPhotonTransformed() const ;
0381 
0382 
0383 
0384     NP* gatherInputGenstep() const ;   // returns a copy of the input genstep array
0385     NP* gatherInputPhoton() const ;   // returns a copy of the input photon array
0386 
0387 
0388 
0389 
0390 
0391 
0392 
0393     void initG4State() ;
0394     NP* makeG4State() const ;
0395     void setG4State(NP* state) ;
0396     NP* gatherG4State() const ;
0397     const NP* getG4State() const ;
0398 
0399 
0400 
0401 #ifdef WITH_OLD_FRAME
0402     void setFrame(const sframe& fr );
0403 #else
0404     void setFr(const sfr& _fr );
0405 #endif
0406     void setFramePlaceholder();
0407 
0408     static const bool transformInputPhoton_VERBOSE ;
0409     static const bool transformInputPhoton_WIDE ;
0410     void transformInputPhoton();
0411 
0412 
0413     NP* createInputGenstep_simtrace();
0414     NP* createInputGenstep_simulate();
0415     NP* createInputGenstep_configured();
0416     void addInputGenstep();
0417 
0418     void assertZeroGenstep();
0419 
0420 
0421     const char* getFrameId() const ;
0422     const NP*   getFrameArray() const ;
0423     static const char* GetFrameId(int idx) ;
0424     static const NP*   GetFrameArray(int idx) ;
0425 
0426     void setFrame_HostsideSimtrace() ;
0427 
0428 #ifdef WITH_OLD_FRAME
0429     void setGeo(const SGeo* cf);
0430 #else
0431     void setSim(const SSim* sim);
0432 #endif
0433     void setFrame(unsigned ins_idx);
0434 
0435     //// below decl order matches impl order : KEEP IT THAT WAY
0436 
0437 
0438     static SEvt* CreateSimtraceEvent();
0439 
0440 
0441     void setCompProvider(const SCompProvider* provider);
0442     bool isSelfProvider() const ;
0443     std::string descProvider() const ;
0444 
0445 
0446     NP* gatherDomain() const ;
0447 
0448     static int  Count() ;
0449     static SEvt* Get_EGPU() ;
0450     static SEvt* Get_ECPU() ;
0451     static SEvt* Get(int idx) ;
0452     static void Set(int idx, SEvt* inst);
0453 
0454     static SEvt* Create_EGPU() ;
0455     static SEvt* Create_ECPU() ;
0456     static SEvt* Create(int idx) ;
0457     static SEvt* CreateOrReuse(int idx) ;
0458 
0459     static SEvt* CreateOrReuse_EGPU();
0460     static SEvt* CreateOrReuse_ECPU();
0461     static void CreateOrReuse();
0462 #ifdef WITH_OLD_FRAME
0463     static void SetFrame(const sframe& fr );
0464 #else
0465     static void SetFr(   const sfr& fr );
0466 #endif
0467 
0468 
0469     bool isEGPU() const ;
0470     bool isECPU() const ;
0471     bool isFirstEvtInstance() const ;  // within the event
0472     bool isLastEvtInstance() const ;   // within the event
0473 
0474     SEvt* getSibling() const ;
0475 
0476 
0477     static bool Exists(int idx);
0478     static bool Exists_ECPU();
0479     static bool Exists_EGPU();
0480     static void Check(int idx);
0481 
0482 #ifndef PRODUCTION
0483     static void AddTag(int idx, unsigned stack, float u );
0484     static int  GetTagSlot(int idx);
0485 #endif
0486 
0487     static sgs AddGenstep(const quad6& q);
0488     static sgs AddGenstep(const NP* a);
0489     static void AddCarrierGenstep();
0490     static void AddTorchGenstep();
0491     void addTorchGenstep();
0492 
0493     static SEvt* LoadAbsolute(const char* dir);
0494     static SEvt* LoadRelative(const char* rel=nullptr, int ins=0, int idx=-1);
0495 
0496     static void ClearOutput();
0497     static void ClearGenstep();
0498     static void Save() ;
0499     //static void SaveExtra(const char* name, const NP* a) ;
0500 
0501     static void Save(const char* bas, const char* rel );
0502     static void Save(const char* dir);
0503     static bool HaveDistinctOutputDirs();
0504 
0505 
0506     static void SaveGenstepLabels(const char* dir, const char* name="gsl.npy");
0507 
0508     static void BeginOfRun();
0509     static void EndOfRun();
0510     //static const int EndOfRun_SProf ;
0511 
0512 
0513     template<typename T>
0514     static void SetRunMeta(const char* k, T v );
0515 
0516     static void SetRunMetaString(const char* k, const char* v );
0517 
0518     //static void SetRunProf(const char* k, const sprof& v);
0519     //static void SetRunProf(const char* k);  // NOW
0520     //void setRunProf_Annotated(const char* hdr) const  ;
0521 
0522     static bool IsSaveNothing();
0523     static void SaveRunMeta(const char* base=nullptr );
0524 
0525 
0526     void setMetaString(const char* k, const char* v);
0527     void setMetaProf(  const char* k, const sprof& v);
0528     void setMetaProf(  const char* k) ;
0529 
0530     template<typename T>
0531     void setMeta( const char* k, T v );
0532 
0533 
0534     void beginOfEvent(int eventID);
0535     void endOfEvent(int eventID);
0536     void reset_counter();
0537 
0538     void endMeta();
0539 
0540 
0541     static bool IndexPermitted(int index);   // index is 1-based
0542     static int  GetIndex(int idx);
0543     static S4RandomArray* GetRandomArray(int idx);
0544 
0545 
0546     // MOVED TO SEventConfig::EventReldir
0547     //static const char*  DEFAULT_RELDIR ;
0548     //static const char* RELDIR ;
0549     //static void SetReldir(const char* reldir);
0550     //static const char* GetReldir();
0551 
0552 
0553     static int64_t GetNumPhotonCollected(int idx);
0554     static int64_t GetNumPhotonGenstepMax(int idx);
0555     static int64_t GetNumPhotonFromGenstep(int idx);
0556     static int64_t GetNumGenstepFromGenstep(int idx);
0557     static int64_t GetNumHit(int idx) ;
0558     static int64_t GetNumHit_EGPU() ;
0559     static int64_t GetNumHit_ECPU() ;
0560 
0561 
0562     static NP* GatherGenstep(int idx);
0563     static NP* GetInputPhoton(int idx);
0564     static void SetInputPhoton(NP* ip);
0565     static bool HasInputPhoton(int idx);
0566 
0567     static bool HasInputPhoton();
0568     static NP* GetInputPhoton();
0569     static std::string DescHasInputPhoton();
0570 
0571 private:
0572     void clear_genstep_vector() ;
0573     void clear_output_vector() ;
0574 public:
0575     void clear_genstep() ;
0576     void clear_output() ;
0577     void clear_extra() ;
0578 
0579     void setIndex(int index_arg) ;
0580     void endIndex(int index_arg) ;
0581     int  getIndexArg() const ;
0582     int  getIndex() const ;
0583     int  getIndexPresentation() const ;
0584     std::string descIndex() const ;
0585 
0586     void incrementIndex() ;
0587     void unsetIndex() ;
0588 
0589     void setInstance(int instance);
0590     int getInstance() const ;
0591 
0592 
0593     int64_t getNumGenstepFromGenstep() const ; // number of collected gensteps from size of collected gensteps vector
0594     int64_t getNumPhotonFromGenstep() const ;  // total photons since last clear from looping over collected gensteps
0595     int64_t getNumGenstepCollected() const ;   // total collected genstep since last clear
0596     int64_t getNumPhotonCollected() const ;    // total collected photons since last clear
0597     int64_t getNumPhotonGenstepMax() const ;   // max photon in genstep since last clear
0598 
0599     static constexpr const unsigned G4_INDEX_OFFSET = 1000000 ;
0600     sgs addGenstep(const NP* a) ;
0601     sgs addGenstep(const quad6& q) ;
0602 
0603     void setNumPhoton(size_t num_photon);
0604     void setNumSimtrace(size_t num_simtrace);
0605     void hostside_running_resize();
0606     void hostside_running_resize_();
0607 
0608     const sgs& get_gs(const spho& label) const ; // lookup genstep label from photon label
0609     unsigned get_genflag(const spho& label) const ;
0610 
0611     void beginPhoton(const spho& sp);
0612     unsigned getCurrentPhotonIdx() const ;
0613 
0614     void resumePhoton(const spho& sp);  // FastSim->SlowSim resume
0615     void rjoin_resumePhoton(const spho& label); // reemission rjoin AND FastSim->SlowSim resume
0616     void rjoinPhoton(const spho& sp);   // reemission rjoin
0617 
0618 
0619     void rjoinRecordCheck(const sphoton& rj, const sphoton& ph  ) const ;
0620     static void ComparePhotonDump(const sphoton& a, const sphoton& b );
0621     void rjoinPhotonCheck(const sphoton& ph) const ;
0622     void rjoinSeqCheck(unsigned seq_flag) const ;
0623 
0624     void pointPhoton(const spho& sp);
0625 
0626     static bool PIDX_ENABLED ;
0627 
0628 #ifndef PRODUCTION
0629     void addTag(unsigned tag, float u);
0630     int getTagSlot() const ;
0631 #endif
0632 
0633     void     finalPhoton(const spho& sp);
0634 
0635     static void AddProcessHitsStamp(int idx, int p);
0636     void addProcessHitsStamp(int p) ;
0637 
0638     void checkPhotonLineage(const spho& sp) const ;
0639 
0640 ////////////////////////////////////////////////////////////////////////////////////////////
0641 ////////////////////////////////////////////////////////////////////////////////////////////
0642 ///////// below methods handle gathering arrays and persisting, not array content //////////
0643 ////////////////////////////////////////////////////////////////////////////////////////////
0644 ////////////////////////////////////////////////////////////////////////////////////////////
0645 
0646     NP* gatherPho0() const ;   // unordered push_back as they come
0647     NP* gatherPho() const ;    // resized at genstep and slotted in
0648     NP* gatherGS() const ;   // genstep labels from std::vector<sgs>
0649 
0650     NP*    gatherGenstep() const ;  // from genstep vector
0651     quad6* getGenstepVecData() const ;
0652     int    getGenstepVecSize() const ;
0653     NP*    makeGenstepArrayFromVector() const ;   // formerly misnamed getGenstepArray
0654     std::string descGenstepArrayFromVector() const;
0655 
0656 
0657     bool haveGenstepVec() const ;
0658 
0659 
0660     NP* gatherPhoton() const ;
0661     NP* gatherRecord() const ;
0662     NP* gatherRec() const ;
0663     NP* gatherAux() const ;
0664     NP* gatherSup() const ;
0665     NP* gatherSeq() const ;
0666     NP* gatherPrd() const ;
0667     NP* gatherTag() const ;
0668     NP* gatherFlat() const ;
0669     NP* gatherSeed() const ;
0670     NP* gatherHit() const ;
0671     NP* gatherHitLite() const ;
0672     NP* gatherSimtrace() const ;
0673 
0674 
0675     NP* makePhoton() const ;
0676     NP* makePhotonLite() const ;
0677 
0678     NP* makeRecord() const ;
0679     NP* makeRec() const ;
0680     NP* makeAux() const ;
0681     NP* makeSup() const ;
0682     NP* makeSeq() const ;
0683     NP* makePrd() const ;
0684     NP* makeTag() const ;
0685     NP* makeFlat() const ;
0686     NP* makeSimtrace() const ;
0687 
0688 
0689     static constexpr const char* TYPENAME = "SEvt" ;
0690 
0691     //[ SCompProvider methods
0692     std::string getMeta() const ;
0693     const char* getTypeName() const ;
0694     NP* gatherComponent(unsigned comp) const ;
0695     //] SCompProvider methods
0696 
0697 
0698     NP* gatherComponent_(unsigned comp) const ;
0699 
0700     void saveGenstep(const char* dir) const ;
0701     void saveGenstepLabels(const char* dir, const char* name="gsl.npy") const ;
0702 
0703     std::string descGS() const ;
0704     std::string descDir() const ;
0705     std::string descFold() const ;
0706     static std::string Brief() ;
0707     std::string brief() const ;
0708     std::string id() const ;
0709 
0710     std::string desc() const ;
0711     std::string descDbg() const ;
0712 
0713     void gather_components();
0714     void gather_metadata();
0715     void gather() ;           // with on device running this downloads
0716 
0717     // add extra metadata arrays to be saved within SEvt fold
0718     void add_array( const char* k, const NP* a );
0719     void addEventConfigArray() ;
0720     void addProcessHits_EPH(NP* eph_meta);
0721 
0722 
0723 
0724     int  load() ;
0725 
0726 
0727 
0728     bool hasIndex() const ;
0729     bool hasInstance() const ;
0730 
0731 
0732     static const char* DefaultBase(const char* base_=nullptr) ;
0733     static const char* RunDir( const char* base_=nullptr );
0734     const char* getDir(const char* base_=nullptr) const ;
0735 
0736     char getInstancePrefix() const ;
0737     std::string getIndexString_(const char* hdr) const ;
0738     const char* getIndexString(const char* hdr) const ;
0739 
0740 
0741     std::string descSaveDir(const char* dir_) const ;
0742 
0743     int  load(const char* dir);
0744     int  loadfold( const char* dir );
0745     void onload();
0746 
0747     // save methods not const as call gather
0748     void save(const char* base, const char* reldir1, const char* reldir2 );
0749     void save(const char* base, const char* reldir );
0750     void save() ;
0751     void save(const char* dir);
0752 
0753 
0754     void saveExtra( const char* name, const NP* a ) const ;
0755     void saveExtra( const char* base, const char* name, const NP* a ) const ;
0756 
0757     void saveFrame(const char* dir_) const ;
0758 
0759     std::string descComponent() const ;
0760     static std::string DescComponent(const NPFold* f);
0761 
0762     std::string descComp() const ;
0763     std::string descVec() const ;
0764 
0765     const NP* getGenstep() const ;
0766 
0767     const NP* getPhoton() const ; // uses SEventConfig::PhotonCompOneName depending on ModeLite ModeMerge
0768     size_t    getNumPhoton() const ;
0769     const NP* getHit() const ;    // uses SEventConfig::HitCompOneName    depending on ModeLite ModeMerge
0770     size_t    getNumHit() const ;
0771 
0772 
0773     const NP* getAux() const ;
0774     const NP* getSup() const ;
0775     const NP* getPho() const ;
0776     const NP* getGS() const ;
0777 
0778     std::string descSimulate() const ;
0779     std::string getCounts() const ;
0780 
0781 
0782 
0783     void getPhoton(sphoton& p, unsigned idx) const ;
0784     void getHit(   sphoton& p, unsigned idx) const ;
0785 
0786     void getLocalPhoton(  sphoton& p, unsigned idx) const ;
0787     void getLocalHit_LEAKY( sphit& ht, sphoton& p, unsigned idx) const ;
0788     void getLocalHit(       sphit& ht, sphoton& p, unsigned idx) const ;
0789     void localize_photon_inplace( sphoton& p ) const ;
0790 
0791 
0792     NP*  localize_photon(const NP* hit, bool consistency_check) const ;
0793 
0794 #ifdef WITH_OLD_FRAME
0795     void getPhotonFrame( sframe& fr, const sphoton& p ) const ;
0796 #else
0797     void getPhotonFrame( sfr& fr, const sphoton& p ) const ;
0798 #endif
0799 
0800     std::string descNum() const ;
0801     std::string descPhoton(unsigned max_print=10) const ;
0802     std::string descLocalPhoton(unsigned max_print=10) const ;
0803     std::string descFramePhoton(unsigned max_print=10) const ;
0804 
0805 
0806     std::string descInputGenstep() const ;
0807     std::string descInputPhoton() const ;
0808 
0809     static std::string DescInputGenstep(int idx) ;
0810     static std::string DescInputPhoton(int idx) ;
0811 
0812     std::string descFull(unsigned max_print=10) const ;
0813 
0814     void getFramePhoton(sphoton& p, unsigned idx) const ;
0815     void getFrameHit(   sphoton& p, unsigned idx) const ;
0816     void applyFrameTransform(sphoton& lp) const ;
0817 
0818     static NP* CountNibbles( const NP* seq );
0819     static NP* CountNibbles_Table( const NP* seqnib );
0820 
0821 };
0822