Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 SSim.hh : Manages input arrays for QUDARap/QSim : Using NPFold plumbing
0004 ==================================================================================
0005 
0006 The SSim instance provides the input arrays to QSim
0007 which does the uploading to the device.
0008 Currently the SSim instance is persisted within CSGFoundry/SSim
0009 using NPFold functionality.
0010 
0011 Initially SSim might seem like an extraneous wrapper on top of stree.h
0012 but on listing features it is clear that the extra layer is worthwhile.
0013 
0014 1. SSim.hh singleton, so stree.h/U4Tree.h can stay headeronly
0015 2. collection of extra NPFold (eg jpmt) unrelated to stree.h
0016 3. switching between alternate array sources so QSim need not know those details
0017 
0018 SSim must be instanciated with SSim::Create prior to CSGFoundry::CSGFoundry
0019 Currently that is done from G4CXOpticks::G4CXOpticks
0020 
0021 
0022 **/
0023 
0024 struct NP ;
0025 struct NPFold ;
0026 struct SBnd ;
0027 struct SPrd ;
0028 struct stree ;
0029 struct SScene ;
0030 struct SPMT ;
0031 struct SBitSet ;
0032 
0033 #include <vector>
0034 #include <string>
0035 #include "plog/Severity.h"
0036 #include "SYSRAP_API_EXPORT.hh"
0037 #include "snam.h"
0038 #include "sframe.h"
0039 
0040 
0041 struct SYSRAP_API SSim
0042 {
0043     const char* relp ;
0044     NPFold*   top ;
0045     NPFold*   extra ;
0046     stree*    tree ;    // instanciated with SSim::SSim
0047     SScene*   scene ;
0048     int64_t   toploadtime ;
0049 
0050     static const plog::Severity LEVEL ;
0051     static const int stree_level ;
0052     static constexpr const char* RELDIR = "SSim" ;
0053     static constexpr const char* EXTRA = "extra" ;
0054     static constexpr const char* JPMT_RELP = "extra/jpmt" ;
0055     static constexpr const char* RELP_DEFAULT = "stree/standard" ;
0056 
0057     static SSim* INSTANCE ;
0058     static SSim* Get();
0059     static SSim* CreateOrReuse();
0060 
0061     static void  AddExtraSubfold(const char* k, const char* dir );
0062     static void  AddExtraSubfold(const char* k, NPFold* f);
0063 
0064     static int Compare( const SSim* a , const SSim* b ) ;
0065     static std::string DescCompare( const SSim* a , const SSim* b );
0066 
0067     static SSim* Create();
0068     static SSim* Load();
0069     static SSim* Load_(const char* dir);
0070     static SSim* Load(const char* base, const char* reldir=RELDIR );
0071 
0072 private:
0073     SSim();
0074     void init();
0075 public:
0076     static void AnnotateFrame( sframe& fr, const SBitSet* elv, const char* caller );
0077 
0078     stree* get_tree() const ;
0079     SScene* get_scene() const ;
0080     void set_override_scene(SScene* _scene);
0081     void initSceneFromTree();
0082 
0083 public:
0084     int lookup_mtline( int mtindex ) const ;
0085     std::string desc_mt() const ;
0086 public:
0087     // top NPFold must be populated with SSim::serialize
0088     // prior to these accessors working
0089     std::string desc() const ;
0090     std::string brief() const ;
0091 
0092     const NP* get(const char* k) const ;
0093     void      set(const char* k, const NP* a) ;
0094 
0095     const NP* get_bnd() const ;
0096     const char* getBndName(unsigned bidx) const ;
0097     int getBndIndex(const char* bname) const ;
0098     const SBnd* get_sbnd() const ;
0099     const SPrd* get_sprd() const ;
0100 
0101 
0102     const NPFold* get_jpmt_nocopy() const ;   // raw PMT info
0103     const NPFold* get_jpmt() const ;   // raw PMT info
0104     const SPMT*   get_spmt() const ;   // struct that summarizes PMT info
0105     const NPFold* get_spmt_f() const ; // fold with summarized PMT info
0106 public:
0107     void add_extra_subfold(const char* k, NPFold* f );
0108 
0109 public:
0110     void save(const char* base, const char* reldir=RELDIR) ;  // not const as may serialize
0111     void load(const char* base, const char* reldir=RELDIR) ;
0112     void load_(const char* dir);
0113     void afterLoadOrCreate();
0114     void serialize();
0115     bool hasTop() const ;
0116 
0117 
0118 public:
0119 
0120     /**
0121     TODO: MOST OF THE BELOW ARE DETAILS THAT ARE
0122     ONLY RELEVANT TO TEST GEOMETRIES HENCE THEY
0123     SHOULD BE RELOCATED ELSEWHERE, AND THE API
0124     UP HERE SLIMMED DOWN DRASTICALLY
0125     **/
0126 
0127     template<typename ... Args> void addFake( Args ... args );
0128     void addFake_( const std::vector<std::string>& specs );
0129 
0130     static void Add(
0131         NP** opticalplus,
0132         NP** bndplus,
0133         const NP* optical,
0134         const NP* bnd,
0135         const std::vector<std::string>& specs
0136         );
0137 
0138     static NP*  AddOptical(
0139         const NP* optical,
0140         const std::vector<std::string>& bnames,
0141         const std::vector<std::string>& specs
0142         ) ;
0143 
0144     static NP*  AddBoundary(
0145         const NP* src,
0146         const std::vector<std::string>& specs
0147         );
0148 
0149     static void GetPerfectValues(
0150         std::vector<float>& values,
0151         unsigned nk, unsigned nl, unsigned nm, const char* name
0152         );
0153 
0154     bool hasOptical() const ;
0155     std::string descOptical() const ;
0156     static std::string DescOptical(const NP* optical, const NP* bnd );
0157 
0158     static std::string GetItemDigest( const NP* bnd, int i, int j, int w );
0159     bool   findName( int& i, int& j, const char* qname ) const ;
0160 public:
0161     void set_extra(const char * k , const NP* f );
0162     const NP* get_extra(const char * k ) const;
0163     static void AddMultiFilm(const char* k, const NP* f);
0164 };
0165 
0166