Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
for i in {1..10}; do
echo 'Sleeping' $i
sleep $i &
# prevent more than 5 tasks at a time
while [[ `jobs|wc -l` -gt 4 ]]; do sleep 1; done;
done
wait
@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]
# 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
#!/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')
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
@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());
#!/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
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
import argparse
import numpy as np
import tqdm
import pickle
import gzip
import ROOT
ROOT.PyConfig.IgnoreCommandLineOptions = True
ROOT.gROOT.SetBatch(True)
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)