source: releases/Mars.2014.05.26/datacenter/db/ctamcinfo.php@ 18752

Last change on this file since 18752 was 17386, checked in by tbretz, 11 years ago
Removed svn:executable property, these are no executables.
File size: 13.2 KB
Line 
1<?php
2{
3 function CreateQuery($alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits)
4 {
5 $fromtable="MCRunData";
6
7 $groups = 0;
8 foreach ($checkgroup as $element)
9 if ($element==-1)
10 $groups++;
11
12 $statusgroups = 0;
13 foreach ($checkstatusgroup as $element)
14 if ($element==-1)
15 $statusgroups++;
16
17 $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
18
19 if ($groups>0 || $statusgroups>0)
20 {
21 if ($groups>0)
22 {
23 foreach ($checkgroup as $key => $element)
24 if ($element==-1)
25 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
26 /*
27 //--------------------------------------------------
28 //$query0 .= " TIMEDIFF(fRunStop, fRunStart), ";
29 // Only available in MySQL>4.1.1
30 $query0 .= "SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0, " .
31 "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60, " .
32 "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)))/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
33 //--------------------------------------------------
34 $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
35 $query0 .= " Min(fZenithDistance) as '" . $alias["Min(fZenithDistance)"] . "', ";
36 $query0 .= " Max(fZenithDistance) as '" . $alias["Max(fZenithDistance)"] . "', ";
37 */
38 }
39 if ($statusgroups>0)
40 {
41 foreach ($checkstatusgroup as $key => $element)
42 if ($element==-1)
43 $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval " . $timelimits[$key] . " hour) < fStartTime,'running','crashed')),if(isnull(" . $needs[$key] . "),'not done','failed'))) ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
44 // $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', ";
45
46// $query0 .= " count(*) as '# Runs'";
47
48 }
49 $query0 .= " COUNT(*) as '# Runs' ";
50 $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' ";
51 $query0 .= ", SUM(fNumEvents) DIV 1000 as '" . $alias["SUM(fNumEvents) DIV 1000"] . "' ";
52 }
53 else
54 {
55 $query0 .= " MCRunData.fMCRunNumber as 'Run' ";
56// $query0 .= " Concat(RunData.fTelescopeNumber,':', RunData.fRunNumber,':', RunData.fFileNumber) as 'Run' ";
57// $query0 .= " Concat('M', RunData.fTelescopeNumber,':', LPAD(RunData.fRunNumber,8, ' '),'/', LPAD(RunData.fFileNumber, 3, ' ')) as 'Tel:Run/File' ";
58
59 if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"]))
60 {
61 $query0 .= ", CONCAT('<A&ws;HREF=\"http://cluster.isdc.unige.ch/cta/compute-0-', fProductionHostKEY , '/simtel/cta-ultra3/0.0deg/Data/', LCASE(fParticleTypeName), '_20deg_90deg_run', LPAD(MCRunData.fMCRunNumber, 6,'0'), '___cta-ultra3_desert.simtel.gz\">simtel.gz</A> <A&ws;HREF=\"http://cluster.isdc.unige.ch/cta/compute-0-', fProductionHostKEY , '/chimp/cta-ultra3/0.0deg/Data/', LCASE(fParticleTypeName), '_20deg_90deg_run', LPAD(MCRunData.fMCRunNumber, 6,'0'), '___cta-ultra3_desert.root\">root</A>') ";
62 $query0 .= " as 'Download'";
63 }
64
65 foreach ($_GET as $key => $element)
66 if ($key!="fLinks" && $_GET[$key]=="On" && $key!="fTest")
67 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
68 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
69 }
70
71 $query0 .= " FROM MCRunData ";
72
73 $query0 .= " LEFT JOIN MCRunProcessStatus USING(fMCRunNumber) ";
74
75 foreach ($_GET as $key => $element)
76 if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
77 $query0 .= GetJoin($fromtable,$key);
78
79 /*
80 if ($_GET["fTest"]!="On")
81 {
82 if ($_GET["fSourceName"]!="On")
83 $query0 .= " LEFT JOIN Source USING(fSourceKEY) ";
84 $query0 .= " WHERE fTest='no'";
85 }
86 */
87
88 foreach ($checkwhere as $key => $element)
89 {
90 if (empty($element) || $element<=0)
91 continue;
92
93 if (strpos($query0, " WHERE ")==FALSE)
94 $query0 .= " WHERE ";
95 else
96 if ($element!=-1)
97 if (strrpos($query0, " AND ")!=strlen($query0)-5)// this if clause doesn't work
98 $query0 .= " AND ";
99
100 if ($element!=-1)
101 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
102 }
103
104 if (strpos($query0, " WHERE ")==FALSE)
105 $query0 .= " WHERE ";
106 else
107 $query0 .= " AND ";
108
109 $query0 .= StatusQuery("fCorsikaSimTelarray", $needs, $timelimits);
110 $query0 .= StatusQuery("fChimp", $needs, $timelimits);
111 $query0 .= StatusQuery("fCTAStar", $needs, $timelimits);
112 $query0 .= StatusQuery("fStereoB", $needs, $timelimits);
113 $query0 .= StatusQuery("fStereoC", $needs, $timelimits);
114 $query0 .= StatusQuery("fStereoG", $needs, $timelimits);
115
116 if ((!empty($_GET["fRunMin"]) || $_GET["fRunMin"]=="0") && !empty($_GET["fRunMax"]))
117 $query0 .= "MCRunData.fMCRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " ";
118
119// if ((!empty($_GET["fZDMin"]) || $_GET["fZDMin"]==0) && !empty($_GET["fZDMax"]))
120// $query0 .= "AND fZenithDistance BETWEEN " . $_GET["fZDMin"] . " AND " . $_GET["fZDMax"] . " ";
121
122/*
123 if (!empty($_GET["fDate"]))
124 $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" ";
125*/
126
127 /*
128 if (!empty($_GET["fSourceN"]))
129 $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
130
131 if (!empty($_GET["fStartDate"]))
132 {
133 if (strpos(strrev($query0), " DNA ")!=0)
134 $query0 .= " AND ";
135
136 $startdate=substr($_GET["fStartDate"], 0, 10);
137 if ($startdate=="0000-00-00")
138 $query0 .=" fRunStart >= '" . $startdate . " 00:00:00' ";
139 else
140 $query0 .= " fRunStart >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
141 }
142
143 if (!empty($_GET["fStopDate"]))
144 {
145 if (strpos(strrev($query0), " DNA ")!=0)
146 $query0 .= " AND ";
147
148 $stopdate=substr($_GET["fStopDate"], 0, 10);
149 $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
150 }
151
152 if (!empty($_GET["fSequenceNo"]) || $_GET["fSequenceNo"]=="0")
153 {
154 if (strpos(strrev($query0), " DNA ")!=0)
155 $query0 .= " AND ";
156
157 $query0 .= " fSequenceFirst = '" . $_GET["fSequenceNo"] . "' ";
158 }
159 */
160
161 //remove WHERE or AND in the end of the query
162 $query0=ereg_replace(" WHERE \$", " ", $query0);
163 $query0=ereg_replace(" AND \$", " ", $query0);
164
165 if ($groups>0)
166 {
167 $query0 .= " GROUP BY ";
168 $num = $groups;
169 foreach ($checkgroup as $key => $element)
170 if ($element==-1)
171 {
172 $query0 .= GetCheck($fromtable,$key);
173 if ($num-->1)
174 $query0 .= ", ";
175 }
176 }
177
178 if ($statusgroups>0)
179 {
180// $query0 .= " GROUP BY ";
181 if (strpos($query0, " GROUP BY ")==FALSE)
182 $query0 .= " GROUP BY ";
183 else
184 $query0 .= ", ";
185 $num = $statusgroups;
186 foreach ($checkstatusgroup as $key => $element)
187 if ($element==-1)
188 {
189 $query0 .= $alias[$key];
190 if ($num-->1)
191 $query0 .= ", ";
192 }
193 }
194
195 if (!empty($_GET["fSortBy"]))
196 {
197 $val=substr($_GET["fSortBy"], 0, -1);
198 $query0 .= " ORDER BY " . GetTable($fromtable, $val) . " ";
199 if (substr($_GET["fSortBy"], -1)=="-")
200 $query0 .= "DESC";
201 }
202 else
203 $query0 .=" ORDER BY MCRunData.fMCRunNumber ASC";
204
205 if (empty($_GET["fNumStart"]))
206 $start=0;
207 else
208 $start=$_GET["fNumStart"];
209
210 if (empty($_GET["fSendTxt"]))
211 $query0 .= " LIMIT " . $start . ", " . $_GET["fNumResults"];
212
213 return $query0;
214 }
215
216 function InitGet()
217 {
218 // Find out whether it is the first call to the php script
219 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
220
221 InitCTAMCRunInfo($first);
222 }
223
224 function PrintForm($host, $user, $pw, $db)
225 {
226 printf("<center>\n");
227 printf("<form action=\"ctamcinfo.php\" METHOD=\"GET\">\n");
228
229 printf("<input id='sh' type='hidden' name='fShowHide' value='");
230 if (!empty($_GET["fShowHide"]))
231 printf("%s", $_GET["fShowHide"]);
232 else
233 printf("1000000010");
234 printf("'>\n");
235 printf("<img id='allbutton' src='minus.png' alt='-' onclick=\"showhide('all')\"> <b>Menu</b>&nbsp;&nbsp;&nbsp;&nbsp;\n");
236 printf("&nbsp;&nbsp;<img id='infobutton' src='plus.png' alt='+' onClick=\"showhide('info');showhide('info2')\"> MCRunInfo \n");
237 printf("&nbsp;&nbsp;<img id='statbutton' src='plus.png' alt='+' onClick=\"showhide('stat');showhide('fail')\"> StatusInfo \n");
238 printf("&nbsp;&nbsp;<img id='rangesbutton' src='plus.png' alt='+' onClick=\"showhide('ranges')\"> Ranges \n");
239
240 printf(" <div id='all' style='display:block'>");
241 PrintCTAMCRunInfoMenu($host,$user,$pw,$db);
242// PrintRunInfo2Menu($host,$user,$pw,$db);
243 PrintCTAMCRunStatMenu();
244 PrintFailMenu();
245 printf(" <div id='ranges' style='display:none'>");
246// PrintSequMenu($host,$user,$pw,$db);
247// PrintNightRangeMenu($host,$user,$pw,$db, "RunData");
248 printf("<p>");
249// PrintZdRangeMenu($host,$user,$pw,$db);
250 PrintCTAMCRunRangeMenu($host,$user,$pw,$db);
251// printf(" <P>\n");
252// PrintSourceMenu($host,$user,$pw,$db);
253 printf("<p>");
254 printf("</div>");
255 printf("</div>");
256 printf(" <P>\n");
257
258 ini_set("mysql.trace_mode", "Off");
259 ini_set("display_errors", "Off");
260
261 PrintNumResPullDown();
262 PrintButtons("ctamcinfo.php");
263
264 printf("</form>\n");
265 printf("</center>\n");
266 printf("</td>\n");
267 printf("</tr>\n");
268 printf("<tr class='Block'>\n");
269 printf("<td>\n");
270 }
271
272 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits)
273 {
274 $db_id = mysql_connect($host, $user, $pw);
275 if ($db_id==FALSE)
276 {
277 printf("mysql_connect returned the following error: %s\n", mysql_error());
278 die("");
279 }
280 mysql_select_db($db);
281 mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
282
283 $query0 = CreateQuery($alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
284
285 $result0 = mysql_query($query0, $db_id);
286 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
287
288 if ($result0)
289 {
290 if ($html=="1" || $html=="2")
291 PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1, "");
292 else
293 PrintText($result0);
294
295 mysql_free_result($result0);
296 mysql_free_result($result1);
297 }
298 mysql_close($db_id);
299
300 if ($html=="1")
301 PrintSubmittedQuery($query0, $db, "");
302 }
303
304 include ("include.php");
305 include ("db.php");
306 include ("menu.php");
307 include ("ctadefs.php");
308
309 ini_set("display_errors", "On");
310 ini_set("mysql.trace_mode", "On");
311
312 if (!empty($_GET["fSendTxt"]))
313 {
314 header("Content-type: application/octet");
315 header("Content-Disposition: attachment; filename=query-result.txt");
316
317 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
318 }
319 else
320 {
321 if (empty($_GET["fPrintTable"]))
322 echo (file_get_contents("index-header.html"));
323
324 $environment = sizeof($_GET);
325
326 InitGet();
327 if (empty($_GET["fPrintTable"]))
328 PrintForm($host, $user, $pw, $db);
329
330 if ($environment==0)
331 printf("No query submitted yet.<BR>");
332 else
333 {
334 if (empty($_GET["fPrintTable"]))
335 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
336 else
337 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
338 }
339
340 if (empty($_GET["fPrintTable"]))
341 echo (file_get_contents("index-footer.html"));
342 }
343
344 ini_set("display_errors", "Off");
345 ini_set("mysql.trace_mode", "Off");
346}
347?>
Note: See TracBrowser for help on using the repository browser.