Skip to content

Instantly share code, notes, and snippets.

@aminnj
Last active July 21, 2018 07:48
Show Gist options
  • Save aminnj/63891461e43fd42615cabc4e82429544 to your computer and use it in GitHub Desktop.
Save aminnj/63891461e43fd42615cabc4e82429544 to your computer and use it in GitHub Desktop.
CSC run registry table bookmarklet
/*
Copy this content as a bookmarklet.
Visit https://cmswbmoffshift.web.cern.ch/cmswbmoffshift/api/query and make sure you're authenticated (should say "Query ID missing?")
Execute the bookmark.
???
Profit.
Note: will need to search for and update the following strings below (whenever conditions change): "PromptReco-v3", "Run2018", "319750"
The queries will return at most 1k rows (usually 4k runs or so) so make sure the run number threshold isn't too small!
Well, this won't be useful after 2018...
*/
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="https://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"2.1.4",function($,L){
var qid = $.ajax({ type:"POST", url:"https://cmswbmoffshift.web.cern.ch/cmswbmoffshift/api/query", data:"SELECT * FROM runreg_csc.datasets q WHERE q.RUN_NUMBER > 319750", dataType:"text", async:false }).responseText;
console.log("1. made a request to the RR api and got the query ID");
var arr = $.ajax({ type:"GET", url:"https://cmswbmoffshift.web.cern.ch/cmswbmoffshift/api/query/"+qid+"/data?type=application/json", data:"", dataType:"", async:false, beforeSend: function(bs) { bs.setRequestHeader("Accept", "application/json"); } }).responseJSON.data;
console.log("2. made another request to get data for the query ID");
var cn = $.ajax({ type:"GET", url:"https://cmswbmoffshift.web.cern.ch/cmswbmoffshift/api/table/runreg_csc/datasets", async:false, beforeSend: function(bs) { bs.setRequestHeader("Accept", "application/json"); } });
console.log("3. made another request to get SQL column names");
console.log(arr);
console.log(cn);
var colnames = $.map(cn.responseJSON.columns,function (val) { return val["name"]; });
var goodcols = [ "RUN_NUMBER", "RUN_CLASS_NAME", "RUN_CREATED", "RUN_MODIFIED", "RDA_NAME", "RDA_STATE", "RDA_CMP_CSC", "RDA_CMP_OCCUPANCY", "RDA_CMP_INTEGRITY", "RDA_CMP_TIMING", "RDA_CMP_EFFICIENCY" ];
var rdaname_to_goodruns = {};
$.each(arr, function(idx,v) {
if (v[colnames.indexOf("RDA_CMP_OCCUPANCY")]=="GOOD") {
var run = v[colnames.indexOf("RUN_NUMBER")];
var name = v[colnames.indexOf("RDA_NAME")];
if (!rdaname_to_goodruns[name]) { rdaname_to_goodruns[name]=[]; };
rdaname_to_goodruns[name].push(run);
};
});
console.log(rdaname_to_goodruns);
var getrunlinks = function(row) {
var name = row[goodcols.indexOf("RDA_NAME")];
var run = row[goodcols.indexOf("RUN_NUMBER")];
var refrun = -1;
if (name in rdaname_to_goodruns) {
refrun = Math.max.apply(null,rdaname_to_goodruns[name].filter(function(v) { return v<run; }));
}
var iscosmics = name.indexOf("Cosmics")>=0;
var iscollisions = name.indexOf("Collisions")>=0;
var isexpress = name.indexOf("Express")>=0;
var dsname = "/";
var series = "Run2018C";
var series2 = "Run2018";
var pd = "";
if (isexpress && iscosmics) { pd = "StreamExpressCosmics"; }
else if (isexpress && !iscosmics) { pd = "StreamExpress"; }
else if (!isexpress && iscosmics) { pd = "Cosmics"; }
else if (!isexpress && !iscosmics) { pd = "SingleMuon"; }
dsname += pd;
dsname += "/"+series+"-";
if (isexpress) { dsname += "Express-v1/DQMIO"; }
if (!isexpress) { dsname += "PromptReco-v3/DQMIO"; }
var link_offdqm = "https://cmsweb.cern.ch/dqm/offline/start?runnr="+run+";dataset="+dsname+";sampletype=offline_data;filter=all;workspace=CSC;size=M;root=CSC/Summary;";
var to_ret = "<a href='"+link_offdqm+"'>"+run+"</a>";
if (refrun > 0) {
var link_autodqm = "http://autodqm.cern.ch/plots.html?subsystem=CSC&data_series="+series2+"&data_sample="+pd+"&data_run="+run+"&ref_series="+series2+"&ref_sample="+pd+"&ref_run="+refrun;
to_ret += " (ref <a href='"+link_autodqm+"'>"+refrun+"</a> | " + (refrun-run) + ")";
}
return to_ret;
};
arr.sort(function(x,y) {return y[0]-x[0];});
$.makeTable = function(data,heading) {
var body = "<table id='table'>";
body += "<thead><tr>";
$.each(heading, function(k , v) { body += "<th>"+v.replace("RDA_","").replace("CMP_","").replace("RUN_","")+"</th>"; });
body += "</tr></thead>";
$.each(data, function() {
if (this[goodcols.indexOf("RDA_CMP_OCCUPANCY")] != "NOTSET") { return; }
if (this[goodcols.indexOf("RDA_STATE")] != "OPEN") { return; }
if (this[goodcols.indexOf("RDA_CMP_CSC")] == "EXCLUDED") { return; }
var row = "";
var style = "";
var icol = 0;
var link = getrunlinks(this);
var isprompt = link.indexOf("Prompt")>=0;
if (isprompt) {
style += "background-color: rgb(137,253,146);";
} else {
if ((Date.now()-Date.parse(this[goodcols.indexOf("RUN_MODIFIED")]))/(3600*24*1000) > 5) { return ; };
}
$.each(this, function(k , v) {
if (icol == 0) {
row += "<td>"+link+"</td>";
} else {
row += "<td>"+v+"</td>";
}
icol += 1;
});
body += "<tr style='"+style+"'>"+row+"</tr>";
});
body += "</table>";
return body;
};
var reduce = function (data) {
return $.map(data, function(val,idx) {
if (goodcols.includes(colnames[idx])) { return val; }
});
};
var reduced_arr = arr.map(reduce);
console.log(reduced_arr);
console.log(goodcols);
var table = $.makeTable(reduced_arr,goodcols);
$("html").prepend("<div id='container'>"+table+"</div>");
$("#container").css({
"padding": "2%",
});
$("table").css({
"align": "center",
"border": "solid 1px #DDEEEE",
"border-collapse": "collapse",
"font": "normal 13px Arial, sans-serif",
});
$("thead th").css({
"background-color": "#DDD",
"border": "solid 1px #000",
"color": "#000",
"padding": "5px",
"text-align": "left",
});
$("tbody td").css({
"border": "solid 1px #000",
"color": "#333",
"padding": "5px",
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment