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

BDSwicMaskAccessor.cxx

Go to the documentation of this file.
00001 #include "BDSwicMaskAccessor.h"
00002 
00003 #include "BeamMonSwicMask.h"
00004 #include "BeamMonSwicRel.h"
00005 
00006 
00007 #include <DatabaseInterface/DbiResultKey.h>
00008 
00009 #include <MessageService/MsgService.h>
00010 CVSID("$Id: BDSwicMaskAccessor.cxx,v 1.4 2005/12/14 21:03:20 bv Exp $");
00011 
00012 
00013 #include <DatabaseInterface/DbiResultPtr.tpl>
00014 template class  DbiResultPtr<BeamMonSwicMask>;
00015 template class  DbiResultPtr<BeamMonSwicRel>;
00016 
00017 using namespace std;
00018 
00019 BDSwicMaskAccessor::BDSwicMaskAccessor()
00020     : fMaskResPtr(new DbiResultPtr<BeamMonSwicMask>)
00021     , fRelResPtr(new DbiResultPtr<BeamMonSwicRel>)
00022     , fMaskResKey(0), fRelResKey(0)
00023 {
00024 }
00025 BDSwicMaskAccessor::~BDSwicMaskAccessor()
00026 {
00027     if (fMaskResPtr) delete fMaskResPtr;
00028     if (fRelResPtr)  delete fRelResPtr;
00029     fMaskResPtr = 0;
00030     fRelResPtr = 0;
00031     fMaskResKey = fRelResKey = 0;
00032 }
00033 
00034 void BDSwicMaskAccessor::AddDevice(const char* device_name)
00035 {
00036     if (fSwicMap.find(device_name) != fSwicMap.end()) return;
00037 
00038     Device dev;
00039     dev.mask = vector<double>(96,1);
00040     dev.rel  = vector<double>(96,1);
00041     dev.prod  = vector<double>(96,1);
00042     fSwicMap[device_name] = dev;
00043 }
00044 
00045 
00046 void BDSwicMaskAccessor::Reset()
00047 {
00048     SwicMap::iterator it, done = fSwicMap.end();
00049     for (it=fSwicMap.begin(); it != done; ++it) {
00050         it->second.mask = vector<double>(96,1);
00051         it->second.rel  = vector<double>(96,1);
00052         it->second.prod = vector<double>(96,1);
00053     }
00054 }
00055 
00056 
00057 bool BDSwicMaskAccessor::SetSpillTime(VldContext vc)
00058 {
00059 
00060     bool tf1 = true;            // db hit?
00061     int nrows1 = fMaskResPtr->NewQuery(vc,0,true);
00062     const DbiResultKey* result_key1 = fMaskResPtr->GetKey();
00063     if (fMaskResKey && result_key1->IsEqualTo(fMaskResKey)) tf1=false;
00064 
00065     bool tf2 = true;            // db hit?
00066     int nrows2 = fRelResPtr->NewQuery(vc,0,true);
00067     const DbiResultKey* result_key2 = fRelResPtr->GetKey();
00068     if (fRelResKey && result_key2->IsEqualTo(fRelResKey)) tf2=false;
00069 
00070     if (!tf1 && !tf2) return false;
00071 
00072 
00073     fMaskResKey = result_key1;
00074     fRelResKey = result_key2;
00075 
00076     this->Reset();
00077 
00078     if (tf1) {
00079         for (int row=0; row<nrows1; ++row) {
00080             const BeamMonSwicMask* mask = fMaskResPtr->GetRow(row);
00081             string name = mask->GetDeviceName();
00082             SwicMap::iterator it = fSwicMap.find(name);
00083             if (it == fSwicMap.end()) {
00084                 MSG("BD",Msg::kDebug) << "No Device for "
00085                                       << name << ", continuing\n";
00086                 continue;
00087             }
00088             int ind = mask->GetOffset();
00089             it->second.mask[ind] = mask->GetMask();
00090         }
00091     }
00092     if (tf2) {
00093         for (int row=0; row<nrows2; ++row) {
00094             const BeamMonSwicRel* rel = fRelResPtr->GetRow(row);
00095             string name = rel->GetDeviceName();
00096             SwicMap::iterator it = fSwicMap.find(name);
00097             if (it == fSwicMap.end()) {
00098                 MSG("BD",Msg::kDebug) << "No Device for " 
00099                                       << name << ", continuing\n";
00100                 continue;
00101             }
00102             it->second.rel = rel->GetChannelsAsDoubles();
00103         }
00104     }
00105 
00106     SwicMap::iterator it, done = fSwicMap.end();
00107     for (it=fSwicMap.begin(); it != done; ++it)
00108         for (int ind=0; ind<96; ++ind)
00109             it->second.prod[ind] = it->second.mask[ind]*it->second.rel[ind];
00110     
00111     return true;
00112 }
00113 
00114 const vector<double>& BDSwicMaskAccessor::GetMask(const char* device_name) const
00115 {
00116     static vector<double> looser;
00117 
00118     SwicMap::const_iterator it = fSwicMap.find(device_name);
00119     if (it == fSwicMap.end()) return looser;
00120 
00121     return it->second.prod;
00122 }

Generated on Mon Feb 15 11:06:24 2010 for loon by  doxygen 1.3.9.1