Skip to content

Instantly share code, notes, and snippets.

Avatar

Andy Mastbaum mastbaum

  • Rutgers University
  • New Brunswick, NJ
View GitHub Profile
@mastbaum
mastbaum / check_smart_status.py
Created Jan 9, 2015
Nagios plugin to monitor the SMART status of hard disks
View check_smart_status.py
#!/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 Dec 1, 2014
CouchDB 1.6.1 on CentOS 6.6 with build-couchdb
View install-build-couchdb.sh
#!/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 Jun 25, 2014
A minimal example of how Orca might interact with the CouchDB database
View orca_db_example.py
'''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 Jun 20, 2014
Example of drawing overlaid histograms from two TTrees in two TFiles
View overlay.C
// 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.
View es.cpp
/**
* 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
Plot PMT hit time residuals from the RAT DS
View time_residuals.py
'''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 Apr 22, 2014
Creating a list of keys from an STL map.
View keys.cpp
/**
* 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 Apr 14, 2014
Nagios SMART status check
View check_smart_status.py
#!/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 Jan 8, 2014
Looping over a TTree
View evcount.cxx
// 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 Dec 21, 2015
Specification for ln Backends
View gist:6300550
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