Package iceprod :: Package core :: Module py3
[hide private]
[frames] | no frames]

Source Code for Module iceprod.core.py3

  1  #   copyright  (c) 2008 
  2  #   the icecube collaboration 
  3  # 
  4  #   @author Juan Carlos Diaz Velez 
  5  # 
  6  #   Extension of the I3Tray module implemented by Troy D. Straszheim 
  7  import logging,sys,os 
  8  logger = logging.getLogger('py3') 
  9   
 10  # need to import this since we need access to i3units functions 
 11  logger.info("loading icecube.icetray") 
 12  try: 
 13    import icecube.icetray as icetray 
 14    from icecube.icetray import * 
 15  except: 
 16    logger.warn("icecube.icetray not found") 
 17    logger.info("loading icetray") 
 18    try: # This is to account for the case in which icetray.so is not in icecube 
 19       import icetray  
 20       from icetray import * 
 21    except: 
 22       logger.warn("icetray not found") 
 23       logger.info("loading ithon") 
 24       try: # old-style ithon 
 25          import ithon as icetray 
 26          from ithon import * 
 27       except:  
 28          logger.warn("ithon not found") 
 29          logger.info("loading libithon") 
 30          try: # really old libithon 
 31            import libithon as icetray 
 32            from libithon import * 
 33          except:  
 34            logger.fatal("!!!!Could not load icetray environment!!! Aborting.") 
 35            sys.exit(2) 
 36   
 37   
 38  # manually create a global symbol 'NaN' 
 39  NaN = float('NaN') 
 40  Inf = float('inf') 
 41   
42 -def load(filename):
43 try: 44 icetray.load(filename) 45 except: 46 print """\n***\n*** Failed to load library. (%s)\n*** %s\n***\n""" % (sys.exc_info()[0], sys.exc_info()[1]) 47 sys.exit(1)
48
49 -def OMKey(string,omnum):
50 return icetray.OMKey(string,omnum)
51
52 -class I3Tray:
53 - def __init__(self):
54 self.last_added = None 55 self.the_tray = icetray.I3Tray()
56
57 - def AddModule(self, type, name):
58 self.the_tray.AddModule(type, name) 59 self.last_added = name 60 return self
61
62 - def AddService(self, type, name):
63 self.the_tray.AddService(type, name) 64 self.last_added = name 65 return self
66
67 - def SetParameter(self, module, param, value):
68 self.the_tray.SetParameter(module, param, value) 69 return self
70
71 - def ConnectBoxes(self, *args):
72 if len(args) == 4: 73 self.the_tray.ConnectBoxes(args[0], args[1], args[2], args[3]) 74 elif len(args) == 3: 75 self.the_tray.ConnectBoxes(args[0], args[1], args[2]) 76 else: 77 print 'Wrong number of arguments', len(args), 'to ConnectBoxes'
78
79 - def __call__(self, *args):
80 for pair in args: 81 print self.last_added +': ', pair[0], '=', pair[1] 82 self.the_tray.SetParameter(self.last_added, pair[0], pair[1]) 83 return self
84
85 - def Execute(*args):
86 if len(args) == 2: 87 args[0].the_tray.Execute(args[1]) 88 else: 89 args[0].the_tray.Execute()
90
91 - def Usage(self):
92 return self.the_tray.Usage()
93
94 - def Finish(self):
95 self.the_tray.Finish()
96 97 98
99 -def units(pvalue,punit):
100 """ 101 Parse I3Units 102 @param pvalue: parameter (double) 103 @param punit: optional parameter I3Unit (string) 104 """ 105 if punit and globals().has_key(punit): 106 return globals()[punit](pvalue) 107 elif not punit == None and not punit == 'None': 108 try: 109 return pvalue * eval("I3Units.%s" % punit) 110 except: 111 logger.error('Cannot parse unit "%s"' % punit) 112 return pvalue 113 else: 114 return pvalue
115