/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

CalibStats.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # zhang@caltech.edu, 2011-05-05
00003 '''
00004 UserData of a collection of calibration statistics
00005 Usage:
00006     nuwa.py --no-history -A "1*s" -n -1 -m"QuickStart.Calibrate" -m"Tagger.CalibStats" input.root
00007 '''
00008 
00009 from UserTagging.UserTaggingAlg import UserTaggingAlg
00010 from Tagger.DataHelpers import CalibDataHelper
00011 
00012 from GaudiPython import SUCCESS, FAILURE
00013 from GaudiPython import gbl
00014 
00015 # ===========================================
00016 class CalibStats(UserTaggingAlg):
00017     'UserData of a collection of calibration statistics'
00018 
00019     def __init__(self, name):
00020         UserTaggingAlg.__init__(self, name)
00021         self.location = '/Event/CalibReadout/CalibReadoutHeader'
00022         
00023     # -------------------------------------------
00024     def initTagList(self):
00025         self.pmtGeomSvc = self.svc('IPmtGeomInfoSvc','PmtGeomInfoSvc')
00026         if self.pmtGeomSvc == None:
00027             self.error("Failed to get PmtGeomInfoSvc")
00028             return FAILURE
00029         
00030         self.myTag = self.addTag('CalibStats', '').setBaseHeader(self.location)
00031         self.myData = self.myTag.addData('CalibStats' , '/Event/Data/CalibStats')
00032         for paraName in CalibDataHelper.DATA_STATS_INT:
00033             self.myData.addInt(paraName)
00034         for paraName in CalibDataHelper.DATA_STATS_FLOAT:
00035             self.myData.addFloat(paraName)
00036         for paraName in CalibDataHelper.DATA_DTLAST_FLOAT:
00037             self.myData.addFloat(paraName)  
00038         for paraName in CalibDataHelper.DATA_DTNEXT_FLOAT:
00039             self.myData.addFloat(paraName) 
00040                                   
00041     # -------------------------------------------
00042     def check(self, evt):
00043         calibHdr = evt[self.location]
00044         if not calibHdr:
00045             self.warning('cannot find %s' % self.location)
00046             return FAILURE
00047         data = CalibDataHelper.stats(calibHdr)
00048         for paraName in CalibDataHelper.DATA_STATS_INT:
00049             self.myData.set(paraName, data[paraName])
00050         for paraName in CalibDataHelper.DATA_STATS_FLOAT:
00051             self.myData.set(paraName, data[paraName])        
00052                 
00053         # shall we add CalibReadoutHeader to the inputHeaders of UserData?
00054         # self.myData.addInputHeader(calibHdr)    
00055         # trigger the saving process
00056         self.myTag.tagIt()
00057         
00058         # save dt to last detector info
00059         calibAES = self.getAES(self.location)
00060         if not calibAES:
00061             self.warning("AES not found in %s" % self.location)
00062             return
00063         data = CalibDataHelper.dtLast(calibAES)
00064         for paraName in CalibDataHelper.DATA_DTLAST_FLOAT:
00065             self.myData.set(paraName, data[paraName])
00066         for paraName in CalibDataHelper.DATA_DTNEXT_FLOAT:
00067             self.myData.set(paraName, -1)
00068     
00069     # -------------------------------------------
00070     def post_save(self, evt):        
00071         # save dt to next detector info
00072         calibStatsAES = self.getAES('/Event/Data/CalibStats')
00073         if not calibStatsAES:
00074             self.warning("AES not found at /Event/Data/CalibStats")
00075             return
00076         
00077         header = calibStatsAES[0]
00078         detId = header.context().GetDetId()
00079         paraName = 'dtNext' + CalibDataHelper.DET_NAMES.get(detId,'') + '_ms'
00080         timeStamp = header.timeStamp()
00081         # print '#', self.execNumber, paraName, timeStamp.GetSec(), timeStamp.GetNanoSec()
00082         for i in range(1, len(calibStatsAES)):
00083             aes_header = calibStatsAES[i]
00084             aes_detId = aes_header.context().GetDetId()
00085             if aes_detId == detId:
00086                 dt = gbl.TimeStamp(timeStamp)
00087                 dt.Subtract(aes_header.timeStamp())
00088                 aes_header.setFloat(paraName, dt.GetSeconds()*1e3)
00089                 # print 'break at', i
00090                 break  # subsequent aes headers already set this dtNext
00091             else:
00092                 if aes_header.getFloat(paraName) < 0:
00093                     dt = gbl.TimeStamp(timeStamp)
00094                     dt.Subtract(aes_header.timeStamp())
00095                     aes_header.setFloat(paraName, dt.GetSeconds()*1e3)
00096         
00097         # # debug
00098         # print '========='
00099         # for i in range(0, len(calibStatsAES)):   
00100         #     aes_header = calibStatsAES[i]
00101         #     print 'aes', i,  CalibDataHelper.DET_NAMES.get(aes_header.context().GetDetId(),'unknown')
00102         #     for paraName in CalibDataHelper.DATA_DTNEXT_FLOAT:  
00103         #         print paraName, aes_header.getFloat(paraName)
00104         # print
00105         
00106 #####  Job Configuration for nuwa.py ########################################
00107 
00108 def configure(argv=[]):
00109     # Setup Service to get PMT position in detectors
00110     from DetHelpers.DetHelpersConf import PmtGeomInfoSvc
00111     pgiSvc = PmtGeomInfoSvc()
00112     pgiSvc.StreamItems = ["/dd/Structure/DayaBay"]   
00113     pass
00114 
00115 def run(app):    
00116     app.ExtSvc += ["PmtGeomInfoSvc"]
00117     myAlg = CalibStats("CalibStats")
00118     app.addAlgorithm(myAlg)
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:54:18 for Tagger by doxygen 1.7.4