function get_rootplot_handle($args) { putenv('ROOTSYS=/afs/cern.ch/cms/external/lcg/external/root/5.12.00/slc3_ia32_gcc323/root'); putenv('LD_LIBRARY_PATH=/afs/cern.ch/cms/external/lcg/external/root/5.12.00/slc3_ia32_gcc323/root/lib:/afs/cern.ch/cms/sw/slc3_ia32_gcc323/external/boost/1.33.1/lib:$LD_LIBRARY_PATH'); putenv('ROOTPLOT=CMSSW_0_8_0/bin/slc3_ia32_gcc323/cmsecal_rootplot'); @system('rm rootplot_error.log'); $handle = popen("\$ROOTPLOT {$args} > rootplot_error.log 2>&1", "w") or die('Failed to open rootplot program'); if (!$handle) { return 0; } flush(); fflush($handle); if (get_rootplot_error()) { pclose($handle); return 0; } return $handle; }
function draw_plot() { if (!isset($_GET['tablefield']) || !isset($_GET['iov_id']) || !isset($_GET['run']) || !isset($_GET['plottype'])) { return 0; } echo "<div class='plot'>"; list($table, $field) = split('\\.', $_GET['tablefield']); $iov_id = $_GET['iov_id']; $run = $_GET['run']; $plottype = $_GET['plottype']; $name = "../ecalconddb/plotcache/run{$run}.{$table}.{$field}.{$iov_id}.{$plottype}"; $names = array(); if ($img_files = glob($name . '*.png')) { // Check cache foreach ($img_files as $img) { array_push($names, preg_replace('/\\.png/', '', $img)); } } elseif ($names = db_make_rootplot($table, $field, $iov_id, $plottype, $name)) { // Draw Plots } else { // Error echo "<h1>ERROR</h1>"; $error_msg = get_rootplot_error(); echo "<p>", $error_msg, "</p>"; } if ($names == 0) { echo "Names is zero."; } foreach ($names as $name) { $img = $name . '.png'; $root = 'download.php?file=' . $name . '.root'; echo "<a href='{$root}' type='application/octet-stream'><img src=\"{$img}\" alt=\"{$img}\"/><br />Click to download ROOT file</a>"; echo " Cached on " . date("Y-m-d H:i:s", filemtime($img)) . "<br />"; } echo "</div>"; }
function db_make_rootplot($table, $field, $iov_id, $plottype, $name) { global $conn; $plot_params = db_fetch_plot_params($table, $field); $fmt = "png"; $title = $plot_params['FIELD_CONTENT']; $chan_name = $plot_params['LOGIC_ID_NAME']; $map_name = $plot_params['MAP_BY_LOGIC_ID_NAME']; if ($plottype == 'histo_all') { $type = 'TH1F'; $grp = 0; $sql = "select {$field} from {$table} where iov_id = :iov_id"; $xtitle = $plot_params['LABEL']; $ytitle = ""; } elseif ($plottype == 'histo_grp') { $type = 'TH1F'; $grp = 1; $sql = "select vd.id1name, cv.id1, d.{$field} from {$table} d, channelview cv, viewdescription vd\n where d.iov_id = :iov_id \n and d.logic_id = cv.logic_id\n and cv.name = cv.maps_to\n and cv.name = vd.name\n order by cv.id1, cv.id2, cv.id3"; $xtitle = $plot_params['LABEL']; $ytitle = ""; } elseif ($plottype == 'graph_all') { $type = 'TGraph'; $grp = 0; $sql = "select rownum, {$field}\n from (select d.{$field} from {$table} d, channelview cv\n where d.iov_id = :iov_id \n and d.logic_id = cv.logic_id\n and cv.name = cv.maps_to\n order by cv.id1, cv.id2, cv.id3)"; $xtitle = $plot_params['LOGIC_ID_EXPLANATION']; $ytitle = $plot_params['LABEL']; } elseif ($plottype == 'graph_grp') { $type = 'TGraph'; $grp = 1; $sql = "select id1name, id1, rownum, {$field}\n from (select vd.id1name, cv.id1, d.{$field} from {$table} d, channelview cv, viewdescription vd\n where d.iov_id = :iov_id \n and d.logic_id = cv.logic_id\n and cv.name = cv.maps_to\n and cv.name = vd.name\n order by cv.id1, cv.id2, cv.id3)"; $xtitle = $plot_params['LOGIC_ID_EXPLANATION']; $ytitle = $plot_params['LABEL']; } elseif ($plottype == 'map_all') { // if (!$map_name) { echo "No map_name."; return 0; } // Cannot map without an _index type mapping $type = 'Map'; $grp = 1; $sql = "select id1name, id1, rownum, {$field}\n from (select vd.id1name, cv.id1, d.{$field} from {$table} d, channelview cv, viewdescription vd\n where d.iov_id = :iov_id \n and d.logic_id = cv.logic_id\n and cv.name = 'EB_crystal_number'\n and cv.name = vd.name\n order by cv.id1, cv.id2, cv.id3)"; $xtitle = ""; $ytitle = ""; } else { die("Unknown plottype"); } $stmt = oci_parse($conn, $sql); oci_bind_by_name($stmt, ':iov_id', $iov_id); oci_execute($stmt); $n = 0; $names = array(); $rptitle = $title; $rpname = $name; while ($row = oci_fetch_row($stmt)) { // Augment titles and file names if there is grouping if ($grp) { $grp_name = array_shift($row); $curr_grp = array_shift($row); } // If the group is over add finish the last plot if ($n != 0 && $grp && $last_grp != $curr_grp) { array_push($names, $rpname); pclose($rootplot); } // Open a rootplot handle if it is the first row or the group changed if ($n == 0 || $grp && $last_grp != $curr_grp) { if ($grp) { $rptitle = $title . " ({$grp_name} {$curr_grp})"; $rpname = $name . ".{$grp_name}{$curr_grp}"; } $histo_min = $plot_params['HISTO_MIN']; $histo_max = $plot_params['HISTO_MAX']; $rootplot = get_rootplot_handle("-T \"{$rptitle}\" -X \"{$xtitle}\" -Y \"{$ytitle}\" {$type} {$fmt} {$rpname} {$histo_min} {$histo_max}"); if (!$rootplot || get_rootplot_error()) { return 0; } } // Write a row of data to the rootplot handle $dataline = join(' ', $row) . "\n"; fwrite($rootplot, $dataline); // Increment $n++; if ($grp) { $last_grp = $curr_grp; } } // Close the last plot array_push($names, $rpname); pclose($rootplot); if ($n == 0) { echo "N is zero"; } if (get_rootplot_error() || $n == 0) { return 0; } return $names; }