\section{Process  Class Reference}
\label{class_Process}\index{Process@{Process}}
{\tt \#include $<$process.h$>$}

Inheritance diagram for Process\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=382pt]{class_Process_inherit_graph}
\end{center}
\end{figure}
Collaboration diagram for Process:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=106pt]{class_Process_coll_graph}
\end{center}
\end{figure}
\subsection*{Public Methods}
\begin{CompactItemize}
\item 
virtual {\bf $\sim$Process} ()
\item 
virtual int {\bf run} ()=0
\item 
virtual void {\bf reset} ()
\begin{CompactList}\small\item\em Run any required operations to reset the process.\item\end{CompactList}\item 
void {\bf run\-Children} ()
\item 
void {\bf run\-Children\-Repeat\-First} ()
\item 
int {\bf run\-Child} (int i)
\item 
int {\bf run\-Next\-Child} ()
\item 
void {\bf add\-Child} (Process $\ast$c=NULL)
\item 
int {\bf num\-Children} () const
\item 
int {\bf num\-Queued} () const
\begin{CompactList}\small\item\em Returns the number of children awaiting execution.\item\end{CompactList}\item 
void {\bf clean\-Queue} ()
\begin{CompactList}\small\item\em Removes all queued jobs without run' ing them.\item\end{CompactList}\item 
void {\bf set\-Priority} (double pri)
\begin{CompactList}\small\item\em Sets the priority of the process (low priorities are executed first.\item\end{CompactList}\item 
double {\bf get\-Priority} () const
\begin{CompactList}\small\item\em Returns the priority of this process.\item\end{CompactList}\item 
int {\bf Compare} (const Process \&p) const
\begin{CompactList}\small\item\em Compares processes based on their priority.\item\end{CompactList}\item 
{\bf MAKECOMPARISONS\_\-WITH\_\-COMPARE} (Process)
\begin{CompactList}\small\item\em Give me all the comparison operators.\item\end{CompactList}\end{CompactItemize}
\subsection*{Protected Methods}
\begin{CompactItemize}
\item 
{\bf Process} (double pri=-INF, int num\-Children=0)
\end{CompactItemize}
\subsection*{Protected Attributes}
\begin{CompactItemize}
\item 
double {\bf Priority}
\begin{CompactList}\small\item\em High priorities are executed first. These can range from -INF to +INF.\item\end{CompactList}\item 
Process$\ast$$\ast$ {\bf Children}
\begin{CompactList}\small\item\em An array of pointers to sub-processes.\item\end{CompactList}\item 
int {\bf num\-C}
\begin{CompactList}\small\item\em The number of total children (including zombies).\item\end{CompactList}\item 
bool {\bf active}
\begin{CompactList}\small\item\em defaults to t, if f, the process is never run.\item\end{CompactList}\end{CompactItemize}
\subsection*{Private Methods}
\begin{CompactItemize}
\item 
void {\bf assert\-Order} ()
\end{CompactItemize}
\subsection*{Private Attributes}
\begin{CompactItemize}
\item 
int {\bf sorted}
\item 
{\bf Queue}$<$Process $\ast$$>$ {\bf Q}
\end{CompactItemize}


\subsection{Detailed Description}
//////////////////////////////////////////////////////////

File: Process.h

Abstract class to manage and provide functionality for a set of 'jobs.' Each job inherits from class Process and can create children, add them to a queue and execute chilren on that queue. All jobs must have a member called {\bf run}(void) {\rm (p.\,\pageref{class_Process_a1})}.

////////////////////////////////////////////////////////// 



Definition at line 24 of file process.h.

\subsection{Constructor \& Destructor Documentation}
\index{Process@{Process}!~Process@{$\sim$Process}}
\index{~Process@{$\sim$Process}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Process::$\sim$Process ()\hspace{0.3cm}{\tt  [virtual]}}\label{class_Process_a0}




Definition at line 18 of file process.C.\footnotesize\begin{verbatim}00019 {
00020   if(Children)
00021     {
00022       for(int i=0; i<numC; ++i)
00023         delete Children[i];
00024       delete[] Children;
00025       Children=0;
00026     }
00027 \end{verbatim}\normalsize 
\index{Process@{Process}!Process@{Process}}
\index{Process@{Process}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Process::Process (double {\em pri} = -INF, int {\em num\-Children} = 0)\hspace{0.3cm}{\tt  [protected]}}\label{class_Process_b0}


Derived classes can construct a process with a specified priority and a specified number of children. These Children are $\ast$not$\ast$ added to the queue. 

Definition at line 4 of file process.C.\footnotesize\begin{verbatim}00005 {
00006   Children=0;
00007   numC = 0;
00008   sorted = 0;
00009 
00010   if(numChildren>0 && (Children = new Process*[numChildren]))
00011     {
00012       for(int i=0; i<numChildren; i++)
00013         Children[i] = 0;
00014       numC = numChildren;
00015     }
00016 \end{verbatim}\normalsize 


\subsection{Member Function Documentation}
\index{Process@{Process}!Compare@{Compare}}
\index{Compare@{Compare}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Process::Compare (const Process \& {\em p}) const\hspace{0.3cm}{\tt  [inline]}}\label{class_Process_a13}


Compares processes based on their priority.



Definition at line 99 of file process.h.\footnotesize\begin{verbatim}00101   {
00102     if(Priority<p.Priority)
00103       return -1;
00104     else if(Priority>p.Priority)
00105       return 1;
00106     return 0;
00107 \end{verbatim}\normalsize 
\index{Process@{Process}!MAKECOMPARISONS_WITH_COMPARE@{MAKECOMPARISONS\_\-WITH\_\-COMPARE}}
\index{MAKECOMPARISONS_WITH_COMPARE@{MAKECOMPARISONS\_\-WITH\_\-COMPARE}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Process::MAKECOMPARISONS\_\-WITH\_\-COMPARE (Process)}\label{class_Process_a14}


Give me all the comparison operators.

\index{Process@{Process}!addChild@{addChild}}
\index{addChild@{addChild}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Process::add\-Child (Process $\ast$ {\em p} = NULL)}\label{class_Process_a7}


Adds a child to the execution queue. Note that processes do not need to queue children from the Children array. For example, a process may add itself to the execution queue for recursive purposes (via add\-Child(this)). 

Definition at line 160 of file process.C.

Referenced by Relax\-Subset::run(), and Cycle\-All::run().\footnotesize\begin{verbatim}00161 {
00162   // If this guy's priority is not extremal, we'll have to resort
00163   // at some point in the future.  If it *is* extremal, we just tack
00164   // this process is on one of the queue's ends.
00165   if(Q && p->Priority <= Q.PeekFront()->Priority)
00166     Q.AddToFront(p);
00167   else if(Q && p->Priority >= Q.PeekBack()->Priority)
00168     Q.AddToBack(p);
00169   else
00170     {
00171       Q.AddToBack(p);
00172       sorted = 0;
00173     }
00174 \end{verbatim}\normalsize 
\index{Process@{Process}!assertOrder@{assertOrder}}
\index{assertOrder@{assertOrder}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Process::assert\-Order ()\hspace{0.3cm}{\tt  [private]}}\label{class_Process_c0}




Definition at line 29 of file process.C.

Referenced by run\-Child(), run\-Children(), run\-Children\-Repeat\-First(), and run\-Next\-Child().\footnotesize\begin{verbatim}00030 {
00031   if (sorted) return;
00032   Process ** child;
00033   int numQ = Q.Number();
00034   if (numQ>0)
00035     {
00036       // Empty out the queue and then sort all the children
00037       // that were in there.
00038       if(!(child = new Process*[numQ]))
00039         DIE("Process::assertOrder memory failure");
00040 
00041       for(int i=0; Q; ++i)
00042         child[i] = Q.RemoveFromBack();
00043 
00044       QuickSortPtrs(child, numQ);
00045 
00046       // ACK!  REMOVE ME
00047 //         for(i=0; i<(nnonhelatoms-1); i++) {
00048 //         for(j=(nnonhelatoms-1); j>i; j--) {
00049 //           atom1 = atomorder[j-1];
00050 //           atom2 = atomorder[j];
00051 // //     debug_i ("SORT:atom1", atom1);
00052 // //     debug_i ("SORT:atom2", atom2);
00053 // //     debug_d ("SORT:a1err", atom_info[atom1].lfnc);
00054 // //     debug_d ("SORT:a2err", atom_info[atom2].lfnc);              
00055 //        if(
00056 //           (fabs(atom_info[atom1].lfnc-atom_info[atom2].lfnc) < 1e-12) &&
00057 //           (atom1 > atom2)
00058 //           ){
00059 //          itemp = atomorder[j-1];
00060 //          atomorder[j-1] = atomorder[j];
00061 //          atomorder[j] = itemp;
00062 //        }
00063 // 
00064 //      }       
00065 //       }
00066 //
00067 
00068       // for equal priority, sort by atom index
00069 //       Process * temp;
00070 //       int atom1, atom2;
00071 //       for(int i=0; i<numQ-1; i++) {      
00072 //      for (int j = numQ-1; j > i;j--){
00073 //        atom1 = ((gwRelaxAtom *) child[j-1])->atom_index; // ALSO FIX THIS IS NOW PUBLIC
00074 //        atom2 = ((gwRelaxAtom *) child[j])->atom_index;
00075 //        if(
00076 //           (fabs(child[j-1]->Priority - child[j]->Priority) < 1e-12) &&
00077 //           (atom1 < atom2)
00078 //           ){
00079 //          temp = child[j-1];
00080 //          child[j-1] = child[j];
00081 //          child[j] = temp;
00082 //        }
00083 //        
00084 //        }       
00085 //      }
00086       
00087       // Put the sorted list back into the queue.
00088       for(int i=0; i<numQ; ++i)
00089         Q.Add(child[i]);
00090 
00091       // Get rid of the extra array of pointers.
00092       delete[] child;
00093 
00094       sorted = 1;
00095     }
00096 \end{verbatim}\normalsize 
\index{Process@{Process}!cleanQueue@{cleanQueue}}
\index{cleanQueue@{cleanQueue}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Process::clean\-Queue ()}\label{class_Process_a10}


Removes all queued jobs without run' ing them.



Definition at line 136 of file process.C.

Referenced by Relax\-Subset::run().\footnotesize\begin{verbatim}00137 {
00138   while(Q)
00139     Q.RemoveFromBack();
00140   // NB not deleted as in runChildren()
00141 \end{verbatim}\normalsize 
\index{Process@{Process}!getPriority@{getPriority}}
\index{getPriority@{getPriority}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}double Process::get\-Priority () const\hspace{0.3cm}{\tt  [inline]}}\label{class_Process_a12}


Returns the priority of this process.



Definition at line 156 of file process.h.

Referenced by gw\-Relax\-Atom::run().\footnotesize\begin{verbatim}00157 { return Priority; }
00158 \end{verbatim}\normalsize 
\index{Process@{Process}!numChildren@{numChildren}}
\index{numChildren@{numChildren}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Process::num\-Children () const\hspace{0.3cm}{\tt  [inline]}}\label{class_Process_a8}


Returns the $\ast$total$\ast$ number of children created by this process. These children are not necessarily queued to execute. Call {\bf num\-Queued}() {\rm (p.\,\pageref{class_Process_a9})} if would like to find the number of children awaiting execution. 

Definition at line 150 of file process.h.\footnotesize\begin{verbatim}00151 { return numC; }
00152 \end{verbatim}\normalsize 
\index{Process@{Process}!numQueued@{numQueued}}
\index{numQueued@{numQueued}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Process::num\-Queued () const\hspace{0.3cm}{\tt  [inline]}}\label{class_Process_a9}


Returns the number of children awaiting execution.



Definition at line 153 of file process.h.\footnotesize\begin{verbatim}00154 { return Q.Number(); }
00155 \end{verbatim}\normalsize 
\index{Process@{Process}!reset@{reset}}
\index{reset@{reset}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Process::reset ()\hspace{0.3cm}{\tt  [inline, virtual]}}\label{class_Process_a2}


Run any required operations to reset the process.



Definition at line 36 of file process.h.\footnotesize\begin{verbatim}00036                       {}
00037 \end{verbatim}\normalsize 
\index{Process@{Process}!run@{run}}
\index{run@{run}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Process::run (void)\hspace{0.3cm}{\tt  [pure virtual]}}\label{class_Process_a1}


Execute this process. Returns the exit status of the process (0 is success, non-zero is error). 

Reimplemented in {\bf Atom\-Buildup} {\rm (p.\,\pageref{class_AtomBuildup_a3})}, {\bf Cycle\-All} {\rm (p.\,\pageref{class_CycleAll_a3})}, {\bf gw\-Relax\-Atom} {\rm (p.\,\pageref{class_gwRelaxAtom_a3})}, {\bf Anim\-Frame} {\rm (p.\,\pageref{class_AnimFrame_a3})}, {\bf jd\-Err\_\-Eval} {\rm (p.\,\pageref{class_jdErr_Eval_a2})}, {\bf jd\-Iterator} {\rm (p.\,\pageref{class_jdIterator_a3})}, {\bf jd\-Occ\_\-Count} {\rm (p.\,\pageref{class_jdOcc_Count_a2})}, {\bf jd\-Rand\_\-Eval} {\rm (p.\,\pageref{class_jdRand_Eval_a2})}, {\bf Relax\-Subset} {\rm (p.\,\pageref{class_RelaxSubset_a3})}, and {\bf Stop\-Eval} {\rm (p.\,\pageref{class_StopEval_a3})}.

Referenced by main(), and run\-Children\-Repeat\-First().\index{Process@{Process}!runChild@{runChild}}
\index{runChild@{runChild}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Process::run\-Child (int {\em i})}\label{class_Process_a5}


Run the child with the i$^\wedge$th smallest priority. This child is $\ast$not$\ast$ removed from the queue! Returns the exit status of the child. 

Definition at line 143 of file process.C.\footnotesize\begin{verbatim}00144 {
00145   if(i<0 || i>=Q.Number())
00146     return -1;
00147 
00148   // Make sure the queue is ordered.
00149   assertOrder();
00150 
00151   return Q.Get(i)->run();
00152 \end{verbatim}\normalsize 
\index{Process@{Process}!runChildren@{runChildren}}
\index{runChildren@{runChildren}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Process::run\-Children ()}\label{class_Process_a3}


Execute all the children that have been added to the queue by order of their priority. After the call, the queue of children is empty. 

Definition at line 117 of file process.C.\footnotesize\begin{verbatim}00118 {
00119   // Make sure the queue is ordered.
00120   assertOrder();
00121 
00122 //   Process * P;
00123 //   while(Q){
00124 //     P = Q.RemoveFromBack();
00125 //     if (P->getPriority() >= 0)
00126 //       P->run();
00127 //   }
00128 \end{verbatim}\normalsize 
\index{Process@{Process}!runChildrenRepeatFirst@{runChildrenRepeatFirst}}
\index{runChildrenRepeatFirst@{runChildrenRepeatFirst}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Process::run\-Children\-Repeat\-First ()}\label{class_Process_a4}


Execute all the children that have been added to the queue by order of their priority. Repeat the first process at the end. After the call, the queue of children is empty. 

Definition at line 98 of file process.C.

Referenced by Cycle\-All::run().\footnotesize\begin{verbatim}00099 {
00100   // Make sure the queue is ordered.
00101   assertOrder();
00102 
00103    Process * P;
00104    if (Q)
00105      P = Q.RemoveFromBack();
00106    else
00107      return;
00108        
00109    P->run();
00110    while (Q)
00111      Q.RemoveFromBack()->run();
00112    P->run();
00113    
00114    
00115 \end{verbatim}\normalsize 
\index{Process@{Process}!runNextChild@{runNextChild}}
\index{runNextChild@{runNextChild}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Process::run\-Next\-Child ()}\label{class_Process_a6}


Runs the child with the next smallest priority. This child is removed from the queue and lost. Returns the exit status of the child. 

Definition at line 154 of file process.C.

Referenced by Relax\-Subset::run().\footnotesize\begin{verbatim}00155 {
00156   assertOrder();
00157   return Q.RemoveFromBack()->run();
00158 \end{verbatim}\normalsize 
\index{Process@{Process}!setPriority@{setPriority}}
\index{setPriority@{setPriority}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Process::set\-Priority (double {\em pri})\hspace{0.3cm}{\tt  [inline]}}\label{class_Process_a11}


Sets the priority of the process (low priorities are executed first.



Definition at line 159 of file process.h.\footnotesize\begin{verbatim}00160 { Priority = pri; }
00161 \end{verbatim}\normalsize 


\subsection{Member Data Documentation}
\index{Process@{Process}!Children@{Children}}
\index{Children@{Children}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Process $\ast$$\ast$ Process::Children\hspace{0.3cm}{\tt  [protected]}}\label{class_Process_n1}


An array of pointers to sub-processes.



Definition at line 126 of file process.h.\index{Process@{Process}!Priority@{Priority}}
\index{Priority@{Priority}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}double Process::Priority\hspace{0.3cm}{\tt  [protected]}}\label{class_Process_n0}


High priorities are executed first. These can range from -INF to +INF.



Definition at line 122 of file process.h.\index{Process@{Process}!Q@{Q}}
\index{Q@{Q}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Queue}$<$ Process $\ast$$>$ Process::Q\hspace{0.3cm}{\tt  [private]}}\label{class_Process_o1}




Definition at line 142 of file process.h.\index{Process@{Process}!active@{active}}
\index{active@{active}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool Process::active\hspace{0.3cm}{\tt  [protected]}}\label{class_Process_n3}


defaults to t, if f, the process is never run.



Definition at line 132 of file process.h.\index{Process@{Process}!numC@{numC}}
\index{numC@{numC}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Process::num\-C\hspace{0.3cm}{\tt  [protected]}}\label{class_Process_n2}


The number of total children (including zombies).



Definition at line 129 of file process.h.\index{Process@{Process}!sorted@{sorted}}
\index{sorted@{sorted}!Process@{Process}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Process::sorted\hspace{0.3cm}{\tt  [private]}}\label{class_Process_o0}




Definition at line 139 of file process.h.

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
{\bf process.h}\item 
{\bf process.C}\end{CompactItemize}
