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

In This Package:

Public Member Functions | Public Attributes
DumpRate::DumpRate Class Reference

List of all members.

Public Member Functions

def __init__
def getEntries
def getRunTimeInfo
def dumpRate

Public Attributes

 thissite

Detailed Description

Get Rate from ROOT file

Definition at line 27 of file DumpRate.py.


Constructor & Destructor Documentation

def DumpRate::DumpRate::__init__ (   self,
  inputFilename 
)

Definition at line 29 of file DumpRate.py.

00030 :
    #def __init__(self):

Member Function Documentation

def DumpRate::DumpRate::getEntries (   self)
Constructor

Definition at line 48 of file DumpRate.py.

00049                         :
00050         inputFile = TFile(self.inputFilename, "READ")
00051         #determine which site this file comes from
00052         for site in self.site:
00053             breakOrNot = 0
00054             for det in self.det:
00055                 histdir = "stats/diagnostics/run_%s/detector_%s%s" % (self.runNo, site, det)
00056                 dir = inputFile.GetDirectory(histdir)
00057                 if dir:
00058                     self.thissite = site
00059                     breakOrNot = 1
00060                     break
00061             if breakOrNot == 1:
00062                 break
00063 
00064         #prepare the histogram path for this site
00065         for det in self.det:
00066             if (self.thissite != 'Far') and ( (det == 'AD3') or (det=='AD4') ):
00067                 continue
00068             histdir = "stats/diagnostics/run_%s/detector_%s%s" % (self.runNo, self.thissite, det)
00069             self.histdir.append(histdir)
00070 
00071         #loop over different detectors
00072         for histdir in self.histdir:
00073             dir = inputFile.GetDirectory( histdir )
00074             #if path does not exist, continue
00075             if not dir:
00076                 continue
00077             self.entries[ histdir.split('/')[-1] ] = {}
00078             #loop different histgrams
00079             for histname in self.histname:
00080                 hist = dir.Get( histname )
00081                 #if hist not exist, continue
00082                 if not hist:
00083                     continue
00084                 #print histdir+'/'+histname
00085                 #save entries info only for those available histograms for each detector
00086                 if histname=='logAdCharge':
00087                     minAdMuEnergyBin = hist.FindBin( math.log10(20*170) )  #170pe/MeV
00088                     maxBin = hist.GetNbinsX()
00089                     self.entries[ (histdir.split('/'))[-1] ][histname] = hist.Integral(minAdMuEnergyBin, maxBin) 
00090                 else:
00091                     self.entries[ (histdir.split('/'))[-1] ][histname] = hist.GetEntries()
00092         
00093         return

def DumpRate::DumpRate::getRunTimeInfo (   self,
  runNo 
)
Talk to offline DB and get the time range of the run

Definition at line 94 of file DumpRate.py.

00095                                    :
00096         """Talk to offline DB and get the time range of the run"""
00097         try:
00098             con = MySQLdb.connect( host = dbhost,
00099                                    user = dbuser,
00100                                    passwd = dbpasswd,
00101                                    db = database )
00102             cursor = con.cursor()
00103             cursor.execute( "SELECT DaqRawDataFileInfoVld.timestart, DaqRawDataFileInfoVld.timeend FROM DaqRawDataFileInfoVld, DaqRawDataFileInfo WHERE DaqRawDataFileInfoVld.seqno = DaqRawDataFileInfo.seqno and DaqRawDataFileInfo.runNo = %s" % runNo )
00104             row = cursor.fetchall()
00105             #if row:
00106             #    print "get file time info successfully"
00107         except MySQLdb.Error,e:
00108             print "Error %d: %s" % (e.args[0], e.args[1])
00109             sys.exit(1)
00110 
00111         cursor.close()
00112         con.close()
00113         return (row[0][0],row[-1][-1])
        
def DumpRate::DumpRate::dumpRate (   self)
calculate rate

Definition at line 114 of file DumpRate.py.

00115                       :
00116         """calculate rate"""
00117         #could use offline DB to get the precise run time range
00118         #or get a rough time range from historgram triggerRate
00119         runTime = self.getRunTimeInfo(self.runNo)
00120         import calendar
00121         starttime = calendar.timegm( runTime[0].timetuple() )
00122         endtime = calendar.timegm( runTime[1].timetuple() )
00123         timeRange = endtime - starttime
00124         self.getEntries()
00125         #print "get entries from summary root file successfully"
00126         wrt = DQDetector.Wrt()
00127         if self.thissite == 'DayaBay':
00128             sitectx = Site.kDayaBay
00129         if self.thissite == 'LingAo':
00130             sitectx = Site.kLingAo
00131         if self.thissite == 'Far':
00132             sitectx = Site.kFar 
00133         cr = ContextRange( sitectx,
00134                            SimFlag.kData|SimFlag.kMC,
00135                            TimeStamp(starttime),
00136                            TimeStamp(endtime) )
00137         wrt.ctx(contextrange=cr, versiondate=TimeStamp(0,0))
00138 
00139         for det,hists in self.entries.items():
00140             detId = self.det.index(det[-3:]) + 1 
00141             singlesRate = -1
00142             ibdRate = -1
00143             spnRate = -1
00144             muonRate = -1
00145             if detId>4:
00146                 muonRate = hists['MuonCharge']/timeRange
00147             else:
00148                 for histname,entries in hists.items():
00149                 #element of self.entries[det] is loop over all the hist in self.histname
00150                     if histname == 'triggerRate':
00151                         singlesRate = entries/timeRange
00152                     if histname == 'ibdCandidateTime':
00153                         ibdRate = entries/timeRange
00154                     if histname == 'spallTimeNCaptureGd':
00155                         spnRate = entries/timeRange
00156                     if histname == 'logAdCharge':
00157                         muonRate = entries/timeRange
00158                 #singlesRate = hists['triggerRate']/timeRange
00159                 #ibdRate = hists['ibdCandidateTime']/timeRange
00160                 #spnRate = hists['spallTimeNCaptureGd']/timeRange
00161                 #muonRate = hists['logAdCharge']/timeRange
00162             
00163             #print detId, singlesRate, ibdRate, spnRate, muonRate
00164             record = DQDetector.Create( RunNo = int( self.runNo ),
00165                                         DetectorId = detId,
00166                                         SinglesRate = singlesRate, 
00167                                         IBDRate = ibdRate,
00168                                         SPNRate = spnRate,
00169                                         MuonRate = muonRate)  
00170             wrt.Write(record)
00171         wrt.Close()
        

Member Data Documentation

Definition at line 48 of file DumpRate.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:54:23 for DQDump by doxygen 1.7.4