Functions | Variables
DCS_db_parser Namespace Reference

Functions

def database_connect ()
 
def main ()
 

Variables

int period = 2
 
string periodname = 'day'
 
string DB_HOST = 'novadcs-far-logger.fnal.gov'
 
string DB_PORT = '5432'
 
string DB_USER = 'nova_reader'
 
 DB_PASS = open(os.environ['NOVADBPWDFILE'], 'r').readlines()[0].strip()
 
string DB_DATABASE = 'nova_prod'
 

Function Documentation

def DCS_db_parser.database_connect ( )
Initiate connection to psql database

Definition at line 57 of file DCS_db_parser.py.

Referenced by main(), POTUptimeData.main(), and POTSpillRate.num_spills_between().

58  """ Initiate connection to psql database
59  """
60 
61  # Initiate connection to database
62  try:
63  db = psycopg2.connect(\
64  "dbname=%s host=%s user=%s password=%s port=%s" % \
65  (DB_DATABASE, DB_HOST, DB_USER, DB_PASS, DB_PORT))
66 
67  except:
68  print "Unable to connect to the database"
69 
70  # Create cursor object so that we can send queries to the db.
71  # Note: The `cursor_factory' argument will create a dictionary
72  # cursor so that columns are returned as a dictionary so that we
73  # can access columns by their name instead of index.
74  global db_cursor
75  db_cursor = db.cursor(cursor_factory = psycopg2.extras.DictCursor)
76 
77 
78 #///////////////////////////////////////////////////////////////////////////////
def database_connect()
def DCS_db_parser.main ( )

1D plots hits vs w //

Definition at line 79 of file DCS_db_parser.py.

References database_connect(), Fill(), and runNovaSAM.str.

79 def main():
80 
81  # Creates database object called db_cursor
83  #FIXME Should check that DB connect worked
84 
85  # CHANGE DATES HERE
86  # Set dates for testing
87  #t0 = datetime(year = 2016, month = 2, day = 9)
88  #t1 = datetime(year = 2016, month = 2, day = 15)
89 
90  # Set dates automatically
91  if time.daylight :
92  #print time.altzone/3600
93  utchrdiff = time.altzone/3600
94  else :
95  #print time.timezone/3600
96  utchrdiff = time.timezone/3600
97  #t1 = datetime.now() + timedelta(hours = 5) #+5hrs for timezone differences
98  # Want times in UTC, since that is what is in DB just use utcnow()
99  t1 = datetime.utcnow()
100  # "now" might not be the best time to use, if script takes a while, probably ok
101  t0 = t1 - timedelta(days = period)
102  #print "t0 = " + str(t0)
103  print " Getting info from DB from UTC t0 = " + str(t0) + "to t1 = " +str(t1)
104 
105  # Start at the first date
106  t = t0
107 
108  # Make a tree
109  f = TFile("trees/dcs_db_readout_multichan_"+periodname+"_"+sys.argv[2]+".root","recreate")
110  tree = TTree("dcs_db_tree","DCS DB readout")
111  firsttime=1
112  if (sys.argv[2] == 'ND') :
113  report_table = "neardet.dcs_analog_report"
114  channel_table = "neardet.dcs_channelid"
115  else :
116  report_table = "fardet.dcs_analog_report"
117  channel_table = "fardet.dcs_channelid"
118 
119  query = ("SELECT * FROM %s as report_tbl, %s as chan_tbl "
120  "WHERE chan_tbl.id=report_tbl.chanid and substring(name,2,1)=':' "
121  #" and substring(name,4,1) = 'L' and (substring(name,3,1) = 'T' or substring(name,3,1) = 'H') " Don't worry about sparse data for now.
122  " and tread>='%s' and tread<='%s' "
123  " order by chanid,tread " % (report_table,channel_table,str(t0), str(t1)) )
124 
125  # Submit query to psql. Store response as a Python object called "reports"
126  db_cursor.execute(query)
127  reports = db_cursor.fetchall()
128  branchname = 'dummy_name'
129  branchcounter = 0
130  for report in reports:
131  # Check if it is a new variable, and make a branch for it.
132  # a better way ot do this would be to output all data with the channel names to one tree, and
133  # change the plotter to select the dat for each variable. We'll stick with this for now.
134  if (branchname != report['name'].replace(':','')) :
135  # Add branch - one for each measurement (if not yet exist)
136  branchcounter = 0
137  vals = array('f', [0])
138  branchname = report['name'].replace(':','') #ROOT really doesn't like branches with ':' in the name
139  tree.Branch(branchname, vals, 'Variable/F')
140  times = TDatime() # sets times equal to current time
141  chantime = 'Time_' + branchname
142  tree.Branch(chantime, times)
143 
144  tread = report['tread']
145  times.Set(tread.year, tread.month, tread.day, tread.hour, tread.minute, tread.second)
146  vals[0] = report['readval']
147  tree.GetBranch(branchname).Fill()
148  tree.GetBranch(chantime).Fill()
149  branchcounter +=1
150  tree.GetBranch(branchname).SetEntries(branchcounter) # May not be needed, Probably does no harm. LMM
151  tree.GetBranch(chantime).SetEntries(branchcounter) # May not be needed, Probably does no harm. LMM
152  tree.SetEntries(-1) # Set entries to # of entries in branches Was needed to get data to file
153  tree.Write()
154  #tree.Print()
155  f.Write()
156  f.Close()
157  # Within the loop you could also construct a histogram with PyROOT, but I
158  # don't think TH1Fs handle dates very well. Generally what we do here is
159  # write the info we want to a TTree and save it in a .root file. Then in
160  # another script, we loop through that TTree and make a TGraph out of it.
161 
162 # Prevent execution on import
correl_yv Fill(-(dy[iP-1][iC-1]), hyv->GetBinContent(iP, iC))
def database_connect()

Variable Documentation

string DCS_db_parser.DB_DATABASE = 'nova_prod'

Definition at line 45 of file DCS_db_parser.py.

string DCS_db_parser.DB_HOST = 'novadcs-far-logger.fnal.gov'

Definition at line 40 of file DCS_db_parser.py.

DCS_db_parser.DB_PASS = open(os.environ['NOVADBPWDFILE'], 'r').readlines()[0].strip()

Definition at line 44 of file DCS_db_parser.py.

string DCS_db_parser.DB_PORT = '5432'

Definition at line 41 of file DCS_db_parser.py.

string DCS_db_parser.DB_USER = 'nova_reader'

Definition at line 42 of file DCS_db_parser.py.

int DCS_db_parser.period = 2

Definition at line 19 of file DCS_db_parser.py.

Referenced by accum_nue_numu_equivalent(), AnaPlotMaker(), DDTOnMonPlotMaker(), ana::SAMQuerySource.EnsureSnapshot(), fnex::CAFToEventList.FindPOTPerPeriod(), cmf::CAFToEventList.FindPOTPerPeriod(), get_cosmic_sample(), get_eventslist(), get_fd_dataspectrum(), getData(), GetLoaders2017(), GetLoaders2017FakeData(), GetLoaders2018(), GetLoaders2020(), main(), make_ehade_histogram(), make_prediction_extrap(), make_prediction_noextrap(), make_prediction_tables(), make_predictions_systs(), make_predictions_systs_fakedata(), make_quantiles_histogram_2020(), make_xsec_wgts_2018_hists(), makePrediction(), MakeValidation(), NuMu2019_BasicPIDPlots_FD(), NuMu2019_BasicPIDPlots_ND(), NuMu2019_BasicPIDPlots_Spectrum(), NuMu2020_BasicPIDPlots_FD(), NuMu2020_BasicPIDPlots_ND(), NuMu2020_BasicPIDPlots_Plot(), NuMu2020_BasicPIDPlots_Spectrum(), OnMonPlotMaker(), fnex::CAFToEventList.PeriodAdjustCosmics(), cmf::CAFToEventList.PeriodAdjustCosmics(), plot_prediction_systs(), NumuEnergyFunc.predict_prod4_fd_had_energy_p(), NumuEnergyFunc.predict_prod4_fd_muon_energy_p(), NumuEnergyFunc.predict_prod4_nd_act_energy_p(), NumuEnergyFunc.predict_prod4_nd_cat_energy_p(), NumuEnergyFunc.predict_prod4_nd_had_energy_p(), NumuEnergyFunc.predict_prod5_fd_had_energy_p(), NumuEnergyFunc.predict_prod5_fd_muon_energy_p(), NumuEnergyFunc.predict_prod5_nd_act_energy_p(), NumuEnergyFunc.predict_prod5_nd_cat_energy_p(), NumuEnergyFunc.predict_prod5_nd_had_energy_p(), cmf::EventListManipulator.reconfigure(), fnex::EventListManipulator.reconfigure(), SwapNDDataLoader(), ana.takeOutTrash(), ana.takeOutTrashByTruth(), and test_nueloaders().

string DCS_db_parser.periodname = 'day'

Definition at line 20 of file DCS_db_parser.py.