source: trunk/Mars/datacenter/db/fact_runinfo.php@ 12665

Last change on this file since 12665 was 12665, checked in by Daniela Dorner, 13 years ago
added (webinterface to display content of factdata.runinfo)
  • Property svn:executable set to *
File size: 12.0 KB
Line 
1<?php
2{
3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup)
4 {
5 $fromtable="RunInfo";
6
7 $groups = 0;
8 foreach ($checkgroup as $element)
9 if ($element==-1)
10 $groups++;
11
12 $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
13
14 if ($groups>0)
15 {
16 foreach ($checkgroup as $key => $element)
17 if ($element==-1)
18 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
19 //don't put a '#' at the beginning of the alias, else SortBy won't work anymore
20 $query0 .= " COUNT(*) as 'NumRuns', ";
21 $query0 .= " Round(Sum(TimeDiff(fRunStop,fRunStart))/60./60.,1) as 'Time [h]' ";
22 }
23 else
24 {
25 $query0 .= " Concat(fRunNumber,'_', LPAD(fFileNumber, 3, 0)) as 'Run' ";
26
27 if (!empty($_GET["fComments"]))
28 {
29 $query0 .= ", if (Count(fComment)>0, Concat('<a&ws;href=\'run_comment.php?fRunNumber=',fRunNumber,'&fFileNumber=', fFileNumber, '\'>', Count(fComment), '</a>'), ' ') ";
30 $query0 .= " as 'Comments'";
31 }
32
33 foreach ($_GET as $key => $element)
34 if ($_GET[$key]=="On")
35 if ($key!="fComments")
36 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
37 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
38 }
39
40 $query0 .= " FROM " . $fromtable;
41
42 foreach ($_GET as $key => $element)
43 if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
44 $query0 .= GetJoin($fromtable, $key);
45 $query0 .= " LEFT JOIN RunComments USING (fRunNumber, fFileNumber) ";
46
47 foreach ($checkwhere as $key => $element)
48 {
49 if (empty($element) || $element<=0)
50 continue;
51
52 if (strpos($query0, " WHERE ")==FALSE)
53 $query0 .= " WHERE ";
54 else
55 if ($element!=-1)
56 if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
57 $query0 .= " AND ";
58
59 if ($element!=-1)
60 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
61 }
62
63 if (strpos($query0, " WHERE ")==FALSE)
64 $query0 .= " WHERE ";
65 else
66 $query0 .= " AND ";
67
68 if (!empty($_GET["fStartDate"]))
69 {
70 $startdate=substr($_GET["fStartDate"], 0, 10);
71 if ($startdate=="0000-00-00")
72 $query0 .=" fRunNumber >= " . $startdate . " ";
73 else
74 $query0 .= " fRunNumber >= " . $startdate . " - 1 ";
75 }
76
77 if (!empty($_GET["fStopDate"]))
78 {
79// if (strpos(strrev($query0), " DNA ")!=0)
80// $query0 .= " AND ";
81
82 $stopdate=substr($_GET["fStopDate"], 0, 10);
83 $query0 .= " AND fRunNumber <= " . $stopdate . " ";
84 }
85
86 if ($groups>0)
87 {
88 $query0 .= " GROUP BY ";
89 $num = $groups;
90 foreach ($checkgroup as $key => $element)
91 if ($element==-1)
92 {
93 $query0 .= GetCheck($fromtable, $key);
94 if ($num-->1)
95 $query0 .= ", ";
96 }
97 }
98 else
99 $query0 .= " GROUP BY fRunNumber, fFileNumber ";
100
101
102
103 if (!empty($_GET["fSortBy"]))
104 {
105 $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " ";
106 if (substr($_GET["fSortBy"], -1)=="-")
107 $query0 .= "DESC";
108 }
109 else
110 if ($groups==0)
111 $query0 .= " ORDER BY Run DESC";
112
113 if (empty($_GET["fNumStart"]))
114 $_GET["fNumStart"]=0;
115
116 if (empty($_GET["fSendTxt"]))
117 $query0 .= " LIMIT " . $_GET["fNumStart"] . ", " . $_GET["fNumResults"];
118
119 return $query0;
120 }
121
122 function InitGet($_GET)
123 {
124 // Find out whether it is the first call to the php script
125 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
126
127 if (empty($_GET["fNumResults"]))
128 $_GET["fNumResults"]="20";
129
130 if (empty($_GET["fNumEvents"]))
131 $_GET["fNumEvents"]=$first?"Off":"";
132
133 if (empty($_GET["fComments"]))
134 $_GET["fComments"]=$first?"On":"";
135
136 if (empty($_GET["fNumPhysicsTrigger"]))
137 $_GET["fNumPhysicsTrigger"]=$first?"On":"";
138
139 if (empty($_GET["Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)"]))
140 $_GET["Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)"]=$first?"On":"";
141
142 if (empty($_GET["fNumPedestalTrigger"]))
143 $_GET["fNumPedestalTrigger"]=$first?"On":"";
144
145 if (empty($_GET["fNumELPTrigger"]))
146 $_GET["fNumELPTrigger"]=$first?"On":"";
147
148 if (empty($_GET["fNumTimeTrigger"]))
149 $_GET["fNumTimeTrigger"]=$first?"On":"";
150
151 if (empty($_GET["fNumExt1Trigger"]))
152 $_GET["fNumExt1Trigger"]=$first?"Off":"";
153
154 if (empty($_GET["fNumExt2Trigger"]))
155 $_GET["fNumExt2Trigger"]=$first?"Off":"";
156
157 if (empty($_GET["fNumILPTrigger"]))
158 $_GET["fNumILPTrigger"]=$first?"Off":"";
159
160 if (empty($_GET["fNumOtherTrigger"]))
161 $_GET["fNumOtherTrigger"]=$first?"Off":"";
162
163 if (empty($_GET["TimeDiff(fRunStop,fRunStart)"]))
164 $_GET["TimeDiff(fRunStop,fRunStart)"]=$first?"On":"";
165
166 if (empty($_GET["fRunStart"]))
167 $_GET["fRunStart"]=$first?"On":"";
168
169 if (empty($_GET["fRunStop"]))
170 $_GET["fRunStop"]=$first?"Off":"";
171
172 if (empty($_GET["fROI"]))
173 $_GET["fROI"]=$first?"On":"";
174
175 if (empty($_GET["fROITimeMarker"]))
176 $_GET["fROITimeMarker"]=$first?"On":"";
177
178 if (empty($_GET["fFitsFileErrors"]))
179 $_GET["fFitsFileErrors"]=$first?"On":"";
180
181 if (empty($_GET["fHasDrsFile"]))
182 $_GET["fHasDrsFile"]=$first?"Off":"";
183
184 if (empty($_GET["fMd5sumRaw"]))
185 $_GET["fMd5sumRaw"]=$first?"Off":"";
186
187 if (empty($_GET["fMd5sumRawZip"]))
188 $_GET["fMd5sumRawZip"]=$first?"Off":"";
189
190 if (empty($_GET["fRunTypeName"]))
191 $_GET["fRunTypeName"]=$first?"On":"";
192
193 }
194
195 function PrintForm($_GET, $host, $user, $pw, $db)
196 {
197 printf("<center>\n");
198 printf("<form action=\"fact_runinfo.php\" METHOD=\"GET\">\n");
199
200 // pull down boxes
201
202 printf(" <table>\n");
203 printf(" <tr><td>\n");
204 PrintPullDown($host, $user, $pw, $db, "RunType", "fRunTypeName", "fRunTypeKEY", "RunType");
205 printf(" </td></tr></table>\n");
206 printf(" <p>\n");
207
208 printf(" <table>\n");
209 printf(" <tr>\n");
210
211 CheckBox("fComments", "comments");
212 CheckBox("fRunStart", "start time");
213 CheckBox("fRunStop", "stop time");
214 CheckBox("TimeDiff(fRunStop,fRunStart)", "duration");
215 CheckBox("fROI", "roi");
216 CheckBox("fNumEvents", "#Evts");
217
218 printf(" </tr>\n");
219 printf(" <tr>\n");
220
221 CheckBox("Round(fNumPhysicsTrigger/Time_to_sec(TimeDiff(fRunStop,fRunStart)),1)", "phys rate");
222 CheckBox("fNumPhysicsTrigger", "#Phys");
223 CheckBox("fNumPedestalTrigger", "#Ped");
224 CheckBox("fNumELPTrigger", "#ELP");
225 CheckBox("fNumTimeTrigger", "#Time");
226
227 printf(" </tr>\n");
228 printf(" <tr>\n");
229
230 CheckBox("fNumExt1Trigger", "#Ext1");
231 CheckBox("fNumExt2Trigger", "#Ext2");
232 CheckBox("fNumILPTrigger", "#ILP");
233 CheckBox("fNumOtherTrigger", "#Other");
234
235 printf(" </tr>\n");
236 printf(" <tr>\n");
237
238 CheckBox("fROITimeMarker", "roi-tm");
239 CheckBox("fFitsFileErrors", "file err");
240 CheckBox("fHasDrsFile", "num drs");
241 CheckBox("fMd5sumRaw", "md5");
242 CheckBox("fMd5sumRawZip", "md5(gz)");
243
244 printf(" </tr>\n");
245 printf(" </table>\n");
246 printf(" <p>\n");
247
248 if (empty($_GET["fStartDate"]))
249 $timemin = GetMin("fRunNumber", "RunInfo", $host, $user, $pw, $db);
250 else
251 $timemin = $_GET["fStartDate"];
252
253 if (empty($_GET["fStopDate"]))
254 $timemax = GetMax("fRunnumber", "RunInfo", $host, $user, $pw, $db);
255 else
256 $timemax = $_GET["fStopDate"];
257
258 printf("Run&nbsp;(yyyymmdd)&nbsp;from&nbsp;<input name=\"fStartDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">\n", $timemin);
259 printf("to&nbsp;<input name=\"fStopDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"%s\">&nbsp;&nbsp;&nbsp;&nbsp;\n", $timemax);
260
261 printf(" Results:\n");
262 printf(" <select name=\"fNumResults\">\n");
263
264 $numres = array("10", "20", "50", "100", "200", "500", "1000", "2000");
265 foreach ($numres as $element)
266 {
267 if ($element==$_GET["fNumResults"])
268 printf("<option value=\"%s\" selected>%3s</option>\n", $element, $element);
269 else
270 printf("<option value=\"%s\">%3s</option>\n", $element, $element);
271 }
272 printf(" </select>\n");
273 printf(" &nbsp;&nbsp;&nbsp;\n");
274
275 ini_set("mysql.trace_mode", "Off");
276 ini_set("display_errors", "Off");
277
278 printf("<input class='Width' type='submit' value='Query Table'>&nbsp;&nbsp;&nbsp;\n");
279 printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"fact_runinfo.php\"'>&nbsp;&nbsp;&nbsp;\n");
280 if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
281 printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>&nbsp;&nbsp;&nbsp;\n", $_SERVER["REQUEST_URI"]);
282 printf("</form>\n");
283 printf("</center>\n");
284 printf("</td>\n");
285 printf("</tr>\n");
286 printf("<tr class='Block'>\n");
287 printf("<td>\n");
288 }
289
290 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup)
291 {
292 $db_id = mysql_connect($host, $user, $pw);
293 if ($db_id==FALSE)
294 {
295 printf("mysql_connect returned the following error: %s\n", mysql_error());
296 die("");
297 }
298 mysql_select_db($db);
299 mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
300
301
302 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup);
303
304 $result0 = mysql_query($query0, $db_id);
305 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
306
307 if ($result0)
308 {
309 if ($html=="1")
310 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
311 else
312 PrintText($result0);
313
314 mysql_free_result($result0);
315 mysql_free_result($result1);
316 }
317 mysql_close($db_id);
318
319 if ($html=="1")
320 PrintSubmittedQuery($query0, $db, "old");
321 }
322
323 include ("include.php");
324 include ("db.php");
325 include ("factdefs.php");
326
327 ini_set("display_errors", "On");
328 ini_set("mysql.trace_mode", "On");
329
330 if (!empty($_GET["fSendTxt"]))
331 {
332 header("Content-type: application/octet");
333 header("Content-Disposition: attachment; filename=query-result.txt");
334
335 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
336 }
337 else
338 {
339 echo (file_get_contents("index-header.html"));
340
341 $environment = sizeof($_GET);
342
343 InitGet($_GET);
344 PrintForm($_GET, $host, $user, $pw, $db);
345
346 if ($environment==0)
347 printf("No query submitted yet.<BR>");
348 else
349 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup);
350
351 echo (file_get_contents("index-footer.html"));
352 }
353
354 ini_set("display_errors", "Off");
355 ini_set("mysql.trace_mode", "Off");
356}
357?>
Note: See TracBrowser for help on using the repository browser.