BMSpillFiller Class Reference
[BeamDataDbi]

Fill BeamMonSpill table row object. More...

#include <BMSpillFiller.h>

Inheritance diagram for BMSpillFiller:
BeamMonFiller

List of all members.

Public Member Functions

 BMSpillFiller (BDEarliest &bde, BDScalar *bdpi[4], BDHornCurrent &bdhc, BDTarget &target, BDHadMuMon *hadmu[4])
 Create a BMSpillFiller with all the BDProcessors it needs.
 ~BMSpillFiller ()
void SetSpillsPerWrite (size_t spills_per_write=3000)
 Set the number of spills to write to one validity range.
void Spill (const RawBeamMonHeaderBlock &rbmhb, const RawBeamMonBlock &rbmb)

Private Member Functions

void DBU (bool all=false)

Private Attributes

BDEarliestfEarliest
BDScalarfToroids [4]
BDHornCurrentfHorn
BDTargetfTarget
std::deque< BeamMonSpill * > fSpills
size_t fSpillsPerWrite
BDHadMuMonfHadMu [4]

Detailed Description

Fill BeamMonSpill table row object.

This filler buffers multiple beam spills in order to write them all to a single validity range. This somewhat reduces the size of the VLD table and speeds up later retrieval.

The spill time is chosen to be the earliest SWIC (VME) timestamp that is consistent (w/in 0.5 seconds) of the devices DAE timestamp or, if none are found, the earliest DAE timestamp.

Author:
(last to touch it)
Author
mdier
Version:
Revision
1.9
Date:
Date
2005/10/31 22:21:40

Contact: bv@bnl.gov

Created on: Wed Apr 13 18:15:34 2005

Id
BMSpillFiller.h,v 1.9 2005/10/31 22:21:40 mdier Exp

Definition at line 48 of file BMSpillFiller.h.


Constructor & Destructor Documentation

BMSpillFiller::BMSpillFiller ( BDEarliest bde,
BDScalar bdpi[4],
BDHornCurrent bdhc,
BDTarget target,
BDHadMuMon hadmu[4] 
)

Create a BMSpillFiller with all the BDProcessors it needs.

Definition at line 31 of file BMSpillFiller.cxx.

References fHadMu, fToroids, and SetSpillsPerWrite().

00036     : fEarliest(bde)
00037     , fHorn(bdhc)
00038     , fTarget(target)
00039     , fSpillsPerWrite(3000)
00040 {
00041     this->SetSpillsPerWrite();
00042     for (int ind=0; ind<4; ++ind) fToroids[ind] = bdpi[ind];
00043     for (int ind=0; ind<4; ++ind) fHadMu[ind]   = hadmu[ind];
00044 }

BMSpillFiller::~BMSpillFiller (  ) 

Definition at line 46 of file BMSpillFiller.cxx.

References DBU(), and fSpills.

00047 {
00048     this->DBU(true);
00049     while (fSpills.size()) {
00050         delete fSpills.back();
00051         fSpills.pop_back();
00052     }
00053 }


Member Function Documentation

void BMSpillFiller::DBU ( bool  all = false  )  [private]

Definition at line 216 of file BMSpillFiller.cxx.

References DbiWriter< T >::Close(), count, done(), fSpills, fSpillsPerWrite, VldTimeStamp::GetSec(), it, SimFlag::kData, Msg::kDebug, Detector::kFar, Detector::kNear, Msg::kVerbose, and MSG.

Referenced by Spill(), and ~BMSpillFiller().

00217 {
00218     // 1. Decide if there are enough spills in a range, o.w. return
00219     // 2. Write them to DBI
00220     // 3. Remove from list
00221     // 4. Call recursively
00222 
00223     size_t nspills = fSpills.size();
00224 
00225     if (!nspills) {
00226         MSG("BDD",Msg::kDebug) << "no spills to send to DB\n";
00227         return;
00228     }
00229 
00230     // Not yet collected enough spills to even consider being full and
00231     // haven't been asked to unconditionally write everything.
00232     if (!all && nspills < fSpillsPerWrite) {
00233         MSG("BDD",Msg::kVerbose)
00234             << "dump all not requested and not enough spills ("
00235             << nspills << " < " << fSpillsPerWrite << endl;
00236         return;
00237     }
00238 
00239     if (nspills > fSpillsPerWrite) nspills = fSpillsPerWrite;
00240 
00241     // Find the spill that is just outside of one spill block length
00242     // away from the first spill.
00243     deque<BeamMonSpill*>::iterator it1=fSpills.begin();
00244     deque<BeamMonSpill*>::iterator done = it1 + nspills;
00245     deque<BeamMonSpill*>::iterator it2 = done;
00246     --it2;
00247     
00248     // Initial vld range includes a padding around the first/last spills
00249     VldTimeStamp beg = (*it1)->SpillTime();
00250     VldTimeStamp end = (*it2)->SpillTime();
00251 
00252     // truncate to integral seconds (DBI does it anyways)
00253     beg = VldTimeStamp(beg.GetSec());
00254     // add 1 second to catch last spill
00255     end = VldTimeStamp(end.GetSec()+1);
00256 
00257     VldRange range(Detector::kNear|Detector::kFar,SimFlag::kData,
00258                    beg,end,"Beam");
00259     VldTimeStamp now;
00260     DbiWriter<BeamMonSpill> writer(range,-1,0,now);
00261     
00262     size_t count = 0;
00263     for (deque<BeamMonSpill*>::iterator it=it1; it != done; ++it) {
00264         writer << **it;
00265         delete *it;
00266         ++count;
00267     }
00268 
00269     MSG("BDD",Msg::kDebug) << " wrote " << count
00270                           <<" for range: " << range << endl;
00271 
00272 
00273     ++it2;
00274     fSpills.erase(it1,it2);
00275 
00276     writer.Close();
00277 
00278     // iterate if necessary.
00279     this->DBU(all);
00280 }

void BMSpillFiller::SetSpillsPerWrite ( size_t  spills_per_write = 3000  ) 

Set the number of spills to write to one validity range.

Definition at line 55 of file BMSpillFiller.cxx.

References fSpillsPerWrite.

Referenced by BMSpillFiller().

00056 {
00057     fSpillsPerWrite = n;
00058 }

void BMSpillFiller::Spill ( const RawBeamMonHeaderBlock rbmhb,
const RawBeamMonBlock rbmb 
)

Call once each spill, after the BDProcessors have visited the data.

Reimplemented from BeamMonFiller.

Definition at line 108 of file BMSpillFiller.cxx.

References BeamMonSpill::StatusBits::beam_type, BDTarget::BpmProjection(), DBU(), fEarliest, fHadMu, fHorn, fSpills, fTarget, fToroids, BeamMonSpill::GetStatusBits(), BDEarliest::GetTimestamps(), BDScalar::GetValue(), BeamMonSpill::StatusBits::horn_on, is_pm_there(), BDSwicPeds::IsPedSpill(), Msg::kDebug, BDTarget::kHE, BDTarget::kLE, BDTarget::kME, BDTarget::kPsHE, BDTarget::kPsME, BDTarget::kUnknown, Msg::kVerbose, Msg::kWarning, min_horn_current, MSG, BeamMonSpill::StatusBits::n_batches, BeamMonSpill::StatusBits::pedestal, BeamMonSpill::StatusBits::pm121_in, BeamMonSpill::StatusBits::pmtgt_in, BDTarget::ProfileProjection(), BeamMonSpill::SetBPM(), BeamMonSpill::SetHadMuInt(), BeamMonSpill::SetHornCurrent(), BeamMonSpill::SetProfile(), BeamMonSpill::SetStatusBits(), BeamMonSpill::SetTimestamps(), BeamMonSpill::SetToroids(), BeamMonSpill::StatusBits::target_in, BDTarget::TargetIn(), and BeamMonSpill::StatusBits::time_source.

Referenced by BeamMonDbuModule::Process().

00110 {
00111     BeamMonSpill* spill = new BeamMonSpill;
00112     BeamMonSpill::StatusBits bits = spill->GetStatusBits(); // is zeroed
00113 
00114     double dae=0, vme=0;
00115     fEarliest.GetTimestamps(dae, vme);
00116     if (dae==0 && vme==0) {
00117         MSG("BDD",Msg::kWarning)
00118             << "Both DAE and VME timestamps are zero.\n";
00119         return;
00120     }
00121 
00122 
00123     if (!vme) bits.time_source = 1;
00124     VldTimeStamp vts_dae(dae), vts_vme(vme);
00125     spill->SetTimestamps(vts_dae,vts_vme);
00126 
00127     spill->SetToroids(fToroids[0]->GetValue(),
00128                       fToroids[1]->GetValue(), 
00129                       fToroids[2]->GetValue(), 
00130                       fToroids[3]->GetValue());
00131 
00132     double horn_current = fHorn.GetValue();
00133     if (fabs(horn_current) > min_horn_current) bits.horn_on = 1;
00134     else {
00135         MSG("BDD",Msg::kDebug) << "Horn current: "
00136                               << horn_current << " not high enough\n";
00137     }
00138     spill->SetHornCurrent(horn_current);
00139 
00140     // BPMs
00141     vector<double> xp,yp,xi,yi,iave;
00142     fTarget.BpmProjection(xp,yp,xi,yi);
00143     for (size_t ind=0; ind<xi.size(); ++ind)
00144         iave.push_back(0.5*(xi[ind]+yi[ind]));
00145     spill->SetBPM(xp,yp,iave);
00146     bits.n_batches = xi.size();
00147 
00148     // profile monitors
00149     double x=0,y=0,w=0,h=0;
00150     fTarget.ProfileProjection(x,y,w,h);
00151     spill->SetProfile(x,y,w,h);
00152 
00153     // Determine which time to use to get the target position
00154     double tgttime=vme;
00155     if (tgttime==0) tgttime=dae;
00156 
00157     bool is_in = false;
00158     double location = -9999;
00159     BDTarget::BeamType beam_type = fTarget.TargetIn(is_in,location,tgttime);
00160     bits.target_in = is_in ? 1 : 0;
00161     if (is_in) {
00162         switch (beam_type) {
00163         case BDTarget::kLE: bits.beam_type = 1; break;
00164         case BDTarget::kME: bits.beam_type = 2; break;
00165         case BDTarget::kHE: bits.beam_type = 3; break;
00166         case BDTarget::kPsME: bits.beam_type = 4; break;
00167         case BDTarget::kPsHE: bits.beam_type = 5; break;
00168         case BDTarget::kUnknown: default:
00169             MSG("BDD",Msg::kDebug)
00170                 << "Unknown beam type, distance = " << location << endl;
00171             bits.beam_type = 0;
00172             break;
00173         }
00174     }
00175     else {
00176         MSG("BDD",Msg::kWarning)
00177             << "Target not in!\n";
00178     }
00179         
00180 
00181     bits.pedestal = BDSwicPeds::IsPedSpill(rbmb);
00182     if (bits.pedestal) MSG("BDD",Msg::kDebug) << "Got ped spill\n";
00183 
00184     bits.pm121_in = is_pm_there(rbmb,"121");
00185     bits.pmtgt_in = is_pm_there(rbmb,"TGT");
00186 
00187     if(!bits.pm121_in) MSG("BDD",Msg::kDebug) << "No pm121\n";
00188     if(!bits.pmtgt_in) MSG("BDD",Msg::kDebug) << "No pmtgt\n";
00189 
00190     spill->SetStatusBits(bits);
00191 
00192     spill->SetHadMuInt(fHadMu[0]->GetTotalCharge(),
00193                        fHadMu[1]->GetTotalCharge(),
00194                        fHadMu[2]->GetTotalCharge(),
00195                        fHadMu[3]->GetTotalCharge());
00196 
00197 
00198     fSpills.push_back(spill);
00199 
00200     BeamMonSpill::StatusBits sb = spill->GetStatusBits();
00201 
00202     MSG("BDD",Msg::kVerbose)
00203         << " horn_on:" << sb.horn_on
00204         << " target_in:" << sb.target_in
00205         << " beam_type:" << sb.beam_type
00206         << " pedestal:" << sb.pedestal
00207         << " pm121_in:" << sb.pm121_in
00208         << " pmtgt_in:" << sb.pmtgt_in
00209         << endl;
00210 
00211     MSG("BDD",Msg::kVerbose) << fSpills.size() << " spills\n";
00212 
00213     this->DBU();
00214 }


Member Data Documentation

Definition at line 72 of file BMSpillFiller.h.

Referenced by Spill().

Definition at line 80 of file BMSpillFiller.h.

Referenced by BMSpillFiller(), and Spill().

Definition at line 74 of file BMSpillFiller.h.

Referenced by Spill().

std::deque<BeamMonSpill*> BMSpillFiller::fSpills [private]

Definition at line 78 of file BMSpillFiller.h.

Referenced by DBU(), Spill(), and ~BMSpillFiller().

Definition at line 79 of file BMSpillFiller.h.

Referenced by DBU(), and SetSpillsPerWrite().

Definition at line 75 of file BMSpillFiller.h.

Referenced by Spill().

Definition at line 73 of file BMSpillFiller.h.

Referenced by BMSpillFiller(), and Spill().


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1