MakeBeamMomentumTable.cc File Reference

#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <stdlib.h>
#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 ()

Function Documentation

double get_beam_p ( const map< int, float > &  m,
int  run 
)

Definition at line 183 of file MakeBeamMomentumTable.cc.

References it.

Referenced by main().

00184 {
00185      typedef std::map<int, float>::const_iterator MIT;
00186      MIT it = m.find(run);
00187      if(it!=m.end()) return it->second;
00188      else return 0.0;
00189      
00190 }

int main ( void   ) 

Definition at line 30 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(), Detector::kCalDet, SimFlag::kData, and DbiResultPtr< T >::NextQuery().

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


Generated on 8 Jul 2019 for loon by  doxygen 1.6.1