Skip to content

Instantly share code, notes, and snippets.

@nsmith-
nsmith- / proxyconfig.md
Last active June 25, 2021 18:15
Proxy auto-configuration guide

Often, when accessing a website only available behind some firewall at a site where we have ssh accces, we can take advantage of ssh built-in SOCKS proxy support to create a tunnel. For instance,

ssh -D8080 lxplus7.cern.ch

followed by configuring your browser to use the SOCKS proxy at localhost:8080 allows access as if you were browsing from inside CERN network.

One downside of this is that all traffic is forwarded through the proxy, where you may only need it to access one specific site. To help with that, we can set up a proxy auto-config

import numpy as np
def repack(array, n):
"""Repack a uint8 array as a contiguous stream of n-bit values
Works for arbitrary 0 < n <= 64, drops tail elements as necessary to evenly divide
"""
if not 0 < n <= 64:
raise ValueError(n)
#!/usr/bin/env python
import argparse
import numpy as np
import tqdm
import pickle
import gzip
import ROOT
ROOT.PyConfig.IgnoreCommandLineOptions = True
ROOT.gROOT.SetBatch(True)
def bestdatasets(primarydataset, campaign, datatier):
'''Get best dataset search string
Form the appropriate wildcard-containing string to find the
most recent dataset corresponding to the input parameters, based on
https://twiki.cern.ch/twiki/bin/viewauth/CMS/PdmVAnalysisSummaryTable
The parameters correspond to the groups extracted using a regular expression:
``/([^/]*)/([^-]*)-[^/]*/(.*)``
applied to a dataset name
#!/usr/bin/env python
# Nick Smith <nick.smith@cern.ch>
import argparse
import numpy as np
import tqdm
import pickle
import gzip
import ROOT
ROOT.PyConfig.IgnoreCommandLineOptions = True
@nsmith-
nsmith- / cosTheta.cpp
Last active September 20, 2018 18:21
#include "Math/GenVector/Boost.h"
#include "Math/LorentzVector.h"
#include "Math/PtEtaPhiE4D.h"
typedef ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiE4D<float>> LorentzVector;
double cosTheta(LorentzVector wP4, LorentzVector zP4, LorentzVector lP4) {
ROOT::Math::Boost boostWcm;
boostWcm.SetComponents(wP4.BoostToCM());
ROOT::Math::Boost boostWZcm;
boostWZcm.SetComponents((wP4+zP4).BoostToCM());
import sys
sys.path.append('/afs/cern.ch/cms/PPD/PdmV/tools/McM/')
from rest import *
mcm = restful(dev=False)
# when not json (so much for being RESTful...)
def get_raw(url):
fullurl = 'https://' + mcm.server + url
#!/usr/bin/env python
# Nick Smith <nick.smith@cern.ch>
# coding: utf-8
import argparse
parser = argparse.ArgumentParser(description='Reads EDM files and dumps raw data from list of FEDs to text files.')
parser.add_argument('--input', '-i', help='EDM File (Note, only reads first event in file, so use edmPickEvents to get right event)', required=True)
parser.add_argument('--output', '-o', help='Output file prefix (will be appended with "_fedN.txt" for N FEDs dumped)', required=True)
parser.add_argument('--feds', '-f', help='List of FEDs to dump, will write one text file per FED', required=True)
parser.add_argument('--label', help='Label in EDM file of FEDRawDataCollection', default='rawDataCollector')
# Delete all tags
git ls-remote -t my-cmssw | sed 's:^.*refs/tags/::' | while read t; do git push my-cmssw :$t; done
# Delete all branches
git ls-remote -h my-cmssw |sed 's:^.*refs/heads/::' | while read b; do git push my-cmssw :$b; done
# Or, save list of branches, and remove ones you want to keep
git ls-remote -h my-cmssw |sed 's:^.*refs/heads/::' > branches_to_del
vim branches_to_del
while read b; do git push my-cmssw :$b; done < branches_to_del
@nsmith-
nsmith- / secondaries_cff.py
Last active August 29, 2015 14:25
Get secondary files inside cmsRun config
def dasQuery(queryString, entryTitle) :
import das_client
dasinfo = das_client.get_data('https://cmsweb.cern.ch', queryString, 0, 0, False)
if dasinfo['status'] != 'ok' :
raise Exception('DAS query failed.\nQuery: %s\nDAS Status returned: %s' % (queryString, dasinfo['status']))
for entry in dasinfo['data'] :
if len(entry[entryTitle]) > 0 :
yield entry[entryTitle][0]