#include <DemoSnarlList.h>
Inheritance diagram for DemoSnarlList:

Public Member Functions | |
| DemoSnarlList () | |
| JobCResult | Ana (const MomNavigator *mom) |
| void | Report () |
| void | HandleCommand (JobCommand *command) |
| void | AddRunSnarl (int r, int s) |
| void | RemoveRunSnarl (int r, int s) |
| void | AddUsingFile (const char *f) |
| void | RemoveUsingFile (const char *f) |
Private Member Functions | |
| std::string | Key (int r, int s) |
Private Attributes | |
| bool | fIsSorted |
| std::list< std::string > | fSnarlList |
| bool | fVetoMode |
Definition at line 21 of file DemoSnarlList.h.
| DemoSnarlList::DemoSnarlList | ( | ) |
| void DemoSnarlList::AddRunSnarl | ( | int | r, | |
| int | s | |||
| ) |
Definition at line 142 of file DemoSnarlList.cxx.
References fIsSorted, and fSnarlList.
Referenced by AddUsingFile(), and HandleCommand().
00143 { 00144 //====================================================================== 00145 // Add the run/snarl (r,s) to the list of records to pass 00146 //====================================================================== 00147 std::string k(this->Key(r,s)); 00148 fSnarlList.push_back(k); 00149 fIsSorted = false; 00150 }
| void DemoSnarlList::AddUsingFile | ( | const char * | f | ) |
Definition at line 169 of file DemoSnarlList.cxx.
References AddRunSnarl(), and run().
Referenced by HandleCommand().
00170 { 00171 //====================================================================== 00172 // Add all the run/snarls from the file f to the list. Assumes format 00173 // is run<space>snarl 00174 //====================================================================== 00175 std::ifstream ifs(f); 00176 int run, snarl; 00177 while (ifs) { 00178 ifs >> run >> snarl; 00179 this->AddRunSnarl(run,snarl); 00180 } 00181 }
| JobCResult DemoSnarlList::Ana | ( | const MomNavigator * | mom | ) | [virtual] |
Implement this for read only access to the MomNavigator
Reimplemented from JobCModule.
Definition at line 30 of file DemoSnarlList.cxx.
References MomNavigator::At(), fIsSorted, fSnarlList, fVetoMode, MsgService::GetCurrentRunSnarl(), RawDaqHeader::GetRun(), RawDaqSnarlHeader::GetSnarl(), MsgService::Instance(), JobCResult::kFailed, JobCResult::kPassed, Msg::kWarning, MSG, and run().
00031 { 00032 //====================================================================== 00033 // Are there records in mom whose run/snarl number matchs one in the 00034 // list? 00035 //====================================================================== 00036 TObject* obj; 00037 for (int i=0; (obj=mom->At(i)); ++i) { 00038 const RawRecord* rr = dynamic_cast<RawRecord*>(obj); 00039 if (rr) { 00040 const RawDaqSnarlHeader* 00041 rdsh = dynamic_cast<const RawDaqSnarlHeader*>(rr->GetRawHeader()); 00042 if (rdsh) { 00043 int run = rdsh->GetRun(); 00044 int snarl = rdsh->GetSnarl(); 00045 std::string k(this->Key(run,snarl)); 00046 if (fIsSorted==false) { // Make sure we're sorted prior to search... 00047 fSnarlList.sort(); 00048 fIsSorted = true; 00049 } 00050 if (std::binary_search(fSnarlList.begin(),fSnarlList.end(),k)) { 00051 if (fVetoMode) { 00052 00053 int nrun, nsnarl; 00054 MsgService::Instance()->GetCurrentRunSnarl(nrun, nsnarl); 00055 MSG("Demo",Msg::kWarning) 00056 << "DemoSnarlList reject at nsnarl = " 00057 << nsnarl << endl; 00058 00059 return JobCResult::kFailed; 00060 } 00061 else return JobCResult::kPassed; 00062 } 00063 } 00064 } 00065 } 00066 if (fVetoMode) return JobCResult::kPassed; 00067 else { 00068 00069 int nrun, nsnarl; 00070 MsgService::Instance()->GetCurrentRunSnarl(nrun, nsnarl); 00071 MSG("Demo",Msg::kWarning) << "DemoSnarlList reject at nsnarl = " 00072 << nsnarl << endl; 00073 return JobCResult::kFailed; 00074 00075 } 00076 }
| void DemoSnarlList::HandleCommand | ( | JobCommand * | command | ) | [virtual] |
Implement to handle a JobCommand
Reimplemented from JobCModule.
Definition at line 95 of file DemoSnarlList.cxx.
References AddRunSnarl(), AddUsingFile(), fVetoMode, JobCommand::HaveOpt(), UtilString::IsInt(), Msg::kWarning, MSG, JobCommand::PopCmd(), JobCommand::PopOpt(), RemoveRunSnarl(), RemoveUsingFile(), and run().
00096 { 00097 std::string c = cmd->PopCmd(); 00098 if (!(c=="Add"||c=="Remove"||c=="VetoMode")) { 00099 MSG("Demo",Msg::kWarning) << 00100 "Only: Add [run#] [snarl#] [filename] and \n" << 00101 " Remove [run#] [snarl#] [filename] and \n" << 00102 " VetoMode <on|off> are supported.\n"; 00103 return; 00104 } 00105 00106 int run = -1; 00107 int snarl = -1; 00108 while (cmd->HaveOpt()) { 00109 std::string opt = cmd->PopOpt(); 00110 if (UtilString::IsInt(opt.c_str())) { 00111 if (run!=-1) { 00112 snarl = atoi(opt.c_str()); 00113 if (c=="Add") { 00114 this->AddRunSnarl(run,snarl); 00115 } 00116 else if (c=="Remove") { 00117 this->RemoveRunSnarl(run,snarl); 00118 } 00119 run = -1; 00120 snarl = -1; 00121 } 00122 else { 00123 run = atoi(opt.c_str()); 00124 } 00125 } 00126 else if ( ( c == "VetoMode" ) && ( opt != "off" ) ) { 00127 fVetoMode = true; 00128 } 00129 else { // Assume all strings are file names 00130 if (c=="Add") { 00131 this->AddUsingFile(opt.c_str()); 00132 } 00133 else if (c=="Remove") { 00134 this->RemoveUsingFile(opt.c_str()); 00135 } 00136 } 00137 } 00138 }
| std::string DemoSnarlList::Key | ( | int | r, | |
| int | s | |||
| ) | [private] |
Definition at line 201 of file DemoSnarlList.cxx.
00202 { 00203 //====================================================================== 00204 // Construct a sortable key using run and snarl numbers 00205 //====================================================================== 00206 char k[1024]; 00207 sprintf(k,"%12d.%12.12d",run,snarl); 00208 return k; 00209 }
| void DemoSnarlList::RemoveRunSnarl | ( | int | r, | |
| int | s | |||
| ) |
Definition at line 154 of file DemoSnarlList.cxx.
References find(), and fSnarlList.
Referenced by HandleCommand(), and RemoveUsingFile().
00155 { 00156 //====================================================================== 00157 // Remove the run/snarl (r,s) to the list of records to pass 00158 //====================================================================== 00159 std::string k(this->Key(r,s)); 00160 std::list<std::string>::iterator itr; 00161 itr = std::find(fSnarlList.begin(), fSnarlList.end(), k); 00162 if (itr!=fSnarlList.end()) { 00163 fSnarlList.erase(itr); 00164 } 00165 }
| void DemoSnarlList::RemoveUsingFile | ( | const char * | f | ) |
Definition at line 185 of file DemoSnarlList.cxx.
References RemoveRunSnarl(), and run().
Referenced by HandleCommand().
00186 { 00187 //====================================================================== 00188 // Remove all the run/snarls from the file f to the list. Assumes format 00189 // is run<space>snarl 00190 //====================================================================== 00191 std::ifstream ifs(f); 00192 int run, snarl; 00193 while (ifs) { 00194 ifs >> run >> snarl; 00195 this->RemoveRunSnarl(run,snarl); 00196 } 00197 }
| void DemoSnarlList::Report | ( | ) | [virtual] |
Implement to spew end of running report
Reimplemented from JobCModule.
Definition at line 80 of file DemoSnarlList.cxx.
References fSnarlList, Msg::kInfo, and MSG.
00081 { 00082 //====================================================================== 00083 // Print the snarl numbers in the list 00084 //====================================================================== 00085 std::list<std::string>::iterator itr(fSnarlList.begin()); 00086 std::list<std::string>::iterator itrEnd(fSnarlList.end()); 00087 MSG("Demo",Msg::kInfo) << "Snarls in list:\n"; 00088 for (; itr!=itrEnd; ++itr) { 00089 MSG("Demo",Msg::kInfo) << (*itr) << "\n"; 00090 } 00091 }
bool DemoSnarlList::fIsSorted [private] |
std::list< std::string > DemoSnarlList::fSnarlList [private] |
Definition at line 40 of file DemoSnarlList.h.
Referenced by AddRunSnarl(), Ana(), RemoveRunSnarl(), and Report().
bool DemoSnarlList::fVetoMode [private] |
1.4.7