00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2005 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 __facility__ = "Online" 00011 __abstract__ = "Application to test the TEM's LRS counters" 00012 __author__ = "R. Claus <Claus@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = ("$Date: 2005/03/21 17:58:11 $").split(' ')[1] 00014 __version__ = "$Revision: 1.2 $" 00015 __release__ = "$Name: R04-12-00 $" 00016 __credits__ = "SLAC" 00017 00018 import LATTE.copyright_SLAC 00019 00020 import threading 00021 import logging as log 00022 import time 00023 00024 from LATTE.runcontrol.rcTransitions import rcTransitions 00025 from LATTE.runcontrol.ArgumentImpl import ArgumentImpl 00026 #from rcHouseKeeping import rcHouseKeeping 00027 00028 from support.SimpleGasuExample import * 00029 from support.MiniGLTExample import * 00030 00031 00032 # Example application implementation. 00033 # Note that the name of the class must be userApplication. 00034 # Look at rcTransitions for names of other transition methods that can be used. 00035 class userApplication(rcTransitions): 00036 "Implmentation class for a user application" 00037 def __init__(self, rc, userId, debug): 00038 rcTransitions.__init__(self, rc, userId, debug) 00039 log.debug("userApplication.__init__()") 00040 00041 def getName(self): 00042 return __name__ 00043 00044 def setup(self): 00045 log.debug("userApplication.setup()") 00046 00047 # Get a TEM instance 00048 if self.lat.TEMcnt() == 1: 00049 tem = self.lat.TEM[self.lat.TEM.keys()[0]] 00050 elif self.lat.TEMcnt() > 1: 00051 #tem = self.lat.TEM.all() 00052 log.fatal("More than one TEM found in the schema") 00053 return -1 00054 else: 00055 log.fatal("No TEM found in the schema") 00056 return -1 00057 00058 # clear TEM stats reg 00059 tem.COMMAND_RESPONSE = 0 00060 00061 # clear TEM status reg 00062 tem.STATUS = 0 00063 00064 # enable output in our GCCCs 00065 # broadcast load of GCCC_REG_CONFIGURATION 00066 00067 bcast_ccc = tem.allCCC() 00068 bcast_ccc.CONFIGURATION = 0x80000000L 00069 00070 # disable all GCRCs in all GCCCs via broadcast # GCCC_REG_LAYER_MASK_0, GCCC_REG_LAYER_MASK_1 00071 bcast_ccc.LAYER_MASK_0 = 0xFFFFFFFFL 00072 bcast_ccc.LAYER_MASK_1 = 0xFFFFFFFFL 00073 ccc0 = tem.downCCC(0) # O$GCCC_00 00074 ccc0.LAYER_MASK_0 = 0xFFFF0000L 00075 ccc0.LAYER_MASK_1 = 0xFFFF000FL 00076 ccc2 = tem.downCCC(2) # O$GCCC_02 00077 ccc2.LAYER_MASK_0 = 0xFFFF0000L 00078 ccc2.LAYER_MASK_1 = 0xFFFF0000L 00079 00080 # config GCFE for calibration -- range 0 first 00081 bcast_cfe = tem.allCCC().allCRC().allCFE() 00082 bcast_cfe.CONFIG_0 = 0x00 00083 bcast_cfe.CONFIG_1 = 0x36 00084 bcast_cfe.FLE_DAC = 0x55 00085 bcast_cfe.FHE_DAC = 0x55 00086 bcast_cfe.LOG_ACPT = 0x10 00087 bcast_cfe.RNG_ULD_DAC = 0x7F 00088 bcast_cfe.REF_DAC = 0x7f 00089 00090 # config GCRC for calibration 00091 bcast_crc = tem.allCCC().allCRC() 00092 bcast_crc.DELAY_1 = 0xFF 00093 bcast_crc.DELAY_2 = 0xFF 00094 bcast_crc.DELAY_3 = 0xFF 00095 bcast_crc.DAC = 0x42FE 00096 bcast_crc.DAC = 0x42FE 00097 00098 # large timeouts for all GCCCs 00099 # broadcast load of GCCC_REG_EVENT_TIMEOUTS 00100 bcast_ccc.EVENT_TIMEOUTS = 0x0 00101 #status = gGCCCread( __GT, temId, 1, GCCC_REG_EVENT_TIMEOUTS, &payload); 00102 #printf("gccc register event timeouts = 0x%08x\n", payload); 00103 00104 # Register environment variables for housekeeping 00105 #hsk = self.getHSK() 00106 #regs = [tem.regs['data_masks'], ccc2.regs['layer_mask_1']] 00107 #hsk.addEnvRegs(regs) 00108 #hsk.setUpdateInterval(1) 00109 00110 # Two choices for the trigger, GEM and MiniGLT 00111 if self.lat.existsGEM(): 00112 self.trigger( SimpleGasuExample() ) 00113 else: 00114 self.trigger( MiniGLTExample() ) 00115 00116 # Override the default event handler 00117 self.selectEventHandler(rcTransitions.EVENT_HANDLER_LEAN_AND_MEAN) 00118 00119 # A state transition can be rejected by not returning None 00120 return None 00121 00122 def startRun(self): 00123 log.debug("userApplication.startRun()") 00124 00125 # Spawn a thread to synchronize commands with events 00126 self.__cmdSynchQuit = False 00127 00128 # A state transition can be rejected by not returning None 00129 return None 00130 00131 def stopRun(self): 00132 log.debug("userApplication.stopRun()") 00133 00134 if self.getBadEvents() == 0 and self.getErrorEvents() == 0: 00135 self.setCompletionStatus(self.COMPL_STATUS_PASSED) 00136 else: 00137 self.setCompletionStatus(self.COMPL_STATUS_FAILED) 00138 00139 self.__cmdSynchQuit = True 00140 00141 # The STOP_RUN transition can not be rejected 00142 00143 def resume(self): 00144 log.debug("userApplication.resume()") 00145 00146 # Issue self trigger to make up for the one that was lost during PAUSE 00147 self.trigger().solicit() 00148 00149 return None 00150 00151 def stop(self): 00152 log.debug("userApplication.stop()") 00153 00154 return self.stopRun() 00155 00156 def teardown(self): 00157 log.debug("userApplication.teardown()") 00158 00159 def process(self, (status, latDatagram)): 00160 "Method called back for each data event taken" 00161 #log.debug("userApplication.process()") 00162 00163 pass 00164 00165 00166 def commandSynch(self): 00167 "Method called by the command synchronization task" 00168 import time 00169 trigger = self.trigger() 00170 00171 # Wait for START_RUN to enable triggers 00172 trigger.waitForMaskEnable() 00173 00174 # Get a TEM instance 00175 if self.lat.TEMcnt() == 1: 00176 tem = self.lat.TEM[self.lat.TEM.keys()[0]] 00177 elif self.lat.TEMcnt() > 1: 00178 # tem = self.lat.TEM.all() 00179 log.fatal("More than one TEM found in the schema") 00180 return -1 00181 else: 00182 log.fatal("No TEM found in the schema") 00183 return -1 00184 00185 lrsId = tem.TIC.regs ['sat_deadtime_lrs_ctr'].id() 00186 print "Deadtime LRS saturation counter ID =", lrsId 00187 tem.TIC.satCtrDisable(lrsId) 00188 print "Deadtime LRS saturation counters disabled" 00189 00190 tem.TIC.sat_deadtime_lrs_ctr = 0 00191 print "Deadtime LRS saturation counters cleared" 00192 00193 tem.TIC.satCtrEnable(lrsId) 00194 print "Deadtime LRS saturation counters enabled" 00195 00196 t = 0 00197 while not self.__cmdSynchQuit and t < 30: 00198 print "Deadtime LRS saturation counter = ", tem.TIC.sat_deadtime_lrs_ctr 00199 time.sleep(1.0) 00200 t += 1 00201 00202 # execute the GUI functions for stopRun, just in case 00203 if not self.__cmdSynchQuit and not self.isRunFromSuite(): 00204 if self.rc is not None: 00205 self.rc.doStop() 00206 00207 def wait(self): 00208 #self.__cmdSynchSem.acquire() 00209 pass 00210 00211 def sync(self): 00212 if __name__ == "__main__" or self.isRunFromSuite(): 00213 self.__cmdSynchSem.release() 00214 pass 00215 00216 00217 # Standalone mode: 00218 if __name__ == "__main__": 00219 import os 00220 log.basicConfig() 00221 log.getLogger("").setLevel(log.DEBUG) 00222 ua = userApplication(None, 321, 0) 00223 prefs = {'datasave': 1, 'datadir':os.path.join(os.environ['ONLINE_ROOT'],'temp')} 00224 ua.setPrefs(prefs) 00225 ua.rcSetup(os.path.join(os.environ['ONLINE_ROOT'], 'repos/simpleTemSchema.xml')) 00226 ua.rcStartRun() 00227 ua.wait() 00228 ua.rcStopRun() 00229 ua.rcTeardown() 00230 00231 # History: 00232 # $Log: temLrsTest.py,v $ 00233 # Revision 1.2 2005/03/21 17:58:11 claus 00234 # Modified to use the first TEM found in the schema, if only one is there, or 00235 # broadcast to all TEMs if there are multiple. 00236 # 00237 # Revision 1.1 2005/02/15 01:38:36 claus 00238 # Initial stab at a tester for the TEM LRS counters. It currently checks 00239 # only whether the deadtime counter functions throw an exception or not. 00240 # 00241 # Revision 1.2 2004/10/18 01:00:19 claus 00242 # Provided switch between 2 examples of adding custom LATcontributions. 00243 # 00244 # Revision 1.4 2004/08/31 03:13:38 stuvi 00245 # Integrated the parameter verifier with Run Control 00246 # 00247 # Revision 1.3 2004/08/18 18:00:15 stuvi 00248 # Updated for LATTE 4. 00249 # All hippo functions go through the Qt GUI bridge now. 00250 # 00251 # Revision 1.2 2004/08/13 04:46:22 claus 00252 # Got rid of obsolete TRUE and FALSE declarations. 00253 # 00254 # Revision 1.1 2004/07/28 21:24:00 stuvi 00255 # Added testAppCal and its supporting classes. 00256 # 00257 # Revision 1.28 2004/07/09 23:14:17 stuvi 00258 # Added "operatorobj" preference that contains the rcUser object and left the "operator" preference to contain the user name. 00259 # 00260 # Revision 1.27 2004/05/03 22:49:36 stuvi 00261 # Added commented out code example that demonstrates how to access the CAL and TKR diagnostics contributions. 00262 # 00263 # Revision 1.26 2004/05/03 21:19:47 stuvi 00264 # Moved non-Runcontrol scripts to the support directory and modified imports accordingly. 00265 # 00266 # Revision 1.25 2004/04/21 21:05:29 stuvi 00267 # Added an example of how to pass the preferences using the setPrefs method when running in standalone mode. 00268 # 00269 # Revision 1.24 2004/04/17 02:23:48 stuvi 00270 # Added teardown() to delete the C++ object for the userArgument 00271 # Fixed LogData parsing based on the evtCli changes 00272 # 00273 # Revision 1.23 2004/03/31 01:01:19 stuvi 00274 # Added commented code on how to parse the error contribution. 00275 # 00276 # Revision 1.22 2004/03/10 22:24:51 panetta 00277 # Upgraded trigger interface. 00278 # Removed dependencies on self.glt. 00279 # 00280 # Revision 1.21 2004/03/04 23:08:47 stuvi 00281 # Removed glt.destination assignment 00282 # 00283 # Revision 1.20 2004/02/20 03:20:23 stuvi 00284 # Added handling of the sweep events and error checking to the process() method, 00285 # 00286 # Revision 1.19 2004/02/13 03:13:25 stuvi 00287 # Sweep events are also sent to user script's process event now, so added code to handle the case. 00288 # 00289 # Revision 1.18 2004/02/02 23:14:00 stuvi 00290 # Changes required to make the scripts work with the new FSM engine. 00291 # 00292 # Revision 1.17 2004/01/30 04:33:44 claus 00293 # Updated for transitions not running in the GUI thread. 00294 # New commandSynch handling. 00295 # 00296 # Revision 1.16 2003/12/19 02:05:26 stuvi 00297 # Added support for creating and updating GUIs from a suite 00298 # 00299 # Revision 1.15 2003/12/11 02:22:35 stuvi 00300 # Suite and standalone mode modifications 00301 # 00302 # Revision 1.14 2003/12/11 01:53:16 stuvi 00303 # Modified code to support suites. 00304 # 00305 # Revision 1.13 2003/11/25 02:16:12 stuvi 00306 # Modified according to the current test setup to generate some results 00307 # 00308 # Revision 1.12 2003/11/04 04:25:11 stuvi 00309 # Changed the commandSynch logic so that the enableMask() call would not pose a threat to snapshot taking. 00310 # 00311 # Revision 1.11 2003/10/31 01:09:37 panetta 00312 # 1) Moved register writes from startRun to setup 00313 # 2) Added GLT enabling logic to __commandSynch 00314 # 3) Gave example of getting the start/stop time from the hardware/event stream 00315 # 00316 # Revision 1.10 2003/10/28 03:17:34 stuvi 00317 # Added support for calculating the event rate correctly using the new GLT behaviour. 00318 # 00319 # Revision 1.9 2003/08/21 21:13:38 stuvi 00320 # no message 00321 # 00322 # Revision 1.8 2003/07/17 00:01:35 stuvi 00323 # no message 00324 # 00325 # Revision 1.7 2003/06/13 23:26:24 stuvi 00326 # Added TEM reset 00327 # 00328 # Revision 1.6 2003/04/12 02:38:34 stuvi 00329 # Added Cancel button handler to argument class 00330 # 00331 # Revision 1.5 2003/04/09 00:45:15 stuvi 00332 # Commented out references to DATA_MASKS register which should not be touched during script execution. 00333 # 00334 # Revision 1.4 2003/04/01 21:04:59 stuvi 00335 # Fixed event count discrepancy when the run is stopped in the middle. 00336 # 00337 # Revision 1.3 2003/03/31 19:23:44 stuvi 00338 # Fixed name 00339 # 00340 # Revision 1.2 2003/03/26 21:59:36 stuvi 00341 # Fixed standalone mode 00342 # 00343 # Revision 1.1 2003/03/11 21:20:55 stuvi 00344 # Moved from RunControl directory 00345 # 00346 # Revision 1.8 2003/02/06 05:19:38 claus 00347 # Added resume; StopRun bug fix 00348 # 00349 # Revision 1.7 2003/02/06 04:14:35 claus 00350 # Fixed StopRun bug 00351 # 00352 # Revision 1.6 2002/12/11 21:18:07 stuvi 00353 # Changed glt register assignments to bit field assignments 00354 # 00355 # Revision 1.5 2002/12/10 01:09:58 claus 00356 # Added path and changed schema/config file for stand-alone mode 00357 # 00358 # Revision 1.4 2002/12/04 01:59:23 claus 00359 # Added message logging 00360 # 00361 # Revision 1.3 2002/12/02 17:17:09 claus 00362 # Added provision to allow application to run stand-alone 00363 # 00364 # Revision 1.2 2002/11/28 02:02:04 claus 00365 # Shuffled constructor arguments 00366 # 00367 # Revision 1.1 2002/11/27 05:02:48 claus 00368 # Initial version of Run Control 00369 #