Functions | Variables
POTUptimeData Namespace Reference

Functions

def fill_table (table, run, t1, t2)
 
def do_runs (t0, runs)
 
def do_pot (table, beam)
 
def do_detector_mass (table, beam)
 
def write_json (table, beam)
 
def options ()
 
def main ()
 

Variables

int TIMESTEP_MIN = 20
 
 TIMESTEP = timedelta(minutes = TIMESTEP_MIN)
 
 HALF_TIMESTEP = timedelta(minutes = TIMESTEP_MIN / 2)
 
int N_DAYS = 400
 
 TODAY = datetime.utcnow()
 
string JSON_FILE_PATH = '/nusoft/app/web/htdoc/nova/datacheck/nearline/'
 
string JSON_BNB_FILE_PATH = '/nusoft/app/web/htdoc/nova/datacheck/nearline/'
 

Detailed Description

  Compute FD mass, delivered POT, and run number over time and
  overwrite json file.

  Based on /Commissioning/uptime_graphic.py

  Fernanda Psihas (psihas@fnal.gov)
  Justin Vasel (jvasel@fnal.gov)

Function Documentation

def POTUptimeData.do_detector_mass (   table,
  beam 
)
Fills the table with detector mass uptime

  Args:
  table : An array

Definition at line 174 of file POTUptimeData.py.

References POTGetData.get_active_chans(), stan::math.round(), and runNovaSAM.str.

Referenced by main().

174 def do_detector_mass(table, beam):
175  """ Fills the table with detector mass uptime
176 
177  Args:
178  table : An array
179 
180  """
181 
182  # The total number of channels for FD are equal to the number of pixels:
183  # 14 diblocks
184  # 12 DCM's
185  # 64 FEB's per diblock-DCM
186  # 32 pixels (channels) per FEB
187  #
188  # The total number of possible channels for ND is 631 per nearline
189 
190  if beam == str("numi"):
191  maxNumChan = 14 * 12 * 64 * 32
192  elif beam == str("bnb"):
193  maxNumChan = 631
194  # Loop over rows
195  for row in table:
196 
197  # If there was no run in progress, set active mass to zero.
198  if (row[1] == 0):
199  row[2] = 0
200  else:
201  # Get the number of active channels for this run
202  numChan = get_active_chans(row[1], beam) * 1.0
203 
204  # Calculate mass of detector in kiltons
205  if beam == str("numi"):
206  mass = 1000 * round(14 * (numChan / maxNumChan) + 0.5, 0)
207  elif beam == str("bnb"):
208  mass = 330 * (numChan / maxNumChan)
209 
210  # Set active mass
211  row[2] = mass
212 
213 
214 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def do_detector_mass(table, beam)
fvar< T > round(const fvar< T > &x)
Definition: round.hpp:23
def get_active_chans(run, beam)
Definition: POTGetData.py:99
def POTUptimeData.do_pot (   table,
  beam 
)
Fills the table with POT info

  Args:
  table : An array

Definition at line 131 of file POTUptimeData.py.

References POTGetData.get_spills(), and POTGetData.pot_between().

Referenced by main().

131 def do_pot(table,beam):
132  """ Fills the table with POT info
133 
134  Args:
135  table : An array
136 
137  """
138 
139  # Initialize variables
140  spills = None
141  lastSpill = datetime(1970, 1, 1)
142 
143  # Loop over rows
144  for row in table:
145  print row[0]
146 
147  # Choose an interval of length TIMESTEP centered at current time
148  t1 = row[0] - HALF_TIMESTEP
149  t2 = row[0] + HALF_TIMESTEP
150 
151  # Optimize fetches from beams database by only grabbing spills
152  # 1 day at a time. If our time interval lies within the next day
153  # worth of spills, then fetch the next day's spills
154  if (t2 > lastSpill):
155 
156  # Reset lastSpill so that we don't grab spills again until
157  # the next day starts
158  lastSpill = t1 + timedelta(days = 1)
159 
160  # Get the new day worth of spills
161  spills = get_spills(t1, 1, beam)
162 
163  # Get total POT delivered during time interval
164  pot = pot_between(t1, t2, spills)
165 
166  # Normalize to kW: 700 kW = 1.3E+17 POT / 60 minutes.
167  # Our POT number is in unites of 1E+18 POT. We must scale the
168  # final number by 100 so that the numbers fit on the plots with
169  # run numbers which are in the 10,000's.
170  row[3] = pot * (700.0 / 0.13) * (60.0 / TIMESTEP_MIN) * 100.0
171 
172 
173 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def pot_between(t0, t1, spills)
Definition: POTGetData.py:309
def do_pot(table, beam)
def get_spills(day, deltaDay, beam)
Definition: POTGetData.py:170
def POTUptimeData.do_runs (   t0,
  runs 
)
Fills the table with run uptime info

  Args:
  t0 : A datetime object
  runs : A list of runs

  Returns:
  table : An array

Definition at line 84 of file POTUptimeData.py.

References fill_table().

Referenced by main().

84 def do_runs(t0, runs):
85  """ Fills the table with run uptime info
86 
87  Args:
88  t0 : A datetime object
89  runs : A list of runs
90 
91  Returns:
92  table : An array
93  """
94 
95  # Threshold by which a run is determined to be down
96  gap = timedelta(minutes = 1)
97 
98  # Initialize variables
99  table = []
100  tLast = t0
101  runLast = 0
102 
103  # Loop over runs
104  for r in runs:
105  tStart = r['tstart']
106  tStop = r['tstop']
107  run = r['run']
108 
109  # Is there a gap between runs? If so, fill that space with 0's
110  if ((tStart - tLast) > gap):
111  table.append([tLast, runLast, 0, 0]) # Finish entry for last run
112  table.append([tLast, 0, 0, 0]) # First downtime entry
113  fill_table(table, 0, tLast, tStart) # Fill downtime entries with 0
114  table.append([tStart, 0, 0, 0]) # Final downtime entry
115 
116  # First entry for new run
117  table.append([tStart, run, 0, 0])
118 
119  # Fill remaining entries for new run
120  fill_table(table, run, tStart, tStop)
121 
122  # Set up the next iteration
123  runLast = run
124  tLast = tStop
125 
126  # Return the table
127  return table
128 
129 
130 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def fill_table(table, run, t1, t2)
def do_runs(t0, runs)
def POTUptimeData.fill_table (   table,
  run,
  t1,
  t2 
)
Fill identical entries in table

  Args:
  table : An array
  run   : A run number
  t1    : A datetime object
  t2    : A datetime object

Definition at line 60 of file POTUptimeData.py.

Referenced by do_runs().

60 def fill_table(table, run, t1, t2):
61  """ Fill identical entries in table
62 
63  Args:
64  table : An array
65  run : A run number
66  t1 : A datetime object
67  t2 : A datetime object
68  """
69 
70  # Make sure there's a large enough difference between t1 and t2
71  if ((t2 - t1) > TIMESTEP):
72 
73  # Loop through TIMESTEPS
74  while (1):
75  t1 += TIMESTEP
76  table.append([t1, run, 0, 0])
77 
78  # Break once we've looped through all TIMESTEPS
79  if (t1 > t2):
80  break
81 
82 
83 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def fill_table(table, run, t1, t2)
def POTUptimeData.main ( )

1D plots hits vs w //

Definition at line 277 of file POTUptimeData.py.

References DCS_db_parser.database_connect(), do_detector_mass(), do_pot(), do_runs(), POTGetData.get_runs(), options(), runNovaSAM.str, and write_json().

277 def main():
278 
279  beam = str("numi")
280  if len(sys.argv) > 1:
281  beam = options()
282  # Initiate connection to psql database
283  print "Connecting to database..."
284  database_connect(beam)
285 
286  # We want to collect a month's worth of information
287  t0 = TODAY - timedelta(days = N_DAYS)
288 
289  # Get list of runs during time period (don't include today)
290  print "Getting runs..."
291  runs = get_runs(t0, N_DAYS - 1, beam)
292 
293  # Build table: Runs
294  print "Doing runs..."
295  table = do_runs(t0, runs)
296 
297  # Build table: POT
298  print "Doing pot..."
299  do_pot(table,beam)
300 
301  # Build table: Detector Mass
302  print "Doing detector mass..."
303  do_detector_mass(table,beam)
304 
305  # Write to JSON file
306  print "Writing JSON to file..."
307  write_json(table,beam)
308 
309 
310 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
311 
312 # Prevent execution on import
def write_json(table, beam)
def do_detector_mass(table, beam)
def get_runs(day, deltaDay, beam)
Definition: POTGetData.py:126
def do_pot(table, beam)
def do_runs(t0, runs)
def database_connect()
def POTUptimeData.options ( )
Parse the command line options

  Returns:
  b {bnb,numi} : Which beam to run POT plots for

Definition at line 251 of file POTUptimeData.py.

References runNovaSAM.str.

Referenced by main().

251 def options():
252  """ Parse the command line options
253 
254  Returns:
255  b {bnb,numi} : Which beam to run POT plots for
256  """
257 
258  # Get options and arguments supplied by user
259  # options that require an argument have a : attached
260  try:
261  (opts, args) = getopt.gnu_getopt(sys.argv[1:], "b:", ["beam="])
262  except getopt.GetoptError as err:
263  print str(err)
264  sys.exit(2)
265 
266  # Loop over arguments supplied
267  for opt, arg in opts:
268  if opt in ("-b", "--beam"):
269  beam = str(arg)
270 
271  return beam
272 
273 #.......................................................................
274 # "MAIN" FUNCTION
275 #
276 #.......................................................................
def POTUptimeData.write_json (   table,
  beam 
)
Converts the table into JSON and writes to file

  Args:
  table : An array

Definition at line 215 of file POTUptimeData.py.

References open(), and runNovaSAM.str.

Referenced by main().

215 def write_json(table,beam):
216  """ Converts the table into JSON and writes to file
217 
218  Args:
219  table : An array
220 
221  """
222 
223  # Initialize the array that will hold the data to be written to a
224  # JSON file
225  jsonData = []
226 
227  # Loop over table
228  for row in table:
229 
230  # Build JSON entry
231  jsonEntry = {"date" : str(row[0]),\
232  "run_number" : str(row[1]),\
233  "mass" : str(row[2]),\
234  "beam_power" : str(row[3])}
235 
236  # Append the JSON entry to the jsonData array
237  jsonData.append(jsonEntry)
238 
239  # Encode the array into JSON and write to a file
240  if beam == str("numi"):
241  file = open(JSON_FILE_PATH, 'w')
242  elif beam == str("bnb"):
243  file = open(JSON_BNB_FILE_PATH, 'w')
244  file.write(json.dumps(jsonData, indent = 2))
245  file.close()
246 
247 #.......................................................................
248 # OPTIONS
249 #
250 #.......................................................................
def write_json(table, beam)
procfile open("FD_BRL_v0.txt")

Variable Documentation

POTUptimeData.HALF_TIMESTEP = timedelta(minutes = TIMESTEP_MIN / 2)

Definition at line 42 of file POTUptimeData.py.

string POTUptimeData.JSON_BNB_FILE_PATH = '/nusoft/app/web/htdoc/nova/datacheck/nearline/'

Definition at line 51 of file POTUptimeData.py.

string POTUptimeData.JSON_FILE_PATH = '/nusoft/app/web/htdoc/nova/datacheck/nearline/'

Definition at line 49 of file POTUptimeData.py.

int POTUptimeData.N_DAYS = 400

Definition at line 45 of file POTUptimeData.py.

POTUptimeData.TIMESTEP = timedelta(minutes = TIMESTEP_MIN)

Definition at line 41 of file POTUptimeData.py.

int POTUptimeData.TIMESTEP_MIN = 20

Definition at line 38 of file POTUptimeData.py.

POTUptimeData.TODAY = datetime.utcnow()

Definition at line 46 of file POTUptimeData.py.