7 import canMan, HTMLTools
as html
9 from collections
import OrderedDict
14 pubContext = os.environ[
"SRT_PUBLIC_CONTEXT"]
15 priContext = os.environ[
"SRT_PRIVATE_CONTEXT"]
16 rootLogon=os.path.join(pubContext,
"Utilities/rootlogon.C")
17 gROOT.Macro(rootLogon)
23 runHistoryFillStyles = [1001, 1001, 1001, 1001, 1001, 0, 0] 24 runHistoryLineWidths = [1, 1, 1, 1, 1, 2, 2] 25 runHistoryLineStyles = [0, 0, 0, 0, 0, 1, 7] 26 runHistoryColors = [kRed-9, kAzure+1, kOrange+1, kMagenta - 6, kGreen - 7, kBlack, kRed] 27 varOpts = ["][", "][", "][", "][", "][", "", "]["] 30 emptyFileColor = kGreen-9
33 recoColor = kMagenta - 7
37 onMonColor = kGray + 2
40 runHistoryFillStyles = [1001, 1001, 1001, 1001, 1001, 0, 0]
41 runHistoryLineWidths = [1, 1, 1, 1, 1, 2, 2]
42 runHistoryLineStyles = [0, 1, 0, 0, 0, 1, 7]
43 runHistoryColors = [emptyFileColor, rawColor, rootColor, recoColor, cafColor, dbColor, onMonColor]
44 varOpts = [
"][",
"][",
"][",
"][",
"][",
"",
"]["]
47 runHistoryFillStylesWithExtra = [1001, 1001, 1001, 1001, 1001, 1001, 0, 0]
48 runHistoryLineWidthsWithExtra = [1, 1, 1, 1, 1, 0, 2, 2]
49 runHistoryLineStylesWithExtra = [0, 0, 0, 0, 0, 0, 1, 7]
50 runHistoryColorsWithExtra = [emptyFileColor, rawColor, rootColor, recoColor, pidColor, cafColor, dbColor, onMonColor]
51 varOptsWithExtra = [
"][",
"][",
"][",
"][",
"][",
"][",
"",
"]["]
56 samweb = samweb_client.SAMWebClient(experiment=
"nova")
62 self.
conn = psycopg2.connect(config +
" password=" + pw)
64 print "I am unable to connect to the database" 67 self.
cur = self.conn.cursor()
71 pw =
open(os.environ[
'NOVADBPWDFILE'],
'r').readlines()[0].strip() 73 dbPort = OrderedDict() 74 dbPort["testbeam"] =
" 5434 " 76 dbConfig = OrderedDict()
77 dbConfig[
"testbeam"] =
"dbname=nova_prod host=ifdbrep.fnal.gov user=nova_reader port=5434" 80 for det, config
in dbConfig.items():
85 onMonDirs = OrderedDict()
86 onMonDirs[
"testbeam"] =
"/bluearc/nova/data/nearline-OnMon/TestBeam/S19-10-22/" 88 onMonTriggerDirs = OrderedDict()
89 onMonTriggerDirs[
"testbeam"] =
"DDActivity1/" 110 hist = TH1F(name,
";Run Number;Number of Subruns", maxRunNum - minRunNum + 1, minRunNum, maxRunNum + 1)
113 command = dataSet +
" " +
" AND Online.RunNumber >= " +
str(minRunNum) +
" AND Online.RunNumber <= " +
str(maxRunNum)
114 print "about to make samweb query:", command
115 files = samweb.listFiles(command)
121 begRun = file.find(
"_r")
122 endRun = file.find(
"_", begRun + 1)
123 run =
int(file[begRun+2:endRun])
126 print "oops : ", file
127 print "number of files returned: ", len(files)
132 additionalDir=
"", checkKeys=
False, printRunNum=
False, lineStyle=1, lineColor=kBlack):
134 hist = TH1F(name,
";Run Number;Number of Subruns", maxRunNum - minRunNum + 1 , minRunNum, maxRunNum + 1)
135 hist.SetLineStyle(lineStyle)
136 hist.SetLineColor(lineColor)
138 multiRunDirs = sorted(os.listdir(path))
140 for multiRunDir
in multiRunDirs:
143 multiRunPath = path + multiRunDir +
"/" 144 if not os.path.isdir(multiRunPath):
146 runDirs = sorted(os.listdir(multiRunPath))
147 for runDir
in runDirs:
149 runNum =
float(runDir)
151 print "Could not parse runDir", runDir
153 if runNum >= minRunNum
and runNum <= maxRunNum:
154 runPath = multiRunPath + runDir +
"/" + additionalDir
155 if not os.path.isdir(runPath):
157 fileNames = sorted(os.listdir(runPath))
158 for fileName
in fileNames:
160 filePath = runPath + fileName
161 rootFile = TFile(filePath)
162 if rootFile.IsZombie()
or rootFile.TestBit(TFile.kRecovered):
164 if not testStr
in fileName:
167 if skipStr
in fileName:
176 maxRunNumDB =
fetchTable(db[detector].cur,
"select max(run) from "+detector+
".runs")[0][0]
180 minRunNumDB =
fetchTable(db[detector].cur,
"select min(run) from "+detector+
".runs where tstart >= ("+maxTime+
" - interval '"+
str(interval)+
"' day);")[0][0]
181 return (maxRunNumDB, minRunNumDB)
183 def getDBRunsHist(minRun, maxRun,table="testbeam", lineStyle=1, lineColor=dbColor):
184 dbRunData =
fetchTable(db[table].cur,
"select run, nsubruns from "+table+
".runs where run >= "+
str(minRun)+
" and run <=" +
str(maxRun) +
" order by run asc;")
185 dbRunsHist = TH1F(
"Number of Subruns in DB",
";Run Number;Number of Subruns", maxRun - minRun+1, minRun, maxRun+1)
186 dbRunsHist.SetLineStyle(lineStyle)
187 dbRunsHist.SetLineColor(lineColor)
188 for line
in dbRunData:
191 if run
and subrun: dbRunsHist.Fill(
float(run),
float(subrun))
198 files = os.listdir(dir)
212 def __init__(self, name, query, color=kBlue, fillStyle=1001, lineWidth=0, lineStyle=0):
222 histId =
str(maxRunNum) +
"-" +
str(minRunNum)
223 if histId
in self.cache.keys():
224 return self.
cache[histId]
226 hist.SetFillColor(self.
color)
227 hist.SetLineColor(self.
color)
231 for axis
in [hist.GetXaxis(), hist.GetYaxis()]:
233 self.
cache[histId] = hist
241 def __init__(self, name, title, legWidth=0.4, legHeight=0.3, padFactor=2):
255 self.tiers.append(tier)
258 def getHists(self, maxRunNum, minRunNum, dbRunsHist, onMonRunsHist):
260 for tier
in self.
tiers:
261 hists.append(tier.getHist(maxRunNum, minRunNum))
262 hists.append(dbRunsHist)
266 hists = self.
getHists(maxRunNum, minRunNum, dbRunsHist, onMonRunsHist)
268 can =
canMan.drawOverlay(hists, varOpts=varOpts, name=self.
name, legPos = [0.15,0.55], legWidth=0.4, legHeight=0.3, padFactor=2, preserveStyle=
True, yOffset=0.9)
273 for tier
in self.
tiers:
278 for tier
in self.
tiers:
283 for tier
in self.
tiers:
288 for tier
in self.
tiers:
293 for tier
in self.
tiers:
294 yield tier.lineWidths
298 for tier
in self.
tiers:
303 paths = OrderedDict()
305 paths[
"testbeam_act"] =
Path(
"testbeam_act",
"TB DDActivity1 Triggers")
307 paths[
"testbeam_act"].addTier(
Tier(
"DDActivity1 Empty Raw Files",
308 'Online.Detector="testbeam" AND data_tier="raw" AND Online.Stream=DDActivity1',
309 color=emptyFileColor))
310 paths[
"testbeam_act"].addTier(
Tier(
"DDActivity1 Raw Files",
311 'Online.Detector="testbeam" AND data_tier="raw" AND Online.Stream=DDActivity1 AND Online.TotalEvents > 0',
313 paths[
"testbeam_act"].addTier(
Tier(
"DDActivity1 ROOT Files",
314 'Online.Detector="testbeam" AND data_tier="artdaq" AND Online.Stream=DDActivity1 AND (daq2rawdigit.base_release R19-09-24-testbeam-production.a OR daq2rawdigit.base_release R19-09-24-testbeam-production.b OR daq2rawdigit.base_release R19-09-24-testbeam-production.c)',
318 paths[
"testbeam_beamline"] =
Path(
"testbeam_beamline",
"TB Beamline Triggers")
320 tbBeamlineRawEmpty =
Tier(
"Beamline Empty Raw Files",
321 'Online.Detector="testbeam" AND data_tier="raw" AND Online.Stream=Beamline',
322 color=emptyFileColor )
323 paths[
"testbeam_beamline"].addTier(tbBeamlineRawEmpty)
325 tbBeamlineRaw =
Tier(
"Beamline Raw Files",
326 'Online.Detector="testbeam" AND data_tier="raw" AND Online.Stream=Beamline AND Online.TotalEvents > 0',
328 paths[
"testbeam_beamline"].addTier(tbBeamlineRaw)
329 tbBeamlineRoot =
Tier(
"Beamline ROOT Files",
330 'Online.Detector="testbeam" AND data_tier="artdaq" AND Online.Stream=Beamline AND (daq2rawdigit.base_release R19-09-24-testbeam-production.a OR daq2rawdigit.base_release R19-09-24-testbeam-production.b OR daq2rawdigit.base_release R19-09-24-testbeam-production.c)',
332 paths[
"testbeam_beamline"].addTier(tbBeamlineRoot)
336 paths[
"testbeam_spill"] =
Path(
"testbeam_spill",
"TB Spill Triggers")
338 tbSpillRawEmpty =
Tier(
"TBSpill Empty Raw Files",
339 'Online.Detector="testbeam" AND data_tier="raw" AND Online.Stream=Spill',
340 color=emptyFileColor )
341 paths[
"testbeam_spill"].addTier(tbSpillRawEmpty)
343 tbSpillRaw =
Tier(
"TBSpill Raw Files",
344 'Online.Detector="testbeam" AND data_tier="raw" AND Online.Stream=Spill AND Online.TotalEvents > 0',
346 paths[
"testbeam_spill"].addTier(tbSpillRaw)
347 tbSpillRoot =
Tier(
"TBSpill ROOT Files",
348 'Online.Detector="testbeam" AND data_tier="artdaq" AND Online.Stream=Spill AND (daq2rawdigit.base_release R19-09-24-testbeam-production.a OR daq2rawdigit.base_release R19-09-24-testbeam-production.b OR daq2rawdigit.base_release R19-09-24-testbeam-production.c)',
350 paths[
"testbeam_spill"].addTier(tbSpillRoot)
def fetchTable(cur, query)
def getHist(self, maxRunNum, minRunNum)
def __init__(self, name, title, legWidth=0.4, legHeight=0.3, padFactor=2)
def __init__(self, config, pw)
def getPlotCanvas(self, maxRunNum, minRunNum, dbRunsHist, onMonRunsHist)
def getMaxMinRunNumDB(detector="testbeam", maxTime="CURRENT_TIMESTAMP", interval=7)
procfile open("FD_BRL_v0.txt")
def countFiles(dir, testStrs=[])
def __init__(self, name, query, color=kBlue, fillStyle=1001, lineWidth=0, lineStyle=0)
def getHists(self, maxRunNum, minRunNum, dbRunsHist, onMonRunsHist)
def getSAMRunsHist(name, maxRunNum, minRunNum, dataSet)
def getCompletedRunsHist(path, name, maxRunNum, minRunNum, testStr="", skipStr=None, additionalDir="", checkKeys=False, printRunNum=False, lineStyle=1, lineColor=kBlack)
def drawOverlay(listOfHists, name="", opt="hist", varOpts=[""], colors=[kRed, kBlue, kGreen, kMagenta, kOrange, kBlack, kViolet, lineStyles=[1], legEntries=[], logY=False, axisMin=0, legPos="right", legTextSize=0, inputCan=None, legHeight=0.15, legWidth=0.2, supressZero=False, padFactor=1.1, lineWidths=[gStyle.GetHistLineWidth()], fillStyles=[0], preserveStyle=False, yOffset=1.05)
def getDBRunsHist(minRun, maxRun, table="testbeam", lineStyle=1, lineColor=dbColor)