<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Josh Cogan&#039;s Projects &#187; Computing</title>
	<atom:link href="http://joshcogan.com/wp/category/computing/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshcogan.com/wp</link>
	<description>Fun stuff Josh works on</description>
	<lastBuildDate>Tue, 19 Aug 2014 16:30:41 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>Ineffective Sorts</title>
		<link>http://joshcogan.com/wp/2013/03/ineffective-sorts/</link>
		<comments>http://joshcogan.com/wp/2013/03/ineffective-sorts/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 16:34:45 +0000</pubDate>
		<dc:creator><![CDATA[Josh]]></dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://joshcogan.com/wp/?p=60</guid>
		<description><![CDATA[So xkcd had a delightful comic a few days ago about Ineffective Sorts (and below), and it really struck a chord with me. I&#8217;ve often hear of people being asked to (pseudo)code quicksort, or something similar, during an interview. This<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://joshcogan.com/wp/2013/03/ineffective-sorts/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>So xkcd had a delightful comic a few days ago about <a href="http://xkcd.com/1185/" title="Ineffective Sorts" target="_blank">Ineffective Sorts (and below)</a>, and it really struck a chord with me. I&#8217;ve often hear of people being asked to (pseudo)code quicksort, or something similar, during an interview.  This really irks me.  If <em>on the job</em> a boss says, &#8220;Quickly Josh, we need a quicksort!!&#8221;, the last thing I&#8217;m gonna do is sit down and stare at a page of pseudo-code riddled with off-by-one errors.  Nor am I very likely to go back to the textbooks and look it up (a much safer option anyway).  Am I really being hired to reimplement STL or Boost libraries?  Because those guys look like they got this stuff pretty darn well.  And its super tested.</p>
<p>But you, my avid reader, protest &#8220;it&#8217;s a test to see how you think and reason&#8221;.  Okay that&#8217;s fair, but I, for the sake of discussion, claim quicksort and other standard algorithms aren&#8217;t the right way to test an applicant&#8217;s reasoning ability.  All applicants know quicksort could be asked, so we all look it up.  Now, when we are sitting down during an interview, we&#8217;re trying to <em>recall</em> all the intricacies of a mature algorithm.  Instead of reasoning through divide-and-conquer, I&#8217;m thinking &#8220;oh crap, now how to I pick the pivot to avoid those QS-attacks?&#8221;. I&#8217;m trying to remember how to get all the details right, when I should be iteratively addressing problems as they arrive.</p>
<p>Of course, if you&#8217;re hiring someone to squeeze out the next 1% of execution time in some DB-query, then absolutely he or she should know every damn intricacy of the standard algorithms. But for the rest of us, I think non-standard brain teasers or puzzles seem much better than reproducing a well-known mature algorithm.</p>
<p>IMHO =)</p>
<div style="width: 723px" class="wp-caption aligncenter"><img src="http://imgs.xkcd.com/comics/ineffective_sorts.png" width="713" height="667" alt="Only Randall Munroe can write Alt Text" class /><p class="wp-caption-text">XKCD always getting to the heart of the matter</p></div>
]]></content:encoded>
			<wfw:commentRss>http://joshcogan.com/wp/2013/03/ineffective-sorts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Printing TTree Branches</title>
		<link>http://joshcogan.com/wp/2013/03/printing-ttree-branches/</link>
		<comments>http://joshcogan.com/wp/2013/03/printing-ttree-branches/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 06:22:15 +0000</pubDate>
		<dc:creator><![CDATA[Josh]]></dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ROOT]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://joshcogan.com/wp/?p=51</guid>
		<description><![CDATA[I use ROOT, you use ROOT, all of high energy physics uses ROOT.  How many times have you found yourself scrolling through that graphical TBrowser trying to find that one particular TBranch in the TTree?  Like someone sends you the<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://joshcogan.com/wp/2013/03/printing-ttree-branches/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I use ROOT, you use ROOT, all of high energy physics uses ROOT.  How many times have you found yourself scrolling through that graphical TBrowser trying to find that one particular TBranch in the TTree?  Like someone sends you the Release17 version of the blah-di-blah centrally produced NTuple and you just want to know if it has &#8220;photon_crazyRecoMethod_px&#8221; in it.  This crap happens to me all the time.  So I decided to write a little Unix-inspired bash script to solve all my life&#8217;s woes; or well..just this one.</p>
<p>The trick here is to get ROOT to echo all the TBranch names to stdout (through TTree::Print()) so that we can use all our normal grep tricks to find that one name we are looking for.  Here is the script in its totality:</p>
<pre>
#!/bin/bash
#./thisScript treeName fileName
{ echo "TFile f(\"$2\", \"READ\")" ; echo "$1-&gt;Print()" ; echo ".q" ; } |\
 root -l -b |\
 grep -v "^[*]Tree" |\
 sed -n -r "s/^[^:]*:([^ ]+)\s+:.*/\1/p"
#EOF</pre>
<p>Bash curly braces always freak me out, because they can do several different jobs. In this particular case, we are moving the output of several commands to stdin of another process.  Remember in the above script, the $1 and $2 get expanded to the first and second arguments passed to the shell script.  Here is, effectively, how the curly braces and ROOT call are interacting&#8230;</p>
<pre>$&gt; root -l -b
##ROOT ASCII ART###
&gt;&gt;&gt;TFile f("$2", "READ")
&gt;&gt;&gt;$1-&gt;Print()
&gt;&gt;&gt;.q
$&gt;</pre>
<p>Which causes ROOT to vomit lots of text like this&#8230;</p>
<pre>
...
*Entries : 172375 : Total Size= 23966439 bytes File Size = 13664685 *
*Baskets : 917 : Basket Size= 32000 bytes Compression= 1.75 *
*............................................................................*
*Br 180 :mooreseg_phi : vector&lt;double&gt; *
*Entries : 172375 : Total Size= 23968281 bytes File Size = 8502181 *
*Baskets : 917 : Basket Size= 32000 bytes Compression= 2.82 *
*............................................................................*
*Br 181 :mooreseg_theta : vector&lt;double&gt; *
*Entries : 172375 : Total Size= 23970123 bytes File Size = 14002768 *
*Baskets : 917 : Basket Size= 32000 bytes Compression= 1.71 *
*............................................................................*
...</pre>
<p>Since all that goes to stdout we can just grep/sed our way through it until we get a pretty list of branch names.  Now we just have a plain text stream.</p>
<pre>
$>./treeprint.sh CollectionTree data12_jte.root
...
mooreseg_z
mooreseg_phi
mooreseg_theta
...
$>
</pre>
<p>Pretty simple huh? How about that for <a href="http://en.wikipedia.org/wiki/Worse_is_better" title=""worse is better"" target="_blank">&#8220;worse is better&#8221;</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://joshcogan.com/wp/2013/03/printing-ttree-branches/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
