Subversion Repositories f9daq

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
268 f9daq 1
<?php
2
 
3
function send_message($id, $message, $progress) {
4
    $d = array('message' => $message , 'progress' => $progress); //prepare json
5
    $x = array('id' => $id, 'data' => $d );
6
    echo json_encode($x) . PHP_EOL;
7
/*
8
   if (PHP_SAPI !== 'cli') {
9
     echo PHP_EOL;
10
     ob_flush();
11
   }
12
   flush();
13
*/
14
}
15
 
16
 
17
function executeCmd($commandLine) {
18
 
19
  $pipe = popen("$commandLine" , 'r');
20
 
21
  if (!$pipe) {
22
    print "pipe failed.";
23
    return "";
24
  }
25
  $output = '';
26
  $out    = '';
27
  while(!feof($pipe)) {
28
    $contents = fread($pipe, 12);
29
    $unpacked = unpack("l*",$contents);
30
    $len0      = sizeof($unpacked);
31
    if ($len0 > 2) {
32
      $id       =  $unpacked[1];
33
      $len      =  $unpacked[2];
34
      $progress =  $unpacked[3];
35
      if ($len>0){
36
        $out= fread($pipe, $len);
37
        send_message($id,$out,$progress);
38
      }
39
      $output .=$out;
40
    }
41
  }
42
  pclose($pipe);
43
  return $output;
44
}
45
 
46
 if (isset($_POST["min"])){
47
   $min =  $_POST["min"];
48
 } else {
49
   $min =  0;
50
 }
51
 
52
 if (isset($_POST["max"])){
53
   $max =  $_POST["max"];
54
 } else {
55
   $max =  10;
56
 }
57
 
58
 if (isset($_POST["fitfun"])){
59
   $fitfun =  $_POST["fitfun"];
60
 } else {
61
   $fitfun =  "gaus";
62
 }
63
 
64
 if (isset($_POST["prm"])){
65
   $prm =  $_POST["prm"];
66
 } else {
67
   $prm =  "0;1;2";
68
 }
69
 
70
 if (isset($_POST["name"])){
71
   $name =  $_POST["name"];
72
 } else {
73
   $name = "h101";
74
 }
75
 
76
 if (isset($_POST["data"])){
77
   $data =  $_POST["data"];
78
 } else {
79
   $data = '{ "_typename" : "TH1F", "fUniqueID" : 0, "fBits" : 50331656, "fName" : "h100", "fTitle" : "Number of particles in the event", "fLineColor" : 602, "fLineStyle" : 1, "fLineWidth" : 1, "fFillColor" : 0, "fFillStyle" : 1001, "fMarkerColor" : 1, "fMarkerStyle" : 1, "fMarkerSize" : 1, "fNcells" : 52, "fXaxis" : { "_typename" : "TAxis", "fUniqueID" : 0, "fBits" : 50331648, "fName" : "xaxis", "fTitle" : "N particles", "fNdivisions" : 510, "fAxisColor" : 1, "fLabelColor" : 1, "fLabelFont" : 42, "fLabelOffset" : 0.005, "fLabelSize" : 0.035, "fTickLength" : 0.03, "fTitleOffset" : 1, "fTitleSize" : 0.035, "fTitleColor" : 1, "fTitleFont" : 42, "fNbins" : 50, "fXmin" : -0.5, "fXmax" : 49.5, "fXbins" : [], "fFirst" : 0, "fLast" : 0, "fBits2" : 0, "fTimeDisplay" : false, "fTimeFormat" : "", "fLabels" : null, "fModLabs" : null }, "fYaxis" : { "_typename" : "TAxis", "fUniqueID" : 0, "fBits" : 50331648, "fName" : "yaxis", "fTitle" : "N events", "fNdivisions" : 510, "fAxisColor" : 1, "fLabelColor" : 1, "fLabelFont" : 42, "fLabelOffset" : 0.005, "fLabelSize" : 0.035, "fTickLength" : 0.03, "fTitleOffset" : 0, "fTitleSize" : 0.035, "fTitleColor" : 1, "fTitleFont" : 42, "fNbins" : 1, "fXmin" : 0, "fXmax" : 1, "fXbins" : [], "fFirst" : 0, "fLast" : 0, "fBits2" : 0, "fTimeDisplay" : false, "fTimeFormat" : "", "fLabels" : null, "fModLabs" : null }, "fZaxis" : { "_typename" : "TAxis", "fUniqueID" : 0, "fBits" : 50331648, "fName" : "zaxis", "fTitle" : "", "fNdivisions" : 510, "fAxisColor" : 1, "fLabelColor" : 1, "fLabelFont" : 42, "fLabelOffset" : 0.005, "fLabelSize" : 0.035, "fTickLength" : 0.03, "fTitleOffset" : 1, "fTitleSize" : 0.035, "fTitleColor" : 1, "fTitleFont" : 42, "fNbins" : 1, "fXmin" : 0, "fXmax" : 1, "fXbins" : [], "fFirst" : 0, "fLast" : 0, "fBits2" : 0, "fTimeDisplay" : false, "fTimeFormat" : "", "fLabels" : null, "fModLabs" : null }, "fBarOffset" : 0, "fBarWidth" : 1000, "fEntries" : 10000, "fTsumw" : 9983, "fTsumw2" : 9983, "fTsumwx" : 175205, "fTsumwx2" : 3620667, "fMaximum" : -1111, "fMinimum" : -1111, "fNormFactor" : 0, "fContour" : [], "fSumw2" : [], "fOption" : "", "fFunctions" : { "_typename" : "TList", "name" : "TList", "arr" : [], "opt" : [] }, "fBufferSize" : 0, "fBuffer" : [], "fBinStatErrOpt" : 0, "fArray" : [0, 0, 0, 0, 86, 122, 117, 135, 176, 263, 306, 367, 412, 508, 596, 643, 618, 566, 524, 552, 503, 439, 418, 374, 333, 311, 229, 222, 188, 172, 123, 120, 92, 82, 81, 53, 47, 32, 36, 28, 27, 17, 14, 9, 10, 6, 8, 6, 4, 5, 3, 17] }';
80
 }
81
 
82
$json  = json_decode($data, true);
83
$class = $json['_typename'];
84
$hname = $json['fName'];
85
$htitle= $json['fTitle'];
86
$xaxis = $json['fXaxis'];
87
$xtitle= $xaxis['fTitle'];
88
$xbins = $xaxis['fNbins'];
89
$xmin  = $xaxis['fXmin'];
90
$xmax  = $xaxis['fXmax'];
91
$yaxis = $json['fYaxis'];
92
$ytitle= $yaxis['fTitle'];
93
 
94
 
95
$hdata='';
96
foreach( $json['fArray'] as $key => $value){
97
        if($key != "0"){
98
            $hdata .= ", ";
99
        }
100
        $hdata .= $value;
101
}
102
 
103
$cmd0  = ".L th1fit.cc+". PHP_EOL;
104
$cmd0 .= "double data[]={". $hdata . "};" .PHP_EOL;
105
$cmd0 .= "th1fit(data, \"$hname\",\"$htitle;$xtitle;$ytitle\", $xbins , $xmin, $xmax, $min ,$max ,\"$fitfun\");". PHP_EOL;
106
 
107
if (file_exists('/opt/root/bin/thisroot.sh')){
108
  $profile ='/opt/root/bin/thisroot.sh';
109
}
110
$cmd  ="bash -c 'source $profile ; root -b -l <<EOL" . PHP_EOL;
111
$cmd .= $cmd0. PHP_EOL;
112
$cmd .= "EOL'". PHP_EOL;
113
executeCmd($cmd);
114
//echo $cmd0;
115
//echo "name=$name min=$min max=$max func=$fitfun data=$data";
116
?>
117