Skip to content

Instantly share code, notes, and snippets.

View mastbaum's full-sized avatar

Andy Mastbaum mastbaum

  • Rutgers University
  • New Brunswick, NJ
View GitHub Profile
@mastbaum
mastbaum / check_smart_status.py
Created January 9, 2015 15:05
Nagios plugin to monitor the SMART status of hard disks
#!/usr/bin/env python
'''Report the SMART status of hard disks using a log file.'''
import argparse
import subprocess
import sys
# Nagios status codes
OK, WARNING, CRITICAL, UNKNOWN = range(4)
@mastbaum
mastbaum / install-build-couchdb.sh
Created December 1, 2014 19:13
CouchDB 1.6.1 on CentOS 6.6 with build-couchdb
#!/bin/bash
git clone git://github.com/jhs/build-couchdb.git
cd build-couchdb
git submodule init
git submodule update
rake erl_checkout="OTP_R15B03-1" git="git://git.apache.org/couchdb.git 1.6.1" install=/opt/build-couchdb-dependencies couchdb_build=/opt/couchdb/1.6.1
@mastbaum
mastbaum / orca_db_example.py
Created June 25, 2014 18:17
A minimal example of how Orca might interact with the CouchDB database
'''A minimal example of how Orca might interact with the CouchDB database
to load settings from the DB at startup and write settings to the DB only
when they change.
Because Orca is the only *producer* of the database data, it can keep track
internally of whether the detector configuration has changed.
NO: Checking in-memory settings against values in the DB
for fec in fecs:
@mastbaum
mastbaum / overlay.C
Created June 20, 2014 16:37
Example of drawing overlaid histograms from two TTrees in two TFiles
// Draw overlaid histograms from a RAT ntuple (for example).
//
// Usage:
// $ root -l -x 'overlay.C("filename1.root", "filename2.root")'
//
// The trick is that histograms are associated with a TDirectory
// upon creation, which is most likely the open file. When the
// directory changes when a new file is opened, the pointer to
// the histogram is invalidated. TH1::SetDirectory is used to
// detach a histogram from a file.
/**
* Plot ES scattering angle for 8B solar neutrinos vs. recoil energy,
* weighted by the neutrino spectrum.
*
* This uses the 8B spectrum and ES cross section code in RAT.
*
* Build:
*
* g++ -g -o es es.cpp -L$RATROOT/lib -I$RATROOT/include \
* -lrat_Linux `root-config --libs --cflags` \
@mastbaum
mastbaum / time_residuals.py
Created May 13, 2014 20:47
Plot PMT hit time residuals from the RAT DS
'''Plot PMT hit time residuals from the RAT DS.
Usage:
$ python time_residuals.py "filenames_*.root"
With one filename or wildcards (use quotes when using wildcards).
The histogram opens in an interactive ROOT window for editing.
'''
@mastbaum
mastbaum / keys.cpp
Created April 22, 2014 21:06
Creating a list of keys from an STL map.
/**
* Creating a list of keys from an STL map.
*
* Build: g++ -o keys keys.cpp
* Run: ./keys
*/
#include <iostream>
#include <map>
#include <string>
@mastbaum
mastbaum / check_smart_status.py
Created April 14, 2014 16:39
Nagios SMART status check
#!/usr/bin/env python
'''Report the SMART status of hard disks using a log file.'''
import argparse
import subprocess
import sys
# Nagios status codes
OK, WARNING, CRITICAL, UNKNOWN = range(4)
@mastbaum
mastbaum / evcount.cxx
Created January 8, 2014 21:16
Looping over a TTree
// Find the number of events simulated and the efficiency for a set of ntuples
// Usage: root -b -q "evcount.cxx([filename], rate=0)" # "filename" can have wildcards
// If provided, rate is events/detector-year
void evcount(TString filenames, float rate=0) {
TChain tc("output");
tc.Add(filenames);
int entries = tc.GetEntries();
cout << "Total entries: " << entries << endl;
// ROOT branch pointers
@mastbaum
mastbaum / gist:6300550
Last active December 21, 2015 11:39
Specification for ln Backends
Backend.get_data_source_list()
Returns: list of data source names
Backend.create_data_source(name, type, reduction, interpolation, unit, description)
Returns: None
Backend.add_data(source_name, time, value)
Returns: (index, url) tuple, where index is index of data point and url is an image URL or None
Raises:
- TimeOrderError: The timestamp for the data point is before the last recorded data point