Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

DemoSnarlList Class Reference

#include <DemoSnarlList.h>

Inheritance diagram for DemoSnarlList:

JobCModule List of all members.

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

Constructor & Destructor Documentation

DemoSnarlList::DemoSnarlList  ) 
 

Definition at line 26 of file DemoSnarlList.cxx.

00026 : fIsSorted(false) { }


Member Function Documentation

void DemoSnarlList::AddRunSnarl int  r,
int  s
 

Definition at line 119 of file DemoSnarlList.cxx.

References fIsSorted, fSnarlList, and s().

Referenced by AddUsingFile(), and HandleCommand().

00120 {
00121 //======================================================================
00122 // Add the run/snarl (r,s) to the list of records to pass
00123 //======================================================================
00124   std::string k(this->Key(r,s));
00125   fSnarlList.push_back(k);
00126   fIsSorted = false;
00127 }

void DemoSnarlList::AddUsingFile const char *  f  ) 
 

Definition at line 146 of file DemoSnarlList.cxx.

References AddRunSnarl(), and run().

Referenced by HandleCommand().

00147 {
00148 //======================================================================
00149 // Add all the run/snarls from the file f to the list. Assumes format
00150 // is run<space>snarl
00151 //======================================================================
00152   std::ifstream ifs(f);
00153   int run, snarl;
00154   while (ifs) { 
00155     ifs >> run >> snarl;
00156     this->AddRunSnarl(run,snarl);
00157   }
00158 }

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, RawRecord::GetRawHeader(), RawDaqHeader::GetRun(), RawDaqSnarlHeader::GetSnarl(), 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           return JobCResult::kPassed;
00052         }
00053       }
00054     }
00055   }
00056   return JobCResult::kFailed;
00057 }

void DemoSnarlList::HandleCommand JobCommand command  )  [virtual]
 

Implement to handle a JobCommand

Reimplemented from JobCModule.

Definition at line 76 of file DemoSnarlList.cxx.

References AddRunSnarl(), AddUsingFile(), JobCommand::HaveOpt(), UtilString::IsInt(), MSG, JobCommand::PopCmd(), JobCommand::PopOpt(), RemoveRunSnarl(), RemoveUsingFile(), and run().

00077 {
00078   std::string c = cmd->PopCmd();
00079   if (!(c=="Add"||c=="Remove")) {
00080     MSG("Demo",Msg::kWarning) << 
00081       "Only: Add [run#] [snarl#] [filename] and \n" <<
00082       "      Remove [run#] [snarl#] [filename] are supported.\n";
00083     return;
00084   }
00085 
00086   int run   = -1;
00087   int snarl = -1;
00088   while (cmd->HaveOpt()) {
00089     std::string opt = cmd->PopOpt();
00090     if (UtilString::IsInt(opt.c_str())) {
00091       if (run!=-1) {
00092         snarl = atoi(opt.c_str());
00093         if (c=="Add") {
00094           this->AddRunSnarl(run,snarl);
00095         }
00096         else {
00097           this->RemoveRunSnarl(run,snarl);
00098         }
00099         run   = -1;
00100         snarl = -1;
00101       }
00102       else {
00103         run = atoi(opt.c_str());
00104       }
00105     }
00106     else { // Assume all strings are file names
00107       if (c=="Add") {
00108         this->AddUsingFile(opt.c_str());
00109       }
00110       else {
00111         this->RemoveUsingFile(opt.c_str());
00112       }
00113     }
00114   }
00115 }

std::string DemoSnarlList::Key int  r,
int  s
[private]
 

Definition at line 178 of file DemoSnarlList.cxx.

References run().

00179 {
00180 //======================================================================
00181 // Construct a sortable key using run and snarl numbers
00182 //======================================================================
00183   char k[1024];
00184   sprintf(k,"%12d.%12.12d",run,snarl);
00185   return k;
00186 }

void DemoSnarlList::RemoveRunSnarl int  r,
int  s
 

Definition at line 131 of file DemoSnarlList.cxx.

References find(), fSnarlList, and s().

Referenced by HandleCommand(), and RemoveUsingFile().

00132 {
00133 //======================================================================
00134 // Remove the run/snarl (r,s) to the list of records to pass
00135 //======================================================================
00136   std::string k(this->Key(r,s));
00137   std::list<std::string>::iterator itr;
00138   itr = std::find(fSnarlList.begin(), fSnarlList.end(), k);
00139   if (itr!=fSnarlList.end()) {
00140     fSnarlList.erase(itr);
00141   }
00142 }

void DemoSnarlList::RemoveUsingFile const char *  f  ) 
 

Definition at line 162 of file DemoSnarlList.cxx.

References RemoveRunSnarl(), and run().

Referenced by HandleCommand().

00163 {
00164 //======================================================================
00165 // Remove all the run/snarls from the file f to the list. Assumes format
00166 // is run<space>snarl
00167 //======================================================================
00168   std::ifstream ifs(f);
00169   int run, snarl;
00170   while (ifs) { 
00171     ifs >> run >> snarl;
00172     this->RemoveRunSnarl(run,snarl);
00173   }
00174 }

void DemoSnarlList::Report  )  [virtual]
 

Implement to spew end of running report

Reimplemented from JobCModule.

Definition at line 61 of file DemoSnarlList.cxx.

References fSnarlList, and MSG.

00062 {
00063 //======================================================================
00064 // Print the snarl numbers in the list
00065 //======================================================================
00066   std::list<std::string>::iterator itr(fSnarlList.begin());
00067   std::list<std::string>::iterator itrEnd(fSnarlList.end());
00068   MSG("Demo",Msg::kInfo) << "Snarls in list:\n";
00069   for (; itr!=itrEnd; ++itr) {
00070     MSG("Demo",Msg::kInfo) << (*itr) << "\n";
00071   }
00072 }


Member Data Documentation

bool DemoSnarlList::fIsSorted [private]
 

Definition at line 39 of file DemoSnarlList.h.

Referenced by AddRunSnarl(), and Ana().

std::list< std::string > DemoSnarlList::fSnarlList [private]
 

Definition at line 40 of file DemoSnarlList.h.

Referenced by AddRunSnarl(), Ana(), RemoveRunSnarl(), and Report().


The documentation for this class was generated from the following files:
Generated on Mon Feb 9 22:56:53 2009 for loon by doxygen 1.3.5