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

Anp::SelectSpill Class Reference

#include <SelectSpill.h>

Inheritance diagram for Anp::SelectSpill:

Anp::AlgSnarl Anp::Base List of all members.

Public Member Functions

 SelectSpill ()
virtual ~SelectSpill ()
bool Run (Record &record)
void Config (const Registry &reg)
bool Init (const Header &header)
void End (const DataBlock &)

Private Types

typedef std::map< std::string,
std::pair< unsigned int,
double > > 
BeamMap

Private Member Functions

bool Count (const std::string &key, const Header &header)
bool PassBeam (const Header &header)
bool PassCoil (const Header &header)
bool PassList (const Header &header)
bool ReadList (const Header &header)

Private Attributes

std::string fBeam
std::string fPathBad
std::string fPathGood
std::string fPathList
std::ofstream fList
BeamMap fMap
bool fListData
bool fPrint
bool fReverse
int fTrigger
double fMinICoil
double fMaxICoil
std::vector< RunSubrunfListBad
std::vector< RunSubrunfListGood
std::vector< RunSubrunfMissGood

Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, double> > Anp::SelectSpill::BeamMap [private]
 

Definition at line 53 of file SelectSpill.h.


Constructor & Destructor Documentation

Anp::SelectSpill::SelectSpill  ) 
 

Definition at line 27 of file SelectSpill.cxx.

00028    :fBeam(""),
00029     fListData(false),
00030     fPrint(false),
00031     fReverse(false),
00032     fTrigger(0),
00033     fMinICoil(4600),
00034     fMaxICoil(5200)
00035 {
00036 }

Anp::SelectSpill::~SelectSpill  )  [virtual]
 

Definition at line 39 of file SelectSpill.cxx.

00040 {
00041 }


Member Function Documentation

void Anp::SelectSpill::Config const Registry reg  )  [virtual]
 

Reimplemented from Anp::AlgSnarl.

Definition at line 78 of file SelectSpill.cxx.

References BeamType::AsString(), fBeam, fList, fListData, fMaxICoil, fMinICoil, fPathBad, fPathGood, fPathList, fPrint, fReverse, Registry::Get(), Registry::KeyExists(), Anp::Read(), reg, and BeamType::TagToEnum().

00079 {
00080    const char *value_beam = 0;   
00081    if(reg.Get("SelectSpillB", value_beam) && value_beam)
00082    {
00083       if(std::strcmp(value_beam, "ALLBEAM") == 0)
00084       {
00085          fBeam.clear();
00086       }
00087       else
00088       {
00089          fBeam = value_beam;
00090       }      
00091    }
00092 
00093    //
00094    // Check that beam is of known type
00095    //
00096    if(!fBeam.empty())
00097    {
00098       BeamType::BeamType_t beam = BeamType::TagToEnum(fBeam.c_str());
00099 
00100       if(beam == BeamType::kUnknown)
00101       {
00102          //
00103          // Try adding to beam string "i" and "z"
00104          //
00105          if(fBeam.size() > 6)
00106          {
00107             beam = BeamType::TagToEnum((fBeam.substr(0, 4)+"z"+fBeam.substr(4, 3)+"i").c_str());
00108          } 
00109          
00110          fBeam = BeamType::AsString(beam); 
00111       }
00112    }
00113 
00114    const char *value_bad  = 0;
00115    const char *value_good = 0;
00116    const char *value_list = 0;
00117 
00118    if(reg.Get("SelectSpillPathBad",  value_bad)  && value_bad)  fPathBad  = value_bad;
00119    if(reg.Get("SelectSpillPathGood", value_good) && value_good) fPathGood = value_good;
00120    if(reg.Get("SelectSpillPathList", value_list) && value_list) fPathList = value_list;
00121 
00122    Anp::Read(reg, "SelectSpillListData", fListData);
00123    Anp::Read(reg, "SelectSpillPrint",    fPrint);
00124    Anp::Read(reg, "SelectSpillReverse",  fReverse);
00125 
00126    reg.Get("SelecSpillMinICoil", fMinICoil);
00127    reg.Get("SelecSpillMaxICoil", fMaxICoil);
00128 
00129    if(reg.KeyExists("PrintConfig"))
00130    {
00131       cout << "SelectSpill::Config" << endl
00132            << "   Beam = " << fBeam << endl
00133            << "   PathBad = " << fPathBad << endl
00134            << "   PathGood = " << fPathGood << endl
00135            << "   PathList = " << fPathList << endl
00136            << "   ListData = " << fListData << endl
00137            << "   Print = " << fPrint << endl
00138            << "   Reverse = " << fReverse << endl
00139            << "   MinICoil = " << fMinICoil << endl
00140            << "   MaxICoil = " << fMaxICoil << endl;
00141    }
00142 
00143    fList.open(fPathList.c_str());
00144 }

bool Anp::SelectSpill::Count const std::string &  key,
const Header header
[private]
 

Definition at line 187 of file SelectSpill.cxx.

References fMap, Anp::Header::Tor101(), Anp::Header::TorTgt(), Anp::Header::Tr101D(), and Anp::Header::TrTgtD().

00188 {
00189    //
00190    // Get (insert for a first time) pointer to current beam string
00191    //
00192    BeamMap::iterator bit = 
00193       fMap.insert(BeamMap::value_type(key, pair<unsigned int, double>(0, 0.0))).first;
00194    
00195    if     (header.TorTgt() > 0.0) (bit -> second).second += header.TorTgt();
00196    else if(header.TrTgtD() > 0.0) (bit -> second).second += header.TrTgtD();
00197    else if(header.Tr101D() > 0.0) (bit -> second).second += header.Tr101D();
00198    else if(header.Tor101() > 0.0) (bit -> second).second += header.Tor101();
00199    else
00200    {
00201       cerr << "SelectSpill::Count - invalid toroid data" << endl;
00202       return false;
00203    }
00204    ++(bit -> second).first; //count snarls
00205 
00206    return true;
00207 }

void Anp::SelectSpill::End const DataBlock  )  [virtual]
 

Reimplemented from Anp::AlgSnarl.

Definition at line 158 of file SelectSpill.cxx.

References fMap, fMissGood, and run().

00159 {
00160    //
00161    // Print number of snarls and pot for each beam
00162    //
00163    
00164    int bwidth = 0, swidth = 0;
00165    for(BeamMap::const_iterator bit = fMap.begin(); bit != fMap.end(); ++bit)
00166    {
00167       bwidth = std::max<int>(bwidth, bit->first.size());
00168       swidth = std::max<int>(swidth, 1+static_cast<int>(std::log10(double(bit->second.first+1))));
00169    }
00170 
00171    for(BeamMap::const_iterator bit = fMap.begin(); bit != fMap.end(); ++bit)
00172    {
00173       cout << "   " << std::setw(bwidth) << bit -> first << " nsnarl = "
00174            << std::setw(swidth) << std::right << bit -> second.first << ", pot = "
00175            << std::setw(6) << std::setprecision(4) << std::left << std::scientific
00176            << bit -> second.second << endl;
00177    }
00178 
00179    cout << "SelectSpill::End - printing " << fMissGood.size() << " missing runs" << endl;
00180    for(vector<RunSubrun>::const_iterator rit = fMissGood.begin(); rit != fMissGood.end(); ++rit)
00181    {
00182       cout << "   " << rit -> run << " " << rit -> subrun << endl;
00183    }
00184 }

bool Anp::SelectSpill::Init const Header header  )  [virtual]
 

Reimplemented from Anp::AlgSnarl.

Definition at line 147 of file SelectSpill.cxx.

References Anp::ReadList().

00148 {
00149    //
00150    // Read good and bad run list for this detector
00151    //
00152    SelectSpill::ReadList(header);
00153 
00154    return true;
00155 }

bool Anp::SelectSpill::PassBeam const Header header  )  [private]
 

Definition at line 210 of file SelectSpill.cxx.

References fBeam, Anp::Header::GetBEAMTYPE(), Anp::Header::GoodBeam(), and Anp::Header::IsData().

00211 {   
00212    //
00213    // Select beam type and apply "good beam" cut
00214    //
00215    if(header.IsData() && !header.GoodBeam()) return false;
00216 
00217    //
00218    // Get beam type for this snarl
00219    //
00220    const string beam = header.GetBEAMTYPE();
00221 
00222    SelectSpill::Count(beam, header);
00223 
00224    //
00225    // Select beam type, if fBeam string is filled
00226    //
00227    if(!fBeam.empty() && fBeam != "ALLBEAM" && fBeam != beam) return false;
00228 
00229    return true;
00230 }

bool Anp::SelectSpill::PassCoil const Header header  )  [private]
 

Definition at line 233 of file SelectSpill.cxx.

References Anp::Header::CoilCur(), Anp::Header::CoilRevs(), Anp::Header::GoodCoil(), Anp::Header::IsData(), Anp::Header::IsFar(), and Anp::Header::IsNear().

00234 {   
00235    //
00236    // Apply near and far detector coil quality cut
00237    //
00238    if(header.IsData())
00239    {
00240       if(!header.GoodCoil()) return false;
00241    }
00242    else
00243    {
00244       return true;
00245    }
00246 
00247    if(header.IsNear())
00248    {
00249       const double icur = std::fabs(header.CoilCur());
00250       if(icur < fMinICoil || icur > fMaxICoil)
00251       {
00252          return false;
00253       }
00254       
00255       if(fReverse)
00256       {
00257          if(!header.CoilRevs()) return false;
00258       }
00259       else
00260       {
00261          if(header.CoilRevs()) return false;
00262       }
00263 
00264       return true;
00265    }
00266    else if(header.IsFar())
00267    {
00268       return true;
00269    }
00270 
00271    return false;
00272 }

bool Anp::SelectSpill::PassList const Header header  )  [private]
 

Definition at line 275 of file SelectSpill.cxx.

References find(), fListBad, fListData, fListGood, fMissGood, Anp::Header::IsData(), Anp::Header::Run(), run(), Anp::Header::Snarl(), and Anp::Header::SubRun().

00276 {
00277    //
00278    // Ignore run and subruns that are on the bad run list, also
00279    // if good run list exists then only pass runs on that list.
00280    //
00281    bool pass = true;
00282 
00283    if(fListData && !header.IsData())
00284    {
00285       return true;
00286    }
00287 
00288    if(!fListBad.empty())
00289    {
00290       const RunSubrun run(header.Run(), header.SubRun());
00291       if(std::find(fListBad.begin(), fListBad.end(), run) != fListBad.end())
00292       {
00293          pass = false;
00294       }
00295    }
00296 
00297    if(!fListGood.empty())
00298    {
00299       pass = false;
00300       for(vector<RunSubrun>::const_iterator rit = fListGood.begin(); rit != fListGood.end(); ++rit)
00301       {
00302          if(rit -> run != header.Run() || rit -> subrun != header.Snarl())
00303          {
00304             continue;
00305          }
00306          
00307          vector<RunSubrun>::iterator fit = std::find(fMissGood.begin(), fMissGood.end(), *rit);
00308          if( fit==fMissGood.end()) cout<<" SelectSpill::PassList  - found no RunSubrun (run: "<<rit->run<<", subrun:"<<rit-> subrun<<")"<<endl;
00309          else cout<<" SelectSpill::PassList - found RunSubrun (run: "<<rit->run<<", subrun:"<<rit-> subrun<<")"<<endl;
00310          fMissGood.erase(fit);
00311 
00312          pass = true;
00313          break;
00314       }
00315    }
00316 
00317    return pass;
00318 }

bool Anp::SelectSpill::ReadList const Header header  )  [private]
 

Definition at line 321 of file SelectSpill.cxx.

References fListBad, fListGood, fMissGood, fPathBad, fPathGood, fPrint, Anp::Header::IsData(), Anp::Header::IsFar(), Anp::Header::IsNear(), and Anp::ReadRunList().

00322 {
00323    //
00324    // Read good run list and bad run list
00325    //
00326    if(fPathBad.empty())
00327    {
00328       string filename;
00329       if     (header.IsNear()) filename = "PhysicsNtuple/Config/RunListNearBad.txt";
00330       else if(header.IsFar())  filename = "PhysicsNtuple/Config/RunListFarBad.txt";
00331 
00332       const char *srt_char = std::getenv("SRT_PRIVATE_CONTEXT");
00333       if(srt_char)
00334       {
00335          fPathBad = std::string(srt_char) + "/" + filename;
00336       }
00337    }
00338 
00339    if(fPathGood.empty())
00340    {
00341       string filename;
00342       if     (header.IsNear()) filename = "PhysicsNtuple/Config/RunListNearGood.txt";
00343       else if(header.IsFar())  filename = "PhysicsNtuple/Config/RunListFarGood.txt";
00344 
00345       const char *srt_char = std::getenv("SRT_PRIVATE_CONTEXT");
00346       if(srt_char)
00347       {
00348          fPathGood = std::string(srt_char) + "/" + filename;
00349       }
00350    }
00351 
00352    if(header.IsData()) fListBad  = Anp::ReadRunList(fPathBad, fPrint);
00353    fListGood = Anp::ReadRunList(fPathGood, fPrint);
00354    fMissGood = fListGood;
00355 
00356    if(!fListBad.empty())
00357    {
00358       cout << "SelectSpill::ReadList - read " << fListBad.size() << " bad run entries from" << endl
00359            << "   " << fPathBad << endl;
00360    }
00361 
00362    if(!fListGood.empty())
00363    {
00364       cout << "SelectSpill::ReadList - read " << fListGood.size() << " good run entries from" << endl
00365            << "   " << fPathGood << endl;
00366    }
00367 
00368    return true;
00369 }

bool Anp::SelectSpill::Run Record record  )  [virtual]
 

Implements Anp::AlgSnarl.

Definition at line 44 of file SelectSpill.cxx.

References fList, Anp::Record::GetHeader(), Anp::Header::Run(), Anp::Header::Snarl(), and Anp::Header::SubRun().

00045 {
00046    //
00047    // Select spills with a given beam type that pass "good beam" cuts
00048    //
00049    const Header &header = record.GetHeader();
00050 
00051    //
00052    // Select beam type and apply beam quality cut
00053    //
00054    if( !SelectSpill::PassBeam(header)) return false;
00055    else SelectSpill::Count("1: PassBeam", header);
00056 
00057    //
00058    // Apply detector coil cut
00059    //
00060    if( !SelectSpill::PassCoil(header)) return false;
00061    else SelectSpill::Count("2: PassCoil", header);
00062 
00063    //
00064    // Check if this snarl is on bad run list or not on good run list
00065    //
00066    if( !SelectSpill::PassList(header)) return false;
00067    else SelectSpill::Count("3: PassList", header);
00068 
00069    if(fList.is_open())
00070    {
00071       fList << header.Run() << " " << header.SubRun() << " " << header.Snarl() << endl;
00072    }
00073 
00074    return true;
00075 }


Member Data Documentation

std::string Anp::SelectSpill::fBeam [private]
 

Definition at line 57 of file SelectSpill.h.

Referenced by Config(), and PassBeam().

std::ofstream Anp::SelectSpill::fList [private]
 

Definition at line 62 of file SelectSpill.h.

Referenced by Config(), and Run().

std::vector<RunSubrun> Anp::SelectSpill::fListBad [private]
 

Definition at line 74 of file SelectSpill.h.

Referenced by PassList(), and ReadList().

bool Anp::SelectSpill::fListData [private]
 

Definition at line 66 of file SelectSpill.h.

Referenced by Config(), and PassList().

std::vector<RunSubrun> Anp::SelectSpill::fListGood [private]
 

Definition at line 75 of file SelectSpill.h.

Referenced by PassList(), and ReadList().

BeamMap Anp::SelectSpill::fMap [private]
 

Definition at line 64 of file SelectSpill.h.

Referenced by Count(), and End().

double Anp::SelectSpill::fMaxICoil [private]
 

Definition at line 72 of file SelectSpill.h.

Referenced by Config().

double Anp::SelectSpill::fMinICoil [private]
 

Definition at line 71 of file SelectSpill.h.

Referenced by Config().

std::vector<RunSubrun> Anp::SelectSpill::fMissGood [private]
 

Definition at line 76 of file SelectSpill.h.

Referenced by End(), PassList(), and ReadList().

std::string Anp::SelectSpill::fPathBad [private]
 

Definition at line 58 of file SelectSpill.h.

Referenced by Config(), and ReadList().

std::string Anp::SelectSpill::fPathGood [private]
 

Definition at line 59 of file SelectSpill.h.

Referenced by Config(), and ReadList().

std::string Anp::SelectSpill::fPathList [private]
 

Definition at line 60 of file SelectSpill.h.

Referenced by Config().

bool Anp::SelectSpill::fPrint [private]
 

Definition at line 67 of file SelectSpill.h.

Referenced by Config(), and ReadList().

bool Anp::SelectSpill::fReverse [private]
 

Definition at line 68 of file SelectSpill.h.

Referenced by Config().

int Anp::SelectSpill::fTrigger [private]
 

Definition at line 70 of file SelectSpill.h.


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:10:35 2010 for loon by  doxygen 1.3.9.1