Anp::FillHeader Class Reference

#include <FillHeader.h>

Inheritance diagram for Anp::FillHeader:
Anp::AlgStore Anp::Base

List of all members.

Public Member Functions

 FillHeader ()
virtual ~FillHeader ()
bool Run (Record &record, TObject *ptr=0)
void Config (const Registry &reg)

Private Attributes

std::string fBeam
bool fBrief
BMSpillAnafSpill

Detailed Description

Definition at line 19 of file FillHeader.h.


Constructor & Destructor Documentation

Anp::FillHeader::FillHeader (  ) 

Definition at line 34 of file FillHeader.cxx.

00035   :fBeam("Unknown"),
00036    fBrief(false),
00037    fSpill(0)
00038 {
00039 }

Anp::FillHeader::~FillHeader (  )  [virtual]

Definition at line 42 of file FillHeader.cxx.

References fSpill.

00043 {
00044    if(fSpill)
00045    {
00046       delete fSpill;
00047    }
00048 }


Member Function Documentation

void Anp::FillHeader::Config ( const Registry reg  )  [virtual]

Reimplemented from Anp::AlgStore.

Definition at line 300 of file FillHeader.cxx.

References bfld::AsString(), fBeam, fBrief, Registry::Get(), Registry::KeyExists(), BeamType::kUnknown, Anp::Read(), and BeamType::TagToEnum().

00301 {
00302    //
00303    // Get beam type for Monte-Carlo snarls from Registry or environment
00304    //
00305 
00306    const char *value_beam = 0;
00307    if(!reg.Get("FillBeam", value_beam))
00308    {
00309       reg.Get("PhysicsNtupleBeam", value_beam);
00310    }
00311 
00312    if(!value_beam)
00313    {
00314       value_beam = std::getenv("PHYSICS_NTUPLE_BEAM");
00315    }
00316 
00317    if(value_beam)
00318    {      
00319       BeamType::BeamType_t beam = BeamType::TagToEnum(value_beam);
00320 
00321       if(beam == BeamType::kUnknown)
00322       {
00323          const string tmps(value_beam);
00324 
00325          //
00326          // Try adding to beam string "i" and "z"
00327          //
00328          if(tmps.size() > 6)
00329          {
00330             beam = BeamType::TagToEnum((tmps.substr(0, 4)+"z"+tmps.substr(4, 3)+"i").c_str());
00331          }
00332       }
00333       
00334       //
00335       // Save valid BeamType string
00336       //
00337       if(beam != BeamType::kUnknown) fBeam = BeamType::AsString(beam);
00338    }
00339 
00340    Anp::Read(reg, "FillHeaderBrief", fBrief);
00341 
00342    if(reg.KeyExists("PrintConfig"))
00343    {
00344       cout << "FillHeader::Config" << endl
00345            << "   BeamType = " << fBeam << endl
00346            << "   Brief = " << fBrief << endl;
00347    }
00348 }

bool Anp::FillHeader::Run ( Record record,
TObject *  ptr = 0 
) [virtual]

Implements Anp::AlgStore.

Definition at line 51 of file FillHeader.cxx.

References BeamType::AsString(), Anp::Header::beamdnsec, Anp::Header::beamdsec, Anp::Header::BeamDTime(), Anp::Header::coilcur, Anp::Header::coilrevs, Anp::Header::cratemask, Munits::day, Anp::Header::detector, fBeam, fBrief, fSpill, BDSpillAccessor::Get(), CoilTools::GetCoilState(), VldTimeStamp::GetDate(), VldContext::GetDetector(), CoilTools::GetMagNear(), MCInfo::GetMCPoT(), VldTimeStamp::GetNanoSec(), SpillServerMonFinder::GetNearestSpill(), RecPhysicsHeader::GetRemoteSpillType(), RecDataHeader::GetRun(), VldTimeStamp::GetSec(), VldContext::GetSimFlag(), RecPhysicsHeader::GetSnarl(), SpillServerMon::GetSpillTimeError(), SpillServerMon::GetSpillTimeFD(), SpillServerMon::GetSpillTimeND(), RecDataHeader::GetSubRun(), RecPhysicsHeader::GetTimeFrame(), SpillTimeFinder::GetTimeOfNearestSpill(), VldContext::GetTimeStamp(), SpillTimeFinder::GetTimeToNearestSpill(), RecPhysicsHeader::GetTrigSrc(), RecHeader::GetVldContext(), CoilStatus::Good(), Anp::Header::goodbeam, Anp::Header::goodcoil, Anp::Header::gooddetc, Anp::Header::goodhv, Anp::Header::gpserror, Anp::Header::gpstime, header, SpillServerMonFinder::Instance(), CoilTools::Instance(), HvStatusFinder::Instance(), SpillTimeFinder::Instance(), DataUtil::IsGoodFDData(), CoilTools::IsOK(), CoilTools::IsReverse(), Detector::kCalDet, SimFlag::kData, Msg::kDebug, Msg::kError, Detector::kFar, SimFlag::kMC, Detector::kNear, Anp::Header::litime, BDSpillAccessor::LoadSpill(), month, MSG, Anp::Header::nsec, Anp::Header::Release(), Anp::Header::relitype, Anp::Header::run, Anp::Header::runperiod, Anp::Header::sec, Anp::Record::Set(), Anp::Header::SetBeamType(), Anp::Header::simflag, Anp::Header::snarl, Anp::Header::spillnsec, Anp::Header::spillsec, Anp::Header::SpillTime(), Anp::Header::spilltype, Anp::Header::subrun, BeamType::TagToEnum(), Anp::Header::time2spill, Anp::Header::timeframe, Anp::Header::tor101, Anp::Header::tortgt, Anp::Header::tr101d, Anp::Header::trigger, Anp::Header::trtgtd, Anp::Header::valid, and Munits::year.

00052 {
00053    //
00054    // Fill snarl header information
00055    //
00056 
00057    NtpStRecord *ntprec = dynamic_cast<NtpStRecord *>(ptr);
00058    if(!ntprec)
00059    {
00060       const MomNavigator *mom = dynamic_cast<const MomNavigator *> (ptr);
00061       if(mom)
00062       {
00063          ntprec = dynamic_cast<NtpStRecord *>(mom -> GetFragment("NtpStRecord")); 
00064       }
00065       else
00066       {
00067          MSG("FillAlg", Msg::kError) << "Failed to find MomNavigator pointer" << endl;
00068          return false;
00069       }      
00070    }
00071 
00072    if(!ntprec)
00073    {
00074       MSG("FillAlg", Msg::kError) << "Failed to get NtpStRecord pointer" << endl;
00075       return false;
00076    }
00077    
00078    const RecCandHeader &ntph = ntprec -> GetHeader();
00079    const VldContext     vldc = ntph.GetVldContext();
00080    const VldTimeStamp   vlds = vldc.GetTimeStamp();
00081    //
00082    // Create and fill Header
00083    //
00084    Header header;
00085    header.run       = ntph.GetRun();
00086    header.subrun    = ntph.GetSubRun();
00087    header.snarl     = ntph.GetSnarl();
00088    header.timeframe = ntph.GetTimeFrame();
00089    header.sec       = vlds.GetSec();
00090    header.nsec      = vlds.GetNanoSec();
00091    header.trigger   = ntph.GetTrigSrc();
00092    header.spilltype = ntph.GetRemoteSpillType();
00093    header.valid     = true;
00094 
00095    if     (vldc.GetDetector() == Detector::kNear)   header.detector = 1;
00096    else if(vldc.GetDetector() == Detector::kFar)    header.detector = 2;
00097    else if(vldc.GetDetector() == Detector::kCalDet) header.detector = 3;
00098       
00099    if     (vldc.GetSimFlag() == SimFlag::kData) header.simflag = 1;
00100    else if(vldc.GetSimFlag() == SimFlag::kMC)   header.simflag = 2;
00101    
00102    //
00103    // get software release information
00104    //
00105    header.relitype = ntprec -> GetRelease();
00106 
00107    //
00108    // Fill brief header information and copy Header into Record.
00109    //   
00110    if(fBrief)
00111    {
00112       record.Set(header);
00113       return true;
00114    }
00115 
00116    if(vldc.GetSimFlag() == SimFlag::kData)
00117    {
00118       //
00119       // Set run period
00120       //
00121       unsigned int year = 0, month = 0, day = 0;
00122       vlds.GetDate(true, 0, &year, &month, &day);
00123 
00124       MSG("FillAlg", Msg::kDebug) << "date: " << year << "/" << month << "/" << day << endl;
00125 
00126       if(year == 2005 || (year == 2006 && month < 4))
00127       {
00128          header.runperiod = 1;
00129       }
00130       else if((year == 2006 && month > 4) || (year == 2007 && month < 9))
00131       {
00132          header.runperiod = 2;
00133       }
00134       else if((year == 2007 && month > 9) || (year == 2008 && month > 0))
00135       {
00136          header.runperiod = 3;
00137       }
00138 
00139       //
00140       // Get spill time info for data
00141       //
00142       if(SpillTimeFinder::Instance().DataIsAvailable(vldc))
00143       {
00144          const VldTimeStamp vts = SpillTimeFinder::Instance().GetTimeOfNearestSpill(vldc);
00145          
00146          header.spillsec   = vts.GetSec();
00147          header.spillnsec  = vts.GetNanoSec();
00148          header.time2spill = SpillTimeFinder::Instance().GetTimeToNearestSpill(vldc);
00149       }
00150       else
00151       {
00152          MSG("FillAlg", Msg::kError) << "SpillTimeFinder data is not available" << endl; 
00153       }
00154      
00155       //
00156       // Get beam data from database storing beam monitoring data
00157       //
00158       const BeamMonSpill *beam_spill = BDSpillAccessor::Get().LoadSpill(vlds);
00159 
00160       if(beam_spill)
00161       { 
00162          header.beamdsec  = beam_spill -> SpillTime().GetSec();
00163          header.beamdnsec = beam_spill -> SpillTime().GetNanoSec();
00164          header.tor101    = beam_spill -> fTor101;
00165          header.tr101d    = beam_spill -> fTr101d;
00166          header.tortgt    = beam_spill -> fTortgt;
00167          header.trtgtd    = beam_spill -> fTrtgtd;
00168          header.SetBeamType(BeamType::AsString(beam_spill -> BeamType()));
00169 
00170          //
00171          // Get result of "good spill cut"
00172          //
00173          if(!fSpill)
00174          {
00175             fSpill = new BMSpillAna();
00176             fSpill -> UseDatabaseCuts(true);
00177          }
00178 
00179          fSpill -> SetSpill(*beam_spill);
00180          fSpill -> SetTimeDiff(header.BeamDTime() - header.SpillTime());
00181 
00182          //
00183          // Beam passed "good beam" cut
00184          //
00185          header.goodbeam = fSpill -> SelectSpill();
00186       }
00187       else       
00188       {
00189          MSG("FillAlg", Msg::kError) << "Failed to load spill: " << vldc << endl;
00190       }
00191 
00192       //
00193       // Get detector coil status and coil current
00194       //
00195       CoilTools &ctool = CoilTools::Instance();
00196 
00197       header.goodcoil = ctool.IsOK(vldc);
00198       header.coilrevs = ctool.IsReverse(vldc);
00199 
00200       //
00201       // Fill GPS time and error, LI time (trigger PMT hit time) and crate mask
00202       //
00203       const SpillServerMon &smon = SpillServerMonFinder::Instance().GetNearestSpill(vldc);
00204 
00205       if(vldc.GetDetector() == Detector::kNear)
00206       {  
00207          //
00208          // Near detector state is good: gps not needed, no li, crates and hv are always on
00209          //
00210          header.gpstime   = smon.GetSpillTimeND().GetSec();
00211          header.gpserror  = smon.GetSpillTimeError();
00212          header.litime    = 0;
00213          header.cratemask = 0;
00214          header.gooddetc  = true;
00215          header.goodhv    = true;
00216 
00217          const Dcs_Mag_Near *mag = ctool.GetMagNear(vldc); 
00218          if(mag)
00219          {
00220             header.coilcur = mag -> GetCurrent();
00221          }
00222          else
00223          {
00224             MSG("FillAlg", Msg::kError) << "Failed to get Dcs_Mag_Near pointer" << endl;
00225          }
00226       }
00227       else if(vldc.GetDetector() == Detector::kFar)
00228       {  
00229          header.gpstime   = smon.GetSpillTimeFD().GetSec();      
00230          header.gpserror  = smon.GetSpillTimeError();
00231          header.litime    = ntprec -> dataquality.litime;
00232          header.cratemask = ntprec -> dataquality.cratemask;
00233 
00234          //
00235          // Get far detector state and high voltage status
00236          //
00237          header.gooddetc = DataUtil::IsGoodFDData(ntprec);
00238          header.goodhv   = HvStatus::Good(HvStatusFinder::Instance().GetHvStatus(vldc));
00239 
00240          const BfldDbiCoilState *bfld1 = ctool.GetCoilState(vldc, 1);
00241          const BfldDbiCoilState *bfld2 = ctool.GetCoilState(vldc, 2);
00242          if(bfld1 && bfld2)
00243          {
00244             header.coilcur = 0.5*(bfld1 -> GetCurrent() + bfld2 -> GetCurrent());
00245          }
00246          else
00247          {
00248             MSG("FillAlg", Msg::kError) << "Failed to get BfldDbiCoilState pointer(s)" << endl; 
00249          }       
00250       }
00251    }
00252    else
00253    {
00254       //
00255       // Set runperiod, spill time to trigger, GPS and detector parameters for Monte-Carlo 
00256       //
00257       header.runperiod  = 0;
00258       header.spillsec   = vlds.GetSec();
00259       header.spillnsec  = vlds.GetNanoSec();
00260       header.gpstime    = vlds.GetSec();
00261       header.gpserror   = 0;
00262       header.litime     = 0;
00263       header.cratemask  = 0;
00264 
00265       //
00266       // Set protons/snarl and beam type for Monte-Carlo
00267       //
00268       header.beamdsec   = vlds.GetSec();
00269       header.beamdnsec  = vlds.GetNanoSec();
00270       header.tor101     = MCInfo::GetMCPoT(vldc.GetDetector(),
00271                                            BeamType::TagToEnum(fBeam.c_str()),
00272                                            header.Release());
00273       header.tr101d     = header.tor101;
00274       header.tortgt     = header.tor101;
00275       header.trtgtd     = header.tor101;
00276       header.coilcur    = 0.0;
00277       header.time2spill = 0.0;
00278       header.SetBeamType(fBeam);
00279 
00280       //
00281       // Monte-Carlo always has "good" beam, coil and detector
00282       //
00283       header.goodbeam = true;
00284       header.goodcoil = true;
00285       header.gooddetc = true;
00286       header.goodhv   = true;
00287    }
00288 
00289    MSG("FillAlg", Msg::kDebug) << header << endl;
00290 
00291    //
00292    // Copy Header into Record
00293    //
00294    record.Set(header);
00295 
00296    return true;
00297 }


Member Data Documentation

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

Definition at line 32 of file FillHeader.h.

Referenced by Config(), and Run().

bool Anp::FillHeader::fBrief [private]

Definition at line 34 of file FillHeader.h.

Referenced by Config(), and Run().

Definition at line 36 of file FillHeader.h.

Referenced by Run(), and ~FillHeader().


The documentation for this class was generated from the following files:

Generated on 18 Oct 2018 for loon by  doxygen 1.6.1