LoadCalDetPIDDB.cxx File Reference

#include "CalDetPID/LoadCalDetPIDDB.h"
#include <fstream>
#include <iostream>
#include <string>
#include <ctime>
#include <stdlib.h>
#include "CalDetPID/CalDetBeamMomentum.h"
#include "CalDetPID/CalDetTOFRange.h"
#include "CalDetPID/CalDetCERRange.h"
#include "CalDetPID/CalDetOverlapWin.h"
#include "CalDetPID/CalDetCERTimeWin.h"
#include "DatabaseInterface/DbiCascader.h"
#include "DatabaseInterface/DbiTableProxyRegistry.h"
#include "DatabaseInterface/DbiWriter.h"
#include "DatabaseInterface/DbiResultPtr.h"
#include "DatabaseInterface/DbiValidityRec.h"
#include "Validity/VldTimeStamp.h"
#include "Validity/VldContext.h"
#include "Validity/VldRange.h"
#include "Conventions/Detector.h"
#include "Conventions/SimFlag.h"
#include "Conventions/CalDigitType.h"
#include "Conventions/Munits.h"
#include "Calibrator/CalTimeCalibration.h"
#include "MessageService/MsgService.h"
#include "Plex/PlexStripEndId.h"

Go to the source code of this file.

Functions

void LoadCalDetPIDDB (bool forreal)
void LoadBeamMomentum (bool forreal)
void LoadTOFRange (bool forreal)
void LoadCERRange (bool forreal)
void LoadOverlapWin (bool forreal)
void LoadCERTimeWin (bool forreal)
void MakeTimeCal (const VldTimeStamp &vts, const VldTimeStamp &vte, Float_t addpos, Float_t addneg, bool forreal)
void PrintTimeCal (const VldTimeStamp &vts)
void DetailedTimeCal (const VldTimeStamp &vts, const VldTimeStamp &vte, Float_t ne, Float_t no, Float_t pe, Float_t po, Float_t nzero, Float_t pzero, bool forreal)
void Load2003NFTiming (bool forreal)
void Load2003NN1mTiming (bool forreal)
void Load2003NNT7Timing (bool forreal)

Function Documentation

void DetailedTimeCal ( const VldTimeStamp vts,
const VldTimeStamp vte,
Float_t  ne,
Float_t  no,
Float_t  pe,
Float_t  po,
Float_t  nzero,
Float_t  pzero,
bool  forreal 
)

Definition at line 738 of file LoadCalDetPIDDB.cxx.

References PlexStripEndId::BuildPlnStripEndKey(), DbiWriter< T >::CanOutput(), DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), DbiTableProxyRegistry::GetCascader(), DbiTableProxyRegistry::Instance(), Detector::kCalDet, SimFlag::kData, StripEnd::kNegative, and StripEnd::kPositive.

Referenced by Load2003NFTiming(), Load2003NN1mTiming(), and Load2003NNT7Timing().

00741 {
00742    if(!forreal){
00743       //  MsgService::Instance()->GetStream("Dbi")->SetLogLevel(Msg::kDebug);
00744       
00745 //  Ask the singleton DbiTableProxyRegistry for the DbiCascader.
00746       DbiCascader& cascader=DbiTableProxyRegistry::Instance().GetCascader();
00747       
00748 //  Define the table.
00749       string tableDescr = "(SEQNO int,  SEIDKEY int,  STRIPENDID int,  SCALE float,  OFFSET float,  SLEWCONST1 float,  SLEWCONST2 float,  SLEWCONST3 float,  SLEWCONST4 float)";
00750       //  Ask the cascader to find a database that will accept it.
00751       Int_t dbNoTemp = cascader.CreateTemporaryTable("CALTIMECALIBRATION",tableDescr);
00752       
00753       if (dbNoTemp<0){
00754          cout << "No  database to will accept temporary tables. " << endl;
00755          return;
00756       }
00757       else{
00758          cout<<"Database number "<<dbNoTemp<<endl;
00759       }
00760    }
00761   VldRange vr(Detector::kCalDet,SimFlag::kData,vts,vte,"by hand");
00762   VldTimeStamp create;
00763 /*
00764   cout<<"Validity time stamp create: "<<endl;
00765   create.Print();
00766   cout<<endl;
00767   cout<<"Validity time stamp start: "<<endl;
00768   vts.Print();
00769   cout<<endl;
00770   cout<<"Validity time stamp end: "<<endl;
00771   vte.Print();
00772   cout<<endl;
00773 */
00774   cout<<"DetailedTimeCal: From "<<vts<<" to "<<vte<<endl;
00775   cout<<"Adding "<<ne<<" to kNegative Even strip ends"<<endl;
00776   cout<<"Adding "<<no<<" to kNegative Odd strip ends"<<endl;
00777 
00778   cout<<"Adding "<<pe<<" to kPositive Even strip ends"<<endl;
00779   cout<<"Adding "<<po<<" to kPositive Odd strip ends"<<endl;
00780 
00781   cout<<"Adding "<<nzero<<" to kNegative plane 0 strip ends"<<endl;
00782   cout<<"Adding "<<pzero<<" to kPositive plane 0 strip ends"<<endl;
00783 
00784 
00785   DbiWriter<CalTimeCalibration> tcal(vr, -1, 0, create);
00786 
00787 //  cout<<"Starting to loop over planes and strips"<<endl;
00788   for(int plane=0;plane<60;plane++){
00789     for(int strip=0;strip<24;strip++){
00790       PlexStripEndId seidn(Detector::kCalDet,plane,strip,
00791                            StripEnd::kNegative);
00792       PlexStripEndId seidp(Detector::kCalDet,plane,strip,
00793                            StripEnd::kPositive);
00794       Int_t seidkeyn = seidn.BuildPlnStripEndKey();
00795       Int_t seidkeyp = seidp.BuildPlnStripEndKey();
00796       if(plane==0){
00797         CalTimeCalibration tcn1(seidkeyn, StripEnd::kNegative,
00798                                1.,nzero,1.,1.,1.,1.);
00799         tcal<<tcn1;
00800 
00801         CalTimeCalibration tcn2(seidkeyp, StripEnd::kPositive,
00802                                1.,pzero,1.,1.,1.,1.);
00803         tcal<<tcn2;
00804         
00805       }
00806       else if(plane%2==0){
00807          CalTimeCalibration tcn1(seidkeyn, StripEnd::kNegative,
00808                                  1.,ne,1.,1.,1.,1.);
00809          tcal<<tcn1;
00810 
00811          CalTimeCalibration tcn2(seidkeyp, StripEnd::kPositive,
00812                                  1.,pe,1.,1.,1.,1.);
00813          tcal<<tcn2;
00814 
00815       }
00816       else{
00817          CalTimeCalibration tcn1(seidkeyn, StripEnd::kNegative,
00818                                  1.,no,1.,1.,1.,1.);
00819          tcal<<tcn1;
00820 
00821          CalTimeCalibration tcn2(seidkeyp, StripEnd::kPositive,
00822                                  1.,po,1.,1.,1.,1.);
00823          tcal<<tcn2;
00824       }
00825 
00826     }
00827   }
00828   if(!tcal.CanOutput()){
00829     cout<<"DetailedTimeCal: Writer can't output!"<<endl;
00830   }
00831   
00832   cout<<"Done."<<endl;
00833   tcal.Close();
00834 }

void Load2003NFTiming ( bool  forreal  ) 

Definition at line 836 of file LoadCalDetPIDDB.cxx.

References DetailedTimeCal(), and Munits::ns.

Referenced by LoadCalDetPIDDB().

00837 {
00838    const VldTimeStamp start1(2003, 8, 1, 0, 0, 0);
00839    const VldTimeStamp end1(2003, 9, 26, 15, 0, 0);
00840 
00841 //   DetailedTimeCal(start1, end1, 0.0, 15.87*Munits::ns, -59.63*Munits::ns, 
00842 //                 -75.63*Munits::ns, -75.63*Munits::ns, -64.63*Munits::ns);
00843 
00844    DetailedTimeCal(start1, end1, 0.0, 15.87*Munits::ns, 
00845                    (-59.63-15.0)*Munits::ns, 
00846                    (-75.63-15.0)*Munits::ns, 
00847                    (-75.63-15.0)*Munits::ns, 
00848                    (-64.63-15.0)*Munits::ns, forreal);
00849 
00850 }

void Load2003NN1mTiming ( bool  forreal  ) 

Definition at line 852 of file LoadCalDetPIDDB.cxx.

References DetailedTimeCal(), and Munits::ns.

Referenced by LoadCalDetPIDDB().

00853 {
00854    const VldTimeStamp start1(2003, 10, 1, 18, 0, 0);
00855    const VldTimeStamp end1(2003, 11, 1, 0, 0, 0);
00856 
00857 //   DetailedTimeCal(start1, end1, 0.0, 15.87*Munits::ns, -59.63*Munits::ns, 
00858 //                 -75.63*Munits::ns, -75.63*Munits::ns, -64.63*Munits::ns);
00859 
00860    DetailedTimeCal(start1, end1, 0.0, -79.94*Munits::ns, -80.21*Munits::ns, 0.0,
00861                    -90.05*Munits::ns, -79.94*Munits::ns, forreal); 
00862 
00863 }

void Load2003NNT7Timing ( bool  forreal  ) 

Definition at line 865 of file LoadCalDetPIDDB.cxx.

References DetailedTimeCal(), and Munits::ns.

Referenced by LoadCalDetPIDDB().

00866 {
00867    const VldTimeStamp start1(2003, 9, 26, 15, 0, 0);
00868    const VldTimeStamp end1(2003, 10, 1, 18, 0, 0);
00869 
00870 //   DetailedTimeCal(start1, end1, 0.0, 15.87*Munits::ns, -59.63*Munits::ns, 
00871 //                 -75.63*Munits::ns, -75.63*Munits::ns, -64.63*Munits::ns);
00872 
00873    DetailedTimeCal(start1, end1, 0.0, -79.94*Munits::ns, -80.21*Munits::ns, 0.0,
00874                    -90.05*Munits::ns, -79.94*Munits::ns, forreal); 
00875 
00876 }

void LoadBeamMomentum ( bool  forreal  ) 

Definition at line 82 of file LoadCalDetPIDDB.cxx.

References DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), det, fname, DbiTableProxyRegistry::GetCascader(), infile, DbiTableProxyRegistry::Instance(), Detector::kCalDet, SimFlag::kData, and run().

Referenced by LoadCalDetPIDDB().

00083 {
00084    if(!forreal){
00085 //  Ask the singleton DbiTableProxyRegistry for the DbiCascader.
00086       DbiCascader& cascader 
00087          = DbiTableProxyRegistry::Instance().GetCascader();
00088       
00089 //  Define the table.
00090       string tableDescr = "(SeqNo int,   RUNNO  int, BEAMMOMENTUM float)";
00091       
00092 //  Ask the cascader to find a database that will accept it.
00093       Int_t dbNoTemp = cascader.CreateTemporaryTable("CALDETBEAMMOMENTUM",
00094                                                      tableDescr);
00095       
00096       if ( dbNoTemp < 0 ) {
00097          std::cout << "No database to will accept temporary tables." 
00098                    << std::endl;
00099          return;
00100       }
00101    }
00102   // open input file
00103   string fname(getenv("SRT_PRIVATE_CONTEXT"));
00104   fname+="/CalDetPID/data/BeamMomentumTable.rawinput";
00105   
00106   ifstream* ifptr = new ifstream(fname.c_str());
00107   if(!ifptr->is_open()){
00108       delete ifptr; ifptr=0;
00109        string fname_save=fname;
00110        fname=getenv("SRT_PUBLIC_CONTEXT");
00111        fname+="/CalDetPID/data/BeamMomentumTable.rawinput";
00112        ifptr = new ifstream(fname.c_str());
00113        if(!ifptr->is_open()){
00114            cout<<"LoadBeamMomentum: Could not open file "<<fname<<".!"<<endl;
00115            cout<<"Also tried "<<fname_save<<endl;
00116            delete ifptr; ifptr=0;
00117            return;
00118            }
00119   }
00120 //  cout<<"LoadBeamMomentum reading from file: "<<fname<<endl;
00121 
00122   ifstream& infile = *ifptr;
00123 
00124   const Detector::Detector_t det=Detector::kCalDet;
00125   const SimFlag::SimFlag_t sim=SimFlag::kData;
00126 
00127   int cntr=0;
00128   while(!infile.eof()){
00129        int run;
00130        float momentum;
00131        time_t lowtime;
00132        time_t hightime;
00133        infile>>run>>momentum>>lowtime>>hightime;
00134        infile.get();
00135        if(!infile.eof()){
00136             // use the file inputs
00137             const CalDetBeamMomentum row(run,momentum);
00138             const VldTimeStamp start(lowtime,0);
00139             const VldTimeStamp end(hightime,0);
00140             const VldRange range(det,sim,start,end,"LoadCalDetPIDDB");
00141             
00142             // make a DbiWriter
00143             const VldTimeStamp now;
00144             Dbi::Task task=0;
00145             int aggno=-1; 
00146             DbiWriter<CalDetBeamMomentum> writer(range,aggno,task,now);
00147            
00148             // write
00149             writer<<row;
00150             cntr++;
00151             if(cntr%100==0){ 
00152                 cout<<"CalDetPID LoadBeamMomentum() : "<<cntr<<"\r"<<flush;
00153 
00154 //                cout<<"CalDetPID LoadBeamMomentum() : "<<cntr<<endl;
00155 //                cout<<"run: "<<run
00156 //                    <<", momentum: "<<momentum
00157 //                    <<", start: "<<start
00158 //                    <<", end: "<<end
00159 //                    <<endl;
00160                 }
00161             if(!writer.Close()){
00162                  cout<<"\nLoadBeamMomentum(): "
00163                      <<"Output error writing data!"<<endl;
00164             }
00165        }
00166   }
00167   cout<<"CalDetPID LoadBeamMomentum() : "<<cntr<<" (done)."<<endl;
00168 
00169   if(ifptr) { delete ifptr; ifptr=0;}
00170 }

void LoadCalDetPIDDB ( bool  forreal  ) 

Definition at line 43 of file LoadCalDetPIDDB.cxx.

References Load2003NFTiming(), Load2003NN1mTiming(), Load2003NNT7Timing(), LoadBeamMomentum(), LoadCERRange(), LoadCERTimeWin(), LoadOverlapWin(), LoadTOFRange(), MakeTimeCal(), and Munits::ns.

00044 {
00045    LoadBeamMomentum(forreal);
00046    LoadTOFRange(forreal);
00047    LoadCERRange(forreal);
00048    LoadOverlapWin(forreal);
00049    LoadCERTimeWin(forreal);
00050    
00051    // load up a time calibrator table
00052    // Should be pretty consistent for entire 2002 run
00053    // I've checked 40616 and 50700 (very similar)
00054    // This is taking out the crate offset due to the timing cable
00055    
00056    //some runs (lower energy runs) taken with US and MID tof have different
00057    //timing offsets
00058    const VldTimeStamp start1(2002, 9, 16, 0, 0, 0);
00059    const VldTimeStamp end1(2002, 9, 28, 13, 48, 0);
00060    const Double_t addneg1=0.0;
00061    const Double_t addpos1=57.0*Munits::ns;
00062    MakeTimeCal(start1, end1, addpos1, addneg1,forreal);
00063    
00064    const VldTimeStamp start2(2002, 9, 28, 13, 49, 0);
00065    const VldTimeStamp end2(2002, 9, 28, 20, 49, 0);
00066    const Double_t addneg2=138.0*Munits::ns;
00067    const Double_t addpos2=194.0*Munits::ns;
00068    MakeTimeCal(start2, end2, addpos2, addneg2,true);
00069    
00070    const VldTimeStamp start3(2002, 9, 28, 20, 50, 0);
00071    const VldTimeStamp end3(2002, 10, 17, 0, 0, 0);
00072    const Double_t addneg3=0.0;
00073    const Double_t addpos3=57.0*Munits::ns;
00074    MakeTimeCal(start3, end3, addpos3, addneg3,true);
00075    
00076    Load2003NFTiming(true);
00077    Load2003NN1mTiming(true);
00078    Load2003NNT7Timing(true);
00079    
00080 }

void LoadCERRange ( bool  forreal  ) 

Definition at line 290 of file LoadCalDetPIDDB.cxx.

References DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), det, fname, DbiTableProxyRegistry::GetCascader(), infile, DbiTableProxyRegistry::Instance(), Detector::kCalDet, SimFlag::kData, and run().

Referenced by LoadCalDetPIDDB().

00291 {
00292    if(!forreal){
00293 //  Ask the singleton DbiTableProxyRegistry for the DbiCascader.
00294       DbiCascader& cascader 
00295          = DbiTableProxyRegistry::Instance().GetCascader();
00296       
00297 //  Define the table.
00298       string tableDescr = "(SeqNo int,   PARTICLETYPE  int,"
00299          " CER0LOW float, CER0HIGH float, "
00300          " CER1LOW float, CER1HIGH float, "
00301          " CER2LOW float, CER2HIGH float)";
00302       
00303       
00304 //  Ask the cascader to find a database that will accept it.
00305       Int_t dbNoTemp = cascader.CreateTemporaryTable("CALDETCERRANGE",
00306                                                      tableDescr);
00307       
00308       if ( dbNoTemp < 0 ) {
00309          std::cout << "No database to will accept temporary tables." 
00310                    << std::endl;
00311          return;
00312       }
00313    }
00314   // open input file
00315   string fname(getenv("SRT_PRIVATE_CONTEXT"));
00316   fname+="/CalDetPID/data/CERRangeTable.rawinput";
00317   
00318   ifstream* ifptr = new ifstream(fname.c_str());
00319   if(!ifptr->is_open()){
00320       delete ifptr; ifptr=0;
00321        string fname_save=fname;
00322        fname=getenv("SRT_PUBLIC_CONTEXT");
00323        fname+="/CalDetPID/data/CERRangeTable.rawinput";
00324        ifptr = new ifstream(fname.c_str());
00325        if(!ifptr->is_open()){
00326             cout<<"LoadCERRange: Could not open file "<<fname<<".!"<<endl;
00327             cout<<"Also tried "<<fname_save<<endl;
00328             delete ifptr; ifptr=0;
00329             return;
00330        }
00331   }
00332   
00333   ifstream& infile = *ifptr;
00334 
00335   const Detector::Detector_t det=Detector::kCalDet;
00336   const SimFlag::SimFlag_t sim=SimFlag::kData;
00337 
00338   time_t save_lowtime=0;
00339   time_t save_hightime=0;
00340   DbiWriter<CalDetCERRange>* writer_ptr=0;
00341   int cntr=0;
00342   while(!infile.eof()){
00343        int run, pid;
00344        float low0,high0,low1,high1,low2,high2;
00345        time_t lowtime;
00346        time_t hightime;
00347        infile>>run>>pid
00348              >>low0>>high0>>low1>>high1>>low2>>high2
00349              >>lowtime>>hightime;
00350        infile.get();
00351        if(!infile.eof()){
00352             // use the file inputs
00353             
00354             // do we need to recreate the writer?
00355             // do so if we have moved on to a new vld range
00356             // assumes all entries in a range come together
00357             if((writer_ptr==0)
00358                ||(lowtime!=save_lowtime)||(hightime!=save_hightime)){
00359                  // do we need to close the writer?
00360                  if(writer_ptr!=0){
00361                       if(!writer_ptr->Close()){
00362                            cout<<"\nLoadCERRange(): "
00363                                <<"Output error writing data!"<<endl;
00364                       }
00365                       delete writer_ptr; writer_ptr=0;
00366                  }
00367                  // make a new writer_ptr
00368                  const VldTimeStamp start(lowtime,0);
00369                  const VldTimeStamp end(hightime,0);
00370                  const VldRange range(det,sim,start,end,"LoadCalDetPIDDB");
00371                  const VldTimeStamp now;
00372                  Dbi::Task task=0;
00373                  int aggno=-1; 
00374                  writer_ptr = 
00375                       new DbiWriter<CalDetCERRange>(range,aggno,task,now);
00376                  save_lowtime=lowtime;
00377                  save_hightime=hightime;
00378             }
00379                            
00380             const CalDetCERRange row(pid, low0, high0, low1, high1,
00381                                      low2, high2);
00382             // write
00383             DbiWriter<CalDetCERRange>& writer= *writer_ptr;
00384             writer<<row;
00385             cntr++;
00386             if(cntr%100==0) 
00387                  cout<<"CalDetPID LoadCERRange() : "<<cntr<<"\r"<<flush;
00388        }
00389   }
00390   // at the end... maybe have to write out one more time
00391   if(writer_ptr){
00392        if(!writer_ptr->Close()){
00393             cout<<"\nLoadCERRange(): Output error writing data!"<<endl;
00394        }
00395        delete writer_ptr; writer_ptr=0;
00396   }
00397   cout<<"CalDetPID LoadCERRange() : "<<cntr<<" (done)."<<endl;
00398 
00399   if(ifptr) {delete ifptr; ifptr=0;}
00400 }

void LoadCERTimeWin ( bool  forreal  ) 

Definition at line 513 of file LoadCalDetPIDDB.cxx.

References DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), det, fname, DbiTableProxyRegistry::GetCascader(), infile, DbiTableProxyRegistry::Instance(), Detector::kCalDet, SimFlag::kData, and run().

Referenced by LoadCalDetPIDDB().

00514 {
00515    if(!forreal){
00516 //  Ask the singleton DbiTableProxyRegistry for the DbiCascader.
00517       DbiCascader& cascader 
00518          = DbiTableProxyRegistry::Instance().GetCascader();
00519       
00520 //  Define the table.
00521       string tableDescr = "(SeqNo int,   PARTICLETYPE  int,"
00522          " WIN0LOW float, WIN0HIGH float, "
00523          " WIN1LOW float, WIN1HIGH float, "
00524          " WIN2LOW float, WIN2HIGH float)";
00525       
00526       
00527 //  Ask the cascader to find a database that will accept it.
00528       Int_t dbNoTemp = cascader.CreateTemporaryTable("CALDETCERTIMEWIN",
00529                                                      tableDescr);
00530       
00531       if ( dbNoTemp < 0 ) {
00532          std::cout << "No database to will accept temporary tables." 
00533                    << std::endl;
00534          return;
00535       }
00536    }
00537   // open input file
00538   string fname(getenv("SRT_PRIVATE_CONTEXT"));
00539   fname+="/CalDetPID/data/CERTimeWinTable.rawinput";
00540   
00541   ifstream* ifptr = new ifstream(fname.c_str());
00542   if(!ifptr->is_open()){
00543       delete ifptr; ifptr=0;
00544        string fname_save=fname;
00545        fname=getenv("SRT_PUBLIC_CONTEXT");
00546        fname+="/CalDetPID/data/CERTimeWinTable.rawinput";
00547        ifptr = new ifstream(fname.c_str());
00548        if(!ifptr->is_open()){
00549             cout<<"LoadCERTimeWin: Could not open file "<<fname<<".!"<<endl;
00550             cout<<"Also tried "<<fname_save<<endl;
00551             delete ifptr; ifptr=0;
00552             return;
00553        }
00554   }
00555   
00556   ifstream& infile = *ifptr;
00557 
00558   const Detector::Detector_t det=Detector::kCalDet;
00559   const SimFlag::SimFlag_t sim=SimFlag::kData;
00560 
00561   time_t save_lowtime=0;
00562   time_t save_hightime=0;
00563   DbiWriter<CalDetCERTimeWin>* writer_ptr=0;
00564   int cntr=0;
00565   while(!infile.eof()){
00566        int run, pid;
00567        float low0,high0,low1,high1,low2,high2;
00568        time_t lowtime;
00569        time_t hightime;
00570        infile>>run>>pid
00571              >>low0>>high0>>low1>>high1>>low2>>high2
00572              >>lowtime>>hightime;
00573        infile.get();
00574        if(!infile.eof()){
00575             // use the file inputs
00576             
00577             // do we need to recreate the writer?
00578             // do so if we have moved on to a new vld range
00579             // assumes all entries in a range come together
00580             if((writer_ptr==0)
00581                ||(lowtime!=save_lowtime)||(hightime!=save_hightime)){
00582                  // do we need to close the writer?
00583                  if(writer_ptr!=0){
00584                       if(!writer_ptr->Close()){
00585                            cout<<"\nLoadCERTimeWin(): "
00586                                <<"Output error writing data!"<<endl;
00587                       }
00588                       delete writer_ptr; writer_ptr=0;
00589                  }
00590                  // make a new writer_ptr
00591                  const VldTimeStamp start(lowtime,0);
00592                  const VldTimeStamp end(hightime,0);
00593                  const VldRange range(det,sim,start,end,"LoadCalDetPIDDB");
00594                  const VldTimeStamp now;
00595                  Dbi::Task task=0;
00596                  int aggno=-1; 
00597                  writer_ptr = 
00598                       new DbiWriter<CalDetCERTimeWin>(range,aggno,task,now);
00599                  save_lowtime=lowtime;
00600                  save_hightime=hightime;
00601             }
00602                            
00603             const CalDetCERTimeWin row(pid, low0, high0, low1, high1,
00604                                      low2, high2);
00605             // write
00606             DbiWriter<CalDetCERTimeWin>& writer= *writer_ptr;
00607             writer<<row;
00608             cntr++;
00609             if(cntr%100==0) 
00610                  cout<<"CalDetPID LoadCERTimeWin() : "<<cntr<<"\r"<<flush;
00611        }
00612   }
00613   // at the end... maybe have to write out one more time
00614   if(writer_ptr){
00615        if(!writer_ptr->Close()){
00616             cout<<"\nLoadCERTimeWin(): Output error writing data!"<<endl;
00617        }
00618        delete writer_ptr; writer_ptr=0;
00619   }
00620   cout<<"CalDetPID LoadCERTimeWin() : "<<cntr<<" (done)."<<endl;
00621 
00622   if(ifptr) {delete ifptr; ifptr=0;}
00623 }

void LoadOverlapWin ( bool  forreal  ) 

Definition at line 403 of file LoadCalDetPIDDB.cxx.

References DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), det, fname, DbiTableProxyRegistry::GetCascader(), infile, DbiTableProxyRegistry::Instance(), Detector::kCalDet, SimFlag::kData, and run().

Referenced by LoadCalDetPIDDB().

00404 {
00405    if(!forreal){
00406 //  Ask the singleton DbiTableProxyRegistry for the DbiCascader.
00407       DbiCascader& cascader 
00408          = DbiTableProxyRegistry::Instance().GetCascader();
00409       
00410 //  Define the table.
00411       
00412       string tableDescr = "(SeqNo int,   PARTICLETYPE  int,"
00413          " WINLOW float, WINHIGH float)";
00414       
00415 //  Ask the cascader to find a database that will accept it.
00416       Int_t dbNoTemp = cascader.CreateTemporaryTable("CALDETOVERLAPWIN",
00417                                                      tableDescr);
00418       
00419       if ( dbNoTemp < 0 ) {
00420          std::cout << "No database to will accept temporary tables." 
00421                    << std::endl;
00422          return;
00423       }
00424    }
00425   // open input file
00426   string fname(getenv("SRT_PRIVATE_CONTEXT"));
00427   fname+="/CalDetPID/data/OverlapWinTable.rawinput";
00428   
00429   ifstream* ifptr = new ifstream(fname.c_str());
00430   if(!ifptr->is_open()){
00431       delete ifptr; ifptr=0;
00432        string fname_save=fname;
00433        fname=getenv("SRT_PUBLIC_CONTEXT");
00434        fname+="/CalDetPID/data/OverlapWinTable.rawinput";
00435        ifptr = new ifstream(fname.c_str());
00436        if(!ifptr->is_open()){
00437             cout<<"LoadOverlapWin: Could not open file "<<fname<<".!"<<endl;
00438             cout<<"Also tried "<<fname_save<<endl;
00439             delete ifptr; ifptr=0;
00440             return;
00441        }
00442   }
00443   
00444   ifstream& infile = *ifptr;
00445 
00446   const Detector::Detector_t det=Detector::kCalDet;
00447   const SimFlag::SimFlag_t sim=SimFlag::kData;
00448 
00449   time_t save_lowtime=0;
00450   time_t save_hightime=0;
00451   DbiWriter<CalDetOverlapWin>* writer_ptr=0;
00452   int cntr=0;
00453   while(!infile.eof()){
00454        int run, pid;
00455        float low,high;
00456        time_t lowtime;
00457        time_t hightime;
00458        infile>>run>>pid
00459              >>low>>high
00460              >>lowtime>>hightime;
00461        infile.get();
00462        if(!infile.eof()){
00463             // use the file inputs
00464             
00465             // do we need to recreate the writer?
00466             // do so if we have moved on to a new vld range
00467             // assumes all entries in a range come together
00468             if((writer_ptr==0)
00469                ||(lowtime!=save_lowtime)||(hightime!=save_hightime)){
00470                  // do we need to close the writer?
00471                  if(writer_ptr!=0){
00472                       if(!writer_ptr->Close()){
00473                            cout<<"\nLoadCERRange(): "
00474                                <<"Output error writing data!"<<endl;
00475                       }
00476                       delete writer_ptr; writer_ptr=0;
00477                  }
00478                  // make a new writer_ptr
00479                  const VldTimeStamp start(lowtime,0);
00480                  const VldTimeStamp end(hightime,0);
00481                  const VldRange range(det,sim,start,end,"LoadCalDetPIDDB");
00482                  const VldTimeStamp now;
00483                  Dbi::Task task=0;
00484                  int aggno=-1; 
00485                  writer_ptr = 
00486                       new DbiWriter<CalDetOverlapWin>(range,aggno,task,now);
00487                  save_lowtime=lowtime;
00488                  save_hightime=hightime;
00489             }
00490                            
00491             const CalDetOverlapWin row(pid, low, high);
00492 
00493             // write
00494             DbiWriter<CalDetOverlapWin>& writer= *writer_ptr;
00495             writer<<row;
00496             cntr++;
00497             if(cntr%100==0) 
00498                  cout<<"CalDetPID LoadOverlapWin() : "<<cntr<<"\r"<<flush;
00499        }
00500   }
00501   // at the end... maybe have to write out one more time
00502   if(writer_ptr){
00503        if(!writer_ptr->Close()){
00504             cout<<"\nLoadOverlapWin(): Output error writing data!"<<endl;
00505        }
00506        delete writer_ptr; writer_ptr=0;
00507   }
00508   cout<<"CalDetPID LoadOverlapWin() : "<<cntr<<" (done)."<<endl;
00509 
00510   if(ifptr) {delete ifptr; ifptr=0;}
00511 }

void LoadTOFRange ( bool  forreal  ) 

Definition at line 172 of file LoadCalDetPIDDB.cxx.

References DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), det, fname, DbiTableProxyRegistry::GetCascader(), infile, DbiTableProxyRegistry::Instance(), Detector::kCalDet, SimFlag::kData, and run().

Referenced by LoadCalDetPIDDB().

00173 {
00174    if(!forreal){
00175 //  Ask the singleton DbiTableProxyRegistry for the DbiCascader.
00176       DbiCascader& cascader 
00177          = DbiTableProxyRegistry::Instance().GetCascader();
00178       
00179 //  Define the table.
00180       string tableDescr = "(SeqNo int,   PARTICLETYPE  int,"
00181          " TDC0LOW float, TDC0HIGH float, "
00182          " TDC1LOW float, TDC1HIGH float, "
00183          " TDC2LOW float, TDC2HIGH float, "
00184          " TDC2MINUSTDC0LOW float, TDC2MINUSTDC0HIGH float, "
00185          " TDC2MINUSTDC1LOW float, TDC2MINUSTDC1HIGH float )";
00186       
00187       
00188 //  Ask the cascader to find a database that will accept it.
00189       Int_t dbNoTemp = cascader.CreateTemporaryTable("CALDETTOFRANGE",
00190                                                      tableDescr);
00191       
00192       if ( dbNoTemp < 0 ) {
00193          std::cout << "No database to will accept temporary tables." 
00194                    << std::endl;
00195          return;
00196       }
00197    }
00198 
00199   // open input file
00200   string fname(getenv("SRT_PRIVATE_CONTEXT"));
00201   fname+="/CalDetPID/data/TOFRangeTable.rawinput";
00202   
00203   ifstream* ifptr = new ifstream(fname.c_str());
00204   if(!ifptr->is_open()){
00205       delete ifptr; ifptr=0;
00206       string fname_save=fname;
00207       fname=getenv("SRT_PUBLIC_CONTEXT");
00208       fname+="/CalDetPID/data/TOFRangeTable.rawinput";
00209       ifptr = new ifstream(fname.c_str());
00210       if(!ifptr->is_open()){
00211           cout<<"LoadTOFRange: Could not open file "<<fname<<".!"<<endl;
00212           cout<<"Also tried "<<fname_save<<endl;
00213           delete ifptr; ifptr=0;
00214           return;
00215           }
00216       }
00217   ifstream& infile= *ifptr;
00218 //  cout<<"LoadTOFRange reading from: "<<fname<<endl;
00219   
00220   const Detector::Detector_t det=Detector::kCalDet;
00221   const SimFlag::SimFlag_t sim=SimFlag::kData;
00222 
00223   time_t save_lowtime=0;
00224   time_t save_hightime=0;
00225   DbiWriter<CalDetTOFRange>* writer_ptr=0;
00226   int cntr=0;
00227   while(!infile.eof()){
00228        int run, pid;
00229        float low0,high0,low1,high1,low2,high2,tmzlow,tmzhigh,tmolow,tmohigh;
00230        time_t lowtime;
00231        time_t hightime;
00232        infile>>run>>pid
00233              >>low0>>high0>>low1>>high1>>low2>>high2
00234              >>tmzlow>>tmzhigh>>tmolow>>tmohigh
00235              >>lowtime>>hightime;
00236        infile.get();
00237        if(!infile.eof()){
00238             // use the file inputs
00239             
00240             // do we need to recreate the writer?
00241             // do so if we have moved on to a new vld range
00242             // assumes all entries in a range come together
00243             if((writer_ptr==0)
00244                ||(lowtime!=save_lowtime)||(hightime!=save_hightime)){
00245                  // do we need to close the writer?
00246                  if(writer_ptr!=0){
00247                       if(!writer_ptr->Close()){
00248                            cout<<"\nLoadTOFRange(): "
00249                                <<"Output error writing data!"<<endl;
00250                       }
00251                       delete writer_ptr; writer_ptr=0;
00252                  }
00253                  // make a new writer_ptr
00254                  const VldTimeStamp start(lowtime,0);
00255                  const VldTimeStamp end(hightime,0);
00256                  const VldRange range(det,sim,start,end,"LoadCalDetPIDDB");
00257                  const VldTimeStamp now;
00258                  Dbi::Task task=0;
00259                  int aggno=-1; 
00260                  writer_ptr = 
00261                       new DbiWriter<CalDetTOFRange>(range,aggno,task,now);
00262                  save_lowtime=lowtime;
00263                  save_hightime=hightime;
00264             }
00265                            
00266             const CalDetTOFRange row(pid, low0, high0, low1, high1,
00267                                      low2, high2, tmzlow, tmzhigh,
00268                                      tmolow,tmohigh);
00269             // write
00270             DbiWriter<CalDetTOFRange>& writer= *writer_ptr;
00271             writer<<row;
00272             cntr++;
00273             if(cntr%100==0) 
00274                  cout<<"CalDetPID LoadTOFRange() : "<<cntr<<"\r"<<flush;
00275        }
00276   }
00277   // at the end... maybe have to write out one more time
00278   if(writer_ptr){
00279        if(!writer_ptr->Close()){
00280             cout<<"\nLoadTOFRange(): Output error writing data!"<<endl;
00281        }
00282        delete writer_ptr; writer_ptr=0;
00283   }
00284   cout<<"CalDetPID LoadTOFRange() : "<<cntr<<" (done)."<<endl;
00285 
00286   if(ifptr) {delete ifptr; ifptr=0;}
00287 }

void MakeTimeCal ( const VldTimeStamp vts,
const VldTimeStamp vte,
Float_t  addpos,
Float_t  addneg,
bool  forreal 
)

Definition at line 625 of file LoadCalDetPIDDB.cxx.

References PlexStripEndId::BuildPlnStripEndKey(), DbiWriter< T >::CanOutput(), DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), DbiTableProxyRegistry::GetCascader(), DbiTableProxyRegistry::Instance(), Detector::kCalDet, SimFlag::kData, StripEnd::kNegative, and StripEnd::kPositive.

Referenced by LoadCalDetPIDDB().

00627 {
00628    if(!forreal){
00629       //  MsgService::Instance()->GetStream("Dbi")->SetLogLevel(Msg::kDebug);
00630       
00631 //  Ask the singleton DbiTableProxyRegistry for the DbiCascader.
00632       DbiCascader& cascader=DbiTableProxyRegistry::Instance().GetCascader();
00633       
00634 //  Define the table.
00635       string tableDescr = "(SEQNO int,  SEIDKEY int,  STRIPENDID int,  SCALE float,  OFFSET float,  SLEWCONST1 float,  SLEWCONST2 float,  SLEWCONST3 float,  SLEWCONST4 float)";
00636       //  Ask the cascader to find a database that will accept it.
00637       Int_t dbNoTemp = cascader.CreateTemporaryTable("CALTIMECALIBRATION",tableDescr);
00638       
00639       if (dbNoTemp<0){
00640          cout << "No  database to will accept temporary tables. " << endl;
00641          return;
00642       }
00643       else{
00644          cout<<"Database number "<<dbNoTemp<<endl;
00645       }
00646    }
00647   
00648   VldRange vr(Detector::kCalDet,SimFlag::kData,vts,vte,"by hand");
00649   VldTimeStamp create;
00650 /*
00651   cout<<"Validity time stamp create: "<<endl;
00652   create.Print();
00653   cout<<endl;
00654   cout<<"Validity time stamp start: "<<endl;
00655   vts.Print();
00656   cout<<endl;
00657   cout<<"Validity time stamp end: "<<endl;
00658   vte.Print();
00659   cout<<endl;
00660 */
00661   cout<<"MakeTimeCal: From "<<vts<<" to "<<vte<<endl;
00662   cout<<"Adding "<<addpos<<" to kPositive strip ends."<<endl;
00663   cout<<"Adding "<<addneg<<" to kNegative strip ends (except plane 0)."<<endl;
00664   cout<<"Adding "<<addpos<<" to plane 0 kNegative strip ends."<<endl;
00665 
00666   DbiWriter<CalTimeCalibration> tcal(vr, -1, 0, create);
00667 
00668 //  cout<<"Starting to loop over planes and strips"<<endl;
00669   for(int plane=0;plane<60;plane++){
00670     for(int strip=0;strip<24;strip++){
00671       PlexStripEndId seidn(Detector::kCalDet,plane,strip,
00672                            StripEnd::kNegative);
00673       PlexStripEndId seidp(Detector::kCalDet,plane,strip,
00674                            StripEnd::kPositive);
00675       Int_t seidkeyn = seidn.BuildPlnStripEndKey();
00676       Int_t seidkeyp = seidp.BuildPlnStripEndKey();
00677       if(plane==0){
00678         CalTimeCalibration tcn(seidkeyn, StripEnd::kNegative,
00679                                1.,addpos,1.,1.,1.,1.);
00680         tcal<<tcn;
00681       }
00682       else{
00683         CalTimeCalibration tcn(seidkeyn, StripEnd::kNegative,
00684                                1.,addneg,1.,1.,1.,1.);
00685         tcal<<tcn;
00686       }
00687       CalTimeCalibration tcp(seidkeyp, StripEnd::kPositive,
00688                              1.,addpos,1.,1.,1.,1.);
00689       tcal<<(tcp);
00690     }
00691   }
00692   if(!tcal.CanOutput()){
00693     cout<<"MakeTimeCal: Writer can't output!"<<endl;
00694   }
00695   
00696   cout<<"Done."<<endl;
00697   tcal.Close();
00698 }

void PrintTimeCal ( const VldTimeStamp vts  ) 

Definition at line 701 of file LoadCalDetPIDDB.cxx.

References DbiValidityRec::GetAggregateNo(), DbiValidityRec::GetCreationDate(), DbiValidityRec::GetDbNo(), DbiValidityRec::GetInsertDate(), DbiResultPtr< T >::GetNumRows(), CalTimeCalibration::GetOffset(), DbiResultPtr< T >::GetRow(), CalTimeCalibration::GetScale(), CalTimeCalibration::GetSEIDkey(), DbiValidityRec::GetSeqNo(), CalTimeCalibration::GetSlewC1(), CalTimeCalibration::GetSlewC2(), CalTimeCalibration::GetSlewC3(), CalTimeCalibration::GetSlewC4(), CalTimeCalibration::GetStripEndId(), DbiValidityRec::GetTask(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), Detector::kCalDet, and SimFlag::kData.

00701                                           {
00702   //now read the data back and print
00703   
00704   cout<<"Trying to get a dbiresultptr"<<endl;
00705   VldContext vc(Detector::kCalDet,SimFlag::kData,vts);
00706   DbiResultPtr<CalTimeCalibration> timecal(vc,0);
00707 
00708   //  timecal.NewQuery(vc,0);
00709   const DbiValidityRec *dvr = timecal.GetValidityRec();
00710   if(dvr!=0){
00711          std::cout<<"Printing the DbiValidityRec()"<<std::endl;
00712          
00713          std::cout<<"AggNo: "<<dvr->GetAggregateNo()<<"\n"
00714                   <<"Creation Date: "<<dvr->GetCreationDate()<<"\n"
00715                   <<"Db No.: "<<dvr->GetDbNo()<<"\n"
00716                   <<"Insert Date: "<<dvr->GetInsertDate()<<"\n"
00717                   <<"Task: "<<dvr->GetTask()<<"\n"
00718                   <<"SeqNo: "<<dvr->GetSeqNo()<<"\n"
00719                   <<"VldRange: "<<dvr->GetVldRange()<<"\n"
00720                   <<std::endl;
00721   }
00722 
00723   for(unsigned int i=0;i<timecal.GetNumRows();i++){
00724     const CalTimeCalibration *readrow = timecal.GetRow(i);
00725     //    readrow->Print();
00726     cout<<"Seidkey "<<readrow->GetSEIDkey()
00727         <<" stripendid "<<readrow->GetStripEndId()
00728         <<" scale "<<readrow->GetScale()
00729         <<" offset "<<readrow->GetOffset()
00730         <<" slew1 "<<readrow->GetSlewC1()
00731         <<" slew2 "<<readrow->GetSlewC2()
00732         <<" slew3 "<<readrow->GetSlewC3()
00733         <<" slew4 "<<readrow->GetSlewC4()<<endl;
00734   }
00735 }


Generated on 14 Dec 2017 for loon by  doxygen 1.6.1