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

LoadCalDetPIDDB.cxx File Reference

#include "CalDetPID/LoadCalDetPIDDB.h"
#include <fstream>
#include <iostream>
#include <string>
#include <ctime>
#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 737 of file LoadCalDetPIDDB.cxx.

References PlexStripEndId::BuildPlnStripEndKey(), DbiWriter< T >::CanOutput(), DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), DbiTableProxyRegistry::GetCascader(), and DbiTableProxyRegistry::Instance().

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

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

void Load2003NFTiming bool  forreal  ) 
 

Definition at line 835 of file LoadCalDetPIDDB.cxx.

References DetailedTimeCal().

Referenced by LoadCalDetPIDDB().

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

void Load2003NN1mTiming bool  forreal  ) 
 

Definition at line 851 of file LoadCalDetPIDDB.cxx.

References DetailedTimeCal().

Referenced by LoadCalDetPIDDB().

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

void Load2003NNT7Timing bool  forreal  ) 
 

Definition at line 864 of file LoadCalDetPIDDB.cxx.

References DetailedTimeCal().

Referenced by LoadCalDetPIDDB().

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

void LoadBeamMomentum bool  forreal  ) 
 

Definition at line 81 of file LoadCalDetPIDDB.cxx.

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

Referenced by LoadCalDetPIDDB().

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

void LoadCalDetPIDDB bool  forreal  ) 
 

Definition at line 42 of file LoadCalDetPIDDB.cxx.

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

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

void LoadCERRange bool  forreal  ) 
 

Definition at line 289 of file LoadCalDetPIDDB.cxx.

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

Referenced by LoadCalDetPIDDB().

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

void LoadCERTimeWin bool  forreal  ) 
 

Definition at line 512 of file LoadCalDetPIDDB.cxx.

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

Referenced by LoadCalDetPIDDB().

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

void LoadOverlapWin bool  forreal  ) 
 

Definition at line 402 of file LoadCalDetPIDDB.cxx.

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

Referenced by LoadCalDetPIDDB().

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

void LoadTOFRange bool  forreal  ) 
 

Definition at line 171 of file LoadCalDetPIDDB.cxx.

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

Referenced by LoadCalDetPIDDB().

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

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

Definition at line 624 of file LoadCalDetPIDDB.cxx.

References PlexStripEndId::BuildPlnStripEndKey(), DbiWriter< T >::CanOutput(), DbiWriter< T >::Close(), DbiCascader::CreateTemporaryTable(), DbiTableProxyRegistry::GetCascader(), and DbiTableProxyRegistry::Instance().

Referenced by LoadCalDetPIDDB().

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

void PrintTimeCal const VldTimeStamp vts  ) 
 

Definition at line 700 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(), and DbiValidityRec::GetVldRange().

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


Generated on Mon Feb 15 11:08:02 2010 for loon by  doxygen 1.3.9.1