#include <iostream>#include <string>#include <fstream>#include <map>#include "CalDetPID/CalDetBeamMomentum.h"#include "DatabaseInterface/Dbi.h"#include "DatabaseInterface/DbiWriter.h"#include "DatabaseInterface/DbiResultPtr.h"#include "DatabaseInterface/DbiCascader.h"#include "DatabaseInterface/DbiTableProxyRegistry.h"#include "Validity/VldContext.h"#include "Validity/VldTimeStamp.h"#include "Validity/VldRange.h"#include "MessageService/MsgService.h"#include "Conventions/Detector.h"#include "Conventions/SimFlag.h"#include "DatabaseUpdater/DbuSubRunSummary.h"Go to the source code of this file.
Functions | |
| double | get_beam_p (const map< int, float > &m, int run) |
| int | main () |
|
||||||||||||
|
Definition at line 182 of file MakeBeamMomentumTable.cc. References run(). Referenced by main(). 00183 {
00184 typedef std::map<int, float>::const_iterator MIT;
00185 MIT it = m.find(run);
00186 if(it!=m.end()) return it->second;
00187 else return 0.0;
00188
00189 }
|
|
|
Definition at line 29 of file MakeBeamMomentumTable.cc. References det, DbuSubRunSummary::fEndTime, DbuSubRunSummary::fRun, DbuSubRunSummary::fStartTime, get_beam_p(), DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), VldTimeStamp::GetSec(), VldRange::GetTimeEnd(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), VldRange::IsCompatible(), and DbiResultPtr< T >::NextQuery(). 00029 {
00030
00031 // read in beamp.dat file
00032 map<int, float> run_mom_map;
00033 char* spc = getenv("SRT_PRIVATE_CONTEXT");
00034 if(spc){
00035 string spc_s = spc; spc_s+="/CalDetPID/data/beamp.dat";
00036 ifstream fin(spc_s.c_str());
00037 if(fin.is_open()){
00038 while(!fin.eof()){
00039 float momentum=0.0; int runno=0;
00040 fin>>runno>>momentum; fin.get();
00041 if(!fin.eof()){
00042 run_mom_map[runno]=momentum;
00043 }
00044 }
00045 }
00046 else{
00047 cout<<"Couldn't find the file :\n"
00048 <<spc_s<<endl;
00049 return -1;
00050 }
00051 }
00052 else{
00053 cout<<"Couldn't get an envvar to find beamp.dat."<<endl;
00054 return -1;
00055 }
00056 // done reading in file
00057
00058 // set up to talk with db.
00059 VldTimeStamp vt(2002, 11, 1, 1, 1, 1);
00060 const VldTimeStamp begin(2002, 9, 16, 1, 1, 1);
00061 const VldTimeStamp end(2002, 10, 16, 17, 0, 0);
00062
00063 const Detector::Detector_t det = Detector::kCalDet;
00064 const SimFlag::SimFlag_t sim = SimFlag::kData;
00065 VldContext vc(det, sim, begin);
00066
00067 cout<<vc<<endl;
00068
00069 DbiResultPtr<DbuSubRunSummary> rsum(vc,0);
00070
00071 UInt_t nrows = rsum.GetNumRows();
00072
00073 cout<<"nrows: "<<nrows<<endl;
00074
00075 const DbiValidityRec* vrptr = rsum.GetValidityRec();
00076 if(vrptr==0) {
00077 cout<<"Null validity rec!"<<endl;
00078 return -1;
00079 }
00080
00081 const VldRange& vr = vrptr->GetVldRange();
00082 cout<<vr<<endl;
00083
00084
00085 // loop over rows
00086 for(UInt_t i=0; i<nrows; i++){
00087 const DbuSubRunSummary* dsrs = rsum.GetRow(i);
00088 cout<<"Row "<<i<<endl;
00089 cout<<*dsrs<<endl;
00090 }
00091
00092 ofstream fout("./BeamMomentumTable.rawinput");
00093
00094 bool keep_going=true;
00095 VldRange vr_save = vr;
00096 int mult_rows=0;
00097 int zero_rows=0;
00098 int time_zero=0;
00099 while(keep_going){
00100 const UInt_t nrf = rsum.NextQuery();
00101 if(nrf!=1) {
00102 // this sometimes happens when there is a vld row but no data
00103 cout<<"Arghh! Something wrong!"<<endl;
00104 if(!rsum.GetValidityRec()){
00105 cout<<"Null ValidityRec()! This is fatal!"<<endl;
00106 keep_going=false;
00107 }
00108 else{
00109 cout<<"Well, there was a vld rec.\n"
00110 <<"The query found "<<nrf<<"rows."<<endl;
00111 if(nrf==0){
00112 cout<<"Assume that there was no table entry "
00113 <<"and move on."<<endl;
00114 zero_rows++;
00115 }
00116 else{
00117 cout<<"It has returned more than one row!"<<endl;
00118 cout<<"This violates my assumptions!"<<endl;
00119 // cout<<"Fatal error, cannot keep going."<<endl;
00120 cout<<"Runs like this appear to be crashes."
00121 <<endl;
00122 cout<<"I'll try to keep going."<<endl;
00123 // keep_going=false;
00124 mult_rows++;
00125 }
00126 }
00127 }
00128 else{
00129 const VldRange& vr_now = rsum.GetValidityRec()->GetVldRange();
00130
00131 // did we move forward?
00132 const VldContext vc_save_start(det,sim, vr_save.GetTimeStart());
00133 // const VldContext vc_save_end(det,sim,vr_save.GetTimeEnd());
00134 // looking for overlap
00135 if( (vr_now.IsCompatible(vc_save_start)) ){
00136 // did not move forward
00137 cout<<"Didn't seem to move forward... keep trying"<<endl;
00138 }
00139 else {
00140 // did move forward
00141 const DbuSubRunSummary* dsrs = rsum.GetRow(0);
00142 cout<<*dsrs<<endl;
00143 const double mom = get_beam_p(run_mom_map, dsrs->fRun);
00144 cout<<"Beam momentum: "<<mom<<"\n"<<endl;
00145
00146 // check for zero start or end dates
00147 // they indicate some error (daq crash?)
00148 if((dsrs->fStartTime.GetSec()!=0)
00149 &&(dsrs->fEndTime.GetSec()!=0)){
00150 // write a line
00151 // run, momentum, start time, end time
00152 // times in seconds (eg, time_t)
00153 fout<<dsrs->fRun
00154 <<" "<<mom
00155 <<" "<<dsrs->fStartTime.GetSec()
00156 <<" "<<dsrs->fEndTime.GetSec()
00157 <<endl;
00158 }
00159 else{
00160 time_zero++;
00161 }
00162 // at end
00163 vr_save=vr_now;
00164 }
00165
00166 }
00167 // check for the end condition
00168 if(vr_save.GetTimeEnd() >= end) keep_going=false;
00169 }
00170
00171 cout<<"There were "<<mult_rows
00172 <<" cases of multiple rows for one query."<<endl;
00173 cout<<"There were "<<zero_rows
00174 <<" cases of zero rows for one query."<<endl;
00175 cout<<"There were "<<time_zero
00176 <<" cases of fStartTime or fEndTime == 0."<<endl;
00177
00178 fout.close();
00179 return 0;
00180 }
|
1.3.9.1