ATLAS Offline Software
LArBadChannelBrowserTools.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 from __future__ import print_function
4 
5 def ChooseOptionFromList(sTitle,sMessage,sPrompt,sChoiceList,iPlusMinus,bPlusMinus,optionDict):
6 
7  print ("")
8  print (sTitle)
9 
10  if bPlusMinus is False:
11  for index,s in enumerate(sChoiceList):
12  print ("%3d : %-20s" % (index+iPlusMinus,s))
13  else:
14  for index,s in enumerate(sChoiceList):
15  print ("%3d/%3d : %-20s" % (index+iPlusMinus,-index,s))
16 
17  # option menu
18  sMenu=""
19  for s,v in optionDict:
20  sMenu=sMenu+s+" "+v+" "
21  if sMenu!="":
22  print ("\n"+sMenu)
23 
24  bValidResponse=False
25  while bValidResponse is False:
26 
27  print (" .. "+sPrompt+" > ", end='')
28  tty = open("/dev/tty", "r+")
29  rep=tty.readline()
30  rep=rep.strip()
31 
32  # response is in option list
33  for s,v in optionDict:
34  if rep==s:
35  return rep
36 
37  # convert response to integer
38  try:
39  iResponse=int(rep)
40 
41  # reponse in indexes
42  if bPlusMinus is False:
43  if iResponse in range(iPlusMinus, len(sChoiceList)+iPlusMinus):
44  return iResponse
45 
46  # reponse in indexes
47  if bPlusMinus is True:
48  if iResponse in range(iPlusMinus, len(sChoiceList)+iPlusMinus+1):
49  return iResponse
50  if iResponse in range(-len(sChoiceList)+iPlusMinus,iPlusMinus-1):
51  return iResponse
52 
53  print ("WARNING : response out of range")
54 
55  except Exception:
56  print ("???")
57 
58 
59 def TypeEnterToContinue(sMessage):
60 
61  if sMessage!="":
62  print (sMessage)
63  print (" .. Type ENTER to continue > ", end='')
64  tty = open("/dev/tty", "r+")
65  tty.readline()
66 
67 
68 def YesNoQuestion(sMessage):
69 
70  print ("")
71  print (sMessage+" [y/n] :", end='')
72  tty = open("/dev/tty", "r+")
73  rep=tty.readline()
74  rep=rep.strip()
75 
76  if rep=="y" or rep=="Y":
77  return 1
78  return 0
79 
80 
81 
82  from ROOT import TSQLServer
83  def getNextAtlasRunNumber(self):
84  """
85  Returns the next free ATLAS run number
86  """
87 
88  runNum = -1
89  server = "oracle://localhost/atlr"
90  statement = "select MAX(RUNNUMBER) FROM atlas_run_number.RUNNUMBER"
91  db = TSQLServer.Connect(server,"atlas_run_number_r","07-Run.Num.rEaDeR")
92  if not db or not db.IsConnected():
93  raise(Exception("Problem connecting to run number server \"%s\"" % server))
94  stmt = db.Statement(statement)
95  if stmt.Process():
96  stmt.StoreResult()
97  stmt.NextResultRow()
98  runNum = (stmt.GetUInt(0)+1)
99  else:
100  raise(Exception("Error in processing statement \"%s\"" % statement ))
101  db.Close()
102  return runNum
103 
104 
105 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.LArBadChannelBrowserTools.TypeEnterToContinue
def TypeEnterToContinue(sMessage)
Definition: LArBadChannelBrowserTools.py:59
Trk::open
@ open
Definition: BinningType.h:40
python.LArBadChannelBrowserTools.YesNoQuestion
def YesNoQuestion(sMessage)
Definition: LArBadChannelBrowserTools.py:68
python.LArBadChannelBrowserTools.ChooseOptionFromList
def ChooseOptionFromList(sTitle, sMessage, sPrompt, sChoiceList, iPlusMinus, bPlusMinus, optionDict)
Definition: LArBadChannelBrowserTools.py:5