MakeCERRangeTable.cc File Reference

#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <stdlib.h>
#include "CalDetPID/CalDetCERRange.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

int main ()

Function Documentation

int main ( void   ) 

Definition at line 30 of file MakeCERRangeTable.cc.

References det, DbuSubRunSummary::fEndTime, DbuSubRunSummary::fRun, DbuSubRunSummary::fStartTime, CalDetCERRange::GetCER0High(), CalDetCERRange::GetCER0Low(), CalDetCERRange::GetCER1High(), CalDetCERRange::GetCER1Low(), CalDetCERRange::GetCER2High(), CalDetCERRange::GetCER2Low(), DbiResultPtr< T >::GetNumRows(), CalDetCERRange::GetParticleType(), DbiResultPtr< T >::GetRow(), VldTimeStamp::GetSec(), VldRange::GetTimeEnd(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), VldRange::IsCompatible(), it, Detector::kCalDet, SimFlag::kData, and DbiResultPtr< T >::NextQuery().

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


Generated on 8 Jul 2019 for loon by  doxygen 1.6.1