Ejemplo n.º 1
0
        public Web.ChunkedResponse HttpGet(Web.Session sess, string page, params string[] queryget)
        {
            if (String.Compare(page, "/qn") == 0)
            {
                return(new SySal.Web.HTMLResponse(Trackers.Length.ToString()));
            }
            int    g                  = -1;
            RWDJob rwdj               = new RWDJob();
            bool   rwdj_zone_set      = false;
            bool   rwdj_strip_set     = false;
            bool   rwdj_outdir_set    = false;
            bool   rwdj_firstview_set = false;
            bool   rwdj_lastview_set  = false;
            bool   rwdj_index_set     = false;
            string jobid              = null;

            foreach (string s in queryget)
            {
                if (s.StartsWith(a_gpu + "="))
                {
                    g = int.Parse(s.Substring(a_gpu.Length + 1));
                    if (g < 0 || g >= Trackers.Length)
                    {
                        return(new SySal.Web.HTMLResponse("ERROR: INVALID QUEUE SPECIFIED"));
                    }
                }
                else if (s.StartsWith(a_rwdz + "="))
                {
                    rwdj.ZoneFile = SySal.Web.WebServer.URLDecode(s.Substring(a_rwdz.Length + 1));
                    rwdj_zone_set = true;
                }
                else if (s.StartsWith(a_rwds + "="))
                {
                    rwdj.StripId   = uint.Parse(s.Substring(a_rwds.Length + 1));
                    rwdj_strip_set = true;
                }
                else if (s.StartsWith(a_rwdi + "="))
                {
                    rwdj.FragmentIndex = (int)uint.Parse(s.Substring(a_rwdi.Length + 1));
                    rwdj_index_set     = true;
                }
                else if (s.StartsWith(a_rwdfv + "="))
                {
                    rwdj.FirstView     = (int)uint.Parse(s.Substring(a_rwdfv.Length + 1));
                    rwdj_firstview_set = true;
                }
                else if (s.StartsWith(a_rwdlv + "="))
                {
                    rwdj.LastView     = (int)uint.Parse(s.Substring(a_rwdlv.Length + 1));
                    rwdj_lastview_set = true;
                }
                else if (s.StartsWith(a_rwdd + "="))
                {
                    rwdj.OutputDir  = SySal.Web.WebServer.URLDecode(s.Substring(a_rwdd.Length + 1));
                    rwdj_outdir_set = true;
                }
                else if (s.StartsWith(a_jobid + "="))
                {
                    jobid = s.Substring(a_jobid.Length + 1);
                }
            }
            if (g >= 0)
            {
                if (String.Compare(page, "/queryjob") == 0)
                {
                    IEnumerable <Job> res = null;
                    lock (Trackers[g].Jobs)
                        res = Trackers[g].Jobs.Where(x => String.Compare(x.ID, jobid) == 0);
                    if (res.Count() == 1)
                    {
                        return(new SySal.Web.HTMLResponse("WAITING"));
                    }
                    res = null;
                    lock (Trackers[g].Completed)
                    {
                        Job jc = Trackers[g].Current;
                        if (jc != null && String.Compare(jc.ID, jobid) == 0)
                        {
                            return(new SySal.Web.HTMLResponse("RUNNING"));
                        }
                        res = Trackers[g].Completed.Where(x => String.Compare(x.ID, jobid) == 0);
                    }
                    if (res.Count() == 1)
                    {
                        Job jj = res.First();
                        return(new SySal.Web.HTMLResponse((rwdj.ExitException.Length > 0) ? ("FAILED\r\n" + jj.ExitException) : "DONE"));
                    }
                    return(new SySal.Web.HTMLResponse("UNKNOWN"));
                }
                else if (String.Compare(page, "/killjob") == 0)
                {
                    bool killed           = false;
                    IEnumerable <Job> res = null;
                    lock (Trackers[g].Jobs)
                    {
                        res = Trackers[g].Jobs.Where(x => String.Compare(x.ID, jobid) == 0);
                        if (res.Count() == 1)
                        {
                            Trackers[g].Jobs.Remove(res.First());
                            killed = true;
                        }
                    }
                    return(new SySal.Web.HTMLResponse(killed ? "KILLED" : "CANNOT KILL"));
                }
                else if (String.Compare(page, "/addrwdj") == 0 && rwdj_zone_set && rwdj_strip_set && rwdj_outdir_set && (rwdj_firstview_set == rwdj_lastview_set && rwdj_index_set == rwdj_firstview_set))
                {
                    rwdj.Id = System.Guid.NewGuid();
                    lock (Trackers[g].Jobs)
                        if (Trackers[g].Jobs.Count > 0 || Trackers[g].Current != null)
                        {
                            return(new SySal.Web.HTMLResponse("REFUSED-BUSY"));
                        }
                        else
                        {
                            Trackers[g].Jobs.Add(rwdj);
                        }
                    JobsWaiting.Set();
                    return(new SySal.Web.HTMLResponse("CREATED " + rwdj.ID));
                }
            }
            System.IO.StringWriter swr = new System.IO.StringWriter();
            swr.WriteLine("<html><head><title>GPUTrackingServer " + ProcessInstance + " at " + ComputerName + "</title>" +
                          "  <style type=\"text/css\"> " +
                          "H1 " +
                          "{ " +
                          " color : Navy; font-family : Segoe UI, Trebuchet MS, Verdana, Helvetica, Arial; font-size : 24px; opacity: 1; line-height: 24px; " +
                          "} " +
                          "H6 " +
                          "{ " +
                          " color : Navy; font-family : Segoe UI, Trebuchet MS, Verdana, Helvetica, Arial; font-size : 12px; opacity: 1; line-height: 24px; " +
                          "} " +
                          "DIV " +
                          "{ " +
                          " color : Blue; font-family : Segoe UI, Trebuchet MS, Verdana, Helvetica, Arial; font-size : 12px; opacity: 1; line-height: 12px; " +
                          "} " +
                          "TD " +
                          "{ " +
                          " color : Navy; font-family : Segoe UI, Trebuchet MS, Verdana, Helvetica, Arial; font-size : 12px; opacity: 1; line-height: 12px; " +
                          "} " +
                          "TH " +
                          "{ " +
                          " color : Blue; font-family : Segoe UI, Trebuchet MS, Verdana, Helvetica, Arial; font-size : 12px; opacity: 1; line-height: 12px; " +
                          "} " +
                          "  </style> " +
                          "</head><body>");
            swr.WriteLine("<h1>GPUTrackingServer " + ComputerName + " running <b>" + Trackers.Length + "</b> GPU(s)</h1><h6>Process Instance " + ProcessInstance + " </h6><hr />");
            swr.WriteLine("<div><form action=\"addrwdj\" metod=\"get\"><table align=\"left\" border=\"0\" width=\"100%\">" +
                          "<tr><th colspan=\"2\" align=\"left\">Add RWD job</th><td width=\"100%\">&nbsp;</td></tr>" +
                          "<tr><td>GPU</td><td><select name=\"" + a_gpu + "\" id=\"" + a_gpu + "\">" + GPUHTMLSelect + "</td></tr>" +
                          "<tr><td>Zone path</td><td><input type=\"text\" name=\"" + a_rwdz + "\" id=\"" + a_rwdz + "\" size=\"100\" /></td></tr>" +
                          "<tr><td>Strip</td><td><input type=\"text\" name=\"" + a_rwds + "\" id=\"" + a_rwds + "\" /></td><td>Index</td><td><input type=\"text\" name=\"" + a_rwdi + "\" id=\"" + a_rwdi + "\" /></td></tr>" +
                          "<tr><td>First View</td><td><input type=\"text\" name=\"" + a_rwdfv + "\" id=\"" + a_rwdfv + "\" /></td><td>Last View</td><td><input type=\"text\" name=\"" + a_rwdlv + "\" id=\"" + a_rwdlv + "\" /></td></tr>" +
                          "<tr><td>Output dir</td><td><input type=\"text\" name=\"" + a_rwdd + "\" id=\"" + a_rwdd + "\" size=\"100\" /></td></tr>" +
                          "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Submit job\" /></td></tr>" +
                          "</table></form></div><br />");
            for (g = 0; g < Trackers.Length; g++)
            {
                Job current = Trackers[g].Current;
                swr.WriteLine("<hr /><br /><div><table align=\"left\" border=\"1\" width=\"100%\"><tr><th>Queue " + g + " current " + ((current == null) ? "" : current.ID) + "</th></tr>");
                string[] jstr = null;
                lock (Trackers[g].Jobs)
                {
                    jstr = new string[Trackers[g].Jobs.Count];
                    int i = 0;
                    foreach (Job jj in Trackers[g].Jobs)
                    {
                        jstr[i++] = jj.ID;
                    }
                }
                foreach (string ss in jstr)
                {
                    swr.WriteLine("<tr><td>" + ss + "</td></tr>");
                }
                swr.WriteLine("</table></div><br />");
            }
            swr.WriteLine("<hr /><br /><div><table align=\"left\"><tr><th colspan=\"2\">Profiling info</th></tr>");
            lock (ProfilingInfo)
            {
                int total = 0;
                foreach (int t in ProfilingInfo.Values)
                {
                    total += t;
                }
                if (total > 0)
                {
                    foreach (string s in ProfilingInfo.Keys)
                    {
                        swr.WriteLine("<tr><td>" + s + "</td><td>" + (ProfilingInfo[s] * 100 / total).ToString() + "</td></tr>");
                    }
                }
            }
            swr.WriteLine("</table></div><br />");
            swr.WriteLine("</body></html>\r\n\r\n");
            return(new SySal.Web.HTMLResponse(swr.ToString()));
        }
Ejemplo n.º 2
0
            public void Process()
            {
                SySal.GPU.MapTracker mptk = Tracker;
                while (Terminate == false)
                {
                    Job o = null;
                    lock (Jobs)
                        if (Jobs.Count > 0)
                        {
                            o = Jobs.First();
                            Jobs.Remove(o);
                            Current = o;
                        }
                    if (o == null)
                    {
                        JobsWaiting.WaitOne(1000);
                        continue;
                    }
                    else if (o is RWDJob)
                    {
                        RWDJob rwdjo = o as RWDJob;
                        System.IO.FileStream outf = null;
                        try
                        {
                            if (C.LogLevel > 0)
                            {
                                Out.WriteLine("Starting processing for " + rwdjo.ZoneFile + " " + rwdjo.StripId);
                            }
                            Zone   z                 = Zone.FromFile(rwdjo.ZoneFile);
                            string imgcorrcfg        = null;
                            string clstchcfg         = null;
                            string trkcfg            = null;
                            string debugdumptemplate = null;
                            foreach (PostProcessingInfo ppi in z.PostProcessingSettings)
                            {
                                switch (ppi.Name.ToLower().Trim())
                                {
                                case "imagecorrection":
                                    imgcorrcfg = ppi.Settings;
                                    if (C.LogLevel >= 3)
                                    {
                                        Out.WriteLine("ImageCorrection: " + imgcorrcfg);
                                    }
                                    break;

                                case "clusterchainer":
                                    clstchcfg = ppi.Settings;
                                    if (C.LogLevel >= 3)
                                    {
                                        Out.WriteLine("ClusterChainer: " + clstchcfg);
                                    }
                                    break;

                                case "tracker":
                                    trkcfg = ppi.Settings;
                                    if (C.LogLevel >= 3)
                                    {
                                        Out.WriteLine("Tracker: " + trkcfg);
                                    }
                                    break;

                                case "debugdumptemplate":
                                    debugdumptemplate = ppi.Settings;
                                    if (C.LogLevel >= 3)
                                    {
                                        Out.WriteLine("DebugDumpTemplate: " + debugdumptemplate);
                                    }
                                    break;
                                }
                            }
                            if (C.LogLevel >= 3)
                            {
                                Out.WriteLine("Setting configuration for " + rwdjo.ZoneFile + " " + rwdjo.StripId);
                            }
                            if (string.IsNullOrWhiteSpace(C.DebugDumpDir) || string.IsNullOrWhiteSpace(debugdumptemplate))
                            {
                                mptk.SetDebugDumpTemplate(null);
                            }
                            else
                            {
                                string debd = C.DebugDumpDir + System.IO.Path.DirectorySeparatorChar + debugdumptemplate;
                                mptk.SetDebugDumpTemplate(debd);
                                if (C.LogLevel >= 3)
                                {
                                    Out.WriteLine("Debug Dump Template is " + debd);
                                }
                            }
                            mptk.SetVerbosity(C.LogLevel);
                            mptk.SetImageCorrection(imgcorrcfg);
                            mptk.SetClusterChainerConfig(clstchcfg);
                            mptk.SetTrackerConfig(trkcfg);
                            float basethickness = -1.0f;
                            try
                            {
                                var xmld = new XmlDocument();
                                xmld.LoadXml(z.ScanSettings);
                                basethickness = float.Parse(xmld.ChildNodes[1]["BaseThickness"].InnerText, System.Globalization.CultureInfo.InvariantCulture);
                            }
                            catch (Exception x)
                            {
                                if (C.LogLevel >= 1)
                                {
                                    Out.WriteLine("Can't find base thickness in zone info:" + Environment.NewLine + z.ScanSettings + Environment.NewLine + ", defaulting to " + basethickness.ToString(System.Globalization.CultureInfo.InvariantCulture) + " (" + x.Message + ")");
                                }
                            }
                            if (basethickness < 0)
                            {
                                throw new Exception("Base thickness is not positive, can't continue.");
                            }
                            if (C.LogLevel >= 1)
                            {
                                Out.WriteLine("Using base thickness = " + basethickness);
                            }
                            if (rwdjo.FirstView < 0 && rwdjo.LastView < 0)
                            {
                                rwdjo.FirstView = 0;
                                rwdjo.LastView  = (int)z.Views - 1;
                            }
                            if (rwdjo.FragmentIndex < 0)
                            {
                                rwdjo.FragmentIndex = (int)rwdjo.StripId + 1;
                            }
                            RawDataFragment rwdf = new RawDataFragment(z, rwdjo.StripId, (uint)rwdjo.FragmentIndex, (uint)rwdjo.FirstView, (uint)rwdjo.LastView);
                            mptk.SetRawDataViewSideConsumer(rwdf);
                            string[] files = new string[z.Views];
                            if (z.HasTop)
                            {
                                if (C.LogLevel >= 1)
                                {
                                    Out.WriteLine("Finding tracks on top for " + rwdjo.ZoneFile + " " + rwdjo.StripId);
                                }
                                int i;
                                for (i = 0; i < z.Views; i++)
                                {
                                    files[i] = z.GetClusterFileName(rwdjo.StripId, true, (uint)i);
                                }
                                mptk.SetDebugMark(rwdjo.StripId * 16);
                                mptk.FindTracks(files, true, 0.0f, z.PlateMap, (uint)rwdjo.FirstView, (uint)rwdjo.LastView);
                            }
                            if (z.HasBottom)
                            {
                                if (C.LogLevel >= 1)
                                {
                                    Out.WriteLine("Finding tracks on bottom for " + rwdjo.ZoneFile + " " + rwdjo.StripId);
                                }
                                int i;
                                for (i = 0; i < z.Views; i++)
                                {
                                    files[i] = z.GetClusterFileName(rwdjo.StripId, false, (uint)i);
                                }
                                mptk.SetDebugMark(rwdjo.StripId * 16 + 1);
                                mptk.FindTracks(files, false, -basethickness, z.PlateMap, (uint)rwdjo.FirstView, (uint)rwdjo.LastView);
                            }
                            if (C.LogLevel >= 1)
                            {
                                Out.WriteLine("Writing tracks for " + rwdjo.ZoneFile + " " + rwdjo.StripId);
                            }
                            string outname  = z.GetRWDFileName((uint)rwdjo.FragmentIndex, rwdjo.OutputDir);
                            string workname = outname + ".twr";
                            outf = new System.IO.FileStream(workname, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
                            rwdf.Save(outf);
                            outf.Flush();
                            outf.Close();
                            outf = null;
                            if (C.LogLevel >= 1)
                            {
                                Out.WriteLine("Done " + rwdjo.ZoneFile + " " + rwdjo.StripId);
                            }

                            /* The RWD must be finalized by the PostProcessManager,
                             * otherwise clashes may occur if the communication is lost while the job is completed. */
                            //System.IO.File.Move(workname, outname);
                        }
                        catch (Exception x)
                        {
                            o.ExitException = x.ToString();
                            Out.WriteLine("\r\nError for " + rwdjo.ZoneFile + " " + rwdjo.StripId + ":\r\n" + x.ToString());

                            /*if (x.Message.IndexOf("GPU-level") >= 0)
                             *  Environment.Exit(-1);*/
                            if (x is System.Runtime.InteropServices.SEHException)
                            {
                                Out.WriteLine("SEHException:\r\n" + (x as System.Runtime.InteropServices.SEHException).ErrorCode);
                            }
                        }
                        finally
                        {
                            if (outf != null)
                            {
                                outf.Close();
                            }
                            mptk.SetRawDataViewSideConsumer(null);
                        }
                    }
                    else
                    {
                        o.ExitException = "Unsupported job type.";
                    }
                    System.DateTime n = System.DateTime.Now;
                    o.ExpirationTime = n.AddHours(1);
                    lock (Completed)
                    {
                        Completed.Add(o);
                        Current = null;
                        System.Collections.Generic.List <Job> ncompl = new List <Job>();
                        ncompl.AddRange(Completed.Where(x => x.ExpirationTime >= n));
                        Completed = ncompl;
                    }
                }
            }