BDSwicPedAccessor Class Reference
[BeamDataUtil]

Access the BeamMonSwicPed database tables. More...

#include <BDSwicPedAccessor.h>

List of all members.

Classes

struct  Device

Public Member Functions

 BDSwicPedAccessor ()
 ~BDSwicPedAccessor ()
void AddDevice (const char *device_name, int minimum_sample_size=10)
bool SetSpillTime (VldContext vc)
int GetPeds (const char *device_name, std::vector< double > &mean, std::vector< double > &sigma) const
int GetPeds (const char *device_name, std::vector< double > &mean) const

Private Types

typedef std::map< std::string,
Device
SwicMap

Private Attributes

SwicMap fSwicMap
DbiResultPtr< BeamMonSwicPeds > * fDRP

Detailed Description

Access the BeamMonSwicPed database tables.

Currently this constructs pedestal values using measurements from the vld range containing the time given in SetSpillTime(). If that doesn't provide enough to satisify the minium_sample_size given in the constructor it will go back in time adding additional vld ranges until the minimum is satisfied.

Author:
(last to touch it)
Author
bv
Version:
Revision
1.6
Date:
Date
2005/05/12 18:48:31

Contact: bv@bnl.gov

Created on: Wed Apr 13 18:14:17 2005

Id
BDSwicPedAccessor.h,v 1.6 2005/05/12 18:48:31 bv Exp

Definition at line 42 of file BDSwicPedAccessor.h.


Member Typedef Documentation

typedef std::map<std::string,Device> BDSwicPedAccessor::SwicMap [private]

Definition at line 75 of file BDSwicPedAccessor.h.


Constructor & Destructor Documentation

BDSwicPedAccessor::BDSwicPedAccessor (  ) 

Definition at line 37 of file BDSwicPedAccessor.cxx.

00038     : fDRP(new DbiResultPtr<BeamMonSwicPeds>)
00039 {
00040 }

BDSwicPedAccessor::~BDSwicPedAccessor (  ) 

Definition at line 42 of file BDSwicPedAccessor.cxx.

References done(), fDRP, fSwicMap, and it.

00043 {
00044     SwicMap::iterator it, done = fSwicMap.end();
00045     for (it=fSwicMap.begin(); it != done; ++it) {
00046         delete it->second.channels;
00047     }
00048     fSwicMap.clear();
00049     if (fDRP) delete fDRP;
00050     fDRP = 0;
00051 }


Member Function Documentation

void BDSwicPedAccessor::AddDevice ( const char *  device_name,
int  minimum_sample_size = 10 
)

Add a device of the given name to the list of ones that should be maintained. The optional minimum sample specifies the minimum number of pedestals desired.

Definition at line 53 of file BDSwicPedAccessor.cxx.

References BDSwicPedAccessor::Device::channels, det, fSwicMap, VldTimeStamp::GetBOT(), VldTimeStamp::GetEOT(), BDSwicPedAccessor::Device::is_profile, is_profile_monitor(), SimFlag::kData, Detector::kFar, Detector::kNear, and BDSwicPedAccessor::Device::range.

Referenced by BDSwicCalibrator::AddDevice().

00055 {
00056     if (fSwicMap.find(device_name) != fSwicMap.end()) return;
00057 
00058     int det = Detector::kNear | Detector::kFar;
00059     int sf = SimFlag::kData;
00060 
00061     Device dev;
00062     dev.channels = new UtilBlockedRunningAverageVector(96,minimum_sample_size);
00063     dev.range = VldRange(det,sf,VldTimeStamp::GetEOT(),VldTimeStamp::GetBOT(),
00064                          "swicpeds");
00065     dev.is_profile = is_profile_monitor(device_name);
00066     fSwicMap[device_name] = dev;
00067 }

int BDSwicPedAccessor::GetPeds ( const char *  device_name,
std::vector< double > &  mean 
) const
int BDSwicPedAccessor::GetPeds ( const char *  device_name,
std::vector< double > &  mean,
std::vector< double > &  sigma 
) const

Get the current pedestal statistics for given device. Return 0 and zero out vectors if the device name isn't known.

Referenced by BDSwicCalibrator::CalibrateOne().

bool BDSwicPedAccessor::SetSpillTime ( VldContext  vc  ) 

Update pedestals. Should be called once per spill. Return true if needed to update peds.

Definition at line 69 of file BDSwicPedAccessor.cxx.

References UtilBlockedRunningAverageVector::Add(), BDSwicPedAccessor::Device::channels, done(), fDRP, fSwicMap, VldTimeStamp::GetBOT(), BeamMonSwicPeds::GetDeviceName(), VldTimeStamp::GetEOT(), BeamMonSwicPeds::GetMeansAsDoubles(), BeamMonSwicPeds::GetNsamples(), DbiResultPtr< T >::GetRow(), BeamMonSwicPeds::GetSigmasAsDoubles(), VldRange::GetTimeEnd(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), BDSwicPedAccessor::Device::is_profile, UtilRunningAverageVector::IsSampleFull(), it, Msg::kDebug, Msg::kWarning, mask_high_peds(), MSG, DbiResultPtr< T >::NewQuery(), DbiResultPtr< T >::NextQuery(), BDSwicPedAccessor::Device::range, VldRange::SetTimeEnd(), and VldRange::SetTimeStart().

Referenced by BDSwicCalibrator::Calibrate().

00070 {
00071     //cerr << "SetSpillTime with vc=" << vc << endl;
00072 
00073 
00074     // First find out if we need to bother
00075     bool finished = true;
00076     SwicMap::iterator it, done = fSwicMap.end();
00077     for (it=fSwicMap.begin(); it != done; ++it) {
00078         //cerr << it->first << ": vr=" << it->second.range << endl;
00079 
00080         if (! it->second.range.IsCompatible(vc)) {
00081             //cerr << "Incompatible, vc=" << vc << endl
00082             //<< "vr=" << it->second.range << endl;
00083             finished = false;
00084             break;
00085         }
00086     }
00087     if (finished) return false;
00088 
00089     // Got to hit the DB.  Maybe there is a smarter way to do this but
00090     // for now just clear everything and start fresh.
00091     for (it=fSwicMap.begin(); it != done; ++it) {
00092         if (!it->second.channels) {
00093             MSG("BD",Msg::kWarning) << "No device channels for " << it->first << endl;
00094             continue;
00095         }
00096         it->second.channels->Clear();
00097         it->second.range.SetTimeStart(VldTimeStamp::GetEOT());
00098         it->second.range.SetTimeEnd(VldTimeStamp::GetBOT());
00099     }
00100 
00101     int nrows = fDRP->NewQuery(vc,0,true);
00102     int n_empty_queries = 0;
00103     for (finished = false; !finished; nrows = fDRP->NextQuery(false)) {
00104 
00105         if (nrows)
00106             n_empty_queries = 0;
00107         else 
00108             ++n_empty_queries;
00109 
00110         if (n_empty_queries > 2) {
00111             MSG("BD",Msg::kWarning) << "Too many empty queries, giving up\n";
00112             return false;
00113         }
00114 
00115         const DbiValidityRec* vr = fDRP->GetValidityRec();
00116         //cerr << "Next query " << n_empty_queries << " with "
00117         //<< nrows << " rows, seqno="
00118         //<< vr->GetSeqNo() << endl
00119         //<< vr->GetVldRange() << endl;
00120 
00121         if (!nrows) {           // hit a gap.
00122             SwicMap::iterator it, done = fSwicMap.end();
00123             for (it=fSwicMap.begin(); it != done; ++it) {
00124                 Device& dev = it->second;
00125                 if (dev.range.GetTimeEnd() < vr->GetVldRange().GetTimeEnd())
00126                     dev.range.SetTimeEnd(vr->GetVldRange().GetTimeEnd());
00127                 if (dev.range.GetTimeStart() > vr->GetVldRange().GetTimeStart())
00128                     dev.range.SetTimeStart(vr->GetVldRange().GetTimeStart());
00129             }
00130             continue;
00131         }
00132 
00133         finished = true;
00134 
00135         for (int row = 0; row<nrows; ++row) {
00136             const BeamMonSwicPeds* peds = fDRP->GetRow(row);
00137             string name = peds->GetDeviceName();
00138             SwicMap::iterator it = fSwicMap.find(name);
00139             if (it == fSwicMap.end()) {
00140                 MSG("BD",Msg::kDebug) << "No Device for " << name << ", continuing\n";
00141                 continue;
00142             }
00143             Device& dev = it->second;
00144 
00145             if (!dev.channels) {
00146                 MSG("BD",Msg::kWarning) << "No Device for " << name << endl;
00147                 continue;
00148             }
00149 
00150             // don't need any more samples
00151             if (dev.channels->IsSampleFull()) {
00152                 MSG("BD",Msg::kDebug) << "Sample not yet full for " << name << ", continuing\n";
00153                 continue;
00154             }
00155 
00156             // enlarge vld range to include this
00157             if (dev.range.GetTimeEnd() < vr->GetVldRange().GetTimeEnd())
00158                 dev.range.SetTimeEnd(vr->GetVldRange().GetTimeEnd());
00159             if (dev.range.GetTimeStart() > vr->GetVldRange().GetTimeStart())
00160                 dev.range.SetTimeStart(vr->GetVldRange().GetTimeStart());
00161             
00162             vector<double> means = peds->GetMeansAsDoubles();
00163             if (dev.is_profile) mask_high_peds(means);
00164             vector<double> sigmas = peds->GetSigmasAsDoubles();
00165             dev.channels->Add(means,sigmas,peds->GetNsamples());
00166 
00167             if (!dev.channels->IsSampleFull()) finished = false;
00168         }
00169     }
00170 
00171     return true;
00172 }


Member Data Documentation

Definition at line 78 of file BDSwicPedAccessor.h.

Referenced by SetSpillTime(), and ~BDSwicPedAccessor().

Definition at line 76 of file BDSwicPedAccessor.h.

Referenced by AddDevice(), SetSpillTime(), and ~BDSwicPedAccessor().


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1