00001 00002 // $Id: JobCGraphVtx.cxx,v 1.6 2008/02/05 19:02:39 scavan Exp $ 00003 // 00004 // Implementation of a forward feeding directed graph 00005 // 00006 // messier@huhepl.harvard.edu 00008 #include "JobCGraphVtx.h" 00009 #include "MessageService/MsgService.h" 00010 CVSID("$Id: JobCGraphVtx.cxx,v 1.6 2008/02/05 19:02:39 scavan Exp $"); 00011 00012 ClassImp(JobCGraphVtx) 00013 00014 //...................................................................... 00015 00016 JobCGraphVtx::JobCGraphVtx() : 00017 fNupStream(0), fNupStreamPassed(0), fNupStreamFailed(0) 00018 { } 00019 00020 //...................................................................... 00021 00022 void JobCGraphVtx::Attach(JobCGraphVtx* JobCGraphVtx) 00023 { 00024 fDownStream.push_back(JobCGraphVtx); 00025 JobCGraphVtx->AddUpStream(); 00026 } 00027 00028 //...................................................................... 00029 00030 void JobCGraphVtx::Detach(JobCGraphVtx* /* JobCGraphVtx */) 00031 { 00032 // not implemented 00033 MSG("JobC",Msg::kWarning) << "Detach not implemented.\n"; 00034 } 00035 00036 //...................................................................... 00037 00038 void JobCGraphVtx::EvaluateGraph(JobCRecord* rec) 00039 { 00040 this->InitGraphEvaluate(); 00041 this->EvaluateNode(rec); 00042 } 00043 00044 //...................................................................... 00045 00046 void JobCGraphVtx::EvaluateNode(JobCRecord* rec) 00047 { 00048 // If we have streams feeding into this JobCGraphVtx check their status 00049 if (fNupStream) { 00050 // If all upstream nodes have failed just propagate that 00051 // information down the line 00052 if (fNupStreamFailed == fNupStream) { 00053 this->SendNotification(false); 00054 return; 00055 } 00056 // Check if we're still waiting for upstream nodes to finish 00057 if ((fNupStreamFailed+fNupStreamPassed)<fNupStream) { 00058 return; 00059 } 00060 } 00061 00062 // Evaluate this node 00063 bool passed = this->EvalInput(rec); 00064 if (fDownStream.size()>0) { 00065 this->SendNotification(passed); 00066 vector<JobCGraphVtx*>::iterator itr(fDownStream.begin()); 00067 vector<JobCGraphVtx*>::iterator itrEnd(fDownStream.end()); 00068 for (;itr!=itrEnd;++itr) (*itr)->EvaluateNode(rec); 00069 } 00070 } 00071 00072 //...................................................................... 00073 00074 void JobCGraphVtx::AddUpStream() { ++fNupStream; } 00075 00076 //...................................................................... 00077 00078 void JobCGraphVtx::ReceiveNotification(bool passfail) 00079 { 00080 if (passfail) ++fNupStreamPassed; 00081 else ++fNupStreamFailed; 00082 } 00083 00084 //...................................................................... 00085 00086 void JobCGraphVtx::SendNotification(bool passfail) 00087 { 00088 vector<JobCGraphVtx*>::iterator itr(fDownStream.begin()); 00089 vector<JobCGraphVtx*>::iterator itrEnd(fDownStream.end()); 00090 for (;itr!=itrEnd;++itr) (*itr)->ReceiveNotification(passfail); 00091 } 00092 00093 //...................................................................... 00094 00095 void JobCGraphVtx::InitGraphEvaluate() 00096 { 00097 fNupStreamPassed = 0; 00098 fNupStreamFailed = 0; 00099 this->DerivedInitGraphEvaluate(); 00100 vector<JobCGraphVtx*>::iterator itr(fDownStream.begin()); 00101 vector<JobCGraphVtx*>::iterator itrEnd(fDownStream.end()); 00102 for (;itr!=itrEnd;++itr) (*itr)->InitGraphEvaluate(); 00103 } 00104 00105 //...................................................................... 00106 00107 JobCGraphVtx* JobCGraphVtx::GetAttached(unsigned int i) const 00108 { 00109 //always true: assert(i>=0); 00110 if (i<fDownStream.size()) return fDownStream[i]; 00111 return 0; 00112 } 00113
1.3.9.1