Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:32

0001     CSGOptiXSimtraceTest_OUTPUT_DIR = os.environ.get("CSGOptiXSimtraceTest_OUTPUT_DIR", None) 
0002     if CSGOptiXSimtraceTest_OUTPUT_DIR is None:
0003         log.fatal(" missing required envvar CSGOptiXSimtraceTest_OUTPUT_DIR ")
0004         sys.exit(1)
0005     pass
0006 
0007     CSGFoundry_DIR = CSGFoundry.FindDirUpTree( CSGOptiXSimtraceTest_OUTPUT_DIR, "CSGFoundry" )
0008 
0009     FOLD = os.path.dirname(CSGFoundry_DIR)
0010 
0011     LEAF = os.environ.get("LEAF", None)   ## LEAF is used to hop between geometries in sibling dirs 
0012 
0013 
0014     print( " CSGOptiXSimtraceTest_OUTPUT_DIR : %s " % CSGOptiXSimtraceTest_OUTPUT_DIR )
0015     print( " LEAF                            : %s " % LEAF )
0016     print( " CSGFoundry_DIR                  : %s " % CSGFoundry_DIR  )
0017     print( " FOLD                            : %s " % FOLD  )
0018 
0019     outdir = CSGOptiXSimtraceTest_OUTPUT_DIR 
0020     outbase = os.path.dirname(outdir)
0021     outleaf = os.path.basename(outdir)
0022     outgeom = outleaf.split("_")[0]  
0023 
0024     outdir2 = os.path.join(outbase, outleaf)  
0025     assert outdir == outdir2 
0026     print( " outleaf                         : %s " % outleaf )
0027 
0028     leaves = list(filter(lambda _:_.startswith(outleaf[:10]),os.listdir(outbase)))
0029     print("\n".join(leaves))
0030 
0031     if not LEAF is None and LEAF != outleaf:
0032         leafgeom = LEAF.split("_")[0]
0033         altdir = outdir.replace(outgeom,leafgeom).replace(outleaf,LEAF)
0034         if os.path.isdir(altdir):
0035             outdir = altdir
0036             print(" OVERRIDE CSGOptiXSimtraceTest_OUTPUT_DIR VIA LEAF envvar %s " % LEAF )
0037             print( " CSGOptiXSimtraceTest_OUTPUT_DIR : %s " % outdir )
0038         else:
0039             print("FAILED to override CSGOptiXSimtraceTest_OUTPUT_DIR VIA LEAF envvar %s " % LEAF )
0040         pass
0041     pass
0042 
0043 
0044 
0045 def copyref( l, g, s, kps ):
0046     """
0047     Copy selected references between scopes::
0048         
0049         copyref( locals(), globals(), self, "bnd,ubnd" )
0050 
0051     :param l: locals() 
0052     :param g: globals() or None
0053     :param s: self or None
0054     :param kps: space delimited string identifying quantities to be copied
0055 
0056     The advantage with using this is that can benefit from developing 
0057     fresh code directly into classes whilst broadcasting the locals from the 
0058     classes into globals for easy debugging. 
0059     """
0060     for k,v in l.items():
0061         kmatch = np.any(np.array([k.startswith(kp) for kp in kps.split()]))
0062         if kmatch:
0063             if not g is None: g[k] = v
0064             if not s is None: setattr(s, k, v )
0065             print(k)
0066         pass
0067     pass
0068 
0069 
0070 def fromself( l, s, kk ):
0071     # nope seems cannot update locals() like this
0072     # possibly generate some simple code and eval it is a workaround 
0073     for k in kk.split(): 
0074         log.info(k)
0075         l[k] = getattr(s, k)
0076     pass
0077 
0078 
0079 def shorten_bname(bname):
0080     elem = bname.split("/")
0081     if len(elem) == 4:
0082         omat,osur,isur,imat = elem
0083         bn = "/".join([omat,osur[:3],isur[:3],imat])
0084     else:
0085         bn = bname
0086     pass 
0087     return bn
0088 
0089 
0090