Exemple #1
0
//***************************************************************************
// PUBLIC METHOD:
// void ossimFfRevb::write(ostream& os) const
//
// Writes an EOSAT Fast Format Rev B formatted header.
//***************************************************************************
void ossimFfRevb::write(ostream& os) const
{
   const char PRODUCT_ID_DESC [PRODUCT_ORDER_NUMBER_DESC_SIZE + 1]
      = "PRODUCT =";

   const char WRS_DESC [WRS_DESC_SIZE + 1]
      = " WRS =";

   const char DATE_DESC [DATE_DESC_SIZE + 1]
      = " ACQUISITION DATE =";
   
   const char SATELLITE_NUMBER_DESC [SAT_NUMBER_DESC_SIZE + 1]
      = " SATELLITE =";
   
   const char INSTRUMENT_TYPE_DESC [INSTRUMENT_TYPE_DESC_SIZE + 1]
      = " INSTRUMENT =";
   
   const char PRODUCT_TYPE_DESC [PRODUCT_TYPE_DESC_SIZE + 1]
      = " PRODUCT TYPE =";
   
   const char PRODUCT_SIZE_DESC [PRODUCT_SIZE_DESC_SIZE + 1]
      = " PRODUCT SIZE =";
   
   const char PROCESSING_TYPE_DESC [PROCESSING_TYPE_DESC_SIZE + 1]
      = " TYPE OF GEODETIC PROCESSING =";
   
   const char RESAMPLING_ALGO_DESC [RESAMPLING_ALGO_DESC_SIZE + 1]
      = " RESAMPLING =";
   
   const char RADIANCE_DESC [RADIANCE_DESC_SIZE + 1]
      = " RAD GAINS/BIASES = ";

   const char VOLUME_NUMBER_DESC [VOLUME_NUMBER_DESC_SIZE + 1]
      = " TAPE SPANNING FLAG=";
   
   const char  FIRST_LINE_DESC [FIRST_LINE_DESC_SIZE + 1]
      = " START LINE #=";

   const char LINES_PER_VOLUME_DESC [LINES_PER_VOLUME_DESC_SIZE + 1]
      = " LINES PER VOL=";

   const char ORIENTATION_ANGLE_DESC [ORIENTATION_ANGLE_DESC_SIZE + 1]
      = " ORIENTATION =";

   const char MAP_PROJ_NAME_DESC [MAP_PROJ_NAME_DESC_SIZE + 1]
      = " PROJECTION =";
 
   const char USGS_PROJ_NUMBER_DESC [USGS_PROJ_NUMBER_DESC_SIZE + 1]
      = " USGS PROJECTION # =";
 
   const char USGS_MAP_ZONE_DESC [USGS_MAP_ZONE_DESC_SIZE + 1]
      = " USGS MAP ZONE =";
 
   const char PROJECTION_PARAMETER_DESC [USGS_PROJ_PARAMS_DESC_SIZE + 1]
      = " USGS PROJECTION PARAMETERS =";

   const char ELLIPSOID_DESC [ELLIPSOID_DESC_SIZE + 1]
      = " EARTH ELLIPSOID =";
      
   const char MAJOR_AXIS_DESC [MAJOR_AXIS_DESC_SIZE+ 1]
      = " SEMI-MAJOR AXIS =";
      
   const char MINOR_AXIS_DESC [MINOR_AXIS_DESC_SIZE+ 1]
      = " SEMI-MINOR AXIS =";
      
   const char PIXEL_GSD_DESC [PIXEL_GSD_DESC_SIZE + 1]
      = " PIXEL SIZE =";
   
   const char PIXELS_PER_LINE_DESC [PIXELS_PER_LINE_DESC_SIZE + 1]
      = " PIXELS PER LINE=";
   
   const char LINES_PER_IMAGE_DESC [LINES_PER_IMAGE_DESC_SIZE + 1]
      = " LINES PER IMAGE=";

   const char UL_DESC [CORNER_DESC_SIZE + 1]
      = " UL ";

   const char UR_DESC [CORNER_DESC_SIZE + 1]
      = " UR ";
   
   const char LR_DESC [CORNER_DESC_SIZE + 1]
      = " LR ";
   
   const char LL_DESC [CORNER_DESC_SIZE + 1]
      = " LL ";
   
   const char BANDS_PRESENT_DESC [BANDS_PRESENT_DESC_SIZE + 1]
      = " BANDS PRESENT =";
   
   const char BLOCKING_FACTOR_DESC [BLOCKING_FACTOR_DESC_SIZE + 1]
      = " BLOCKING FACTOR =";
   
   const char RECORD_LENGTH_DESC [RECORD_LENGTH_DESC_SIZE + 1]
      = " RECORD LENGTH =";
   
   const char SUN_ELEVATION_DESC [SUN_ELEVATION_DESC_SIZE + 1]
      = " SUN ELEVATION =";
   
   const char SUN_AZIMUTH_DESC [SUN_AZIMUTH_DESC_SIZE + 1]
      = " SUN AZIMUTH =";

   const char CENTER_DESC [CENTER_DESC_SIZE + 1]
      = " CENTER ";
   
   const char OFFSET_DESC [OFFSET_DESC_SIZE + 1]
      = " OFFSET=";
   
   const char REV_DESC [REV_DESC_SIZE + 1]
      = " REV";
      
   const char SPACE[] = " ";

   //***
   // Start at beginning of the stream.
   //***
   os.seekp(0, ios::beg);
   os << setiosflags(ios::fixed)  // Disable scientific mode.
      << setiosflags(ios::left)
       
      << PRODUCT_ID_DESC
      << setw(PRODUCT_ORDER_NUMBER_SIZE)
      << theProductOrderNumber

      << WRS_DESC         
      << setw(PATH_ROW_NUMBER_SIZE) 
      << thePathRowNumber

      << DATE_DESC
      << setw(DATE_SIZE) 
      << theAcquisitionDate

      << SATELLITE_NUMBER_DESC
      << setw(SAT_NUMBER_SIZE) 
      << theSatNumber 

      << INSTRUMENT_TYPE_DESC
      << setw(INSTRUMENT_TYPE_SIZE) 
      << theInstrumentType

      << PRODUCT_TYPE_DESC
      << setw(PRODUCT_TYPE_SIZE) 
      << theProductType

      << PRODUCT_SIZE_DESC
      << setw(PRODUCT_SIZE_SIZE) 
      << theProductSize

      << setw(MAP_SHEET_SIZE)
      << theMapSheetName

      << PROCESSING_TYPE_DESC
      << setw(PROCESSING_TYPE_SIZE) 
      << theProcessingType

      << RESAMPLING_ALGO_DESC
      << setw(RESAMPLING_ALGO_SIZE) 
      << theResampAlgorithm

      << RADIANCE_DESC;

   int i;
   for (i=0; i<NUMBER_OF_BANDS-1; i++) // Output six of the seven bands.
   {
      os << setw(RADIANCE_SIZE) << theBandRadiance[i] << SPACE;
   }

   os << setw(RADIANCE_SIZE) << theBandRadiance[6] // Last one no space.

      << VOLUME_NUMBER_DESC
      << setw(VOLUME_NUMBER_SIZE) 
      << theVolumeNumber

      << resetiosflags(ios::left)
      << setiosflags(ios::right)

      << FIRST_LINE_DESC
      << setw(FIRST_LINE_IN_VOLUME_SIZE) 
      << the1stLineInVolume

      << LINES_PER_VOLUME_DESC 
      << setw(LINES_PER_VOLUME_SIZE) 
      << theLinesPerVolume 

      << ORIENTATION_ANGLE_DESC 
      << setprecision(2) << setw(ORIENTATION_ANGLE_SIZE) 
      << theOrientationAngle  

      << MAP_PROJ_NAME_DESC
      << setw(MAP_PROJ_NAME_SIZE) 
      << theMapProjName

      << USGS_PROJ_NUMBER_DESC 
      << setw(USGS_PROJ_NUMBER_SIZE) 
      << theUsgsProjNumber 

      << USGS_MAP_ZONE_DESC 
      << setw(USGS_MAP_ZONE_SIZE) 
      << theUsgsMapZone 

      << PROJECTION_PARAMETER_DESC;

   for (i=0; i<NUMBER_OF_PROJECTION_PARAMETERS; i++)
   {
      os << setw(USGS_PROJ_PARAMS_SIZE)
         << theUsgsProjParam[i];
   }

   
   os << setiosflags(ios::left)

      << ELLIPSOID_DESC
      << setw(ELLIPSOID_SIZE)
      << theEllipsoid
      << resetiosflags(ios::left)
      << setprecision(3)

      << setiosflags(ios::right)

      << MAJOR_AXIS_DESC
      << setw(MAJOR_AXIS_SIZE) 
      << theSemiMajorAxis 

      << MINOR_AXIS_DESC
      << setw(MINOR_AXIS_SIZE) 
      << theSemiMinorAxis

      << setprecision(2)

      << PIXEL_GSD_DESC
      << setw(PIXEL_GSD_SIZE) 
      << theGsd
      
      << PIXELS_PER_LINE_DESC
      << setw(PIXELS_PER_LINE_SIZE) 
      << thePixelsPerLine
 
      << LINES_PER_IMAGE_DESC
      << setw(LINES_PER_IMAGE_SIZE) 
      << theLinesPerImage

      << setprecision(3)

      << UL_DESC
      << setw(LON_SIZE)
      << theUlLon
      << SPACE
      << setw(LAT_SIZE)
      << theUlLat
      << SPACE
      << setw(EASTING_SIZE)
      << theUlEasting
      << SPACE
      << setw(NORTHING_SIZE) 
      << theUlNorthing

      << UR_DESC
      << setw(LON_SIZE)
      << theUrLon
      << SPACE
      << setw(LAT_SIZE)
      << theUrLat
      << SPACE
      << setw(EASTING_SIZE)
      << theUrEasting
      << SPACE
      << setw(NORTHING_SIZE) 
      << theUrNorthing

      << LR_DESC
      << setw(LON_SIZE)
      << theLrLon
      << SPACE
      << setw(LAT_SIZE)
      << theLrLat
      << SPACE
      << setw(EASTING_SIZE)
      << theLrEasting
      << SPACE
      << setw(NORTHING_SIZE) 
      << theLrNorthing

      << LL_DESC
      << setw(LON_SIZE)
      << theLlLon
      << SPACE
      << setw(LAT_SIZE)
      << theLlLat
      << SPACE
      << setw(EASTING_SIZE)
      << theLlEasting
      << SPACE
      << setw(NORTHING_SIZE) 
      << theLlNorthing

      << resetiosflags(ios::right);

   os << BANDS_PRESENT_DESC
      << setw(BANDS_PRESENT_SIZE) 
      << theBandsPresentString

      << BLOCKING_FACTOR_DESC
      << setw(BLOCKING_FACTOR_SIZE) 
      << theBlockingFactor

      << RECORD_LENGTH_DESC
      << setw(RECORD_LENGTH_SIZE) 
      << theRecordSize
         
      << SUN_ELEVATION_DESC
      << setw(SUN_ELEVATION_SIZE) 
      << theSunElevation
         
      << SUN_AZIMUTH_DESC
      << setw(SUN_AZIMUTH_SIZE) 
      << theSunAzimuth
         
      << CENTER_DESC 
      << setw(LON_SIZE) 
      << theCenterLon 
      << SPACE
      << setw(LAT_SIZE)
      << theCenterLat
      << SPACE
      << setiosflags(ios::right)
      << setw(EASTING_SIZE)
      << theCenterEasting
      << SPACE
      << setw(NORTHING_SIZE)
      << theCenterNorthing
      << setw(CENTER_SAMPLE_SIZE)
      << theCenterSample
      << setw(CENTER_LINE_SIZE)
      << theCenterLine

      << OFFSET_DESC
      << setw(OFFSET_SIZE)
      << theOffset

      << REV_DESC
      << setw(FORMAT_VERSION_SIZE)
      << theFormatVersion << flush;  // Byte count of file should be 1536.

}
Exemple #2
0
void nuint09_qel2(int isample, int include_fsi=0)
{
  cout << " ***** running: QEL.2" << endl;
  if(include_fsi==0) { cout << "-FSI" << endl;  }
  else 
  if(include_fsi==1) { cout << "+FSI" << endl;  }
  else
   return;

  if(isample<0 || isample >= kNSamples) return;

  const char * label = kLabel[isample];

  int A = kA[isample];
  int Z = kZ[isample];
  int N = A-Z;

  // get cross section graphs

  TFile fsig("../sig/splines.root","read");
  TDirectory * sig_dir = (TDirectory *) fsig.Get(label);  

  TGraph * sig_graph_qelcc = (TGraph*) sig_dir->Get("qel_cc_n");

  // range & spacing

  const int    nKEp    = 60;
  const double KEpmin  =  0.01;
  const double KEpmax  =  1.50;

  // create output stream

  ostringstream out_filename;
  if(include_fsi==0) { out_filename << label << ".qel_2.dsig_dKEp.data";         }
  else               { out_filename << label << ".qel_2.dsig_dKEp_withFSI.data"; }

  ofstream out_stream(out_filename.str().c_str(), ios::out);

  // write out txt file

  out_stream << "# [" << label << "]" << endl;
  out_stream << "#  " << endl;
  out_stream << "# [QEL.2]:" << endl;
  out_stream << "#  Cross section as a function of f/s proton kinetic energy at E_nu= 0.5, 1.0 GeV." << endl;
  out_stream << "#  " << endl;
  out_stream << "#  Note:" << endl;
  if(include_fsi==1)
  {
     out_stream << "#   - INCLUDING FSI " << endl;
  }
  out_stream << "#   - proton energies are _kinetic_ energies " << endl;
  out_stream << "#   - proton kinetic energy KE in GeV, between KEmin = " << KEpmin << " GeV, KEmax = " << KEpmax << " GeV "  << endl;
  out_stream << "#   - cross sections in 1E-38 cm^2 / GeV" << endl;
  out_stream << "#   - quoted cross section is nuclear cross section per nucleon contributing in the scattering (eg only neutrons for nu_mu QELCC)" << endl;
  out_stream << "#  Columns:" << endl;
  out_stream << "#  |  KE(p)  |  sig(QELCC; Ev=0.5GeV)  | sig(QELCC; Ev=1.0GeV) | " << endl;

  out_stream << setiosflags(ios::fixed) << setprecision(6);

  //
  // load event data
  //

  TChain * chain = new TChain("gst");

  // loop over CC/NC cases
  for(int iwkcur=0; iwkcur<kNWCur; iwkcur++) {
    // loop over energies
    for(int ie=0; ie<kNEnergies; ie++) {
       // loop over runs for current case
       for(int ir=0; ir<kNRunsPerCase; ir++) {
	  // build filename
	  ostringstream filename;
          int run_number = kRunNu[isample][iwkcur][ie][ir];
          filename << "../gst/gntp." << run_number << ".gst.root";
          // add to chain
          cout << "Adding " << filename.str() << " to event chain" << endl;
          chain->Add(filename.str().c_str());
       }
    }
  }


  //
  // get QELCC cross sections at given energies for normalization purposes
  //
  double sig_qelcc_0500MeV = sig_graph_qelcc->Eval(0.5) / N; 
  double sig_qelcc_1000MeV = sig_graph_qelcc->Eval(1.0) / N; 

  //
  // book histograms
  //
  TH1D * hst_dsig_dKEp_qelcc_0500MeV = new TH1D("hst_dsig_dKEp_qelcc_0500MeV","dsig/dKEp, nu_mu QEL CC, Enu=0.5 GeV", nKEp, KEpmin, KEpmax);
  TH1D * hst_dsig_dKEp_qelcc_1000MeV = new TH1D("hst_dsig_dKEp_qelcc_1000MeV","dsig/dKEp, nu_mu QEL CC, Enu=1.0 GeV", nKEp, KEpmin, KEpmax);

  //
  // fill histograms
  //
  if(include_fsi==0) {
    chain->Draw("(Ei-0.938)>>hst_dsig_dKEp_qelcc_0500MeV","qel&&cc&&Ev>0.49&&Ev<0.51&&pdgi==2212","GOFF");
    chain->Draw("(Ei-0.938)>>hst_dsig_dKEp_qelcc_1000MeV","qel&&cc&&Ev>0.99&&Ev<1.01&&pdgi==2212","GOFF");
  } else {
    chain->Draw("(Ef-0.938)>>hst_dsig_dKEp_qelcc_0500MeV","qel&&cc&&Ev>0.49&&Ev<0.51&&pdgf==2212","GOFF");
    chain->Draw("(Ef-0.938)>>hst_dsig_dKEp_qelcc_1000MeV","qel&&cc&&Ev>0.99&&Ev<1.01&&pdgf==2212","GOFF");
  }

  //
  // normalize
  //
  double norm_qelcc_0500MeV = hst_dsig_dKEp_qelcc_0500MeV -> Integral("width") / sig_qelcc_0500MeV;
  double norm_qelcc_1000MeV = hst_dsig_dKEp_qelcc_1000MeV -> Integral("width") / sig_qelcc_1000MeV;

  if (norm_qelcc_0500MeV > 0) hst_dsig_dKEp_qelcc_0500MeV -> Scale(1./norm_qelcc_0500MeV);
  if (norm_qelcc_1000MeV > 0) hst_dsig_dKEp_qelcc_1000MeV -> Scale(1./norm_qelcc_1000MeV);

  for(int i = 1; i <= hst_dsig_dKEp_qelcc_1000MeV->GetNbinsX(); i++) {

     double KEp = hst_dsig_dKEp_qelcc_1000MeV->GetBinCenter(i);

     double dsig_dKEp_qelcc_0500MeV = hst_dsig_dKEp_qelcc_0500MeV -> GetBinContent(i);
     double dsig_dKEp_qelcc_1000MeV = hst_dsig_dKEp_qelcc_1000MeV -> GetBinContent(i);

     dsig_dKEp_qelcc_0500MeV = TMath::Max(0., dsig_dKEp_qelcc_0500MeV);
     dsig_dKEp_qelcc_1000MeV = TMath::Max(0., dsig_dKEp_qelcc_1000MeV);

     out_stream << setw(15) << KEp 
                << setw(15) << dsig_dKEp_qelcc_0500MeV
                << setw(15) << dsig_dKEp_qelcc_1000MeV
                << endl;
  }

  out_stream.close();

  delete chain;
}
void ossimQtSingleImageWindow::trackImageWidget(ossimQtMouseEvent* event)
{
    if (!event)
    {
        return;
    }

    if (!theImageChain.valid())
    {
        event->getEvent()->ignore();
        return;
    }

    switch(event->getQtEventType())
    {
    case QEvent::MouseButtonPress:
    case QEvent::MouseMove:
    {
        //---
        // We want to track only left clicks or left down and drag.
        //---
        if( (event->getState()  == Qt::LeftButton) ||
                (event->getButton() == Qt::LeftButton) )
        {
            ossimIpt pt = event->getShiftPoint();
            std::ostringstream os;
            os << setiosflags(ios::right)
               << "line:"    << setw(9) << pt.y
               << "    sample:" << setw(9) << pt.x
               << "    pixel value";

            ossim_uint8 r;
            ossim_uint8 g;
            ossim_uint8 b;
            theImageWidget->getRgb(pt, r, g, b);

            const ossim_uint32 BANDS =
                theImageChain->getNumberOfOutputBands();
            switch (BANDS)
            {
            case 1:
                os << ":" << setw(6) << int(r);
                break;
            case 2:
                os << "s:" << setw(6) << int(r) << setw(6) << int(g);
                break;
            default:
                os << "s:" << setw(6) << int(r) << setw(6) << int(g)
                   << setw(6) << int(b);
                break;
            }

            QString qs = os.str().c_str();
            statusBar()->message(qs);
        }
        else
        {
            event->getEvent()->ignore();
        }
        break;
    }

    default:
    {
        event->getEvent()->ignore();
        break;
    }
    }
}
Exemple #4
0
void nuint09_1pi1(int isample, int single_pion_sources=0, int stage=1)
{
  cout << " ***** running: 1PI.1" << endl;

  if(isample<0 || isample >= kNSamples) return;
  if(single_pion_sources<0 || single_pion_sources>2) return;

  const char * label = kLabel[isample];

  int A = kA[isample];

  // get cross section graphs

  TFile fsig("../sig/splines.root","read");
  TDirectory * sig_dir = (TDirectory *) fsig.Get(label);  

  TGraph * sig_graph_totcc = (TGraph*) sig_dir->Get("tot_cc");

  // range & spacing

  const int    nEnu   = 60;
  const double Enumin =  0.05;
  const double Enumax = 30.00;

  // create output stream

  ostringstream out_filename;
  out_filename << label;

  if      (single_pion_sources==0) out_filename << ".1pi_1a.";
  else if (single_pion_sources==1) out_filename << ".1pi_1b.";
  else if (single_pion_sources==2) out_filename << ".1pi_1c.";

  if(stage==0) out_filename << "no_FSI.";

  out_filename << "sig1pi_vs_Enu.data";
  ofstream out_stream(out_filename.str().c_str(), ios::out);

  // write out txt file

  out_stream << "# [" << label << "]" << endl;
  out_stream << "#  " << endl;
  out_stream << "# [1PI.1]:" << endl;
  out_stream << "#  Total cross section for 1 pion (pi+ only) production as a function of energy" << endl;
  if(stage==0) {
    out_stream << "#  ***** NO FSI: The {X pi+} state is a primary hadronic state" << endl;
  }
  if(single_pion_sources==0) {
     out_stream << "#  1pi sources: All" << endl;
  }
  else if(single_pion_sources==1) {
     out_stream << "#  1pi sources: P33(1232) resonance only" << endl;
  }
  else if(single_pion_sources==2) {
     out_stream << "#  1pi sources: All resonances only" << endl;
  }
  out_stream << "#  " << endl;
  out_stream << "#  Note:" << endl;
  out_stream << "#   - neutrino energy E in GeV, linear spacing between Emin = " << Enumin << " GeV, Emax = " << Enumax << " GeV "  << endl;
  out_stream << "#   - cross sections in 1E-38 cm^2 " << endl;
  out_stream << "#   - quoted cross section is nuclear cross section divided with number of nucleons A" << endl;
  out_stream << "#  Columns:" << endl;
  out_stream << "#  |  Energy     |   sig(nu_mu + A -> mu- 1pi+ X)   |  "  << endl;

  out_stream << setiosflags(ios::fixed) << setprecision(6);

  //
  // load event data
  // 
    
  TChain * chain = new TChain("gst");
  
  // loop over CC/NC cases
  for(int iwkcur=0; iwkcur<kNWCur; iwkcur++) {
       // loop over runs for current case
       for(int ir=0; ir<kNRunsPerCase; ir++) {
          // build filename
          ostringstream filename;
          int run_number = kRunNu1PI1[isample][iwkcur][ir];

          cout << "isample = " << isample << ", iwkcur = " << iwkcur << ", ir = " << ir << ", run = " << run_number << endl;

          filename << "../gst/gntp." << run_number << ".gst.root";
          // add to chain
          cout << "Adding " << filename.str() << " to event chain" << endl;
          chain->Add(filename.str().c_str());
       }
  } 

  //
  // book histograms
  //
  TH1D * hst_cc1pip = new TH1D("hst_cc1pip","CC1pi+ events, Enu spectrum", nEnu, Enumin, Enumax);
  TH1D * hst_allcc  = new TH1D("hst_allcc", "all CC events, Enu spectrum", nEnu, Enumin, Enumax);

  //
  // fill histograms
  //

  chain->Draw("Ev>>hst_allcc", "cc","GOFF");

  if(stage==1) {
    if(single_pion_sources==0) {
      //all sources
      chain->Draw("Ev>>hst_cc1pip","cc&&pdgf==211&&nfpip==1&&nfpim==0&&nfpi0==0","GOFF");
    }
    else if(single_pion_sources==1) {
      //P33(1232) only
      chain->Draw("Ev>>hst_cc1pip","cc&&resid==0&&res&&pdgf==211&&nfpip==1&&nfpim==0&&nfpi0==0","GOFF");
    }
    else if(single_pion_sources==2) {
      //all resonances only
      chain->Draw("Ev>>hst_cc1pip","cc&&res&&pdgf==211&&nfpip==1&&nfpim==0&&nfpi0==0","GOFF");
    }
  }
  else if(stage==0) {
    if(single_pion_sources==0) {
      //all sources
      chain->Draw("Ev>>hst_cc1pip","cc&&pdgi==211&&nipip==1&&nipim==0&&nipi0==0","GOFF");
    }
    else if(single_pion_sources==1) {
      //P33(1232) only
      chain->Draw("Ev>>hst_cc1pip","cc&&resid==0&&res&&pdgi==211&&nipip==1&&nipim==0&&nipi0==0","GOFF");
    }
    else if(single_pion_sources==2) {
      //all resonances only
      chain->Draw("Ev>>hst_cc1pip","cc&&res&&pdgi==211&&nipip==1&&nipim==0&&nipi0==0","GOFF");
    }
  }

  cout << "CC1pi+ nevents: " << hst_cc1pip->GetEntries() << endl;
  cout << "ALLCC  nevents: " << hst_allcc->GetEntries() << endl;

  //
  // compute sig(CC1pi+) and write out in txt file expected by NuINT organizers
  // Also write out root graph in temp file to be re-used at later benchmarking calc
  //

  double e[nEnu], sig[nEnu];

  for(int i=1; i <= hst_cc1pip->GetNbinsX(); i++) {

     double Enu = hst_cc1pip->GetBinCenter(i);

     double Ncc1pip = hst_cc1pip -> GetBinContent(i);
     double Nallcc  = hst_allcc  -> GetBinContent(i);

     double sig_cc1pip=0;
     if(Nallcc>0) { sig_cc1pip = (Ncc1pip/Nallcc) * sig_graph_totcc->Eval(Enu) / A; }

     out_stream << setw(15) << Enu << setw(15) << sig_cc1pip << endl;

     e  [i-1] = Enu;
     sig[i-1] = sig_cc1pip;
  }

  out_stream.close();

  TFile ftmp("./cc1pip_tmp.root","recreate");
  TGraph * grCC1pip = new TGraph(nEnu,e,sig);  
  grCC1pip->Write("CC1pip");
  hst_allcc->Write();
  hst_cc1pip->Write();

  // visual inspection
  TCanvas * c1 = new TCanvas("c1","",20,20,500,500);
  grCC1pip->Draw("alp");
  c1->Update();

  ftmp.Close();

  delete chain;
}
Exemple #5
0
int main(){
	chdir(QUERY_DATA_PATH);
	EnvDB *env = new EnvDB();
	env->open();
	
	BDBOpe db_r_1(env->getEnv(), "1.1.DSM");
	BDBOpe db_r_2(env->getEnv(), "1.2.DSM");
	BDBOpe db_n_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n_2(env->getEnv(), "2.2.DSM");
	BDBOpe db_n_3(env->getEnv(), "2.3.DSM");
	BDBOpe db_s_1(env->getEnv(), "3.1.DSM");
	BDBOpe db_s_4(env->getEnv(), "3.4.DSM");
	BDBOpe db_c_1(env->getEnv(), "6.1.DSM");
	BDBOpe db_c_4(env->getEnv(), "6.4.DSM");
	BDBOpe db_o(env->getEnv(), "ORDERS.row");
	BDBOpe db_l(env->getEnv(), "LINEITEM.row");
	
	SecondDB *sDB,*sDB_o;
	int (*pf)(Db *sdbp, const Dbt*pkey, const Dbt *pdata, Dbt *skey);
	pf = L_1_secondary;
	sDB = new SecondDB(env->getEnv(), "8.1.secondary");
	sDB->setNumCmp();
	
	int (*pf_o)(Db *sdbp, const Dbt*pkey, const Dbt *pdata, Dbt *skey);
	pf_o = O_2_secondary;
	sDB_o = new SecondDB(env->getEnv(), "7.2.secondary");
	sDB_o->setNumCmp();
	
	db_r_1.open();
	db_r_2.open();
	db_n_1.open();
	db_n_2.open();
	db_n_3.open();
	db_s_1.open();
	db_s_4.open();
	db_c_1.open();
	db_c_4.open();
	db_o.open();
	db_l.open();
	sDB->open(0);
	db_l.associate(sDB->getDb(), pf);
	sDB->openCursor();
	sDB_o->open(0);
	db_o.associate(sDB_o->getDb(), pf_o);
	sDB_o->openCursor();


	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	Operator *o31, *o32, *o33, *o34, *o35, *o36, *o37, *o38, *o39, *o40;



	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;
	TABLE_REC tableRec_s;

	
/* set table info */
	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;
	
	tableRec_n.tableID = 2;
	tableRec_n.attriNum = 4;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;

	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;
	


/* aet attriRec */
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];
	

	AttributeManager AM(env->getEnv());
	

	AM.getForTableID(tableRec_r, attriRec_r);
	AM.getForTableID(tableRec_n, attriRec_n);
	AM.getForTableID(tableRec_c, attriRec_c);
	AM.getForTableID(tableRec_o, attriRec_o);
	AM.getForTableID(tableRec_l, attriRec_l);
	AM.getForTableID(tableRec_s, attriRec_s);

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("ASIA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1994-01-01");
	DatePosVal pv3(1,(unsigned char *)"1995-01-01");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LT, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);
	
	
/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 2;
	group[0].attributeID = 2;
	
/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 0;
	so1[0].attributeID = 0;
	so1[0].position = 1;
	so1[0].option = 1;

/* Projection1 */

	OPERATION_NODE pro1[2];
	pro1[0].tableID = 2;
	pro1[0].attributeID = 1;
	pro1[1].tableID = 2;
	pro1[1].attributeID = 2;
	
/* Projection2 */

	OPERATION_NODE pro2[3];
	pro2[0].tableID = 3;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 3;
	pro2[1].attributeID = 4;
	pro2[2].tableID = 2;
	pro2[2].attributeID = 2;
	
/* Projection3 */

	OPERATION_NODE pro3[3];
	pro3[0].tableID = 2;
	pro3[0].attributeID = 2;
	pro3[1].tableID = 8;
	pro3[1].attributeID = 6;
	pro3[2].tableID = 8;
	pro3[2].attributeID = 7;

/* Projection4 */

	OPERATION_NODE pro4[3];
	pro4[0].tableID = 2;
	pro4[0].attributeID = 2;
	pro4[1].tableID = 6;
	pro4[1].attributeID = 1;
	pro4[2].tableID =6;
	pro4[2].attributeID = 4;

/* Projection5 */

	OPERATION_NODE pro5[3];
	pro5[0].tableID = 2;
	pro5[0].attributeID = 2;
	pro5[1].tableID = 6;
	pro5[1].attributeID = 4;
	pro5[2].tableID = 7;
	pro5[2].attributeID = 1;

/* Projection6 */

	OPERATION_NODE pro6[5];
	pro6[0].tableID = 2;
	pro6[0].attributeID = 2;
	pro6[1].tableID = 6;
	pro6[1].attributeID = 4;
	pro6[2].tableID = 8;
	pro6[2].attributeID = 3;
	pro6[3].tableID = 8;
	pro6[3].attributeID = 6;
	pro6[4].tableID = 8;
	pro6[4].attributeID = 7;

/* Projection11 */
	
	OPERATION_NODE pro11[4];
	pro11[0].tableID = 2;
	pro11[0].attributeID = 2;
	pro11[1].tableID = 6;
	pro11[1].attributeID = 4;
	pro11[2].tableID = 7;
	pro11[2].attributeID = 1;
	pro11[3].tableID = 7;
	pro11[3].attributeID = 5;
	
	
	OPERATION_NODE op1;
	op1.tableID = 2;
	op1.attributeID = 3;
	
	OPERATION_NODE op2;
	op2.tableID = 3;
	op2.attributeID = 4;
	
	OPERATION_NODE op3;
	op3.tableID = 8;
	op3.attributeID = 3;
	
	OPERATION_NODE op4;
	op4.tableID = 7;
	op4.attributeID = 2;
	
	OPERATION_NODE op5;
	op5.tableID = 6;
	op5.attributeID = 4;

/* index position */
	
	OPERATION_NODE pro10[1];
	pro10[0].tableID = 7;
	pro10[0].attributeID = 1;
	
	
/* Join1 */
	OPERATION_NODE pn1[2];
	pn1[0].tableID = 2;
	pn1[0].attributeID = 1;
	pn1[1].tableID = 6;
	pn1[1].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn1[1];
	jpn1[0].rightNode = pn1[0];
	jpn1[0].leftNode = pn1[1];

/* Join2 */
	OPERATION_NODE pn2[2];
	pn2[0].tableID = 6;
	pn2[0].attributeID = 1;
	pn2[1].tableID = 7;
	pn2[1].attributeID = 2;

	
	JOIN_OPERATION_NODE jpn2[1];
	jpn2[0].rightNode = pn2[0];
	jpn2[0].leftNode = pn2[1];
	
/* Join3 */
	OPERATION_NODE pn3[2];
	pn3[0].tableID = 7;
	pn3[0].attributeID = 1;
	pn3[1].tableID = 8;
	pn3[1].attributeID = 1;

	
	JOIN_OPERATION_NODE jpn3[1];
	jpn3[0].rightNode = pn3[0];
	jpn3[0].leftNode = pn3[1];

/* Join4 */
	OPERATION_NODE pn4[4];
	pn4[0].tableID = 3;
	pn4[0].attributeID = 1;
	pn4[1].tableID = 3;
	pn4[1].attributeID = 4;
	pn4[2].tableID = 8;
	pn4[2].attributeID = 3;
	pn4[3].tableID = 6;
	pn4[3].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn4[2];
	jpn4[0].rightNode = pn4[0];
	jpn4[0].leftNode = pn4[2];
	jpn4[1].rightNode = pn4[1];
	jpn4[1].leftNode = pn4[3];

	
/* exec */
	
	o1 = new ScanDSM(&db_r_2, &attriRec_r[1], 1);
	o2 = new SelectBitOut((Node *)&an1 ,(unsigned int)1);
	o2->setPreOperator(o1);
	o3 = new ScanDSM(&db_r_1, &attriRec_r[0], 1);
	o4 = new BitFilter(o3, o2);

	o5 = new ScanDSM(&db_n_3, &attriRec_n[2], 1);
	o6 = new JoinIndex_OneHash(o4, o5); 

	
	o7 = new ScanDSM(&db_n_1, &attriRec_n[0], 1);
	o8 = new ScanFromJI(o7, o6, &op1);
	o9 = new ScanDSM(&db_n_2, &attriRec_n[1], 1);
	//n_name, n_natonkey, r_regionkey, n_nationkey
	o10 = new ScanFromJI(o9, o8, &op1);
	
	//n_name, n_natonkey
	o11 = new Projection(pro1, 2);
	o11->setPreOperator(o10);

	o12 = new ScanDSM(&db_c_4, &attriRec_c[3], 1);
	o13 = new ScanDSM(&db_c_1, &attriRec_c[0], 1);
	o14 = new ScanFromJI(o13, o12, &op5);
	
	o15 = new OneSideHashJoin(o10, o14 , jpn1, 1);
	//n_name, c_custkey, c_nationkey
	o16 = new Projection(pro4, 3);
	o16->setPreOperator(o15);
	
	/* ======== Nested Loop Join with Index ============ */
	IndexScan *IS_o = new IndexScan((BDBOpe *)sDB_o, attriRec_o, 9);
	o17 = new NestedJoin_Index(IS_o, o16, pn2);
	o18 = new Projection(pro11, 4);
	o18->setPreOperator(o17);

	//o17 = new ScanDSM(&db_o_5, &attriRec_o[4], 1);
	o19 = new Selection((Node *)&an4 ,(unsigned int)2);
	o19->setPreOperator(o18);
	//o19 = new ScanDSM(&db_o_2, &attriRec_o[1], 1);
	//o20 = new BitFilter(o19, o18);
	
	/* ======================================================= */
	
	
	//o21 = new ScanDSM(&db_o_1, &attriRec_o[0], 1);
	//o_order, o_custkey
	//o22 = new ScanFromJI(o21, o20, &op4);
	
	//n_name, c_custkey, c_nationkey, o_order, o_custkey
	//o23 = new OneSideHashJoin(o16, o22 , jpn2, 1);
	
	//n_name, c_nationkey, o_order
	o24 = new Projection(pro5, 3);
	o24->setPreOperator(o19);

	/* ======== Nested Loop Join with Index ============ */

	IndexScan *IS = new IndexScan((BDBOpe *)sDB, attriRec_l, 16);
	o25 = new NestedJoin_Index(IS, o24, pro10);
	o26 = new Projection(pro6, 5);
	o26->setPreOperator(o25);
	
	/* ======================================================= */
	
	//l_orderkey, l_extendedprice, l_discount, l_suppkey

	o33 = new ScanDSM(&db_s_4, &attriRec_s[3], 1);
	o34 = new ScanDSM(&db_s_1, &attriRec_s[0], 1);
	o35 = new ScanFromJI(o34, o33, &op2);

	o36 = new OneSideHashJoin(o35, o26 , jpn4, 2);



	o37 = new Projection(pro3, 3);
	o37->setPreOperator(o36);
	
	o38 = new GroupBy(group, 1, aggre, 1);
	o38->setPreOperator(o37);

	o39 = new Sort(so1, 1);
	o39->setPreOperator(o38);
	
	o40 = new OutPut(TIME_OUT);

	o40->setPreOperator(o39);
	o40->init(env->getEnv());
	cout << "TEST START Q5" << endl;
	
	cout << setprecision(4);
	cout << setiosflags(ios::fixed); 
	o40->exec();
}
int main(int argc, char** argv) {
    Galois::StatManager M;
    LonestarStart(argc, argv, name, desc, url);

    Graph g;
    G = &g;

    G->structureFromFile(filename.c_str());

    NumNodes = G->size();

#if SHARE_SINGLE_BC
    std::vector<cache_line_storage<BCrecord> > cb(NumNodes);
    CB = &cb;
#else
    Galois::GVectorElementAccumulator<std::vector<double> > cb;
    CB = &cb;
#endif

    initGraphData();

    int iterations = NumNodes;
    if (iterLimit)
        iterations = iterLimit;

    boost::filter_iterator<HasOut,Graph::iterator>
    begin = boost::make_filter_iterator(HasOut(G), g.begin(), g.end()),
    end = boost::make_filter_iterator(HasOut(G), g.end(), g.end());

    iterations = std::min((int) std::distance(begin, end), iterations);

    std::cout
            << "NumNodes: " << NumNodes
            << " Iterations: " << iterations << "\n";

    end = begin;
    std::advance(end, iterations);
    std::vector<GNode> tmp;
    std::copy(begin, end, std::back_inserter(tmp));

    typedef GaloisRuntime::WorkList::dChunkedLIFO<1> WL;
    Galois::StatTimer T;
    T.start();
    Galois::for_each<WL>(tmp.begin(), tmp.end(), process());
    T.stop();

    if (forceVerify || !skipVerify) {
        verify();
    } else { // print bc value for first 10 nodes
#if SHARE_SINGLE_BC
#else
        const std::vector<double>& bcv = CB->reduce();
#endif
        for (int i=0; i<10; ++i)
#if SHARE_SINGLE_BC
            std::cout << i << ": " << setiosflags(std::ios::fixed) << std::setprecision(6) << (*CB)[i].data.bc << "\n";
#else
            std::cout << i << ": " << setiosflags(std::ios::fixed) << std::setprecision(6) << bcv[i] << "\n";
#endif
#if SHOULD_PRODUCE_CERTIFICATE
        printBCcertificate();
#endif
    }
    std::cerr << "Application done...\n";

    Galois::StatTimer tt("cleanup");
    tt.start();
    cleanupData();
    tt.stop();

    return 0;
}
Exemple #7
0
void DbDiskInfo::printStatus(tlgpfs_disk_info_t* disk, bool detailed)
{
    if(disk == NULL)
        cerr<<"Can't print a null structure of status!"<<endl;

    cout<<setiosflags(ios::left)<<setw(20)<<"cluster_id"     <<setiosflags(ios::left)<<setw(40)<<"(cluster id)"             <<": "<< disk->cluster_id      <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"disk_name"      <<setiosflags(ios::left)<<setw(40)<<"(disk name)"              <<": "<< disk->disk_name       <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"health"         <<setiosflags(ios::left)<<setw(40)<<"(health status)"          <<": "<<string((*disk->health == HEALTHY)?"healthy":((*disk->health == UNHEALTHY)?"unhealthy":"unknown"))<<endl;
    if(!detailed)
        return;
    cout<<setiosflags(ios::left)<<setw(20)<<"node_name"      <<setiosflags(ios::left)<<setw(40)<<"(node name)"              <<": "<< disk->node_name       <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"status"         <<setiosflags(ios::left)<<setw(40)<<"(disk status)"            <<": "<< disk->status          <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"availability"   <<setiosflags(ios::left)<<setw(40)<<"(disk availability)"      <<": "<< disk->availability    <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"pool_name"      <<setiosflags(ios::left)<<setw(40)<<"(storage pool name)"      <<": "<< disk->pool_name       <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"vol_id"         <<setiosflags(ios::left)<<setw(40)<<"(volume id)"              <<": "<< disk->vol_id          <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"meta_data"      <<setiosflags(ios::left)<<setw(40)<<"(disk meta data)"         <<": "<< disk->meta_data       <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"data"           <<setiosflags(ios::left)<<setw(40)<<"(disk data)"              <<": "<< disk->data            <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"disk_wait"      <<setiosflags(ios::left)<<setw(40)<<"(disk wait)"              <<": "<< disk->disk_wait       <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"total_space"    <<setiosflags(ios::left)<<setw(40)<<"(total space)"            <<": "<<*disk->total_space     <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"full_blk_space" <<setiosflags(ios::left)<<setw(40)<<"(full block space)"       <<": "<<*disk->full_blk_space  <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"sub_blk_space"  <<setiosflags(ios::left)<<setw(40)<<"(sub block space)"        <<": "<<*disk->sub_blk_space   <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"fail_group_id"  <<setiosflags(ios::left)<<setw(40)<<"(failure group id)"       <<": "<<*disk->fail_group_id   <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"is_free"        <<setiosflags(ios::left)<<setw(40)<<"(if is free)"             <<": "<<*disk->is_free         <<endl;
    cout<<setiosflags(ios::left)<<setw(20)<<"change"         <<setiosflags(ios::left)<<setw(40)<<"(change value)"           <<": "<<*disk->change          <<endl;

}
double cosnn1nnint(double a11,double a12, double b1, int n11, int n12, int m1,
		   double aM, double bM1, double bM2,
		   double a21,double a22, double b2, int n21, int n22, int m2){
  double ret = cosnn1nnintwork(a11,a12,b1,n11,n12,(m1<0 ? -m1 : m1),
			       aM ,bM1 ,bM2,
			       a21,a22,b2,n21,n22,(m2<0 ? -m2 : m2));
  if(0) {
    cout << setprecision(10) << setiosflags(ios::fixed);
    // cout << setprecision(10); //  << setiosflags(ios::fixed);
    cout << "{1/(2*Pi)^2*NIntegrate[";
    if(m1) cout << "Cos["<<m1<<"*phi1]*";
    if(m2) cout << "Cos["<<m2<<"*phi2]*";
    cout << "(\n";
    for  (int i1=0;i1<(m1?2*m1:1);i1++) {
      for(int i2=0;i2<(m2?2*m2:1);i2++) {
	cout << "(";
	if((i1+i2)%2==1) cout << "-";
	cout << "1)/(\n";
	if(n11) {
	  cout        << "("<<mexp(a11)
		      << "+"<<mexp(b1 )<< "*Cos[phi1";
	  if(m1) cout << "+"<<i1<<"*Pi/"<<m1;
	  cout        <<"])^"<<n11<<"\n";
	}
	if(n12) { 
	  cout        << "("<<mexp(a12)
		      << "+"<<mexp(b1 )<< "*Cos[phi1";
	  if(m1) cout << "+"<<i1<<"*Pi/"<<m1;
	  cout        <<"])^"<<n12<<"\n";
	}
	cout          << "("<<mexp(aM )
		      << "+"<<mexp(bM1)<< "*Cos[phi1";
	if(m1) cout   << "+"<<i1<<"*Pi/"<<m1;
	cout          <<"]";
	cout          << "+"<<mexp(bM2)<< "*Cos[phi2";
	if(m2) cout   << "+"<<i2<<"*Pi/"<<m2;
	cout          <<"])\n";
	if(n21) {
	  cout        << "("<<mexp(a21)
		      << "+"<<mexp(b2 )<< "*Cos[phi2";
	  if(m2) cout << "+"<<i2<<"*Pi/"<<m2;
	  cout        <<"])^"<<n21<<"\n";
	}
	if(n22) {
	  cout        << "("<<mexp(a22)
		      << "+"<<mexp(b2 )<< "*Cos[phi2";
	  if(m2) cout << "+"<<i2<<"*Pi/"<<m2;
	  cout        <<"])^"<<n22<<"\n";
	}
	
	cout   << ")\n";
	if(i2!=2*m2-1) if(m2) cout << "+\n";
      }
      if(i1!=2*m1-1) if(m1) cout << "+\n";
    }
    cout        << "),{phi1,0";
    if(m1) cout << "+Pi/"<<2*m1;
    cout        <<",2*Pi";
    if(m1) cout <<    "/"<<2*m1;
    if(m1) cout << "+Pi/"<<2*m1;
    cout        <<"},{phi2,0";
    if(m2) cout << "+Pi/"<<2*m2;
    cout        <<",2*Pi";
    if(m2) cout <<    "/"<<2*m2;
    if(m2) cout << "+Pi/"<<2*m2;
    cout        <<"}],\n";
    cout << mexp(ret) << "}\n";
  }
  return ret;
} // cosnn1nnint
void ComputeEfficiency( TH1& hist_pass, TH1& hist_fail)
{


  TString effType = hist_pass.GetName();
  effType.ReplaceAll("Zmass","");
  effType.ReplaceAll("Pass","");
 
  double lowerLim = 0.0;
  double upperLim = 1.0;
  double numerator = hist_pass.Integral();
  double nfails    = hist_fail.Integral();
  double bkgFractionInNum = 0.0;
  double bkgFractionInFail = 0.0;

  nfails  *= (1.0 - bkgFractionInFail); 
  numerator *= (1.0 - bkgFractionInNum); 

  double denominator = numerator + nfails;
  double eff = numerator/ denominator;
  ClopperPearsonLimits(numerator, denominator, lowerLim, upperLim);
  double errUp = upperLim -eff;
  double errLo = eff -  lowerLim;

/*
  // ********** Make and save Canvas for the plots ********** //
  gROOT->ProcessLine(".L ~/tdrstyle.C");
  setTDRStyle();
  tdrStyle->SetErrorX(0.5);
  tdrStyle->SetPadLeftMargin(0.19);
  tdrStyle->SetPadRightMargin(0.10);
  tdrStyle->SetPadBottomMargin(0.15);
  tdrStyle->SetLegendBorderSize(0);
  tdrStyle->SetTitleYOffset(1.5);
  char temp[100];

  TString cname = TString("plot_") + effType;
  cname.ReplaceAll("Gsf","ScToGsf");
  cname.ReplaceAll("Id","GsfToWP");
  cname.Append("_Pass");
  TCanvas* c = new TCanvas(cname,cname,500,500);
  hist_pass.Draw("E1");
  TPaveText *plotlabel4 = new TPaveText(0.6,0.82,0.8,0.87,"NDC");
   plotlabel4->SetTextColor(kBlack);
   plotlabel4->SetFillColor(kWhite);
   plotlabel4->SetBorderSize(0);
   plotlabel4->SetTextAlign(12);
   plotlabel4->SetTextSize(0.03);
   sprintf(temp, "Signal = %.2f #pm %.2f", numerator, sqrt(numerator) );
   plotlabel4->AddText(temp);
  TPaveText *plotlabel5 = new TPaveText(0.6,0.77,0.8,0.82,"NDC");
   plotlabel5->SetTextColor(kBlack);
   plotlabel5->SetFillColor(kWhite);
   plotlabel5->SetBorderSize(0);
   plotlabel5->SetTextAlign(12);
   plotlabel5->SetTextSize(0.03);
   sprintf(temp, "Bkg fraction = %.2f", bkgFractionInNum);
   plotlabel5->AddText(temp);
  TPaveText *plotlabel6 = new TPaveText(0.6,0.87,0.8,0.92,"NDC");
   plotlabel6->SetTextColor(kBlack);
   plotlabel6->SetFillColor(kWhite);
   plotlabel6->SetBorderSize(0);
   plotlabel6->SetTextAlign(12);
   plotlabel6->SetTextSize(0.03);
   plotlabel6->AddText("Passing probes");
  TPaveText *plotlabel7 = new TPaveText(0.6,0.72,0.8,0.77,"NDC");
   plotlabel7->SetTextColor(kBlack);
   plotlabel7->SetFillColor(kWhite);
   plotlabel7->SetBorderSize(0);
   plotlabel7->SetTextAlign(12);
   plotlabel7->SetTextSize(0.03); 
   sprintf(temp, "Eff = %.3f + %.3f - %.3f", eff, errUp, errLo); 
   plotlabel7->AddText(temp);
  plotlabel4->Draw();
  plotlabel5->Draw();
  plotlabel6->Draw();
  plotlabel7->Draw();
  c->SaveAs( cname + TString(".eps"));
  c->SaveAs( cname + TString(".gif"));
  //c->SaveAs( cname + TString(".root"));
  delete c;


  cname.ReplaceAll("_Pass", "_Fail"); 
  TCanvas* c2 = new TCanvas(cname,cname,500,500);
  hist_fail.Draw("E1");

  TPaveText *plotlabel4 = new TPaveText(0.6,0.82,0.8,0.87,"NDC");
   plotlabel4->SetTextColor(kBlack);
   plotlabel4->SetFillColor(kWhite);
   plotlabel4->SetBorderSize(0);
   plotlabel4->SetTextAlign(12);
   plotlabel4->SetTextSize(0.03);
   sprintf(temp, "Signal = %.2f #pm %.2f", nfails, sqrt(nfails) );
   plotlabel4->AddText(temp);
  TPaveText *plotlabel5 = new TPaveText(0.6,0.77,0.8,0.82,"NDC");
   plotlabel5->SetTextColor(kBlack);
   plotlabel5->SetFillColor(kWhite);
   plotlabel5->SetBorderSize(0);
   plotlabel5->SetTextAlign(12);
   plotlabel5->SetTextSize(0.03);
   sprintf(temp, "Bkg fraction = %.2f", bkgFractionInFail);
   plotlabel5->AddText(temp);
  TPaveText *plotlabel6 = new TPaveText(0.6,0.87,0.8,0.92,"NDC");
   plotlabel6->SetTextColor(kBlack);
   plotlabel6->SetFillColor(kWhite);
   plotlabel6->SetBorderSize(0);
   plotlabel6->SetTextAlign(12);
   plotlabel6->SetTextSize(0.03);
   plotlabel6->AddText("Failing probes");
  TPaveText *plotlabel7 = new TPaveText(0.6,0.72,0.8,0.77,"NDC");
   plotlabel7->SetTextColor(kBlack);
   plotlabel7->SetFillColor(kWhite);
   plotlabel7->SetBorderSize(0);
   plotlabel7->SetTextAlign(12);
   plotlabel7->SetTextSize(0.03);
   sprintf(temp, "Eff = %.3f + %.3f - %.3f", eff, errUp, errLo);
   plotlabel7->AddText(temp);
   plotlabel4->Draw();
   plotlabel5->Draw();
   plotlabel6->Draw();
   plotlabel7->Draw();

     c2->SaveAs( cname + TString(".eps"));
    c2->SaveAs( cname + TString(".gif"));
  //c2->SaveAs( cname + TString(".root"));
  delete c2;
*/
  // cout << "########################################" << endl;
  effType.ReplaceAll("Gsf","");
  effType.ReplaceAll("Id95_","");
  effType.ReplaceAll("Id95","");
  effType.ReplaceAll("Id80_","");
  effType.ReplaceAll("Id80","");
  effType.ReplaceAll("HLT95_","");
  effType.ReplaceAll("HLT95","");
  effType.ReplaceAll("HLT80_","");
  effType.ReplaceAll("HLT80","");

 char* effTypeToPrint = (char*) effType;

  cout << effTypeToPrint << "    " 
       << setiosflags(ios::fixed) << setprecision(4) << eff 
       << " + " << errUp << " - " <<  errLo 
       << setiosflags(ios::fixed) << setprecision(0)
       << "    " << numerator << "    "  << nfails << endl;
  //cout << "########################################" << endl;

}
Exemple #10
0
sim_results simrun( const sim_parameters par, const string dir_init )
{
  // ----- PREPARE SIMULATION -----

  // assume something went wrong until we are sure it didn't
  sim_results res;
  res.success = false;

  // make a folder to work in
  stringstream tmp;
  tmp << setfill( '0' );
  tmp << "./" << dir_init << '/';
  const string dir = tmp.str();
  tmp.str( "" );
  // folder for images of the model
  if ( par.take_images != 0 ) {
    tmp << dir << "images/" ;
    const string image_dir = tmp.str();
    tmp.str( "" );
    if ( system( ( "mkdir " + image_dir ).c_str() ) != 0 ) {
      cout << "ERROR while making the image directory " << dir << endl;
      return res;
    }
  }

  // start a logfile
  ofstream run_log( ( dir + "run.log" ).c_str() );
  if ( !run_log.is_open() ) {
    cout << "ERROR while opening the run log file in " << dir << endl;
    return res;
  }
  run_log.precision( numeric_limits<double>::digits10 + 1 );

  // write the simulations parameters to the logfile
  run_log << "Simulation running in " << dir
          << endl << endl
          << "--- PARAMETERS ---" << endl
          << "system          = " << par.system_type << endl
          << "N               = " << par.N << endl
          << "periodic        = " << par.periodic << endl
          << "init            = " << par.init << endl
          << "drysweeps       = " << par.drysweeps << endl
          << "bins            = " << par.bins << endl
          << "binwidth        = " << par.binwidth << endl
          << "intersweeps     = " << par.intersweeps << endl
          << "smode_perbin    = " << par.smode_perbin << endl
          << "smode_permcs    = " << par.smode_permcs << endl
          << "J               = " << par.J << endl
          << "g               = " << par.g << endl
          << "B               = " << par.B << endl
          << "T               = " << par.T << endl << endl;
  run_log.flush();


  // ----- RUN SIMULATION -----

  time_t rawtime;
  time( &rawtime );
  run_log << ctime( &rawtime ) << "-> creating the system\n\n";
  run_log.flush();

  // create a new model
  SystemModel* model;
  if ( par.system_type == 1 ) {
    model = new IsingModel1d( par.N, par.periodic, par.J, par.B,
                              par.T, par.use_fsize_correction, dir );
  } else if ( par.system_type == 2 ) {
    model = new IsingModel2d( par.N, par.periodic, par.J, par.B, par.T,
                              par.use_fsize_correction, dir );
  } else if ( par.system_type == 3 ) {
    model = new IsingModel2dWolff( par.N, par.periodic, par.J, par.T,
                                   par.use_fsize_correction, dir );
  } else if ( par.system_type == 4 ) {
    model = new IsingModel2dDipole( par.N, par.periodic, par.J, par.g, par.B,
                                    par.T, dir );
  } else if ( par.system_type == 5 ) {
    model = new Ising2dDipSqr( par.N, par.periodic, par.J, par.g, par.B,
                               par.T, par.use_fsize_correction, dir );
  } else if ( par.system_type == 6 ) {
    model = new Ising2dDipHC( par.N, par.J, par.g, par.B,
                              par.T, par.use_fsize_correction, dir );
  // ___ ADD CUSTOM SYSTEM MODELS HERE ___

  } else {
    cout << "ERROR creating the model system in " << dir << endl;
    return res;
  }
  if ( model->prepare( par.init ) == false ) {
    cout << "ERROR preparing the models spins in " << dir << endl;
    delete model;
    return res;
  }
  unsigned int spin_count = model->spin_count();

  // open measurement logfiles
  ofstream h_log( ( dir + "h.log" ).c_str() );
  ofstream m_log( ( dir + "m.log" ).c_str() );
  if ( !( h_log.is_open() && m_log.is_open() ) ) {
    cout << "ERROR while opening measurement log files in " << dir << endl;
    delete model;
    return res;
  }

  // initialize binning array
  vector <bin_results> binres;
  // initialize the magnetization data log (needed for autocorr calc only)
  vector <float> m_memlog;
  // initialize the spin-spin correlation
  vector <double> ss_corr;
  try {
    // try to allocate enough memory ...
    binres.reserve( par.bins );
    unsigned int ss_corr_size = model->ss_corr().size();
    ss_corr.reserve( ss_corr_size );
    for ( unsigned int i = 0; i < ss_corr_size; i++ ) {
      ss_corr.push_back( 0 );
    }
    if ( par.calc_autocorr ) {
      m_memlog.reserve( par.bins * par.binwidth );
    }
  } catch ( bad_alloc ) {
    cout << "ERROR while allocating memory in " << dir << endl;
    delete model;
    return res;
  }
  run_log
      << 1 + ( ( sizeof( m_memlog ) + m_memlog.capacity() * sizeof( float )
         + sizeof( binres ) + binres.capacity() * sizeof( bin_results ) ) / 1024 )
      << "KiB of memory reserved\n\n";


  time( &rawtime );
  run_log << ctime( &rawtime ) << "-> relaxing the system\n\n";
  run_log.flush();

  // perform dry runs to reach thermal equilibrium
  model->mcstep_dry( par.drysweeps );

  time( &rawtime );
  run_log << ctime( &rawtime ) << "-> simulation started\n\n";
  run_log.flush();


  // binning loop
  for ( unsigned int bin = 0; bin < par.bins; bin++ ) {
    //double startTime = current_time();

    // initialize variables to measure the systems properties
    double h = 0, h2 = 0;
    double m = 0, m2 = 0;
    // sample loop
    for ( unsigned int sample = 0; sample < par.binwidth; sample++ ) {
      double thissample_h = model->h();
      double thissample_m = model->m();
      // write this sample's properties to the logfile
      h_log << model->t() << ' ' << thissample_h << endl;
      m_log << model->t() << ' ' << thissample_m << endl;
      if ( par.calc_autocorr ) {
        m_memlog.push_back( float( thissample_m ) );
      }
      // remember the sample's properties to calculate their mean value
      h 	+= thissample_h;
      h2 	+= thissample_h * thissample_h;
      m 	+= thissample_m;
      m2 	+= thissample_m * thissample_m;
      // make an image of the system
      if ( ( par.take_images != 0 ) &&
           ( ( bin * par.binwidth + sample ) % par.take_images == 0 ) ) {
        tmp << dir << "images/"	<< setw( 9 ) << model->t() << ".png";
        const string image_file = tmp.str();
        tmp.str( "" );
        model->get_image().write( image_file );
      }
      // flip the spins!
      for ( unsigned int step = 0; step < par.intersweeps; step++ ) {
        model->special_permcs( par.smode_permcs );
        model->mcstep();
      }
    }

    if ( par.calc_sscorr ) {
      // spin-spin correlation calculation
      vector <double> ss_corr_thisbin = model->ss_corr();
      for ( unsigned int i = 0; i < par.N; i++ ) {
        ss_corr[i] += ss_corr_thisbin[i];
      }
    }

    // invoke the systems special function
    model->special_perbin( par.smode_perbin );

    // calculate mean
    h = h / par.binwidth;
    h2 = h2 / par.binwidth;
    m = m / par.binwidth;
    m2 = m2 / par.binwidth;

    // write the bin's results to binres
    bin_results this_binres;
    this_binres.h			= h;
    this_binres.h2		= h2;
    this_binres.m 		= m;
    this_binres.m2		= m2;
    binres.push_back( this_binres );

    //cout << "Bin: " << current_time() - startTime <<  "ms" << endl;
  }

  // all measurements done ... let's tidy things up
  delete model;
  h_log.close();
  m_log.close();

  // calculate simulation results from the individual bins
  double h  = 0, 	sigma3_h  = 0;
  double h2 = 0, 	sigma3_h2 = 0;
  double m  = 0, 	sigma3_m  = 0;
  double m2 = 0, 	sigma3_m2 = 0;
  // average values
  for ( unsigned int bin = 0; bin < par.bins; bin++ ) {
    h  += binres[bin].h  / par.bins;
    h2 += binres[bin].h2 / par.bins;
    m  += binres[bin].m  / par.bins;
    m2 += binres[bin].m2 / par.bins;
  }
  if ( par.calc_sscorr ) {
    for ( unsigned int i = 0; i < par.N; i++ ) {
      ss_corr[i] /= par.bins;
    }
  }
  // calculate susceptibilities
  double c = spin_count / par.T / par.T * ( h2 - h * h );
  double x = spin_count / par.T * ( m2 - m * m );

  // calculate variance of the results from the bins first
  for ( unsigned int bin = 0; bin < par.bins; bin++ ) {
    sigma3_h 	+= pow( ( binres[bin].h	 - h ),  2 ) / par.bins;
    sigma3_h2	+= pow( ( binres[bin].h2 - h2 ), 2 ) / par.bins;
    sigma3_m 	+= pow( ( binres[bin].m  - m ),  2 ) / par.bins;
    sigma3_m2	+= pow( ( binres[bin].m2 - m2 ), 2 ) / par.bins;
  }
  // use variances to calculate the error of the average
  sigma3_h 	= 3 * sqrt( sigma3_h  / par.bins );
  sigma3_h2	= 3 * sqrt( sigma3_h2 / par.bins );
  sigma3_m 	= 3 * sqrt( sigma3_m  / par.bins );
  sigma3_m2	= 3 * sqrt( sigma3_m2 / par.bins );

  // calculate errors of the susceptibilities (bootstrapping)
  double sigma3_c = 0, sigma3_x = 0;
  gsl_rng* rng;  // make a new random number generator ...
  rng = gsl_rng_alloc( gsl_rng_mt19937 );
  gsl_rng_set( rng, rand() );
  for ( unsigned int bsset = 0; bsset < par.bins; bsset++ ) {
    double bsset_h = 0, bsset_h2 = 0, bsset_m = 0, bsset_m2 = 0;
    for ( unsigned int bssample = 0; bssample < par.bins; bssample++ ) {
      unsigned int bssample_this = gsl_rng_uniform_int( rng, par.bins );
      bsset_h  += binres[bssample_this].h;
      bsset_h2 += binres[bssample_this].h2;
      bsset_m  += binres[bssample_this].m;
      bsset_m2 += binres[bssample_this].m2;
    }
    bsset_h /= par.bins;
    bsset_h2 /= par.bins;
    bsset_m /= par.bins;
    bsset_m2 /= par.bins;

    // calculate the c and x for the selected set ...
    double bsset_c = spin_count / par.T / par.T
                     * ( bsset_h2 - bsset_h * bsset_h );
    double bsset_x = spin_count / par.T * ( bsset_m2 - bsset_m * bsset_m );

    sigma3_c += pow( ( bsset_c - c ), 2 ) / par.bins;
    sigma3_x += pow( ( bsset_x - x ), 2 ) / par.bins;
  }
  sigma3_c = 3 * sqrt( sigma3_c );
  sigma3_x = 3 * sqrt( sigma3_x );
  gsl_rng_free( rng );

  time( &rawtime );
  run_log << ctime( &rawtime ) << "-> simulation finished";
  if ( par.calc_autocorr ) {
    run_log << " ... starting autocorrelation calculation";
  }
  run_log << "\n\n";
  run_log.flush();


  // ----- AUTOCORRELATION CALCULATION -----

  double tau = 0;
  if ( par.calc_autocorr ) {
    // open output file
    ofstream acout_log( ( dir + "ac.log" ).c_str() );
    if ( !acout_log.is_open() ) {
      cout << "ERROR while opening the acout_log file in " << dir << endl;
      return res;
    }
    // loop over different delta_t
    double norm = 1;
    for ( unsigned int d = 0; d < par.binwidth; d++ ) {
      double product = 0;
      unsigned int acsamples = m_memlog.size() - d;
      for ( unsigned int i = 0; i < acsamples; i++ ) {
        unsigned int sample = i;
        product += m_memlog[sample] * m_memlog[sample + d];
      }
      product = product / acsamples;
      if ( d == 0 ) {
        norm = ( product - m * m );
      }
      tau += ( product - m * m ) / norm * par.intersweeps;
      acout_log << d* par.intersweeps << ' '
                << ( product - m * m ) / norm << endl;
    }
    acout_log.close();

    // estimate if bins are correlated
    if ( tau > ( par.binwidth * par.intersweeps ) / 4 ) {
      cout << "WARNING: bins correlated in " << dir << endl;
      run_log << "!!!!! WARNING !!!!!\n"
              << "Bins correlated: Errors and autocorr time are underestimated!"
              << endl << endl;
      run_log.flush();
    }
  }


  // ----- WRITE SPIN-SPIN CORRELATIONS TO DISK -----

  if ( par.calc_sscorr ) {
    // correction for wrap-around errors with periodic boundaries
    if ( par.periodic ) {
      for ( unsigned int i = 1; i < ss_corr.size(); i++ ) {
        ss_corr[i] = ( ss_corr[i] + ss_corr[ss_corr.size() - 1] ) / 2;
        ss_corr.pop_back();
      }
    }

    // open output file
    ofstream sscorr_log( ( dir + "sscorr.log" ).c_str() );
    if ( !sscorr_log.is_open() ) {
      cout << "ERROR while opening the sscorr_log file in " << dir << endl;
      return res;
    }
    double norm = ss_corr[0] - m * m;
    for ( unsigned int i = 0; i < ss_corr.size(); i++ ) {
      sscorr_log << i << ' ' << ( ss_corr[i] - m * m ) / norm
                 << ' ' << ss_corr[i] / ss_corr[0] << endl;
    }
    sscorr_log.close();
  }


  // ---- RESULT OUTPUT -----

  // write simulation results to the output struct
  res.h = h;
  res.sigma3_h = sigma3_h;
  res.c = c;
  res.sigma3_c = sigma3_c;
  res.m = m;
  res.sigma3_m = sigma3_m;
  res.x = x;
  res.sigma3_x = sigma3_x;
  res.tau = tau;

  // write simulation results to the logfile
  run_log.precision( numeric_limits<float>::digits10 + 1 ); 
  run_log.setf( ios::scientific );
  run_log.setf( ios::showpos );
  run_log << "--- RESULTS ---\n"
          << "h	= " << h << "  +-  " << sigma3_h << endl
          << "c	= " << c << "  +-  " << sigma3_c << endl
          << "m	= " << m << "  +-  " << sigma3_m << endl
          << "chi	= " << x << "  +-  " << sigma3_x << endl
          << "tau = " << tau 		<< "\n\n";
  run_log.flush();

  // write results to a pyxplot readable output file
  ofstream results_file( ( dir + "results.dat" ).c_str() );
  if ( !results_file.is_open() ) {
    cout << "FATAL ERROR: unable to create results.dat in " << dir << endl;
    return res;
  }
  results_file << setiosflags( ios::scientific );
  results_file.setf( ios::showpos );
  results_file.precision( numeric_limits<float>::digits10 + 1 );
  results_file << par.N << ' '
               << par.J << ' '
               << par.g << ' '
               << par.B << ' '
               << par.T << ' '
               << res.h << ' ' << res.sigma3_h << ' '
               << res.c << ' ' << res.sigma3_c << ' '
               << res.m << ' ' << res.sigma3_m << ' '
               << res.x << ' ' << res.sigma3_x << ' '
               << res.tau		<< endl;
  results_file.close();


  // ----- PLOTTING -----

  if ( par.run_plot ) {
    time( &rawtime );
    run_log << ctime( &rawtime ) << "-> starting to plot the results\n\n";
    run_log.flush();
  }

  // run_plot
  ofstream run_plot( ( dir + "run_plot.gnu" ).c_str() );
  if ( !run_plot.is_open() ) {
    cout << "ERROR while opening run_plot.gnu in " << dir << endl;
    return res;
  }
  tmp << "system_type = " << par.system_type
      << ", N = " << par.N << ", periodic = " << par.periodic
      << ", init = " << par.init << ", drysweeps = " << par.drysweeps
      << ", bins = " << par.bins << ", binwidth = " << par.binwidth
      << ", intersweeps = " << par.intersweeps
      << ", J = " << par.J << ", g = " << par.g
      << ", B = " << par.B << ", T = " << par.T;
  int plot_size = ( par.bins * par.binwidth < 1600 ) ?
                  1600 : min( ( uint )10000, par.bins * par.binwidth );
  run_plot <<
           "	set terminal pngcairo size " << plot_size << ",600 \n\
	set output 'run_plot.png' \n\n\
	set multiplot layout 2,1 title '" << tmp.str() << "'\n\
	set grid x y \n\
	set mxtics 10 \n\
	set key top left \n\
	set arrow from graph 0,first " << m << " to graph 1,first " << m
           << " ls -1 lw 2 nohead" << endl;
  for ( unsigned int bin = 0; bin < par.bins; bin++ ) {
    double sep = double( bin ) / double( par.bins );
    run_plot <<"\
    set arrow from graph " << sep << ",0 to graph " << sep << ",1 nohead\n\
		set arrow from graph " << sep << ", first " << binres[bin].m << "\
		to graph " << sep + 1 / double( par.bins ) << ", first " << binres[bin].m
             << " ls -1 lw 1 nohead\n";
  }
  run_plot << "\
  plot 'm.log' with lines ls 2 title 'magnetization ("
  << m << " +- "	<< sigma3_m << ")' \n\
	unset arrow\n\
	set arrow from graph 0,first " << h << " to graph 1,first "
  << h << " ls -1 lw 2 nohead" << endl;
  for ( unsigned int bin = 0; bin < par.bins; bin++ ) {
    double sep = double( bin ) / double( par.bins );
    run_plot << "\
    set arrow from graph " << sep << ",0 to graph " << sep << ",1 nohead\n\
		set arrow from graph " << sep << ", first " << binres[bin].h << "\
		to graph " << sep + 1 / double( par.bins ) << ", first " << binres[bin].h
    << " ls -1 lw 1 nohead\n";
  }
  run_plot << "\
  plot 'h.log' with lines ls 1 title 'energy per spin ("
  << h << " +- " << sigma3_h << ")' \n";
  tmp.str( "" );
  run_plot.close();

  if ( par.run_plot && par.bins * par.binwidth <= 1e5 ) {
    if ( system( ( "cd " + dir + " ; gnuplot run_plot.gnu" ).c_str() ) != 0 ) {
      cout << "ERROR while running gnuplot run_plot.gnu in " << dir << endl;
      return res;
    }
  }

  // magnetization and energy histogram plots
  ofstream histo_plot( ( dir + "histo_plot.pyx" ).c_str() );
  if ( !histo_plot.is_open() ) {
    cout << "ERROR while opening histo_plot.gnu in " << dir << endl;
    return res;
  }
  histo_plot <<
             "	set terminal pdf\n\
	set output 'mhisto_plot.pdf'\n\
	set title 'magnetization histogram'\n\
	histogram m() 'm.log' using $2 binorigin 0.005 binwidth 0.01\n\
	plot m(x) with boxes notitle \n\
	set output 'hhisto_plot.pdf'\n\
	set title 'energy histogram'\n\
	histogram h() 'h.log' using $2 binorigin 0.005 binwidth 0.01\n\
	plot h(x) with boxes notitle";
  histo_plot.close();
  if ( par.run_plot ) {
    if ( system( ( "cd " + dir + " ; pyxplot histo_plot.pyx" ).c_str() ) != 0 ) {
      cout << "ERROR running pyxplot histo_plot.pyx in " << dir << endl;
      return res;
    }
  }

  // ac_plot
  if ( par.calc_autocorr ) {
    ofstream ac_plot( ( dir + "ac_plot.gnu" ).c_str() );
    if ( !ac_plot.is_open() ) {
      cout << "ERROR while opening ac_plot.gnu in " << dir << endl;
      return res;
    }
    ac_plot <<
            "		set terminal pngcairo size 1000,600\n\
		set output 'ac_plot.png'\n\
		set grid x y\n\
		set arrow from graph 0, first 0 to graph 1, first 0 nohead lw 2\n\
		set title 'magnetization autocorrelation'\n\
		set arrow from first " << tau << ", graph 0 to first "
    << tau << ", graph 1 nohead\n\
		plot 'ac.log' with linespoints notitle";
    ac_plot.close();
    if ( par.run_plot ) {
      if ( system( ( "cd " + dir + " ; gnuplot ac_plot.gnu" ).c_str() ) != 0 ) {
        cout << "ERROR while running gnuplot ac_plot.gnu in " << dir << endl;
        return res;
      }
    }
  }

  // sscorr_plot
  if ( par.calc_sscorr ) {
    ofstream sscorr_plot( ( dir + "sscorr_plot.gnu" ).c_str() );
    if ( !sscorr_plot.is_open() ) {
      cout << "ERROR while opening sscorr_plot.gnu in " << dir << endl;
      return res;
    }
    sscorr_plot <<
                " 		set terminal pngcairo size 1000,600\n\
		set output 'sscorr_plot.png'\n\
		set grid x y\n\
		set arrow from graph 0, first 0 to graph 1, first 0 nohead lw 2\n\
		set title 'spin-spin correlation'\n\
		plot 'sscorr.log' u 1:2 with linespoints title '<s1s2> - <m>^2', \\\n\
			 'sscorr.log' u 1:3 with linespoints title '<s1s2> '";
    sscorr_plot.close();
    if ( par.run_plot ) {
      if ( system( ( "cd " + dir + " ; gnuplot sscorr_plot.gnu" ).c_str() )
                                                                        != 0 ) {
        cout << "ERROR running gnuplot sscorr_plot.gnu in " << dir << endl;
        return res;
      }
    }
  }
Exemple #11
0
void BenchMarkAll(double t)
{
	logtotal = 0;
	logcount = 0;

	cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl;
	cout << "<THEAD><TR><TH>Algorithm<TH>Bytes Processed<TH>Time Taken<TH>Megabytes(2^20 bytes)/Second\n<TBODY>" << endl;

	BenchMarkKeyless<CRC32>("CRC-32", t);
	BenchMarkKeyless<Adler32>("Adler-32", t);
	BenchMarkKeyless<MD2>("MD2", t);
	BenchMarkKeyless<MD5>("MD5", t);
	BenchMarkKeyless<SHA>("SHA-1", t);
	BenchMarkKeyless<SHA256>("SHA-256", t);
	BenchMarkKeyless<SHA512>("SHA-512", t);
	BenchMarkKeyless<HAVAL3>("HAVAL (pass=3)", t);
	BenchMarkKeyless<HAVAL4>("HAVAL (pass=4)", t);
	BenchMarkKeyless<HAVAL5>("HAVAL (pass=5)", t);
#ifdef WORD64_AVAILABLE
	BenchMarkKeyless<Tiger>("Tiger", t);
#endif
	BenchMarkKeyless<RIPEMD160>("RIPE-MD160", t);
	BenchMarkKeyless<PanamaHash<false> >("Panama Hash (little endian)", t);
	BenchMarkKeyless<PanamaHash<true> >("Panama Hash (big endian)", t);
	BenchMarkKeyed<MDC<MD5> >("MDC/MD5", t);
	BenchMarkKeyed<LREncryption<MD5> >("Luby-Rackoff/MD5", t);
	BenchMarkKeyed<DESEncryption>("DES", t);
	BenchMarkKeyed<DES_XEX3_Encryption>("DES-XEX3", t);
	BenchMarkKeyed<DES_EDE3_Encryption>("DES-EDE3", t);
	BenchMarkKeyed<IDEAEncryption>("IDEA", t);
	BenchMarkKeyed<RC2Encryption>("RC2", t);
	BenchMarkKeyed<RC5Encryption>("RC5 (r=16)", t);
	BenchMarkKeyed<BlowfishEncryption>("Blowfish", t);
	BenchMarkKeyed<Diamond2Encryption>("Diamond2", t);
	BenchMarkKeyed<Diamond2LiteEncryption>("Diamond2 Lite", t);
	BenchMarkKeyed<ThreeWayDecryption>("3-WAY", t);
	BenchMarkKeyed<TEAEncryption>("TEA", t);
	BenchMarkKeyed<SAFER_SK64_Encryption>("SAFER (r=8)", t);
	BenchMarkKeyed<GOSTEncryption>("GOST", t);
#ifdef WORD64_AVAILABLE
	BenchMarkKeyed<SHARKEncryption>("SHARK (r=6)", t);
#endif
	BenchMarkKeyed<CAST128Encryption>("CAST-128", t);
	BenchMarkKeyed<CAST256Encryption>("CAST-256", t);
	BenchMarkKeyed<SquareEncryption>("Square", t);
	BenchMarkKeyed<SKIPJACKEncryption>("SKIPJACK", t);
	BenchMarkKeyed<RC6Encryption>("RC6", t);
	BenchMarkKeyed<MARSEncryption>("MARS", t);
	BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (128-bit key)", t, 16);
	BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (192-bit key)", t, 24);
	BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (256-bit key)", t, 32);
	BenchMarkKeyed<TwofishEncryption>("Twofish", t);
	BenchMarkKeyed<SerpentEncryption>("Serpent", t);
	BenchMarkKeyed<ARC4>("ARC4", t);
	BenchMarkKeyed<SEAL>("SEAL", t);
	{
		WAKEEncryption c(key, new BitBucket);
		BenchMark("WAKE", c, t);
	}
	BenchMarkKeyed<PanamaCipher<false> >("Panama Cipher (little endian)", t);
	BenchMarkKeyed<PanamaCipher<true> >("Panama Cipher (big endian)", t);
	BenchMarkKeyed<SapphireEncryption>("Sapphire", t);
	BenchMarkKeyed<MD5MAC>("MD5-MAC", t);
	BenchMarkKeyed<XMACC<MD5> >("XMACC/MD5", t);
	BenchMarkKeyed<HMAC<MD5> >("HMAC/MD5", t);
	BenchMarkKeyed<CBC_MAC<RijndaelEncryption> >("CBC-MAC/Rijndael", t);
	BenchMarkKeyed<DMAC<RijndaelEncryption> >("DMAC/Rijndael", t);

	{
		Integer p("CB6C,B8CE,6351,164F,5D0C,0C9E,9E31,E231,CF4E,D551,CBD0,E671,5D6A,7B06,D8DF,C4A7h");
		Integer q("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,A2AFh");
		Integer s("63239752671357255800299643604761065219897634268887145610573595874544114193025997412441121667211431");
		BlumBlumShub c(p, q, s);
		BenchMark("BlumBlumShub 512", c, t);
	}
	{
		Integer p("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,9E2C,"
				  "8572,64C3,4CF4,188A,44D4,2130,1135,7982,6FF6,EDD3,26F0,5FAA,BAF4,A81E,7ADC,B80Bh");
		Integer q("C8B9,5797,B349,6BA3,FD72,F2C0,A796,8A65,EE0F,B4BA,272F,4FEE,4DB1,06D5,ECEB,7142,"
				  "E8A8,E5A8,6BF9,A32F,BA37,BACC,8A75,8A6B,2DCE,D6EC,B515,980A,4BB1,08FB,6F2C,2383h");
		Integer s("3578,8F00,2965,71A4,4382,699F,45FD,3922,8238,241B,CEBA,0543,3443,E8D9,12FB,AC46,"
				  "7EC4,8505,EC9E,7EE8,5A23,9B2A,B615,D0C4,9448,F23A,ADEE,E850,1A7A,CA30,0B5B,A408,"
				  "D936,21BA,844E,BDD6,7848,3D1E,9137,CC87,DAA5,773B,D45A,C8BB,5392,1393,108B,6992,"
				  "74E3,C5E2,C235,A321,0111,3BA4,BAB4,1A2F,17EE,C371,DE67,01C9,0F3D,907A,B252,9BDDh");
		BlumBlumShub c(p, q, s);
		BenchMark("BlumBlumShub 1024", c, t);
	}
	{
		Integer p("EB56,978A,7BA7,B5D9,1383,4611,94F5,4766,FCEF,CF41,958A,FC41,43D0,839F,C56B,B568,"
				  "4ED3,9E5A,BABB,5ACE,8B11,CEBC,88A2,7C12,FFEE,E6E8,CF0A,E231,5BC2,DEDE,80B7,32F6,"
				  "340E,D8A6,B7DE,C779,7EE5,0E16,9C88,FC9F,2A0E,EE6C,7D47,C5F2,6B06,EB8C,F1C8,2E67,"
				  "5B82,8C28,4FB8,542F,2874,C355,CEEE,7A54,1B06,A8AB,8B66,6A5C,9DB2,72B8,74F3,7BC7h");
		Integer q("EB6B,3645,4591,8343,7331,7CAC,B02E,4BB9,DEF5,8EDC,1772,DB9B,9571,5FAB,1CDD,4FB1,"
				  "7B9A,07CD,E715,D448,F552,CBBD,D387,C037,DE70,6661,F360,D0E8,D42E,292A,9321,DDCB,"
				  "0BF9,C514,BFAC,3F2C,C06E,DF64,A9B8,50D6,AC4F,B9E4,014B,5624,2B40,A0D4,5D0B,6DD4,"
				  "0989,D00E,0268,99AB,21DB,0BB4,DB38,84DA,594F,575F,95AC,1B70,45E4,96C8,C6AD,CE67h");
		Integer s("C75A,8A0D,E231,295F,C08A,1716,8611,D5EC,E9EF,B565,90EC,58C0,57D0,DA7D,C6E6,DB00,"
				  "2282,1CA7,EA31,D64E,768C,0B19,8563,36DF,2226,F4EC,74A4,2844,2E8D,37E8,53DC,0172,"
				  "5F56,8CF9,B444,CA02,78B3,17AF,7C78,D320,16AE,AC3D,B97F,7259,1B8F,9C84,6A16,B878,"
				  "0595,70BB,9C52,18B5,9100,9C1F,E85A,4035,06F3,5F38,7462,F01D,0462,BFBC,A4CD,4A45,"
				  "3A77,E7F8,DED1,D6EF,CEF7,0937,CD3F,3AF1,4F88,932D,6D4B,002C,3735,304C,C5D3,B88A,"
				  "B57B,24B6,5346,9B46,5153,B7ED,B216,C181,B1C6,C52E,CD2B,E0AA,B1BB,0A93,C92E,4F79,"
				  "4931,E303,7C8F,A408,8ACF,56CD,6EC0,76A2,5015,6BA4,4C50,C44D,53B9,E168,5F84,B381,"
				  "2514,10B2,00E5,B4D1,4156,A2FE,0BF6,6F33,0A1B,91C6,31B8,1C90,02F1,FB1F,C494,8B65h");
		BlumBlumShub c(p, q, s);
		BenchMark("BlumBlumShub 2048", c, t);
	}
	cout << "</TABLE>" << endl;

	cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl;
	cout << "<THEAD><TR><TH>Operation<TH>Iterations<TH>Total Time<TH>Milliseconds/Operation" << endl;
	cout << "<TBODY style=\"background: yellow\">" << endl;
	BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa512.dat", "RSA 512", t);
	BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi512.dat", "Rabin 512", t);
	BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum512.dat", "BlumGoldwasser 512", t);
	BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc512.dat", "LUC 512", t);
	BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc512.dat", "ElGamal 512", t);

	cout << "<TBODY style=\"background: white\">" << endl;
	BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa1024.dat", "RSA 1024", t);
	BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi1024.dat", "Rabin 1024", t);
	BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum1024.dat", "BlumGoldwasser 1024", t);
	BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc1024.dat", "LUC 1024", t);
	BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc1024.dat", "ElGamal 1024", t);
	BenchMarkCrypto<LUCELG_Decryptor, LUCELG_Encryptor>("lucc512.dat", "LUCELG 512", t);

	cout << "<TBODY style=\"background: yellow\">" << endl;
	BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa2048.dat", "RSA 2048", t);
	BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi2048.dat", "Rabin 2048", t);
	BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum2048.dat", "BlumGoldwasser 2048", t);
	BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc2048.dat", "LUC 2048", t);
	BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc2048.dat", "ElGamal 2048", t);
	BenchMarkCrypto<LUCELG_Decryptor, LUCELG_Encryptor>("lucc1024.dat", "LUCELG 1024", t);

	cout << "<TBODY style=\"background: white\">" << endl;
	BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa512.dat", "RSA 512", t);
	BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi512.dat", "Rabin 512", t);
	BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw512.dat", "RW 512", t);
	BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc512.dat", "LUC 512", t);
	BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr512.dat", "NR 512", t);
	BenchMarkSignature<DSAPrivateKey, DSAPublicKey>("dsa512.dat", "DSA 512", t);

	cout << "<TBODY style=\"background: yellow\">" << endl;
	BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa1024.dat", "RSA 1024", t);
	BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi1024.dat", "Rabin 1024", t);
	BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw1024.dat", "RW 1024", t);
	BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc1024.dat", "LUC 1024", t);
	BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr1024.dat", "NR 1024", t);
	BenchMarkSignature<DSAPrivateKey, DSAPublicKey>("dsa1024.dat", "DSA 1024", t);
	BenchMarkSignature<LUCELG_Signer<SHA>, LUCELG_Verifier<SHA> >("lucs512.dat", "LUCELG 512", t);

	cout << "<TBODY style=\"background: white\">" << endl;
	BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa2048.dat", "RSA 2048", t);
	BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi2048.dat", "Rabin 2048", t);
	BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw2048.dat", "RW 2048", t);
	BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc2048.dat", "LUC 2048", t);
	BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr2048.dat", "NR 2048", t);
	BenchMarkSignature<LUCELG_Signer<SHA>, LUCELG_Verifier<SHA> >("lucs1024.dat", "LUCELG 1024", t);

	cout << "<TBODY style=\"background: yellow\">" << endl;
	BenchMarkKeyAgreement<XTR_DH>("xtrdh171.dat", "XTR-DH 171", t);
	BenchMarkKeyAgreement<XTR_DH>("xtrdh342.dat", "XTR-DH 342", t);
	BenchMarkKeyAgreement<DH>("dh512.dat", "DH 512", t);
	BenchMarkKeyAgreement<DH>("dh1024.dat", "DH 1024", t);
	BenchMarkKeyAgreement<DH>("dh2048.dat", "DH 2048", t);
	BenchMarkKeyAgreement<LUCDIF>("lucd512.dat", "LUCDIF 512", t);
	BenchMarkKeyAgreement<LUCDIF>("lucd1024.dat", "LUCDIF 1024", t);
	BenchMarkKeyAgreement<MQV>("mqv512.dat", "MQV 512", t);
	BenchMarkKeyAgreement<MQV>("mqv1024.dat", "MQV 1024", t);
	BenchMarkKeyAgreement<MQV>("mqv2048.dat", "MQV 2048", t);

	cout << "<TBODY style=\"background: white\">" << endl;
	{
		Integer modulus("199999999999999999999999980586675243082581144187569");
		Integer a("659942,b7261b,249174,c86bd5,e2a65b,45fe07,37d110h");
		Integer b("3ece7d,09473d,666000,5baef5,d4e00e,30159d,2df49ah");
		Integer x("25dd61,4c0667,81abc0,fe6c84,fefaa3,858ca6,96d0e8h");
		Integer y("4e2477,05aab0,b3497f,d62b5e,78a531,446729,6c3fach");
		Integer r("100000000000000000000000000000000000000000000000151");
		Integer k(2);
		Integer d("76572944925670636209790912427415155085360939712345");

		ECP ec(modulus, a, b);
		ECP::Point P(x, y);
		P = ec.Multiply(k, P);
		ECP::Point Q(ec.Multiply(d, P));
		ECDecryptor<ECP> cpriv(ec, P, r, Q, d);
		ECEncryptor<ECP> cpub(cpriv);
		ECSigner<ECP, SHA> spriv(cpriv);
		ECVerifier<ECP, SHA> spub(spriv);
		ECDHC<ECP> ecdhc(ec, P, r, k);
		ECMQVC<ECP> ecmqvc(ec, P, r, k);

		BenchMarkEncryption("ECIES over GF(p) 168", cpub, t);
		BenchMarkDecryption("ECIES over GF(p) 168", cpriv, cpub, t);
		BenchMarkSigning("ECNR over GF(p) 168", spriv, t);
		BenchMarkVerification("ECNR over GF(p) 168", spriv, spub, t);
		BenchMarkKeyGen("ECDHC over GF(p) 168", ecdhc, t);
		BenchMarkAgreement("ECDHC over GF(p) 168", ecdhc, t);
		BenchMarkKeyGen("ECMQVC over GF(p) 168", ecmqvc, t);
		BenchMarkAgreement("ECMQVC over GF(p) 168", ecmqvc, t);
	}

	cout << "<TBODY style=\"background: yellow\">" << endl;
	{
		Integer r("3805993847215893016155463826195386266397436443");
		Integer k(12);
		Integer d("2065729449256706362097909124274151550853609397");

		GF2NT gf2n(155, 62, 0);
		byte b[]={0x7, 0x33, 0x8f};
		EC2N ec(gf2n, PolynomialMod2::Zero(), PolynomialMod2(b,3));
		EC2N::Point P(0x7B, 0x1C8);
		P = ec.Multiply(k, P);
		EC2N::Point Q(ec.Multiply(d, P));
		ECDecryptor<EC2N> cpriv(ec, P, r, Q, d);
		ECEncryptor<EC2N> cpub(cpriv);
		ECSigner<EC2N, SHA> spriv(cpriv);
		ECVerifier<EC2N, SHA> spub(spriv);
		ECDHC<EC2N> ecdhc(ec, P, r, k);
		ECMQVC<EC2N> ecmqvc(ec, P, r, k);

		BenchMarkEncryption("ECIES over GF(2^n) 155", cpub, t);
		BenchMarkDecryption("ECIES over GF(2^n) 155", cpriv, cpub, t);
		BenchMarkSigning("ECNR over GF(2^n) 155", spriv, t);
		BenchMarkVerification("ECNR over GF(2^n) 155", spriv, spub, t);
		BenchMarkKeyGen("ECDHC over GF(2^n) 155", ecdhc, t);
		BenchMarkAgreement("ECDHC over GF(2^n) 155", ecdhc, t);
		BenchMarkKeyGen("ECMQVC over GF(2^n) 155", ecmqvc, t);
		BenchMarkAgreement("ECMQVC over GF(2^n) 155", ecmqvc, t);
	}
	cout << "</TABLE>" << endl;

	cout << "Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/logcount) << endl;
}
Exemple #12
0
int main(){
	chdir(QUERY_DATA_PATH);

	EnvDB *env = new EnvDB();
	env->open();	
	
	BDBOpe db_r(env->getEnv(), "REGION.row");
	BDBOpe db_n1(env->getEnv(), "NATION.row");
	BDBOpe db_c(env->getEnv(), "CUSTOMER.row");
	BDBOpe db_o(env->getEnv(), "ORDERS.row");
	BDBOpe db_l(env->getEnv(), "LINEITEM.row");
	BDBOpe db_p(env->getEnv(), "PART.row");
	BDBOpe db_s(env->getEnv(), "SUPPLIER.row");
	BDBOpe db_n2(env->getEnv(), "NATION.row");
	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	
	db_r.open();
	db_n1.open();
	db_c.open();
	db_o.open();
	db_l.open();
	db_p.open();
	db_s.open();
	db_n2.open();

	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n1;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;
	TABLE_REC tableRec_p;
	TABLE_REC tableRec_s;
	TABLE_REC tableRec_n2;
	
/* set table info */
	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;
	
	tableRec_n1.tableID = 2;
	tableRec_n1.attriNum = 4;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;

	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;

	tableRec_p.tableID = 4;
	tableRec_p.attriNum = 9;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_n2.tableID = 2;
	tableRec_n2.attriNum = 4;

/* aet attriRec */
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n1[tableRec_n1.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];
	ATTRIBUTE_REC attriRec_p[tableRec_p.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_n2[tableRec_n2.attriNum];

	AttributeManager AM(env->getEnv());


	AM.getForTableID(tableRec_r, attriRec_r);
	AM.getForTableID(tableRec_n1, attriRec_n1);
	AM.getForTableID(tableRec_c, attriRec_c);
	AM.getForTableID(tableRec_o, attriRec_o);
	AM.getForTableID(tableRec_l, attriRec_l);
	AM.getForTableID(tableRec_p, attriRec_p);
	AM.getForTableID(tableRec_s, attriRec_s);
	AM.getForTableID(tableRec_n2, attriRec_n2);

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("AMERICA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1995-01-01");
	DatePosVal pv3(1,(unsigned char *)"1996-12-31");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LE, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);

/* selection3 */
	VarStrPosVal pv4(1,25);
	string str2("ECONOMY ANODIZED STEEL");
	pv4.set((unsigned char*)str2.c_str());

	ValueNode vn4 = ValueNode(&pv4);
	ColumnRefNode cn3;
	cn3.tableID = 4;
	cn3.attriID = 5;
	AxprNode an5 = AxprNode(EQ, &cn3, &vn4);
	
	
/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 7;
	group[0].attributeID = 5;




/* Join1 */

	OPERATION_NODE pn1[2];
	pn1[0].tableID = 1;
	pn1[0].attributeID = 1;
	pn1[1].tableID = 2;
	pn1[1].attributeID = 3;
	

	JOIN_OPERATION_NODE jpn1[1];
	jpn1[0].rightNode = pn1[0];
	jpn1[0].leftNode = pn1[1];
	
	
/* Join2 */
	OPERATION_NODE pn2[2];
	pn2[0].tableID = 2;
	pn2[0].attributeID = 1;
	pn2[1].tableID = 6;
	pn2[1].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn2[1];
	jpn2[0].rightNode = pn2[0];
	jpn2[0].leftNode = pn2[1];

/* Join3 */
	OPERATION_NODE pn3[2];
	pn3[0].tableID = 6;
	pn3[0].attributeID = 1;
	pn3[1].tableID = 7;
	pn3[1].attributeID = 2;

	
	JOIN_OPERATION_NODE jpn3[1];
	jpn3[0].rightNode = pn3[0];
	jpn3[0].leftNode = pn3[1];
	
/* Join4 */
	OPERATION_NODE pn4[2];
	pn4[0].tableID = 7;
	pn4[0].attributeID = 1;
	pn4[1].tableID = 8;
	pn4[1].attributeID = 1;

	
	JOIN_OPERATION_NODE jpn4[1];
	jpn4[0].rightNode = pn4[0];
	jpn4[0].leftNode = pn4[1];

/* Join5 */
	OPERATION_NODE pn5[2];
	pn5[0].tableID = 4;
	pn5[0].attributeID = 1;
	pn5[1].tableID = 8;
	pn5[1].attributeID = 2;

	
	JOIN_OPERATION_NODE jpn5[1];
	jpn5[0].rightNode = pn5[0];
	jpn5[0].leftNode = pn5[1];
	
/* Join6 */
	OPERATION_NODE pn6[2];
	pn6[0].tableID = 3;
	pn6[0].attributeID = 1;
	pn6[1].tableID = 8;
	pn6[1].attributeID = 3;

	
	JOIN_OPERATION_NODE jpn6[1];
	jpn6[0].rightNode = pn6[0];
	jpn6[0].leftNode = pn6[1];

/* Join7 */
	OPERATION_NODE pn7[2];
	pn7[0].tableID = 2;
	pn7[0].attributeID = 1;
	pn7[1].tableID = 3;
	pn7[1].attributeID = 4;

	
	JOIN_OPERATION_NODE jpn7[1];
	jpn7[0].rightNode = pn7[0];
	jpn7[0].leftNode = pn7[1];



/* Projection1 */

	OPERATION_NODE pro1[1];
	pro1[0].tableID = 1;
	pro1[0].attributeID = 1;

/* Projection2 */

	OPERATION_NODE pro2[2];
	pro2[0].tableID = 2;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 2;
	pro2[1].attributeID = 3;

/* Projection3 */

	OPERATION_NODE pro3[1];
	pro3[0].tableID = 6;
	pro3[0].attributeID = 1;
	
/* Projection4 */

	OPERATION_NODE pro4[2];
	pro4[0].tableID = 7;
	pro4[0].attributeID = 1;
	pro4[1].tableID = 7;
	pro4[1].attributeID = 5;

/* Projection5 */
	
	OPERATION_NODE pro5[1];
	pro5[0].tableID = 4;
	pro5[0].attributeID = 1;

/* Projection6 */
	
	OPERATION_NODE pro6[2];
	pro6[0].tableID = 3;
	pro6[0].attributeID = 1;
	pro6[1].tableID = 3;
	pro6[1].attributeID = 4;

/* Projection7 */
	
	OPERATION_NODE pro7[2];
	pro7[0].tableID = 2;
	pro7[0].attributeID = 1;
	pro7[1].tableID = 2;
	pro7[1].attributeID = 2;

/* Projection8 */
	
	OPERATION_NODE pro8[7];
	pro8[0].tableID = 7;
	pro8[0].attributeID = 5;
	pro8[1].tableID = 2;
	pro8[1].attributeID = 2;
	pro8[2].tableID = 8;
	pro8[2].attributeID = 6;
	pro8[3].tableID = 8;
	pro8[3].attributeID = 7;
	pro8[4].tableID = 8;
	pro8[4].attributeID = 1;
	pro8[5].tableID = 8;
	pro8[5].attributeID = 2;
	pro8[6].tableID = 8;
	pro8[6].attributeID = 3;
	
	
/* Extract */
	OPERATION_NODE ex[1];
	ex[0].tableID = 7;
	ex[0].attributeID = 5;

/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 7;
	so1[0].attributeID = 5;
	so1[0].option = 0;

	o1 = new Scan(&db_r, attriRec_r, 3);
//	cout << "OK new o1" << endl;
	o2 = new Selection((Node *)&an1 ,(unsigned int)1);
//	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	o3 = new Projection(pro1, 1);
	o3->setPreOperator(o2);
//	cout << "OK new o3" << endl;
	
	o4 = new Scan(&db_n1, attriRec_n1, 4);
//	cout << "OK new o4" << endl;
	o5 = new OneSideHashJoin(o3, o4 , jpn1, 1);
//	cout << "OK new o5" << endl;
	o6 = new Projection(pro2, 1);
	o6->setPreOperator(o5);
//	cout << "OK new o6" << endl;
	
	
	o7 = new Scan(&db_c, attriRec_c, 8);
//	cout << "OK new o7" << endl;
	o8 = new OneSideHashJoin(o6, o7 , jpn2, 1);
//	cout << "OK new o8" << endl;
	o9 = new Projection(pro3, 1);
	o9->setPreOperator(o8);
//	cout << "OK new o9" << endl;
	

	o10 = new Scan(&db_o, attriRec_o, 9);
//	cout << "OK new o10" << endl;
	o11 = new Selection((Node *)&an4 ,(unsigned int)2);
//	cout << "OK new o11" << endl;
	o11->setPreOperator(o10);
	
	o12 = new OneSideHashJoin(o9, o11 , jpn3, 1);
//	cout << "OK new o12" << endl;


	o13 = new Projection(pro4, 2);
	o13->setPreOperator(o12);
//	cout << "OK new o13" << endl;
	
	o14 = new Scan(&db_l, attriRec_l, 16);
//	cout << "OK new o14" << endl;
	o15 = new OneSideHashJoin(o13, o14 , jpn4, 1);
//	cout << "OK new o15" << endl;

	o16 = new Scan(&db_p, attriRec_p, 9);
//	cout << "OK new o16" << endl;
	o17 = new Selection((Node *)&an5 ,(unsigned int)1);
//	cout << "OK new o17" << endl;
	o17->setPreOperator(o16);
	o18 = new Projection(pro5, 1);
	o18->setPreOperator(o17);
//	cout << "OK new o18" << endl;
	o19 = new OneSideHashJoin(o18, o15 , jpn5, 1);
//	cout << "OK new o19" << endl;
	
	
	o20 = new Scan(&db_s, attriRec_s, 7);
//	cout << "OK new o20" << endl;
	o21 = new Projection(pro6, 2);
	o21->setPreOperator(o20);
//	cout << "OK new o21" << endl;
	o22 = new OneSideHashJoin(o21, o19 , jpn6, 1);
//	cout << "OK new o22" << endl;
	
	o23 = new Scan(&db_n2, attriRec_n2, 4);
//	cout << "OK new o23" << endl;
	o24 = new Projection(pro7, 2);
	o24->setPreOperator(o23);
//	cout << "OK new o24" << endl;
	o25 = new OneSideHashJoin(o24, o22 , jpn7, 1);
//	cout << "OK new o25" << endl;
	
	o26 = new Extract(ex, true, false, false);
	o26->setPreOperator(o25);
//	cout << "OK new o26" << endl;
	
	o27 = new Projection(pro8, 7);
	o27->setPreOperator(o26);
//	cout << "OK new o27" << endl;


	o28 = new GroupBy(group, 1, aggre, 1);
	o28->setPreOperator(o27);
//	cout << "OK new o28" << endl;

	o29 = new Sort(so1, 1);
	o29->setPreOperator(o28);
//	cout << "OK new o29" << endl;


	o30 = new OutPut(STD_OUT);
//	cout << "OK new o30" << endl;

	o30->setPreOperator(o29);
	o30->init(env->getEnv());
//	cout << "TEST START" << endl;
	
	cout << setprecision(2);
	cout << setiosflags(ios::fixed); 
	o30->exec();
}
void CompositeGenerator::logTime(ostream& out, float time)
{
    out << setiosflags(ios::fixed) << setprecision(2) << time / 1000 << " sec" << endl;
}
Exemple #14
0
void backup_client_leave(Clientlink client_leave){
    ofstream fout("history_client.txt",ios_base::out | ios_base::in);

    fout.seekp(0,ios::end);


   // else{//客户名字	性别	身份证	电话	入住房号	入住时间	住房时间	离店时间	房间类型
   // fout<<setiosflags(ios::left)
  //   <<setw(10)
    fout.width(16);
    fout<<setiosflags(ios::left)<<client_leave->person.name;
    fout.width(16);
    fout<<setiosflags(ios::left)<<client_leave->person.sex;
    fout.width(16);
    fout<<setiosflags(ios::left)<<client_leave->person.identy;
    fout.width(16);
    fout<<setiosflags(ios::left)<<client_leave->person.telephone;
    fout.width(16);
    fout<<setiosflags(ios::left)<<client_leave->person.roomnumber;
    fout.width(16);
    fout<<setiosflags(ios::left)<<client_leave->person.timein;
    fout.width(16);
    fout<<setiosflags(ios::left)<<client_leave->person.staytime;
    fout.width(16);
    fout<<setiosflags(ios::left)<<client_leave->person.leavetime;
    fout.width(16);
    if (client_leave->person.roomtype == single)
       fout<<setiosflags(ios::left)<<"单人间"<<endl;
    else
        if (client_leave->person.roomtype == standard)
            fout<<setiosflags(ios::left)<<"标准间"<<endl;
    else
        if (client_leave->person.roomtype == business)
            fout<<setiosflags(ios::left)<<"商务间"<<endl;
    else
        if (client_leave->person.roomtype == deluxe)
            fout<<setiosflags(ios::left)<<"豪华套房"<<endl;
    else
        if (client_leave->person.roomtype == president)
            fout<<setiosflags(ios::left)<<"总统套房"<<endl;
}
Exemple #15
0
int main(int argc, const char *argv[])
{
     try {
          // Empty model
          ClpSimplex  model;

          // Objective - just nonzeros
          int objIndex[] = {0, 2};
          double objValue[] = {1.0, 4.0};
          // Upper bounds - as dense vector
          double upper[] = {2.0, COIN_DBL_MAX, 4.0};

          // Create space for 3 columns
          model.resize(0, 3);
          // Fill in
          int i;
          // Virtuous way
          // First objective
          for (i = 0; i < 2; i++)
               model.setObjectiveCoefficient(objIndex[i], objValue[i]);
          // Now bounds (lower will be zero by default but do again)
          for (i = 0; i < 3; i++) {
               model.setColumnLower(i, 0.0);
               model.setColumnUpper(i, upper[i]);
          }
          /*
            We could also have done in non-virtuous way e.g.
            double * objective = model.objective();
            and then set directly
          */
          // Faster to add rows all at once - but this is easier to show
          // Now add row 1 as >= 2.0
          int row1Index[] = {0, 2};
          double row1Value[] = {1.0, 1.0};
          model.addRow(2, row1Index, row1Value,
                       2.0, COIN_DBL_MAX);
          // Now add row 2 as == 1.0
          int row2Index[] = {0, 1, 2};
          double row2Value[] = {1.0, -5.0, 1.0};
          model.addRow(3, row2Index, row2Value,
                       1.0, 1.0);
          // solve
          model.dual();

          /*
            Adding one row at a time has a significant overhead so let's
            try a more complicated but faster way

            First time adding in 10000 rows one by one
          */
          model.allSlackBasis();
          ClpSimplex modelSave = model;
          double time1 = CoinCpuTime();
          int k;
          for (k = 0; k < 10000; k++) {
               int row2Index[] = {0, 1, 2};
               double row2Value[] = {1.0, -5.0, 1.0};
               model.addRow(3, row2Index, row2Value,
                            1.0, 1.0);
          }
          printf("Time for 10000 addRow is %g\n", CoinCpuTime() - time1);
          model.dual();
          model = modelSave;
          // Now use build
          CoinBuild buildObject;
          time1 = CoinCpuTime();
          for (k = 0; k < 10000; k++) {
               int row2Index[] = {0, 1, 2};
               double row2Value[] = {1.0, -5.0, 1.0};
               buildObject.addRow(3, row2Index, row2Value,
                                  1.0, 1.0);
          }
          model.addRows(buildObject);
          printf("Time for 10000 addRow using CoinBuild is %g\n", CoinCpuTime() - time1);
          model.dual();
          model = modelSave;
          int del[] = {0, 1, 2};
          model.deleteRows(2, del);
          // Now use build +-1
          CoinBuild buildObject2;
          time1 = CoinCpuTime();
          for (k = 0; k < 10000; k++) {
               int row2Index[] = {0, 1, 2};
               double row2Value[] = {1.0, -1.0, 1.0};
               buildObject2.addRow(3, row2Index, row2Value,
                                   1.0, 1.0);
          }
          model.addRows(buildObject2, true);
          printf("Time for 10000 addRow using CoinBuild+-1 is %g\n", CoinCpuTime() - time1);
          model.dual();
          model = modelSave;
          model.deleteRows(2, del);
          // Now use build +-1
          CoinModel modelObject2;
          time1 = CoinCpuTime();
          for (k = 0; k < 10000; k++) {
               int row2Index[] = {0, 1, 2};
               double row2Value[] = {1.0, -1.0, 1.0};
               modelObject2.addRow(3, row2Index, row2Value,
                                   1.0, 1.0);
          }
          model.addRows(modelObject2, true);
          printf("Time for 10000 addRow using CoinModel+-1 is %g\n", CoinCpuTime() - time1);
          model.dual();
          model = ClpSimplex();
          // Now use build +-1
          CoinModel modelObject3;
          time1 = CoinCpuTime();
          for (k = 0; k < 10000; k++) {
               int row2Index[] = {0, 1, 2};
               double row2Value[] = {1.0, -1.0, 1.0};
               modelObject3.addRow(3, row2Index, row2Value,
                                   1.0, 1.0);
          }
          model.loadProblem(modelObject3, true);
          printf("Time for 10000 addRow using CoinModel load +-1 is %g\n", CoinCpuTime() - time1);
          model.writeMps("xx.mps");
          model.dual();
          model = modelSave;
          // Now use model
          CoinModel modelObject;
          time1 = CoinCpuTime();
          for (k = 0; k < 10000; k++) {
               int row2Index[] = {0, 1, 2};
               double row2Value[] = {1.0, -5.0, 1.0};
               modelObject.addRow(3, row2Index, row2Value,
                                  1.0, 1.0);
          }
          model.addRows(modelObject);
          printf("Time for 10000 addRow using CoinModel is %g\n", CoinCpuTime() - time1);
          model.dual();
          model.writeMps("b.mps");
          // Method using least memory - but most complicated
          time1 = CoinCpuTime();
          // Assumes we know exact size of model and matrix
          // Empty model
          ClpSimplex  model2;
          {
               // Create space for 3 columns and 10000 rows
               int numberRows = 10000;
               int numberColumns = 3;
               // This is fully dense - but would not normally be so
               int numberElements = numberRows * numberColumns;
               // Arrays will be set to default values
               model2.resize(numberRows, numberColumns);
               double * elements = new double [numberElements];
               CoinBigIndex * starts = new CoinBigIndex [numberColumns+1];
               int * rows = new int [numberElements];;
               int * lengths = new int[numberColumns];
               // Now fill in - totally unsafe but ....
               // no need as defaults to 0.0 double * columnLower = model2.columnLower();
               double * columnUpper = model2.columnUpper();
               double * objective = model2.objective();
               double * rowLower = model2.rowLower();
               double * rowUpper = model2.rowUpper();
               // Columns - objective was packed
               for (k = 0; k < 2; k++) {
                    int iColumn = objIndex[k];
                    objective[iColumn] = objValue[k];
               }
               for (k = 0; k < numberColumns; k++)
                    columnUpper[k] = upper[k];
               // Rows
               for (k = 0; k < numberRows; k++) {
                    rowLower[k] = 1.0;
                    rowUpper[k] = 1.0;
               }
               // Now elements
               double row2Value[] = {1.0, -5.0, 1.0};
               CoinBigIndex put = 0;
               for (k = 0; k < numberColumns; k++) {
                    starts[k] = put;
                    lengths[k] = numberRows;
                    double value = row2Value[k];
                    for (int i = 0; i < numberRows; i++) {
                         rows[put] = i;
                         elements[put] = value;
                         put++;
                    }
               }
               starts[numberColumns] = put;
               // assign to matrix
               CoinPackedMatrix * matrix = new CoinPackedMatrix(true, 0.0, 0.0);
               matrix->assignMatrix(true, numberRows, numberColumns, numberElements,
                                    elements, rows, starts, lengths);
               ClpPackedMatrix * clpMatrix = new ClpPackedMatrix(matrix);
               model2.replaceMatrix(clpMatrix, true);
               printf("Time for 10000 addRow using hand written code is %g\n", CoinCpuTime() - time1);
               // If matrix is really big could switch off creation of row copy
               // model2.setSpecialOptions(256);
          }
          model2.dual();
          model2.writeMps("a.mps");
          // Print column solution
          int numberColumns = model.numberColumns();

          // Alternatively getColSolution()
          double * columnPrimal = model.primalColumnSolution();
          // Alternatively getReducedCost()
          double * columnDual = model.dualColumnSolution();
          // Alternatively getColLower()
          double * columnLower = model.columnLower();
          // Alternatively getColUpper()
          double * columnUpper = model.columnUpper();
          // Alternatively getObjCoefficients()
          double * columnObjective = model.objective();

          int iColumn;

          std::cout << "               Primal          Dual         Lower         Upper          Cost"
                    << std::endl;

          for (iColumn = 0; iColumn < numberColumns; iColumn++) {
               double value;
               std::cout << std::setw(6) << iColumn << " ";
               value = columnPrimal[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
               value = columnDual[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
               value = columnLower[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
               value = columnUpper[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
               value = columnObjective[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;

               std::cout << std::endl;
          }
          std::cout << "--------------------------------------" << std::endl;
          // Test CoinAssert
          std::cout << "If Clp compiled without NDEBUG below should give assert, if with NDEBUG or COIN_ASSERT CoinError" << std::endl;
          model = modelSave;
          model.deleteRows(2, del);
          // Deliberate error
          model.deleteColumns(1, del + 2);
          // Now use build +-1
          CoinBuild buildObject3;
          time1 = CoinCpuTime();
          for (k = 0; k < 10000; k++) {
               int row2Index[] = {0, 1, 2};
               double row2Value[] = {1.0, -1.0, 1.0};
               buildObject3.addRow(3, row2Index, row2Value,
                                   1.0, 1.0);
          }
          model.addRows(buildObject3, true);
     } catch (CoinError e) {
          e.print();
          if (e.lineNumber() >= 0)
               std::cout << "This was from a CoinAssert" << std::endl;
     }
     return 0;
}
Exemple #16
0
int main() {

  //CAVITY FLOW 
  auto dt = 0.0005; 
  auto t = clock(); 

  // GRID 
  //  Block2* grid = new Block2({0, 0, 0}, {1.0, 2.0, 0}, 10, 20);
  Block2* grid = new Block2({0, 0, 0}, {1.0, 1.0, 0}, 10, 10);
  // grid->adaptCriteria(); 

  // CONST variables; sv->specific volume
  double sv1 = 0.1; double mu1 = 0.067;   double g = 0; //-1;
  double sv2 = 1;   double mu2 = 0.00067; double sigma = 1;

  // FIELD variables;
  grid->addVar({"p", "vor", "I"}); 
    
  // initial and bc values; say this is rho*u then divide it by rho 
  auto u = grid->getVar("u"); 
  u->set(0.0);
  u->setBC("west", "val", 0); u->setBC("east", "val", 0);
  u->setBC("south", "val", 0); u->setBC("north", "val", 0); 
  auto v = grid->getVar("v"); 
  v->set(0.0);
  v->setBC("west", "val", 0); v->setBC("east", "val", 0);
  v->setBC("south", "val", 0); v->setBC("north", "val", 0); 


  auto p = grid->getVar("p");
  p->setBC("south", "val", 0);  
  p->setBC("north", "val", 0);  
  p->setBC("west", "val", 0);  
  p->setBC("east", "val", 0);  
  p->set(0.0); 

  grid->levelHighBound[0] = 3;
  grid->levelHighBound[1] = 3; 
  grid->levelHighBound[2] = 0; 

  auto I = grid->getVar("I"); 
  I->set(0.0); 
  double pi = 4.0*atan(1);  
  for (auto j = 0; j < 4; ++j) {
    for (auto i = 0; i < grid->listCell.size(); ++i) {
      auto x = grid->listCell[i]->getCoord(); // - Vec3(0.5, 0.5); 
      double r = 0.125 - (x - Vec3(0.5, 0.5)).abs();       
      I->set(i, 1.0/(1.0 + exp(-2.0*80*(r)))); 
      r = 0.125 - (x - Vec3(0.5, 0.625)).abs(); 
      // I->set(i, max(0.0, min(1.0, I->get(i) + 1.0/(1.0 + exp(-2.0*80*(r))))));
    }    
    grid->solBasedAdapt2(grid->getError(I)); 
    grid->adapt(); 
  }
  auto gI = grid->valGrad(I); 
  auto gp = grid->valGrad(p);
  // grid->addVec("st"); 
  // auto stx = grid->getVar("stx"); 
  // auto sty = grid->getVar("sty"); 
  grid->writeVTK("rise"); 

  // exit(1); 
  auto vor = grid->getVar("vor"); 

  // solver behavior
  u->solver = "Gauss"; u->itmax = 200; u->tol = 1e-4; 
  v->solver = "Gauss"; v->itmax = 200; v->tol = 1e-4; 
  p->itmax = 2000; p->tol = 1e-5; 

  I->solver = "Gauss"; I->itmax = 100; I->tol = 1e-6; 

  VecX<double> rho; 
  VecX<double> mu; 
   
  dt=0.0001; 
  // Time control 
  grid->setDt(dt);  
  double time= 0; double endTime = 10.0; 
  int filecnt = 0; int it = 0, writeInt = 1; auto adaptInt = 10; 
  ofstream myfile; 
  while (time < endTime) {
    cout << setiosflags(ios::scientific) << setprecision(2); 
    cout << "------------- Processing TIME = "<< time << " ------------------"<<endl; 

    auto vel = grid->getVel();
    auto diverge = grid->valDiv(vel);
    cout << "+ div=("<<diverge.min()<<":" << diverge.max()<<") "; 
    cout << " u=(" << vel.comp(0).min()<<":"<<vel.comp(0).max()<<")"; 
    cout << " v=(" << vel.comp(1).min()<<":"<<vel.comp(1).max()<<")"<< endl; 
    //    cout << grid->valDiv(vel) << endl; 

    // Interface move
    grid->lockBC(I); 
    I->solve (grid->ddt(1.0) 
     	      +grid->divRK2E(vel, 1.0)
	       ); 
    grid->unlockBC(); 

    gI = grid->valGrad(I);
    // for (auto i = 0; i < gI.comp(0).size(); ++i) {
    //   double mag = 1.0/gI.abs(); 
    //   gI[i][0] *= mag; 
    //   gI[i][1] *= mag; 
    //   gI[i][2] *= mag; 
    // }
    
    // auto gK = grid->valDiv(gI);

    // double mingk = 100; double maxgk = -100; 
    // for (auto i = 0; i < gK.size(); ++i) {
    //   if (gK[i] > maxgk) maxgk = gK[i]; 
    //   if (gK[i] < mingk) mingk = gK[i]; 
    // }

    // cout << " curv=(" << mingk<<":"<<maxgk<<")"<< endl; 
    // cout << " nx=(" << gI.comp(0).min()<<":"<<gI.comp(0).max()<<")"<< endl; 
    // cout << " ny=(" << gI.comp(1).min()<<":"<<gI.comp(1).max()<<")"<< endl; 
 
    // for (auto i = 0; i < grid->listCell.size(); ++i) {
    //   gI[i][0] *= gK[i]; 
    //   gI[i][1] *= gK[i]; //sigma*(sv1 + I->get(i) * (sv2 - sv1)); 
    // }

    vor->set(grid->valGrad(v).comp(0) - grid->valGrad(u).comp(1)); 
    auto gu = grid->valGrad(u); 
    auto gv = grid->valGrad(v);

    // rho*d(u)/dt + rho*u*d(u)/dx = -dp/dx + mu*d2u/dx2 + rho*g + sigma*nx; 
    // u : rhou & v : rhov

    for (auto i = 0; i < grid->listCell.size(); ++i) {
      rho[i] = 1.0/(sv1 + I->get(i) * (sv2 - sv1)); 
      vel[i][0] *= rho[i]; 
      vel[i][1] *= rho[i]; 
    }  
    mu = mu1 + I->data * (mu2 - mu1); 

    grid->lockBC(u); 
    u->solve(
             grid->ddt(rho) 
   	     + grid->div(vel, 1, {0.5}) 
  	     - grid->laplace(mu, {0.5}) 
	     - grid->source(0, sigma*gI.comp(0)) //*(sv1 + I->data *(sv2 - sv1))) // gradX is not defined; 
             );
    grid->unlockBC();

    grid->lockBC(v); 
    v->solve(
	     grid->ddt(rho) 
   	     + grid->div(vel, 1, {0.5})
   	     - grid->laplace(mu, {0.5})
   	     - grid->source(0, sigma*gI.comp(1) - rho*g) //*(sv1 + I->data *(sv2 - sv1)))
	     );
    grid->unlockBC();     

    //    grid->solBasedAdapt(vor->data);
    //    grid->solBasedAdapt(gp);
    if ((it == 1) || (it % adaptInt) == 0) { 
      //grid->solBasedAdapt(gu, 1.0);
      //      grid->solBasedAdapt(grid->valGrad(vor), 0.4);
      grid->solBasedAdapt2(grid->getError(I)); 
      grid->solBasedAdapt(vor->data, 0.9); 
      // for (auto i = 0; i < grid->listCell.size(); ++i)
      // 	for (auto j = 0; j< 3; ++j) 
      // 	  grid->listCell[i]->checkNgbrLevel(j); 
      grid->adapt(); 
    }

    // if (periodic) grid->adapt();
    auto velstar = grid->getVel();    

    auto vsdiv = grid->valDiv(velstar); 
    cout << "+ div=("<<vsdiv.min()<<":" << vsdiv.max()<<") "<<endl; 
    //cout << grid->valDiv(velstar) << endl; 
    //cin.ignore().get(); 

    // d(rhou)/dt = -dp/dx
    // div(rhou(n+1))/dt-div(u(n))/dt = -d2p/dx2
    // dt/den*d2p/dx2 = 
    grid->lockBC(p); 
    p->solve(grid->laplace(dt*(sv1 + I->data *(sv2 - sv1)))
			   - grid->source(0, grid->valDiv(velstar))
			   );
    grid->unlockBC(); 

    gp = grid->valGrad(p); 
    for (auto i = 0; i < grid->listCell.size(); ++i) {
      gp[i][0] *= dt*(sv1 + I->get(i) *(sv2 - sv1) ); 
      gp[i][1] *= dt*(sv1 + I->get(i) *(sv2 - sv1) ); 
    }
    //cout << gp <<endl; 
    u->set(velstar.comp(0)-gp.comp(0));  // 
    v->set(velstar.comp(1)-gp.comp(1));  //
    //grid->correctVel(velstar, dt/rho1); 

    grid->setDt(dt); 
    time += dt; 

    //grid->solBasedAdapt(vor->data);
    //    grid->solBasedAdapt(gv);
    //grid->refine2(); 
    if (( it++ % writeInt) == 0) {
      //grid->writeFace("face"+std::to_string(filecnt)+".vtk"); 
      std::string flname="rise"+std::to_string(filecnt++)+".vtk"; 
      myfile.open(flname); 
      myfile << grid << endl;
      myfile.close(); 
            
    } 

    cout << "---------------------------------------------------"<<endl; 
    //cin.ignore().get(); 
  }

 
  delete(grid); 

  return 0; 
}
Exemple #17
0
void TestSystem::printMetrics(int is_accurate, double cpu_time, double gpu_time, double gpu_full_time, double speedup, double fullspeedup)
{
    cout << setiosflags(ios_base::left);
    stringstream stream;

#if 0
    if(is_accurate == 1)
        stream << "Pass";
    else if(is_accurate_ == 0)
        stream << "Fail";
    else if(is_accurate == -1)
        stream << " ";
    else
    {
        std::cout<<"is_accurate errer: "<<is_accurate<<"\n";
        exit(-1);
    }
#endif

    std::stringstream &cur_subtest_description = getCurSubtestDescription();

#if GTEST_OS_WINDOWS&&!GTEST_OS_WINDOWS_MOBILE

    WORD color;
    const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
    // Gets the current text color.
    CONSOLE_SCREEN_BUFFER_INFO buffer_info;
    GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
    const WORD old_color_attrs = buffer_info.wAttributes;
    // We need to flush the stream buffers into the console before each
    // SetConsoleTextAttribute call lest it affect the text that is already
    // printed but has not yet reached the console.
    fflush(stdout);

    if(is_accurate == 1||is_accurate == -1)
    {
        color = old_color_attrs;
        printMetricsUti(cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, stream, cur_subtest_description);

    } else
    {
        color = GetColorAttribute(COLOR_RED);
        SetConsoleTextAttribute(stdout_handle,
                                color| FOREGROUND_INTENSITY);

        printMetricsUti(cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, stream, cur_subtest_description);
        fflush(stdout);
        // Restores the text color.
        SetConsoleTextAttribute(stdout_handle, old_color_attrs);
    }
#else
    GTestColor color = COLOR_RED;
    if(is_accurate == 1|| is_accurate == -1)
    {
        printMetricsUti(cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, stream, cur_subtest_description);

    } else
    {
        printf("\033[0;3%sm", GetAnsiColorCode(color));
        printMetricsUti(cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, stream, cur_subtest_description);
        printf("\033[m");  // Resets the terminal to default.
    }
#endif
}
Exemple #18
0
void sum_based_on_radius(vector<protein> whole_protein)
{
         int i,j;  
         double ang_ala,ave_ang_ala,k_ala;
         double ang_val,ave_ang_val,k_val;
         double ang_phe,ave_ang_phe,k_phe;
         double ang_pro,ave_ang_pro,k_pro;
         double ang_met,ave_ang_met,k_met;
         double ang_ile,ave_ang_ile,k_ile;
         double ang_leu,ave_ang_leu,k_leu;
         double ang_asp,ave_ang_asp,k_asp;
         double ang_glu,ave_ang_glu,k_glu;
         double ang_lys,ave_ang_lys,k_lys;
         double ang_arg,ave_ang_arg,k_arg;
         double ang_ser,ave_ang_ser,k_ser;
         double ang_thr,ave_ang_thr,k_thr;
         double ang_tyr,ave_ang_tyr,k_tyr;
         double ang_his,ave_ang_his,k_his;
         double ang_cys,ave_ang_cys,k_cys;
         double ang_asn,ave_ang_asn,k_asn;
         double ang_gln,ave_ang_gln,k_gln;
         double ang_trp,ave_ang_trp,k_trp;

	 ang_ala=0;k_ala=0;ave_ang_ala=0;
	 ang_val=0;k_val=0;ave_ang_val=0;
	 ang_phe=0;k_phe=0;ave_ang_phe=0;
	 ang_pro=0;k_pro=0;ave_ang_pro=0;
	 ang_met=0;k_met=0;ave_ang_met=0;
	 ang_ile=0;k_ile=0;ave_ang_ile=0;
	 ang_leu=0;k_leu=0;ave_ang_leu=0;
	 ang_asp=0;k_asp=0;ave_ang_asp=0;
	 ang_glu=0;k_glu=0;ave_ang_glu=0;
	 ang_lys=0;k_lys=0;ave_ang_lys=0;
	 ang_arg=0;k_arg=0;ave_ang_arg=0;
	 ang_ser=0;k_ser=0;ave_ang_ser=0;
	 ang_thr=0;k_thr=0;ave_ang_thr=0;
	 ang_tyr=0;k_tyr=0;ave_ang_tyr=0;
	 ang_his=0;k_his=0;ave_ang_his=0;
	 ang_cys=0;k_cys=0;ave_ang_cys=0;
	 ang_asn=0;k_asn=0;ave_ang_asn=0;
	 ang_gln=0;k_gln=0;ave_ang_gln=0;
	 ang_trp=0;k_trp=0;ave_ang_trp=0;
         
            
         double angle_total_value=0;
         int angle_total_num=0;

	 for(i=0;i<whole_protein.size();i++)
	 {
           for(j=0;j<whole_protein[i].residue_str.size();j++)
           {  
             // angle_total_value=angle_total_value+whole_protein[i].residue_str[j].angle;
             // angle_total_num=angle_total_num+1;
             // }
             /// ///}
         if(whole_protein[i].residue_str[j].distance>160 
            &&whole_protein[i].residue_str[j].distance<=180) 
         {  
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"ALA",3)==0)
	   {
	   ang_ala=ang_ala+whole_protein[i].residue_str[j].angle;
	   k_ala=k_ala+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"VAL",3)==0)
	   {
	   ang_val=ang_val+whole_protein[i].residue_str[j].angle;
	   k_val=k_val+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"PHE",3)==0)
	   {
	   ang_phe=ang_phe+whole_protein[i].residue_str[j].angle;
	   k_phe=k_phe+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"PRO",3)==0)
	   {
	   ang_pro=ang_pro+whole_protein[i].residue_str[j].angle;
	   k_pro=k_pro+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"MET",3)==0)
	   {
	   ang_met=ang_met+whole_protein[i].residue_str[j].angle;
	   k_met=k_met+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"ILE",3)==0)
	   {
	   ang_ile=ang_ile+whole_protein[i].residue_str[j].angle;
	   k_ile=k_ile+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"LEU",3)==0)
	   {
	   ang_leu=ang_leu+whole_protein[i].residue_str[j].angle;
	   k_leu=k_leu+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"ASP",3)==0)
	   {
	   ang_asp=ang_asp+whole_protein[i].residue_str[j].angle;
	   k_asp=k_asp+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"GLU",3)==0)
	   {
	   ang_glu=ang_glu+whole_protein[i].residue_str[j].angle;
	   k_glu=k_glu+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"LYS",3)==0)
	   {
	   ang_lys=ang_lys+whole_protein[i].residue_str[j].angle;
	   k_lys=k_lys+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"ARG",3)==0)
	   {
	   ang_arg=ang_arg+whole_protein[i].residue_str[j].angle;
	   k_arg=k_arg+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"SER",3)==0)
	   {
	   ang_ser=ang_ser+whole_protein[i].residue_str[j].angle;
	   k_ser=k_ser+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"THR",3)==0)
	   {
	   ang_thr=ang_thr+whole_protein[i].residue_str[j].angle;
	   k_thr=k_thr+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"TYR",3)==0)
	   {
	   ang_tyr=ang_tyr+whole_protein[i].residue_str[j].angle;
	   k_tyr=k_tyr+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"HIS",3)==0)
	   {
	   ang_his=ang_his+whole_protein[i].residue_str[j].angle;
	   k_his=k_his+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"CYS",3)==0)
	   {
	   ang_cys=ang_cys+whole_protein[i].residue_str[j].angle;
	   k_cys=k_cys+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"ASN",3)==0)
	   {
	   ang_asn=ang_asn+whole_protein[i].residue_str[j].angle;
	   k_asn=k_asn+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"GLN",3)==0)
	   {
	   ang_gln=ang_gln+whole_protein[i].residue_str[j].angle;
	   k_gln=k_gln+1;
	   }
	  if(strncmp(whole_protein[i].residue_str[j].res_id,"TRP",3)==0)
	   {
	   ang_trp=ang_trp+whole_protein[i].residue_str[j].angle;
	   k_trp=k_trp+1;
	   }
          }// end of if 
         } //end of for(j=0
         }//end of for(i=0	
          
	   if(k_ala!=0)
	   {ave_ang_ala=ang_ala/k_ala;}
	   if(k_val!=0)
	   {ave_ang_val=ang_val/k_val;}
	   if(k_phe!=0)
	   {ave_ang_phe=ang_phe/k_phe;}
	   if(k_pro!=0)
	   {ave_ang_pro=ang_pro/k_pro;}
	   if(k_met!=0)
	   {ave_ang_met=ang_met/k_met;}
	   if(k_ile!=0)
	   {ave_ang_ile=ang_ile/k_ile;}
	   if(k_leu!=0)
	   {ave_ang_leu=ang_leu/k_leu;}
	   if(k_asp!=0)
	   {ave_ang_asp=ang_asp/k_asp;}
	   if(k_glu!=0)
	   {ave_ang_glu=ang_glu/k_glu;}
	   if(k_lys!=0)
	   {ave_ang_lys=ang_lys/k_lys;}
	   if(k_arg!=0)
	   {ave_ang_arg=ang_arg/k_arg;}
	   if(k_ser!=0)
	   {ave_ang_ser=ang_ser/k_ser;}
	   if(k_thr!=0)
	   {ave_ang_thr=ang_thr/k_thr;}
	   if(k_tyr!=0)
	   {ave_ang_tyr=ang_tyr/k_tyr;}
	   if(k_his!=0)
	   {ave_ang_his=ang_his/k_his;}
	   if(k_cys!=0)
	   {ave_ang_cys=ang_cys/k_cys;}
	   if(k_asn!=0)
	   {ave_ang_asn=ang_asn/k_asn;}
	   if(k_gln!=0)
	   {ave_ang_gln=ang_gln/k_gln;}
	   if(k_trp!=0)
	   {ave_ang_trp=ang_trp/k_trp;}
	   
	 ofstream file("radius_160_180.txt",ios::out|ios::app);

           file<<setiosflags(ios::left)<<setw(5)
	       <<"ALA"
               <<setiosflags(ios::left)<<setw(5)
	       <<"VAL"
               <<setiosflags(ios::left)<<setw(5)
	       <<"PHE"
               <<setiosflags(ios::left)<<setw(5)
	       <<"PRO"
               <<setiosflags(ios::left)<<setw(5)
	       <<"MET"
               <<setiosflags(ios::left)<<setw(5)
	       <<"ILE"
               <<setiosflags(ios::left)<<setw(5)
	       <<"LEU"
               <<setiosflags(ios::left)<<setw(5)
	       <<"ASP"
               <<setiosflags(ios::left)<<setw(5)
	       <<"GLU"
               <<setiosflags(ios::left)<<setw(5)
	       <<"LYS"
               <<setiosflags(ios::left)<<setw(5)
	       <<"ARG"
               <<setiosflags(ios::left)<<setw(5)
	       <<"SER"
               <<setiosflags(ios::left)<<setw(5)
	       <<"THR"
               <<setiosflags(ios::left)<<setw(5)
	       <<"TYR"
               <<setiosflags(ios::left)<<setw(5)
	       <<"HIS"
               <<setiosflags(ios::left)<<setw(5)
	       <<"CYS"
               <<setiosflags(ios::left)<<setw(5)
	       <<"ASN"
               <<setiosflags(ios::left)<<setw(5)
	       <<"GLN"
               <<setiosflags(ios::left)<<setw(5)
	       <<"TRP"<<endl;
    
           file<<setiosflags(ios::fixed)
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_ala
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_val
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_phe
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_pro
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_met
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_ile
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_leu
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_asp
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_glu
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_lys
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_arg
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_ser
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_thr
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_tyr
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_his
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_cys
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_asn
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_gln
               <<setiosflags(ios::left)<<setprecision(0)<<setw(5)
	       <<ave_ang_trp<<endl;
             file.close();
}// end of function geo_of_
std::ostream& ossimNitfRsmecaTag::print(std::ostream& out,
                                        const std::string& prefix) const
{
   std::string pfx = prefix;
   pfx += getTagName();
   pfx += ".";
   ossim_uint32 i = 0;

   out << setiosflags(std::ios::left)
       << pfx << std::setw(24) << "CETAG:" << getTagName() << "\n"
       << pfx << std::setw(24) << "CEL:" << getSizeInBytes() << "\n"
       << pfx << std::setw(24) << "IID:" << m_iid << "\n" 
       << pfx << std::setw(24) << "EDITION:" << m_edition << "\n"
       << pfx << std::setw(24) << "TID:" << m_tid << "\n"
       << pfx << std::setw(24) << "INCLIC:" << m_inclic << "\n"
       << pfx << std::setw(24) << "INCLUC:" << m_incluc << "\n";

   if(m_inclicFlag)
   {
      out << pfx << std::setw(24) << "NPAR:" << m_npar << "\n"
          << pfx << std::setw(24) << "NPARO:" << m_nparo << "\n"
          << pfx << std::setw(24) << "IGN:" << m_ign << "\n"
          << pfx << std::setw(24) << "CVDATE:" << m_cvdate << "\n"
          << pfx << std::setw(24) << "XUOL:" << m_xuol << "\n"
          << pfx << std::setw(24) << "YUOL:" << m_yuol << "\n"
          << pfx << std::setw(24) << "ZUOL:" << m_zuol << "\n"
          << pfx << std::setw(24) << "XUXL:" << m_xuxl << "\n"
          << pfx << std::setw(24) << "XUYL:" << m_xuyl << "\n"
          << pfx << std::setw(24) << "XUZL:" << m_xuzl << "\n"
          << pfx << std::setw(24) << "YUXL:" << m_yuxl << "\n"
          << pfx << std::setw(24) << "YUYL:" << m_yuyl << "\n"
          << pfx << std::setw(24) << "YUZL:" << m_yuzl << "\n"
          << pfx << std::setw(24) << "ZUXL:" << m_zuxl << "\n"
          << pfx << std::setw(24) << "ZUYL:" << m_zuyl << "\n"
          << pfx << std::setw(24) << "ZUZL:" << m_zuzl << "\n"
          << pfx << std::setw(24) << "IRO:" << m_iro << "\n"
          << pfx << std::setw(24) << "IRX:" << m_irx << "\n"
          << pfx << std::setw(24) << "IRY:" << m_iry << "\n"
          << pfx << std::setw(24) << "IRZ:" << m_irz << "\n"
          << pfx << std::setw(24) << "IRXX:" << m_irxx << "\n"
          << pfx << std::setw(24) << "IRXY:" << m_irxy << "\n"
          << pfx << std::setw(24) << "IRXZ:" << m_irxz << "\n"
          << pfx << std::setw(24) << "IRYY:" << m_iryy << "\n"
          << pfx << std::setw(24) << "IRYZ:" << m_iryz << "\n"
          << pfx << std::setw(24) << "IRZZ:" << m_irzz << "\n"
          << pfx << std::setw(24) << "ICO:" << m_ico << "\n"
          << pfx << std::setw(24) << "ICX:" << m_icx << "\n"
          << pfx << std::setw(24) << "ICY:" << m_icy << "\n"
          << pfx << std::setw(24) << "ICZ:" << m_icz << "\n"
          << pfx << std::setw(24) << "ICXX:" << m_icxx << "\n"
          << pfx << std::setw(24) << "ICXY:" << m_icxy << "\n"
          << pfx << std::setw(24) << "ICXZ:" << m_icxz << "\n"
          << pfx << std::setw(24) << "ICYY:" << m_icyy << "\n"
          << pfx << std::setw(24) << "ICYZ:" << m_icyz << "\n"
          << pfx << std::setw(24) << "ICZZ:" << m_iczz << "\n"
          << pfx << std::setw(24) << "GXO:" << m_gxo << "\n"
          << pfx << std::setw(24) << "GYO:" << m_gyo << "\n"
          << pfx << std::setw(24) << "GZO:" << m_gzo << "\n"
          << pfx << std::setw(24) << "GXR:" << m_gxr << "\n"
          << pfx << std::setw(24) << "GYR:" << m_gyr << "\n"
          << pfx << std::setw(24) << "GZR:" << m_gzr << "\n"
          << pfx << std::setw(24) << "GS:" << m_gs << "\n"
          << pfx << std::setw(24) << "GXX:" << m_gxx << "\n"
          << pfx << std::setw(24) << "GXY:" << m_gxy << "\n"
          << pfx << std::setw(24) << "GXZ:" << m_gxz << "\n"
          << pfx << std::setw(24) << "GYX:" << m_gyx << "\n"
          << pfx << std::setw(24) << "GYY:" << m_gyy << "\n"
          << pfx << std::setw(24) << "GYZ:" << m_gyz << "\n"
          << pfx << std::setw(24) << "GZX:" << m_gzx << "\n"
          << pfx << std::setw(24) << "GZY:" << m_gzy << "\n"
          << pfx << std::setw(24) << "GZZ:" << m_gzz << "\n";
	
      for (i=0; i<m_ignNum; ++i)
      {
         m_isg[i].print(out, prefix, i);
	
      }
      for (i=0; i<m_mapNum; ++i)
      {
         ossimString field = "MAP" + ossimString::toString(i) + ":";	
         out << pfx << std::setw(24) << field << m_map[i] << "\n"; 
      }
   }
   if (m_inclucFlag)
   {
      out << pfx << std::setw(24) << "URR:" << m_urr << "\n"
          << pfx << std::setw(24) << "URC:" << m_urc << "\n"
          << pfx << std::setw(24) << "UCC:" << m_ucc << "\n"
          << pfx << std::setw(24) << "UNCSR:" << m_uncsr << "\n";
     
      for (i=0; i<m_rowCorSegNum; ++i)
      {
	 ossimString field = "UCORSR" + ossimString::toString(i) + ":";
	 out << pfx << std::setw(24) << field << m_ucorsr[i] << "\n";
      }
      for (i=0; i<m_rowCorSegNum; ++i)
      {
         ossimString field = "UTAUSR" + ossimString::toString(i) + ":";
         out << pfx << std::setw(24) << field << m_utausr[i] << "\n";
      }
      
      for (i=0; i<m_colCorSegNum; ++i)
      {
         ossimString field = "UCORSC" + ossimString::toString(i) + ":";
         out << pfx << std::setw(24) << field << m_ucorsc[i] << "\n";
      }
      for (i=0; i<m_colCorSegNum; ++i)
      {
         ossimString field = "UTAUSC" + ossimString::toString(i) + ":";
         out << pfx << std::setw(24) << field << m_utausc[i] << "\n";
      }
   }
   
   out.flush();
   
   return out;
}
void performFit(string inputDir, string inputParameterFile, string label,
                string PassInputDataFilename, string FailInputDataFilename, 
                string PassSignalTemplateHistName, string FailSignalTemplateHistName)
{

  gBenchmark->Start("fitZCat");

  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //==============================================================================================================
  
  const Double_t mlow  = 60;
  const Double_t mhigh = 120;
  const Int_t    nbins = 24;

  TString effType = inputDir;

  // The fit variable - lepton invariant mass
  RooRealVar* rooMass_ = new RooRealVar("Mass","m_{ee}",mlow, mhigh, "GeV/c^{2}");
  RooRealVar Mass = *rooMass_;
  Mass.setBins(nbins);

  // Make the category variable that defines the two fits,
  // namely whether the probe passes or fails the eff criteria.
  RooCategory sample("sample","") ;
  sample.defineType("Pass", 1) ;
  sample.defineType("Fail", 2) ; 


  RooDataSet *dataPass  = RooDataSet::read((inputDir+PassInputDataFilename).c_str(),RooArgList(Mass));
  RooDataSet *dataFail  = RooDataSet::read((inputDir+FailInputDataFilename).c_str(),RooArgList(Mass));

  RooDataSet *dataCombined = new RooDataSet("dataCombined","dataCombined", RooArgList(Mass), RooFit::Index(sample), 
                                            RooFit::Import("Pass",*dataPass),
                                            RooFit::Import("Fail",*dataFail));



  //*********************************************************************************************
  //Define Free Parameters
  //*********************************************************************************************
  RooRealVar* ParNumSignal =  LoadParameters(inputParameterFile, label,"ParNumSignal");
  RooRealVar* ParNumBkgPass =  LoadParameters(inputParameterFile, label,"ParNumBkgPass");
  RooRealVar* ParNumBkgFail =  LoadParameters(inputParameterFile, label, "ParNumBkgFail");
  RooRealVar* ParEfficiency  = LoadParameters(inputParameterFile, label, "ParEfficiency");
  RooRealVar* ParPassBackgroundExpCoefficient = LoadParameters(inputParameterFile, label, "ParPassBackgroundExpCoefficient");
  RooRealVar* ParFailBackgroundExpCoefficient = LoadParameters(inputParameterFile, label, "ParFailBackgroundExpCoefficient");
  RooRealVar* ParPassSignalMassShift = LoadParameters(inputParameterFile, label, "ParPassSignalMassShift");
  RooRealVar* ParFailSignalMassShift = LoadParameters(inputParameterFile, label, "ParFailSignalMassShift");
  RooRealVar* ParPassSignalResolution = LoadParameters(inputParameterFile, label, "ParPassSignalResolution");
  RooRealVar* ParFailSignalResolution = LoadParameters(inputParameterFile, label, "ParFailSignalResolution");



// new RooRealVar  ("ParPassSignalMassShift","ParPassSignalMassShift",-2.6079e-02,-10.0, 10.0);   //ParPassSignalMassShift->setConstant(kTRUE);  
//   RooRealVar* ParFailSignalMassShift = new RooRealVar  ("ParFailSignalMassShift","ParFailSignalMassShift",7.2230e-01,-10.0, 10.0);   //ParFailSignalMassShift->setConstant(kTRUE);  
//   RooRealVar* ParPassSignalResolution = new RooRealVar ("ParPassSignalResolution","ParPassSignalResolution",6.9723e-01,0.0, 10.0);     ParPassSignalResolution->setConstant(kTRUE);  
//   RooRealVar* ParFailSignalResolution = new RooRealVar ("ParFailSignalResolution","ParFailSignalResolution",1.6412e+00,0.0, 10.0);     ParFailSignalResolution->setConstant(kTRUE);  

  //*********************************************************************************************
  //
  //Load Signal PDFs
  //
  //*********************************************************************************************

  TFile *Zeelineshape_file =  new TFile("res/photonEfffromZee.dflag1.eT1.2.gT40.mt15.root", "READ");
  TH1* histTemplatePass = (TH1D*) Zeelineshape_file->Get(PassSignalTemplateHistName.c_str());
  TH1* histTemplateFail = (TH1D*) Zeelineshape_file->Get(FailSignalTemplateHistName.c_str());

  //Introduce mass shift coordinate transformation 
//   RooFormulaVar PassShiftedMass("PassShiftedMass","@0-@1",RooArgList(Mass,*ParPassSignalMassShift));
//   RooFormulaVar FailShiftedMass("FailShiftedMass","@0-@1",RooArgList(Mass,*ParFailSignalMassShift));

  RooGaussian  *PassSignalResolutionFunction =  new RooGaussian("PassSignalResolutionFunction","PassSignalResolutionFunction",Mass,*ParPassSignalMassShift,*ParPassSignalResolution);
  RooGaussian  *FailSignalResolutionFunction =  new RooGaussian("FailSignalResolutionFunction","FailSignalResolutionFunction",Mass,*ParFailSignalMassShift,*ParFailSignalResolution);


  RooDataHist* dataHistPass = new RooDataHist("dataHistPass","dataHistPass", RooArgSet(Mass), histTemplatePass);
  RooDataHist* dataHistFail = new RooDataHist("dataHistFail","dataHistFail", RooArgSet(Mass), histTemplateFail);
  RooHistPdf* signalShapePassTemplatePdf = new RooHistPdf("signalShapePassTemplatePdf", "signalShapePassTemplatePdf", Mass, *dataHistPass, 1);
  RooHistPdf* signalShapeFailTemplatePdf = new RooHistPdf("signalShapeFailTemplatePdf", "signalShapeFailTemplatePdf", Mass, *dataHistFail, 1);

  RooFFTConvPdf* signalShapePassPdf = new RooFFTConvPdf("signalShapePassPdf","signalShapePassPdf"  , Mass, *signalShapePassTemplatePdf,*PassSignalResolutionFunction,2);
  RooFFTConvPdf* signalShapeFailPdf = new RooFFTConvPdf("signalShapeFailPdf","signalShapeFailPdf"  , Mass, *signalShapeFailTemplatePdf,*FailSignalResolutionFunction,2);


  // Now define some efficiency/yield variables  
  RooFormulaVar* NumSignalPass = new RooFormulaVar("NumSignalPass", "ParEfficiency*ParNumSignal", RooArgList(*ParEfficiency,*ParNumSignal));
  RooFormulaVar* NumSignalFail = new RooFormulaVar("NumSignalFail", "(1.0-ParEfficiency)*ParNumSignal", RooArgList(*ParEfficiency,*ParNumSignal));


  //*********************************************************************************************
  //
  // Create Background PDFs
  //
  //*********************************************************************************************
  RooExponential* bkgPassPdf = new RooExponential("bkgPassPdf","bkgPassPdf",Mass, *ParPassBackgroundExpCoefficient);
  RooExponential* bkgFailPdf = new RooExponential("bkgFailPdf","bkgFailPdf",Mass, *ParFailBackgroundExpCoefficient);


 //*********************************************************************************************
  //
  // Create Total PDFs
  //
  //*********************************************************************************************
  RooAddPdf pdfPass("pdfPass","pdfPass",RooArgList(*signalShapePassPdf,*bkgPassPdf), RooArgList(*NumSignalPass,*ParNumBkgPass));
  RooAddPdf pdfFail("pdfFail","pdfFail",RooArgList(*signalShapeFailPdf,*bkgFailPdf), RooArgList(*NumSignalFail,*ParNumBkgFail));

  // PDF for simultaneous fit
   RooSimultaneous totalPdf("totalPdf","totalPdf", sample);
   totalPdf.addPdf(pdfPass,"Pass");
//    totalPdf.Print();
   totalPdf.addPdf(pdfFail,"Fail");
   totalPdf.Print();


   //*********************************************************************************************
  //
  // Perform Fit
  //
  //*********************************************************************************************
   RooFitResult *fitResult = 0;

  // ********* Fix with Migrad first ********** //  
   fitResult = totalPdf.fitTo(*dataCombined, RooFit::Save(true), 
                              RooFit::Extended(true), RooFit::PrintLevel(-1));
   fitResult->Print("v");


//   // ********* Fit With Minos ********** //  
//    fitResult = totalPdf.fitTo(*dataCombined, RooFit::Save(true), 
//                               RooFit::Extended(true), RooFit::PrintLevel(-1), RooFit::Minos());
//    fitResult->Print("v");




//   // ********* Fix Mass Shift and Fit For Resolution ********** //  
//    ParPassSignalMassShift->setConstant(kTRUE); 
//    ParFailSignalMassShift->setConstant(kTRUE); 
//    ParPassSignalResolution->setConstant(kFALSE); 
//    ParFailSignalResolution->setConstant(kFALSE); 
//    fitResult = totalPdf.fitTo(*dataCombined, RooFit::Save(true), 
//    RooFit::Extended(true), RooFit::PrintLevel(-1));
//    fitResult->Print("v");


//   // ********* Do Final Fit ********** //  
//    ParPassSignalMassShift->setConstant(kFALSE); 
//    ParFailSignalMassShift->setConstant(kFALSE); 
//    ParPassSignalResolution->setConstant(kTRUE); 
//    ParFailSignalResolution->setConstant(kTRUE); 
//    fitResult = totalPdf.fitTo(*dataCombined, RooFit::Save(true), 
//                                             RooFit::Extended(true), RooFit::PrintLevel(-1));
//    fitResult->Print("v");





  double nSignalPass = NumSignalPass->getVal();
  double nSignalFail    = NumSignalFail->getVal();
  double denominator = nSignalPass + nSignalFail;

  printf("\nFit results:\n");
  if( fitResult->status() != 0 ){
    std::cout<<"ERROR: BAD FIT STATUS"<<std::endl;
  }

  printf("    Efficiency = %.4f +- %.4f\n", 
	 ParEfficiency->getVal(), ParEfficiency->getPropagatedError(*fitResult));  
  cout << "Signal Pass: "******"Signal Fail: " << nSignalFail << endl;

  cout << "*********************************************************************\n";
  cout << "Final Parameters\n";
  cout << "*********************************************************************\n";
  PrintParameter(ParNumSignal, label,"ParNumSignal");
  PrintParameter(ParNumBkgPass, label,"ParNumBkgPass");
  PrintParameter(ParNumBkgFail, label, "ParNumBkgFail");
  PrintParameter(ParEfficiency  , label, "ParEfficiency");
  PrintParameter(ParPassBackgroundExpCoefficient , label, "ParPassBackgroundExpCoefficient");
  PrintParameter(ParFailBackgroundExpCoefficient , label, "ParFailBackgroundExpCoefficient");
  PrintParameter(ParPassSignalMassShift , label, "ParPassSignalMassShift");
  PrintParameter(ParFailSignalMassShift , label, "ParFailSignalMassShift");
  PrintParameter(ParPassSignalResolution , label, "ParPassSignalResolution");
  PrintParameter(ParFailSignalResolution , label, "ParFailSignalResolution");
  cout << endl << endl;


  //--------------------------------------------------------------------------------------------------------------
  // Make plots 
  //==============================================================================================================  
  TFile *canvasFile = new TFile("Efficiency_FitResults.root", "UPDATE");


  RooAbsData::ErrorType errorType = RooAbsData::Poisson;

  Mass.setBins(NBINSPASS);
  TString cname = TString((label+"_Pass").c_str());
  TCanvas *c = new TCanvas(cname,cname,800,600);
  RooPlot* frame1 = Mass.frame();
  frame1->SetMinimum(0);
  dataPass->plotOn(frame1,RooFit::DataError(errorType));
  pdfPass.plotOn(frame1,RooFit::ProjWData(*dataPass), 
  RooFit::Components(*bkgPassPdf),RooFit::LineColor(kRed));
  pdfPass.plotOn(frame1,RooFit::ProjWData(*dataPass));
  frame1->Draw("e0");
  
  TPaveText *plotlabel = new TPaveText(0.23,0.87,0.43,0.92,"NDC");
   plotlabel->SetTextColor(kBlack);
   plotlabel->SetFillColor(kWhite);
   plotlabel->SetBorderSize(0);
   plotlabel->SetTextAlign(12);
   plotlabel->SetTextSize(0.03);
   plotlabel->AddText("CMS Preliminary 2010");
  TPaveText *plotlabel2 = new TPaveText(0.23,0.82,0.43,0.87,"NDC");
   plotlabel2->SetTextColor(kBlack);
   plotlabel2->SetFillColor(kWhite);
   plotlabel2->SetBorderSize(0);
   plotlabel2->SetTextAlign(12);
   plotlabel2->SetTextSize(0.03);
   plotlabel2->AddText("#sqrt{s} = 7 TeV");
  TPaveText *plotlabel3 = new TPaveText(0.23,0.75,0.43,0.80,"NDC");
   plotlabel3->SetTextColor(kBlack);
   plotlabel3->SetFillColor(kWhite);
   plotlabel3->SetBorderSize(0);
   plotlabel3->SetTextAlign(12);
   plotlabel3->SetTextSize(0.03);
  char temp[100];
  sprintf(temp, "%.4f", LUMINOSITY);
  plotlabel3->AddText((string("#int#font[12]{L}dt = ") + 
  temp + string(" pb^{ -1}")).c_str());
  TPaveText *plotlabel4 = new TPaveText(0.6,0.82,0.8,0.87,"NDC");
   plotlabel4->SetTextColor(kBlack);
   plotlabel4->SetFillColor(kWhite);
   plotlabel4->SetBorderSize(0);
   plotlabel4->SetTextAlign(12);
   plotlabel4->SetTextSize(0.03);
   double nsig = ParNumSignal->getVal();
   double nErr = ParNumSignal->getError();
   double e = ParEfficiency->getVal();
   double eErr = ParEfficiency->getError();
   double corr = fitResult->correlation(*ParEfficiency, *ParNumSignal);
   double err = ErrorInProduct(nsig, nErr, e, eErr, corr);
   sprintf(temp, "Signal = %.2f #pm %.2f", NumSignalPass->getVal(), err);
   plotlabel4->AddText(temp);
   TPaveText *plotlabel5 = new TPaveText(0.6,0.77,0.8,0.82,"NDC");
   plotlabel5->SetTextColor(kBlack);
   plotlabel5->SetFillColor(kWhite);
   plotlabel5->SetBorderSize(0);
   plotlabel5->SetTextAlign(12);
   plotlabel5->SetTextSize(0.03);
   sprintf(temp, "Bkg = %.2f #pm %.2f", ParNumBkgPass->getVal(), ParNumBkgPass->getError());
   plotlabel5->AddText(temp);
   TPaveText *plotlabel6 = new TPaveText(0.6,0.87,0.8,0.92,"NDC");
   plotlabel6->SetTextColor(kBlack);
   plotlabel6->SetFillColor(kWhite);
   plotlabel6->SetBorderSize(0);
   plotlabel6->SetTextAlign(12);
   plotlabel6->SetTextSize(0.03);
   plotlabel6->AddText("Passing probes");
   TPaveText *plotlabel7 = new TPaveText(0.6,0.72,0.8,0.77,"NDC");
   plotlabel7->SetTextColor(kBlack);
   plotlabel7->SetFillColor(kWhite);
   plotlabel7->SetBorderSize(0);
   plotlabel7->SetTextAlign(12);
   plotlabel7->SetTextSize(0.03); 
   sprintf(temp, "Eff = %.3f #pm %.3f", ParEfficiency->getVal(), ParEfficiency->getErrorHi());
   plotlabel7->AddText(temp);
   TPaveText *plotlabel8 = new TPaveText(0.6,0.72,0.8,0.66,"NDC");
   plotlabel8->SetTextColor(kBlack);
   plotlabel8->SetFillColor(kWhite);
   plotlabel8->SetBorderSize(0);
   plotlabel8->SetTextAlign(12);
   plotlabel8->SetTextSize(0.03);
   sprintf(temp, "#chi^{2}/DOF = %.3f", frame1->chiSquare());
   plotlabel8->AddText(temp);

  plotlabel4->Draw();
  plotlabel5->Draw();
  plotlabel6->Draw();
  plotlabel7->Draw();
  plotlabel8->Draw();

//   c->SaveAs( cname + TString(".eps"));
  c->SaveAs( cname + TString(".gif"));
  canvasFile->WriteTObject(c, c->GetName(), "WriteDelete");

 
  Mass.setBins(NBINSFAIL);
  cname = TString((label+"_Fail").c_str());
  TCanvas* c2 = new TCanvas(cname,cname,800,600);
  RooPlot* frame2 = Mass.frame();
  frame2->SetMinimum(0);
  dataFail->plotOn(frame2,RooFit::DataError(errorType));
  pdfFail.plotOn(frame2,RooFit::ProjWData(*dataFail), 
  RooFit::Components(*bkgFailPdf),RooFit::LineColor(kRed));
  pdfFail.plotOn(frame2,RooFit::ProjWData(*dataFail));
  frame2->Draw("e0");

  plotlabel = new TPaveText(0.23,0.87,0.43,0.92,"NDC");
   plotlabel->SetTextColor(kBlack);
   plotlabel->SetFillColor(kWhite);
   plotlabel->SetBorderSize(0);
   plotlabel->SetTextAlign(12);
   plotlabel->SetTextSize(0.03);
   plotlabel->AddText("CMS Preliminary 2010");
 plotlabel2 = new TPaveText(0.23,0.82,0.43,0.87,"NDC");
   plotlabel2->SetTextColor(kBlack);
   plotlabel2->SetFillColor(kWhite);
   plotlabel2->SetBorderSize(0);
   plotlabel2->SetTextAlign(12);
   plotlabel2->SetTextSize(0.03);
   plotlabel2->AddText("#sqrt{s} = 7 TeV");
  plotlabel3 = new TPaveText(0.23,0.75,0.43,0.80,"NDC");
   plotlabel3->SetTextColor(kBlack);
   plotlabel3->SetFillColor(kWhite);
   plotlabel3->SetBorderSize(0);
   plotlabel3->SetTextAlign(12);
   plotlabel3->SetTextSize(0.03);
   sprintf(temp, "%.4f", LUMINOSITY);
   plotlabel3->AddText((string("#int#font[12]{L}dt = ") + 
                        temp + string(" pb^{ -1}")).c_str());
   plotlabel4 = new TPaveText(0.6,0.82,0.8,0.87,"NDC");
   plotlabel4->SetTextColor(kBlack);
   plotlabel4->SetFillColor(kWhite);
   plotlabel4->SetBorderSize(0);
   plotlabel4->SetTextAlign(12);
   plotlabel4->SetTextSize(0.03);
   err = ErrorInProduct(nsig, nErr, 1.0-e, eErr, corr);
   sprintf(temp, "Signal = %.2f #pm %.2f", NumSignalFail->getVal(), err);
   plotlabel4->AddText(temp);
   plotlabel5 = new TPaveText(0.6,0.77,0.8,0.82,"NDC");
   plotlabel5->SetTextColor(kBlack);
   plotlabel5->SetFillColor(kWhite);
   plotlabel5->SetBorderSize(0);
   plotlabel5->SetTextAlign(12);
   plotlabel5->SetTextSize(0.03);
   sprintf(temp, "Bkg = %.2f #pm %.2f", ParNumBkgFail->getVal(), ParNumBkgFail->getError());
   plotlabel5->AddText(temp);
   plotlabel6 = new TPaveText(0.6,0.87,0.8,0.92,"NDC");
   plotlabel6->SetTextColor(kBlack);
   plotlabel6->SetFillColor(kWhite);
   plotlabel6->SetBorderSize(0);
   plotlabel6->SetTextAlign(12);
   plotlabel6->SetTextSize(0.03);
   plotlabel6->AddText("Failing probes");
   plotlabel7 = new TPaveText(0.6,0.72,0.8,0.77,"NDC");
   plotlabel7->SetTextColor(kBlack);
   plotlabel7->SetFillColor(kWhite);
   plotlabel7->SetBorderSize(0);
   plotlabel7->SetTextAlign(12);
   plotlabel7->SetTextSize(0.03);
   sprintf(temp, "Eff = %.3f #pm %.3f", ParEfficiency->getVal(), ParEfficiency->getErrorHi(), ParEfficiency->getErrorLo());
   plotlabel7->AddText(temp);
   plotlabel8 = new TPaveText(0.6,0.72,0.8,0.66,"NDC");
   plotlabel8->SetTextColor(kBlack);
   plotlabel8->SetFillColor(kWhite);
   plotlabel8->SetBorderSize(0);
   plotlabel8->SetTextAlign(12);
   plotlabel8->SetTextSize(0.03);
   sprintf(temp, "#chi^{2}/DOF = %.3f", frame2->chiSquare());
   plotlabel8->AddText(temp);

//   plotlabel->Draw();
//   plotlabel2->Draw();
//   plotlabel3->Draw();
  plotlabel4->Draw();
  plotlabel5->Draw();
  plotlabel6->Draw();
  plotlabel7->Draw();
  plotlabel8->Draw();

  c2->SaveAs( cname + TString(".gif"));
//   c2->SaveAs( cname + TString(".eps"));
//   c2->SaveAs( cname + TString(".root"));
  canvasFile->WriteTObject(c2, c2->GetName(), "WriteDelete");

  canvasFile->Close();

  
  effTextFile.width(40);
  effTextFile << label;
  effTextFile.width(20);
  effTextFile  << setiosflags(ios::fixed) << setprecision(4) << left << ParEfficiency->getVal() ;
  effTextFile.width(20);
  effTextFile  << left << ParEfficiency->getErrorHi();
  effTextFile.width(20);
  effTextFile  << left << ParEfficiency->getErrorLo();
  effTextFile.width(14);
  effTextFile  << setiosflags(ios::fixed) << setprecision(2) << left << nSignalPass ;
  effTextFile.width(14);
  effTextFile << left << nSignalFail << endl;

} 
//
// Saving test setup information to a file.
//
BOOL CPageSetup::SaveConfig( ostream& outfile )
{
	// Update memory variables with data located on GUI.
	UpdateData( TRUE );

	// Save test setup information.
	outfile << "'TEST SETUP ============================"
			"========================================" << endl;

	outfile << "'Test Description" << endl
			<< "\t" << (LPCTSTR)test_name << endl;

	// Save run time information.

	outfile << setiosflags( ios::left );

	outfile << "'Run Time" << endl
			<< "'\t" << setw(11) << "hours"
				<< setw(11) << "minutes"
				<< "seconds" << endl
			<< "\t" << setw(11) << hours
				<< setw(11) << minutes
				<< seconds << endl;

	// Save miscellaneous information.
	outfile << "'Ramp Up Time (s)" << endl
			<< "\t" << ramp_time << endl;

	outfile << "'Default Disk Workers to Spawn" << endl
			<< "\t";
	
	if (disk_worker_count == -1)
		outfile << "NUMBER_OF_CPUS" << endl;
	else
		outfile << disk_worker_count << endl;

	outfile << "'Default Network Workers to Spawn" << endl
			<< "\t";

	if (net_worker_count == -1)
		outfile << "NUMBER_OF_CPUS" << endl;
	else
		outfile << net_worker_count << endl;

	outfile << "'Record Results" << endl << "\t";

	switch (result_type)
	{
	case RecordAll:
		outfile << "ALL" << endl;
		break;
	case RecordNoTargets:
		outfile << "NO_TARGETS" << endl;
		break;
	case RecordNoWorkers:
		outfile << "NO_WORKERS" << endl;
		break;
	case RecordNoManagers:
		outfile << "NO_MANAGERS" << endl;
		break;
	case RecordNone:
		outfile << "NONE" << endl;
		break;
	default:
		ErrorMessage("Error while saving test setup information.  "
			"Record Results setting in Test Setup tab is invalid.  "
			"Please report this as an Iometer bug.");
		return FALSE;
	}

	// Save worker cycling information.
	outfile << "'Worker Cycling" << endl
			<< "'\t" << setw(11) << "start"
				<< setw(11) << "step"
				<< "step type" << endl
			<< "\t" << setw(11) << worker_cycling.start
				<< setw(11) << worker_cycling.step;

	switch (worker_cycling.step_type)
	{
	case StepLinear:
		outfile << "LINEAR" << endl;
		break;
	case StepExponential:
		outfile << "EXPONENTIAL" << endl;
		break;
	default:
		ErrorMessage("Error saving test setup data.  Worker cycling step type "
						"is neither StepLinear nor StepExponential.");
		return FALSE;
	}

	// Save disk cycling information.
	outfile << "'Disk Cycling" << endl
			<< "'\t" << setw(11) << "start"
				<< setw(11) << "step"
				<< "step type" << endl
			<< "\t" << setw(11)	<< target_cycling.start
				<< setw(11) << target_cycling.step;

	switch (target_cycling.step_type)
	{
	case StepLinear:
		outfile << "LINEAR" << endl;
		break;
	case StepExponential:
		outfile << "EXPONENTIAL" << endl;
		break;
	default:
		ErrorMessage("Error saving test setup data.  Disk cycling step type "
						"is neither StepLinear nor StepExponential.");
		return FALSE;
	}

	// Save queue cycling information.
	outfile << "'Queue Depth Cycling" << endl
			<< "'\t" << setw(11) << "start"
				<< setw(11) << "end"
				<< setw(11) << "step"
				<< "step type" << endl
			<< "\t" << setw(11) << queue_cycling.start
				<< setw(11) << queue_cycling.end
				<< setw(11) << queue_cycling.step;

	switch (queue_cycling.step_type)
	{
	case StepLinear:
		outfile << "LINEAR" << endl;
		break;
	case StepExponential:
		outfile << "EXPONENTIAL" << endl;
		break;
	default:
		ErrorMessage("Error saving test setup data.  Queue depth cycling step type "
						"is neither LINEAR nor EXPONENTIAL.");
		return FALSE;
	}

	// Save test type.
	outfile << "'Test Type" << endl << "\t";

	switch (test_type)
	{
	case CyclingTargets:
		outfile << "CYCLE_TARGETS" << endl;
		break;
	case CyclingWorkers:
		outfile << "CYCLE_WORKERS" << endl;
		break;
	case CyclingIncTargetsParallel:
		outfile << "INCREMENT_TARGETS_PARALLEL" << endl;
		break;
	case CyclingIncTargetsSerial:
		outfile << "INCREMENT_TARGETS_SERIAL" << endl;
		break;
	case CyclingWorkersTargets:
		outfile << "CYCLE_WORKERS_AND_TARGETS" << endl;
		break;
	case CyclingQueue:
		outfile << "CYCLE_OUTSTANDING_IOS" << endl;
		break;
	case CyclingQueueTargets:
		outfile << "CYCLE_OUTSTANDING_IOS_AND_TARGETS" << endl;
		break;
	default:
		outfile << "NORMAL" << endl;
		break;
	}
		
	// Mark end of test setup information.
	outfile << "'END test setup" << endl;

	return TRUE;	// no errors (FALSE indicates an error)
}
Exemple #22
0
std::ostream& ossimNitfFileHeaderV2_0::print(std::ostream& out,
                                             const std::string& prefix) const
{
   out << setiosflags(std::ios::left)
       << prefix << std::setw(24) << "FHDR:"
       << theFileTypeVersion << "\n"
       << prefix << std::setw(24) << "CLEVEL:"
       << theComplexityLevel << "\n"
       << prefix << std::setw(24) << "STYPE:"
       << theSystemType  << "\n"    
       << prefix << std::setw(24) << "OSTAID:"
       << theOriginatingStationId << "\n"
       << prefix << std::setw(24) << "FDT:"
       << theDateTime  << "\n"      
       << prefix << std::setw(24) << "FTITLE:"
       << theFileTitle  << "\n"     
       << prefix << std::setw(24) << "FSCLAS:"
       << theSecurityClassification << "\n"
       << prefix << std::setw(24) << "FSCODE:"
       << theCodewords << "\n"
       << prefix << std::setw(24) << "FSCTLH:"
       << theControlAndHandling << "\n"
       << prefix << std::setw(24) << "FSREL:"
       << theReleasingInstructions << "\n"
       << prefix << std::setw(24) << "FSCAUT:"
       << theClassificationAuthority << "\n"
       << prefix << std::setw(24) << "FSCTLN:"
       << theSecurityControlNumber << "\n"
       << prefix << std::setw(24) << "FSDWNG:"
       << theSecurityDowngrade << "\n"
       << prefix << std::setw(24) << "FSDEVT:"
       << theDowngradingEvent << "\n"
       << prefix << std::setw(24) << "FSCOP:"
       << theCopyNumber << "\n"
       << prefix << std::setw(24) << "FSCPYS:"
       << theNumberOfCopies << "\n"
       << prefix << std::setw(24) << "ENCRYP:"
       << theEncryption << "\n"
       << prefix << std::setw(24) << "ONAME:"
       << theOriginatorsName << "\n"
       << prefix << std::setw(24) << "OPHONE:"
       << theOriginatorsPhone << "\n"
       << prefix << std::setw(24) << "FL:"
       << theFileLength << "\n"
       << prefix << std::setw(24) << "HL:"
       << theHeaderLength << "\n"
       << prefix << std::setw(24) << "NUMI:"
       << theNumberOfImageInfoRecords << "\n";

   ossim_uint32 index;
   
   for (index = 0; index < theNitfImageInfoRecords.size(); ++index)
   {
      std::ostringstream os;
      os << std::setw(3) << std::setfill('0') << (index+1) << ":";
      
      ossimString tmpStr = "LISH";
      tmpStr += os.str();
      
      out << prefix << std::setw(24) << tmpStr
          << theNitfImageInfoRecords[index].theImageSubheaderLength << "\n";
      tmpStr = "LI";
      tmpStr += os.str();
      
      out << prefix << std::setw(24) << tmpStr
          << theNitfImageInfoRecords[index].theImageLength << "\n";
   }

   out << prefix << std::setw(24) << "NUMS:" << theNumberOfSymbolInfoRecords
       << "\n";

   for (index = 0; index < theNitfSymbolInfoRecords.size(); ++index)
   {
      std::ostringstream os;
      os << std::setw(3) << std::setfill('0') << (index+1) << ":";

      ossimString tmpStr = "LSSH";
      tmpStr += os.str();

      out << tmpStr
          << theNitfSymbolInfoRecords[index].theSymbolSubheaderLength << "\n";

      tmpStr = "LS";
      tmpStr += os.str();

      out << tmpStr 
          << theNitfSymbolInfoRecords[index].theSymbolLength << "\n";
   }

   
   out << prefix << std::setw(24) << "NUML:" << theNumberOfLabelInfoRecords
       << "\n";

   for (index = 0; index < theNitfLabelInfoRecords.size(); ++index)
   {
      std::ostringstream os;
      os << std::setw(3) << std::setfill('0') << (index+1) << ":";

      ossimString tmpStr = "LLSH";
      tmpStr += os.str();

      out << tmpStr
          << theNitfLabelInfoRecords[index].theLabelSubheaderLength  << "\n";

      tmpStr = "LL";
      tmpStr += os.str();

      out << tmpStr 
          << theNitfLabelInfoRecords[index].theLabelLength << "\n";
   }

   out << prefix << std::setw(24) << "NUMT:" << theNumberOfTextFileInfoRecords
       << "\n";

   for (index = 0; index < theNitfTextInfoRecords.size(); ++index)
   {
      std::ostringstream os;
      os << std::setw(3) << std::setfill('0') << (index+1) << ":";

      ossimString tmpStr = "LTSH";
      tmpStr += os.str();

      out << prefix << std::setw(24) << tmpStr
          << theNitfTextInfoRecords[index].theTextSubheaderLength << "\n";

      tmpStr = "LT";
      tmpStr += os.str();

      out << prefix << std::setw(24) << tmpStr 
          << theNitfTextInfoRecords[index].theTextLength<< "\n";
   }

   out << prefix << std::setw(24) << "NUMDES:"
       << theNumberOfDataExtSegInfoRecords << "\n";

   for (index = 0; index < theNitfDataExtSegInfoRecords.size(); ++index)
   {
      std::ostringstream os;
      os << std::setw(3) << std::setfill('0') << (index+1) << ":";

      ossimString tmpStr = "LDSH";
      tmpStr += os.str();

      out << prefix << std::setw(24) << tmpStr
          << theNitfDataExtSegInfoRecords[index].theDataExtSegSubheaderLength
          << "\n";

      tmpStr = "LD";
      tmpStr += os.str();

      out << prefix << std::setw(24) << tmpStr 
          << theNitfDataExtSegInfoRecords[index].theDataExtSegLength << "\n";
   }

   out << prefix << std::setw(24) << "NUMRES:"
       << theNumberOfResExtSegInfoRecords << "\n";

   for (index = 0; index < theNitfResExtSegInfoRecords.size(); ++index)
   {
      std::ostringstream os;
      os << std::setw(3) << std::setfill('0') << (index+1) << ":";

      ossimString tmpStr = "LRSH";
      tmpStr += os.str();

      out << tmpStr
          << theNitfResExtSegInfoRecords[index].theResExtSegSubheaderLength
          << "\n";

      tmpStr = "LR";
      tmpStr += os.str();

      out << tmpStr 
          << theNitfResExtSegInfoRecords[index].theResExtSegLength
          << "\n";
   }

   out << prefix << std::setw(24) << "UDHDL:"
       << theUserDefinedHeaderDataLength << "\n"
       << prefix << std::setw(24) << "UDHOFL:"
       << theUserDefinedHeaderOverflow << "\n"
       << prefix << std::setw(24) << "XHDL:"
       << theExtendedHeaderDataLength << "\n";
   
   return ossimNitfFileHeader::print(out, prefix);
}
Exemple #23
0
int main(){
	chdir(QUERY_DATA_PATH);
	EnvDB *env = new EnvDB();
	env->open();
	
	BDBOpe db_r_1(env->getEnv(), "1.1.DSM");
	BDBOpe db_r_2(env->getEnv(), "1.2.DSM");
	BDBOpe db_n_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n2_1(env->getEnv(), "2.1.DSM");
	BDBOpe db_n2_2(env->getEnv(), "2.2.DSM");
	BDBOpe db_n_3(env->getEnv(), "2.3.DSM");
	BDBOpe db_s_1(env->getEnv(), "3.1.DSM");
	BDBOpe db_s_4(env->getEnv(), "3.4.DSM");
	BDBOpe db_p_1(env->getEnv(), "4.1.DSM");
	BDBOpe db_p_5(env->getEnv(), "4.5.DSM");
	BDBOpe db_c_1(env->getEnv(), "6.1.DSM");
	BDBOpe db_c_4(env->getEnv(), "6.4.DSM");
	BDBOpe db_o(env->getEnv(), "ORDERS.row");
	BDBOpe db_l(env->getEnv(), "LINEITEM.row");
	
	SecondDB *sDB1;
	int (*pf1)(Db *sdbp, const Dbt*pkey, const Dbt *pdata, Dbt *skey);
	pf1 = L_1_secondary;
	sDB1 = new SecondDB(env->getEnv(), "8.1.secondary");
	sDB1->setNumCmp();
	
	SecondDB *sDB2;
	int (*pf2)(Db *sdbp, const Dbt*pkey, const Dbt *pdata, Dbt *skey);
	pf2 = O_2_secondary;
	sDB2 = new SecondDB(env->getEnv(), "7.2.secondary");
	sDB2->setNumCmp();

	Operator *o1, *o2, *o3, *o4, *o5, *o6, *o7, *o8, *o9, *o10;
	Operator *o11, *o12, *o13, *o14, *o15, *o16, *o17, *o18, *o19, *o20;
	Operator *o21, *o22, *o23, *o24, *o25, *o26, *o27, *o28, *o29, *o30;
	Operator *o31, *o32, *o33, *o34, *o35, *o36, *o37, *o38, *o39, *o40;
	Operator *o41, *o42, *o43, *o44, *o45, *o46, *o47, *o48, *o49, *o50, *o51;
	db_r_1.open();
	db_r_2.open();
	db_n_1.open();
	db_n2_1.open();
	db_n2_2.open();
	db_n_3.open();
	db_s_1.open();
	db_s_4.open();
	db_p_1.open();
	db_p_5.open();
	db_c_1.open();
	db_c_4.open();
	
	
	db_o.open();
	sDB2->open(0);
	db_o.associate(sDB2->getDb(), pf2);
	sDB2->openCursor();
	
	db_l.open();
	sDB1->open(0);
	db_l.associate(sDB1->getDb(), pf1);
	sDB1->openCursor();

	TABLE_REC tableRec_r;
	TABLE_REC tableRec_n;
	TABLE_REC tableRec_s;
	TABLE_REC tableRec_p;
	TABLE_REC tableRec_c;
	TABLE_REC tableRec_o;
	TABLE_REC tableRec_l;

	tableRec_r.tableID = 1;
	tableRec_r.attriNum = 3;

	tableRec_n.tableID = 2;
	tableRec_n.attriNum = 4;
	
	tableRec_s.tableID = 3;
	tableRec_s.attriNum = 7;
	
	tableRec_p.tableID = 4;
	tableRec_p.attriNum = 9;
	
	tableRec_c.tableID = 6;
	tableRec_c.attriNum = 8;
	
	tableRec_o.tableID = 7;
	tableRec_o.attriNum = 9;
	
	tableRec_l.tableID = 8;
	tableRec_l.attriNum = 16;
	
	
	ATTRIBUTE_REC attriRec_r[tableRec_r.attriNum];
	ATTRIBUTE_REC attriRec_n[tableRec_n.attriNum];
	ATTRIBUTE_REC attriRec_s[tableRec_s.attriNum];
	ATTRIBUTE_REC attriRec_p[tableRec_p.attriNum];
	ATTRIBUTE_REC attriRec_c[tableRec_c.attriNum];
	ATTRIBUTE_REC attriRec_o[tableRec_o.attriNum];
	ATTRIBUTE_REC attriRec_l[tableRec_l.attriNum];

	AttributeManager AM(env->getEnv());
	
	AM.getForTableID(tableRec_r, attriRec_r);
	AM.getForTableID(tableRec_n, attriRec_n);
	AM.getForTableID(tableRec_s, attriRec_s);
	AM.getForTableID(tableRec_p, attriRec_p);
	AM.getForTableID(tableRec_c, attriRec_c);
	AM.getForTableID(tableRec_o, attriRec_o);
	AM.getForTableID(tableRec_l, attriRec_l);

/* selection1 */
	FixStrPosVal pv1(1,25);
	string str1("AMERICA");
	pv1.setStr(str1);

	ValueNode vn1 = ValueNode(&pv1);
	ColumnRefNode cn1;
	cn1.tableID = 1;
	cn1.attriID = 2;
	AxprNode an1 = AxprNode(EQ, &cn1, &vn1);
	

/* selection2 */

	DatePosVal pv2(1,(unsigned char *)"1995-01-01");
	DatePosVal pv3(1,(unsigned char *)"1996-12-31");
	

	ValueNode vn2 = ValueNode(&pv2);
	ValueNode vn3 = ValueNode(&pv3);
	ColumnRefNode cn2;
	cn2.tableID = 7;
	cn2.attriID = 5;
	AxprNode an2 = AxprNode(GE, &cn2, &vn2);
	AxprNode an3 = AxprNode(LE, &cn2, &vn3);
	AxprNode an4 = AxprNode(AND, &an2, &an3);

/* selection3 */
	VarStrPosVal pv4(1,25);
	string str2("ECONOMY ANODIZED STEEL");
	pv4.set((unsigned char*)str2.c_str());

	ValueNode vn4 = ValueNode(&pv4);
	ColumnRefNode cn3;
	cn3.tableID = 4;
	cn3.attriID = 5;
	AxprNode an5 = AxprNode(EQ, &cn3, &vn4);
	

	
/*Join1*/
	OPERATION_NODE jop1, jop2;
	jop1.tableID = 6;
	jop1.attributeID = 4;
	jop2.tableID = 6;
	jop2.attributeID = 1;
	
	JOIN_OPERATION_NODE jon1;
	jon1.rightNode = jop1;
	jon1.leftNode = jop2;

/*Join2*/
	OPERATION_NODE jop3, jop4;
	jop3.tableID = 7;
	jop3.attributeID = 2;
	jop4.tableID = 7;
	jop4.attributeID = 5;
	
	JOIN_OPERATION_NODE jon2;
	jon2.rightNode = jop3;
	jon2.leftNode = jop4;

/*Join3*/
	OPERATION_NODE jop5, jop6;
	jop5.tableID = 7;
	jop5.attributeID = 5;
	jop6.tableID = 7;
	jop6.attributeID = 1;
	
	JOIN_OPERATION_NODE jon3;
	jon3.rightNode = jop5;
	jon3.leftNode = jop6;

/*Join4*/
	OPERATION_NODE jop7, jop8;
	jop7.tableID = 7;
	jop7.attributeID = 1;
	jop8.tableID = 8;
	jop8.attributeID = 1;
	
	JOIN_OPERATION_NODE jon4;
	jon4.rightNode = jop7;
	jon4.leftNode = jop8;
	
/*Join5*/
	OPERATION_NODE jop9, jop10;
	jop9.tableID = 4;
	jop9.attributeID = 1;
	jop10.tableID = 8;
	jop10.attributeID = 2;
	
	JOIN_OPERATION_NODE jon5;
	jon5.rightNode = jop9;
	jon5.leftNode = jop10;

/*Join6*/
	OPERATION_NODE jop11, jop12;
	jop11.tableID = 3;
	jop11.attributeID = 1;
	jop12.tableID = 8;
	jop12.attributeID = 3;
	
	JOIN_OPERATION_NODE jon6;
	jon6.rightNode = jop11;
	jon6.leftNode = jop12;
	
/* Projection1 */

	OPERATION_NODE pro1[1];
	pro1[0].tableID = 6;
	pro1[0].attributeID = 1;
	
	
/* Projection2 */

	OPERATION_NODE pro2[2];
	pro2[0].tableID = 7;
	pro2[0].attributeID = 1;
	pro2[1].tableID = 7;
	pro2[1].attributeID = 5;
	
/* Projection3 */

	OPERATION_NODE pro3[1];
	pro3[0].tableID = 8;
	pro3[0].attributeID = 2;
	
/* Projection4 */

	OPERATION_NODE pro4[2];
	pro4[0].tableID = 8;
	pro4[0].attributeID = 3;
	pro4[1].tableID = 2;
	pro4[1].attributeID = 2;

/* Projection5 */

	OPERATION_NODE pro5[4];
	pro5[0].tableID = 7;
	pro5[0].attributeID = 5;
	pro5[1].tableID = 2;
	pro5[1].attributeID = 2;
	pro5[2].tableID = 8;
	pro5[2].attributeID = 6;
	pro5[3].tableID = 8;
	pro5[3].attributeID = 7;
	
/* Projection6 */

	OPERATION_NODE pro6[5];
	pro6[0].tableID = 7;
	pro6[0].attributeID = 5;
	pro6[1].tableID = 8;
	pro6[1].attributeID = 2;
	pro6[2].tableID = 8;
	pro6[2].attributeID = 3;
	pro6[3].tableID = 8;
	pro6[3].attributeID = 6;
	pro6[4].tableID = 8;
	pro6[4].attributeID = 7;

/* Projection7 */

	OPERATION_NODE pro7[4];
	pro7[0].tableID = 7;
	pro7[0].attributeID = 5;
	pro7[1].tableID = 8;
	pro7[1].attributeID = 3;
	pro7[2].tableID = 8;
	pro7[2].attributeID = 6;
	pro7[3].tableID = 8;
	pro7[3].attributeID = 7;

/* Projection8 */

	OPERATION_NODE pro8[2];
	pro8[0].tableID = 3;
	pro8[0].attributeID = 1;
	pro8[1].tableID = 2;
	pro8[1].attributeID = 2;

/* Projection9 */

	OPERATION_NODE pro9[4];
	pro9[0].tableID = 2;
	pro9[0].attributeID = 2;
	pro9[1].tableID = 7;
	pro9[1].attributeID = 5;
	pro9[2].tableID = 8;
	pro9[2].attributeID = 6;
	pro9[3].tableID = 8;
	pro9[3].attributeID = 7;

/* Extract */
	OPERATION_NODE ex[1];
	ex[0].tableID = 7;
	ex[0].attributeID = 5;

/* GROUP */
	IntPosVal pv5(1, 1);
	ValueNode vn5 = ValueNode(&pv5);
	ColumnRefNode cn4[2];
	cn4[0].tableID = 8;
	cn4[0].attriID = 6;
	cn4[1].tableID = 8;
	cn4[1].attriID = 7;
	ArithmeticNode arith1(SUB, &vn5, &cn4[1]);
	ArithmeticNode arith2(MUL, &cn4[0], &arith1);
	
	Aggregation *aggre[1];
	aggre[0] = new Sum(&arith2, 2);
	
	
	OPERATION_NODE group[1];
	group[0].tableID = 7;
	group[0].attributeID = 5;

/* Sort 1 */
	OPERATION_NODE so1[1];
	so1[0].tableID = 7;
	so1[0].attributeID = 5;
	so1[0].option = 0;
	
	


	OPERATION_NODE op1;
	op1.tableID = 2;
	op1.attributeID = 3;
	
	OPERATION_NODE op2;
	op2.tableID = 6;
	op2.attributeID = 4;
	
	OPERATION_NODE op3;
	op3.tableID = 7;
	op3.attributeID = 2;
	
	OPERATION_NODE op4;
	op4.tableID = 8;
	op4.attributeID = 1;
	
	OPERATION_NODE op5;
	op5.tableID = 3;
	op5.attributeID = 4;
	
	OPERATION_NODE op6;
	op6.tableID = 2;
	op6.attributeID = 2;
	
	
/* index position */
	
	OPERATION_NODE idx1[1];
	idx1[0].tableID = 7;
	idx1[0].attributeID = 1;
	
/* index position */
	
	OPERATION_NODE idx2[1];
	idx2[0].tableID = 6;
	idx2[0].attributeID = 1;

//===============================================================-


	o1 = new ScanDSM(&db_r_2, &attriRec_r[1], 1);
//	cout << "OK new o1" << endl;
	
	o2 = new SelectBitOut((Node *)&an1 ,(unsigned int)1);
//	cout << "OK new o2" << endl;
	o2->setPreOperator(o1);
	
	o3 = new ScanDSM(&db_r_1, attriRec_r, 1);
//	cout << "OK new o3" << endl;
	
	o4 = new BitFilter(o3, o2);
//	cout << "OK new o4" << endl;
	
	
	o5 = new ScanDSM(&db_n_3, &attriRec_n[2], 1);
//	cout << "OK new o5" << endl;
	
	o6 = new JoinIndex_OneHash(o4, o5); 
//	cout << "OK new o6" << endl;
	
	o7 = new ScanDSM(&db_n_1, &attriRec_n[0], 1);
//	cout << "OK new o7" << endl;
	
	o8 = new ScanFromJI(o7, o6, &op1);
//	cout << "OK new o8" << endl;

	o9 = new ScanDSM(&db_c_4, &attriRec_c[3], 1);
//	cout << "OK new o9" << endl;

	o10 = new JoinIndex_OneHash(o8, o9); 
//	cout << "OK new o10" << endl;
	
	o11 = new ScanDSM(&db_c_1, &attriRec_c[0], 1);
//	cout << "OK new o11" << endl;
	
	o12 = new ScanFromJI(o11, o10, &op2);
//	cout << "OK new o12" << endl;
	
	o13 = new Projection(pro1, 1);
	o13->setPreOperator(o12);
	

/* ======== Nested Loop Join with Index ============ */

	IndexScan *IS2 = new IndexScan((BDBOpe *)sDB2, attriRec_o, 9);
	o14 = new NestedJoin_Index(IS2, o13, idx2);
	//l_partkey, l_suppkey, l_extentdedprice, l_discount, o_orderdate
	//o15 = new Projection(pro6, 5);
	//o15->setPreOperator(o22);
	
/* ======================================================= */
	

	o17 = new Selection((Node *)&an4 ,(unsigned int)2);
//	cout << "OK new o17" << endl;
	o17->setPreOperator(o14);
	

	o21 = new Projection(pro2, 2);
	o21->setPreOperator(o17);
//	cout << "OK new o21" << endl;


/* ======== Nested Loop Join with Index ============ */

	IndexScan *IS1 = new IndexScan((BDBOpe *)sDB1, attriRec_l, 16);
	o22 = new NestedJoin_Index(IS1, o21, idx1);
	//l_partkey, l_suppkey, l_extentdedprice, l_discount, o_orderdate
	o23 = new Projection(pro6, 5);
	o23->setPreOperator(o22);
	
/* ======================================================= */
	
	
	

	o24 = new ScanDSM(&db_p_5, &attriRec_p[4], 1);
//	cout << "OK new o24" << endl;

	o25 = new SelectBitOut((Node *)&an5 ,1);
//	cout << "OK new o25" << endl;
	o25->setPreOperator(o24);
	
	o26 = new ScanDSM(&db_p_1, &attriRec_p[0], 1);
//	cout << "OK new o26" << endl;

	o27 = new BitFilter(o26, o25);
//	cout << "OK new o27" << endl;
	
	
	o29 = new OneSideHashJoin(o27, o23, &jon5, 1); 
//	cout << "OK new o29" << endl;
	
	o30 = new Projection(pro7, 4);
	o30->setPreOperator(o29);
//	cout << "OK new o30" << endl;
	
	
	
	
	o32 = new ScanDSM(&db_n2_1, &attriRec_n[0], 1);
//	cout << "OK new o32" << endl;
	/**/
	o33 = new ScanDSM(&db_n2_2, &attriRec_n[1], 1);
//	cout << "OK new o33" << endl;
	
	o34 = new ScanFromJI(o32, o33, &op6);
//	cout << "OK new o34" << endl;
	/*  */
	o35 = new ScanDSM(&db_s_4, &attriRec_s[3], 1);
//	cout << "OK new o35" << endl;
	
	o36 = new JoinIndex_OneHash(o34, o35); 
//	cout << "OK new o36" << endl;
	
	o37 = new ScanDSM(&db_s_1, &attriRec_s[0], 1);
//	cout << "OK new o37" << endl;
	
	o38 = new ScanFromJI(o37, o36, &op5);
//	cout << "OK new o38" << endl;

	o39 = new Projection(pro8, 2);
	o39->setPreOperator(o38);
	
	
	o40 = new OneSideHashJoin(o39, o30, &jon6,1); 
//	cout << "OK new o40" << endl;
	
	
	
	
	
	
	o41 = new Projection(pro9, 4);
	o41->setPreOperator(o40);
//	cout << "OK new o41" << endl;
	/*l_suppkey, n_name, l_partkey, o_orderdate,*/

	
	o48 = new Extract(ex, true, false, false);
	o48->setPreOperator(o41);
//	cout << "OK new o48" << endl;
	
	o49 = new GroupBy(group, 1, aggre, 1);
	o49->setPreOperator(o48);
//	cout << "OK new o49" << endl;
	
	o50 = new Sort(so1, 1);
	o50->setPreOperator(o49);
//	cout << "OK new o50" << endl;


	o51 = new OutPut(TIME_OUT);
//	cout << "OK new o51" << endl;
	o51->setPreOperator(o50);
	o51->init(env->getEnv());
	cout << "TEST START" << endl;
	
	cout << setprecision(2);
	cout << setiosflags(ios::fixed); 
	o51->exec();
	

}
Exemple #24
0
bool LogHandler::handle(MatchHandlerParamter& para, AdResultMap& result) {
  TimeStat ts;
  TimeStat subts;
  AdInfoSeq ad_info_seq;

  ::MyUtil::StrSeq pv_log_seq;
  //::MyUtil::StrSeq engine_log_seq;
  ::MyUtil::StrSeq cpm_log_seq;

  UserProfile & profile = para.userProfile_;
  ostringstream log;
  //ostringstream engine_log;
  ostringstream cpm_log;
  MyUtil::LongSeq group_id_seq;
  vector<SelectedAdGroupPtr> zone_selected  =para.final_selected_groups_;
  std::sort(zone_selected.begin(), zone_selected.end(), sortByPos);
  for(vector<SelectedAdGroupPtr>::iterator sit = zone_selected.begin();
      sit != zone_selected.end(); ++sit){
    AdInfo ad_info;
    MyUtil::Date date(time(NULL));
    AdGroupPtr group_ptr = (*sit)->group_;
    group_id_seq.push_back(group_ptr->group_id());
    map<Ice::Long,Ice::Long> creative2widget = group_ptr->creative2widget();
    if(!group_ptr->creative_ids().empty()){
      ad_info.creativeid = *(group_ptr->creative_ids().begin());
    } else{
      ad_info.creativeid = 0;
    }
    ad_info.groupid = group_ptr->group_id();
    ad_info.updateTime = 0;
    LogParas log_para;
    log_para.cost_ = (*sit)->cost_;
    log_para.user_profile_ = para.userProfile_; //profile;
    log_para.pv_time_ = Date(time(NULL)).time();
    log_para.creative_id_ = ad_info.creativeid;
    log_para.zone_id_ = para.adzone_->id();
    log_para.max_price_ = group_ptr->max_price(log_para.zone_id_);
    log_para.ad_count_ = para.count();
    log_para.next_load_time_ = para.next_load_time_;
    log_para.refresh_idx_ = para.refresh_idx_;
    Ice::Long group_id = ad_info.creativeid / 100000;
    ostringstream append_info;
    if(!para.tag_.empty()) {
      append_info << para.tag_;
    } else {
      append_info << "rr_0";
    }
    //展示的绝对位置
    log_para.pos_ = (*sit)->pos_;
    log_para.demo_state_ = (*sit)->demo_state_;
    log_para.demo_ctr_ = (*sit)->demo_ctr_;
    log_para.widget_id_ = (*sit)->selected_widget_id_;    
    append_info << '_' << log_para.widget_id_;
    log_para.append_info_ = append_info.str();
    log_para.session_id_ = LogHelper::instance().MakeSessionId(log_para);
    log_para.demo_ctr_ = LogHelper::instance().TransCtr(log_para); //隐藏点击率
    ad_info.text = LogHelper::instance().MakeText(log_para);
    if(!(*sit)->extra_.empty()) {
      ad_info.updateTime = -1;
    } else {
      ad_info.updateTime = 0;
    }
    ad_info_seq.push_back(ad_info);

    //call AdLogAdapter
    Ice::Long zone_id = log_para.zone_id_;
    Ice::Long creativeid = log_para.creative_id_;
    string http = LogHelper::instance().MakeHttp(log_para);
    string ip = LogHelper::instance().MakeIp(profile.ip());
    int uid = profile.id();

    string deal_referer = para.referer_;
    LogHelper::instance().Process(deal_referer);
    MCE_DEBUG("LogHandler::handle-->gid:"<<(*sit)->group_->group_id()<<",pos:" <<(*sit)->pos_);

    //int sort_type = EngineConfig::instance().sort_type();
    int sort_type = EngineConfig::instance().server_index();
    //transtype修改,现在写的是数据库里读出来的,不再是写死的
    //display_type:1=轮播, 2= cpm ,3=余量, 4= cpc, 5=产品
    double cost = log_para.cost_;
    if(group_ptr->IsCpm()){
      log << setprecision(5);
    } else if(group_ptr->IsCpc()){//cpc的pv cost=0,cpm为相应扣费
      log << setprecision(0);
      cost = 0;
    }

    log << EngineConfig::instance().server_name() << "||" << ip << "||" << date.toDateTime() << "||\"GET "
        << http << " HTTP/1.0\"||200||undefined||" << log_para.session_id_ << "||undefined||" << group_ptr->trans_type() << "||" << sort_type << "||none||"
        << deal_referer << "||" << zone_id << "^B^B^B^B^B^B^B||" << creativeid << "^B" << group_ptr->member_id()
        << "^B" << group_ptr->bid_unit_id() << "^B" <<  setiosflags(ios::fixed) << cost  << setiosflags(ios::scientific) << setprecision(6)
        << "^B" << group_ptr->max_price(zone_id) << "^B" << deal_referer
        << "^B" << log_para.pos_ <<"^B" << log_para.demo_state_ << "^B2^B"<<log_para.demo_ctr_<<"||" << group_ptr->display_type();
    if((!log_para.append_info_.empty()) && (log_para.append_info_.compare("-") != 0)) {
      log << "||" << log_para.append_info_;
    }
    pv_log_seq.push_back(log.str());
    log.str("");

    if(group_ptr->IsCpm()){//cpm
     //cpm价格具体逻辑写在caculate_cost里面,要/1000
      cpm_log << log_para.creative_id_ << ',' << group_id << ',' 
              << group_ptr->campaign_id() << ',' << group_ptr->member_id() << ',' << log_para.zone_id_ << ','
	      << LogHelper::instance().FormatedClickTime(time(NULL)) << ',' << setiosflags(ios::fixed) << setprecision(5)
	      << log_para.cost_ << ',' << group_ptr->bid_unit_id() << ',' << uid << ',' << '0';
      cpm_log_seq.push_back(cpm_log.str());
      cpm_log.str("");
    }
  }
  /*engine_log << "pvlog=1\tuserid=" << profile.id() << "\tage="<< profile.age()
    << "\tgender="<< profile.gender() << "\tstage=" << profile.stage()
    << "\tgrade=" << profile.grade() << "\tcurrent_area="
    <<  ((profile.current_area().empty()) ? "-" : profile.current_area())
    << "\tip_area=" << ((profile.ip_area().empty()) ? "-" : profile.ip_area())
    << "\tschool=" << profile.school() << "\tzone_id=" << para.adzone_->id()
    << "\tgroup_id=" << group_ptr->group_id() << "\tmax_price=" << group_ptr->max_price(zone_id)
    << "\tapp_id=" << LogHelper::instance().GetAppId(para.referer_)
    << "\tmember_id=" << group_ptr->member_id() << "\tsystem_time=" << date.toDateTime();
    engine_log_seq.push_back(engine_log.str());
    engine_log.str("");*/

  result[para.adzone_->id()] = ad_info_seq;
  try {
    subts.reset();
    AdLogAdapter::instance().PvBatch(pv_log_seq);
    STATISTICS("LogHandler::handle --> TIME_TEST write pv_log : " << subts.getTime());
  } catch (Ice::Exception& e) {
    MCE_WARN("LogHandler::handle AdLogAdapter.PvBatch ERR line:" << __LINE__ << " err:" << e);
  } catch (std::exception& e) {
    MCE_WARN("LogHandler::handle AdLogAdapter.PvBatch ERR line:" << __LINE__ << " err:" << e.what());
  }
  ////////////////
  if(!cpm_log_seq.empty()){//cpm单独打charge_pv
    try {
      AdLogAdapter::instance().PvForCharge(cpm_log_seq);
    } catch (Ice::Exception& e) {
      MCE_WARN("LogHandler::handle AdLogAdapter.CpmBatch ERR line:" << __LINE__ << " err:" << e);
    } catch (std::exception& e) {
      MCE_WARN("LogHandler::handle AdLogAdapter.CpmBatch ERR line:" << __LINE__ << " err:" << e.what());
    }
  }

  /*try {
    subts.reset();
    AdLogAdapter::instance().EngineLogBatch(engine_log_seq);
    STATISTICS("LogHandler::handle --> TIME_TEST write engine_log : "
    << subts.getTime());
    } catch (Ice::Exception& e) {
    MCE_WARN("LogHandler::handle AdLogAdapter.EngineLogBatch ERR line:"
    << __LINE__ << " err:" << e);
    } catch (std::exception& e) {
    MCE_WARN("LogHandler::handle AdLogAdapter.EngineLogBatch ERR line:"
    << __LINE__ << " err:" << e.what());
    }*/

  //STATISTICS("LogHandler::handle --> time = " << ts.getTime());
  return true;
}
Exemple #25
0
int main()
{
    srand(time(NULL));

    cout << "Vector:" << endl << endl;
    insertVector(0);    // Insert at start
    insertVector(1);    // Insert at middle
    insertVector(2);    // Insert at end
    deleteVector(0);    // Removes at first
    deleteVector(1);
    deleteVector(2);
    walkVector(0);
    walkVector(1);

    cout << endl;

    cout << "Deque:" << endl << endl;
    insertDeque(0);    // Insert at start
    insertDeque(1);    // Insert at middle
    insertDeque(2);    // Insert at end
    deleteDeque(0);    // Removes at first
    deleteDeque(1);
    deleteDeque(2);
    walkDeque(0);
    walkDeque(1);

    // START OF ASSIGNMENT 4

	linkedListType<int> *temp1;
	temp1 = new linkedListType<int>;

	timer t1;

	cout << endl << "Linked List" << endl;
	t1.start();
	for(int c = 0; c<=5000; c++)
			temp1->insertLast(rand() % 512);
	t1.stop();

	t1.start();
	temp1->insertFirst(1);	// Insert at first
	temp1->insertFirst(2);	// Insert at first
	temp1->insertFirst(3);	// Insert at first
	t1.stop();
	cout << setw(25) << setiosflags(ios::left) << "Insertion at first: " << setw(7) << resetiosflags(ios::left) << t1.putTime() << endl;
	// Test to see if it was inserted correctly
	if(temp1->getType(0) != 3)	// It should equal 3
		cout << "There was an error" << endl;

	t1.start();
	temp1->insertMiddle(13);	// Insert at middle
	temp1->insertMiddle(14);	// Insert at middle
	temp1->insertMiddle(15);	// Insert at middle
	t1.stop();
	cout << setw(25) << setiosflags(ios::left) << "Insertion at middle: " << setw(7) << resetiosflags(ios::left) <<  t1.putTime() << endl;
	// Test to see if it was inserted correctly
	// ... the middle should be 15
	if(temp1->getType((temp1->length() / 2)) != 15)
		cout << "There was an error!" << endl;


	t1.start();
	temp1->insertLast(20);		// Insert at last
	temp1->insertLast(21);		// Insert at last
	temp1->insertLast(22);		// Insert at last
	t1.stop();
	cout << setw(25) << setiosflags(ios::left) << "Insertion at last: " << setw(7) << resetiosflags(ios::left) << t1.putTime() << endl;
	// Test the insertion
	if(temp1->getType(temp1->length() - 1) != 22)
	{
		cout << "There was an error!" << endl;
	}

	t1.start();
	temp1->deleteLocation(0);	// Removal at first
	temp1->deleteLocation(0);	// Removal at first
	temp1->deleteLocation(0);	// Removal at first
	t1.stop();
	cout << setw(25) << setiosflags(ios::left) << "Removal at first: " << setw(7) << resetiosflags(ios::left) << t1.putTime() << endl;
	// Test the removal
	// it cannot be 3, because that's what was there before
	if(temp1->getType(temp1->length()) == 3)
		cout << "There was an error!" << endl;

	t1.start();
	temp1->deleteLocation(temp1->length() / 2);	// Removal at middle
	temp1->deleteLocation(temp1->length() / 2);	// Removal at middle
	temp1->deleteLocation(temp1->length() / 2);	// Removal at middle
	t1.stop();
	cout << setw(25) << setiosflags(ios::left) << "Removal at middle: " << setw(7) << resetiosflags(ios::left) << t1.putTime() << endl;

	t1.start();
	temp1->deleteLocation(temp1->length());	// Removal at end
	temp1->deleteLocation(temp1->length());	// Removal at end
	temp1->deleteLocation(temp1->length());	// Removal at end
	t1.stop();
	cout << setw(25) << setiosflags(ios::left) << "Removal at end: " << setw(7) << resetiosflags(ios::left) << t1.putTime() << endl;
	// Test the removal
	// It shouldn't equal 22, because that's what was there
	if(temp1->getType(temp1->length()) == 22)
		cout << "There was an error" << endl;

// Walk forwards	
	t1.start();
	for(int temp = 0; temp < temp1->length(); temp++)
		// cout << temp << ": " << temp1->getType(temp) << endl;
		int x = temp1->getType(temp);	// Clean up output a bit
	t1.stop();
	cout << setw(25) << setiosflags(ios::left) << "Walk forwards: " << setw(7) << resetiosflags(ios::left) << t1.putTime() << endl;
	
// Walk backwards
	t1.start();
	temp1->reverseList();
	for(int temp = 0; temp < temp1->length(); temp++)
		// cout << temp << ": " << temp1->getType(temp) << endl;
		int x = temp1->getType(temp); // clean up output
	t1.stop();
	cout << setw(25) << setiosflags(ios::left) << "Walk backwards: " << setw(7) << resetiosflags(ios::left) << t1.putTime() << endl;


    return(0);
}
void Employee::printOut( ) const
{
    cout << name<<": $" << setiosflags (ios::fixed) << setprecision (2)
        << grossPay << endl;
} // printOut
Exemple #27
0
int main (int argc, const char *argv[])
{
     ClpSimplex  model;
     int status;
     // Keep names when reading an mps file
     if (argc < 2)
          status = model.readMps("../../Data/Sample/p0033.mps", true);
     else
          status = model.readMps(argv[1], true);

     if (status) {
          fprintf(stderr, "Bad readMps %s\n", argv[1]);
          fprintf(stdout, "Bad readMps %s\n", argv[1]);
          exit(1);
     }
#ifdef STYLE1
     if (argc < 3 || !strstr(argv[2], "primal")) {
          // Use the dual algorithm unless user said "primal"
          model.initialDualSolve();
     } else {
          model.initialPrimalSolve();
     }
#else
     ClpSolve solvectl;


     if (argc < 3 || (!strstr(argv[2], "primal") && !strstr(argv[2], "barrier"))) {
          // Use the dual algorithm unless user said "primal" or "barrier"
          std::cout << std::endl << " Solve using Dual: " << std::endl;
          solvectl.setSolveType(ClpSolve::useDual);
          solvectl.setPresolveType(ClpSolve::presolveOn);
          model.initialSolve(solvectl);
     } else if (strstr(argv[2], "barrier")) {
          // Use the barrier algorithm if user said "barrier"
          std::cout << std::endl << " Solve using Barrier: " << std::endl;
          solvectl.setSolveType(ClpSolve::useBarrier);
          solvectl.setPresolveType(ClpSolve::presolveOn);
          model.initialSolve(solvectl);
     } else {
          std::cout << std::endl << " Solve using Primal: " << std::endl;
          solvectl.setSolveType(ClpSolve::usePrimal);
          solvectl.setPresolveType(ClpSolve::presolveOn);
          model.initialSolve(solvectl);
     }
#endif
     std::string modelName;
     model.getStrParam(ClpProbName, modelName);
     std::cout << "Model " << modelName << " has " << model.numberRows() << " rows and " <<
               model.numberColumns() << " columns" << std::endl;

     // remove this to print solution

     exit(0);

     /*
       Now to print out solution.  The methods used return modifiable
       arrays while the alternative names return const pointers -
       which is of course much more virtuous.

       This version just does non-zero columns

      */
#if 0
     int numberRows = model.numberRows();

     // Alternatively getRowActivity()
     double * rowPrimal = model.primalRowSolution();
     // Alternatively getRowPrice()
     double * rowDual = model.dualRowSolution();
     // Alternatively getRowLower()
     double * rowLower = model.rowLower();
     // Alternatively getRowUpper()
     double * rowUpper = model.rowUpper();
     // Alternatively getRowObjCoefficients()
     double * rowObjective = model.rowObjective();

     // If we have not kept names (parameter to readMps) this will be 0
     assert(model.lengthNames());

     // Row names
     const std::vector<std::string> * rowNames = model.rowNames();


     int iRow;

     std::cout << "                       Primal          Dual         Lower         Upper        (Cost)"
               << std::endl;

     for (iRow = 0; iRow < numberRows; iRow++) {
          double value;
          std::cout << std::setw(6) << iRow << " " << std::setw(8) << (*rowNames)[iRow];
          value = rowPrimal[iRow];
          if (fabs(value) < 1.0e5)
               std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
          else
               std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
          value = rowDual[iRow];
          if (fabs(value) < 1.0e5)
               std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
          else
               std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
          value = rowLower[iRow];
          if (fabs(value) < 1.0e5)
               std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
          else
               std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
          value = rowUpper[iRow];
          if (fabs(value) < 1.0e5)
               std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
          else
               std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
          if (rowObjective) {
               value = rowObjective[iRow];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
          }
          std::cout << std::endl;
     }
#endif
     std::cout << "--------------------------------------" << std::endl;

     // Columns

     int numberColumns = model.numberColumns();

     // Alternatively getColSolution()
     double * columnPrimal = model.primalColumnSolution();
     // Alternatively getReducedCost()
     double * columnDual = model.dualColumnSolution();
     // Alternatively getColLower()
     double * columnLower = model.columnLower();
     // Alternatively getColUpper()
     double * columnUpper = model.columnUpper();
     // Alternatively getObjCoefficients()
     double * columnObjective = model.objective();

     // If we have not kept names (parameter to readMps) this will be 0
     assert(model.lengthNames());

     // Column names
     const std::vector<std::string> * columnNames = model.columnNames();


     int iColumn;

     std::cout << "                       Primal          Dual         Lower         Upper          Cost"
               << std::endl;

     for (iColumn = 0; iColumn < numberColumns; iColumn++) {
          double value;
          value = columnPrimal[iColumn];
          if (fabs(value) > 1.0e-8) {
               std::cout << std::setw(6) << iColumn << " " << std::setw(8) << (*columnNames)[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
               value = columnDual[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
               value = columnLower[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
               value = columnUpper[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;
               value = columnObjective[iColumn];
               if (fabs(value) < 1.0e5)
                    std::cout << setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14) << value;
               else
                    std::cout << setiosflags(std::ios::scientific) << std::setw(14) << value;

               std::cout << std::endl;
          }
     }
     std::cout << "--------------------------------------" << std::endl;

     return 0;
}
Exemple #28
0
int CreateTotalStatFile()
{
    ofstream out;
    ofstream out_list;
    unsigned int ii;
    
    map <string,TTL_ML_Data_Pack*> :: const_iterator pIter;

    
    out.open("ML_OV_Summary.txt");
    
    if(!out) 
    {

	    cerr<<"\nCan not create the summary report file containing information about the functions specified in the monitor list..."<<endl;

	    return 1;

    }

    cerr << "\nCreating summary report file (ML_OV_Summary.txt) containing information about the functions specified in the monitor list..." << endl;

    out<<setw(30)<<setiosflags(ios::left)<<"Function"<<setw(12)<<"   IN_ML"
    <<setw(12)<<" IN_ML_UMA"
    <<setw(12)<<"  OUT_ML"
    <<setw(12)<<"OUT_ML_UMA"
    <<setw(12)<<"  IN_ALL"
    <<setw(12)<<"IN_ALL_UMA"
    <<setw(12)<<"  OUT_ALL"
    <<setw(12)<<"OUT_ALL_UMA"
    <<endl;

    out<<setw(30)<<"-----------------------------"<<setw(12)<<"-----------"
    <<setw(12)<<"-----------"
    <<setw(12)<<"-----------"
    <<setw(12)<<"-----------"
    <<setw(12)<<"-----------"
    <<setw(12)<<"-----------"
    <<setw(12)<<"-----------"
    <<setw(12)<<"-----------"
    <<endl;

        
    for ( pIter = ML_OUTPUT.begin( ) ; pIter != ML_OUTPUT.end( ) ; pIter++ )
    {
     out << setw(30) << setiosflags(ios::left) << pIter -> first;
     
     out << setw(11) << setiosflags(ios::right) << pIter->second->total_IN_ML << " " <<
	    setw(11) << pIter->second->total_IN_ML_UMA << " " <<
	    setw(11) << pIter->second->total_OUT_ML << " " << 
	    setw(11) << pIter->second->total_OUT_ML_UMA << " " <<
	    setw(11) << pIter->second->total_IN_ALL << " " <<
	    setw(11) << pIter->second->total_IN_ALL_UMA << " " <<
	    setw(11) << pIter->second->total_OUT_ALL << " " <<
	    setw(11) << pIter->second->total_OUT_ALL_UMA << endl ;
	    
     
     out.unsetf(ios::right);
     
     // store the list of communicating functions for each kernel in ML
     // consumers
     out_list.open((pIter -> first+"_(p).txt").c_str());
	 if(!out_list) 
     {
	    cerr<<"\nCan not create the report file containing the list of communicating functions for kernels ..."<<endl;
	    return 1;
     }
     
	 for(ii=0; ii < pIter->second->consumers.size(); ii++)  	  
	 		out_list << pIter->second->consumers[ii] << endl;
	 
	 out_list.close();

     // producers
     out_list.open((pIter -> first+"_(c).txt").c_str());
	 if(!out_list) 
     {
	    cerr<<"\nCan not create the report file containing the list of communicating functions for kernels ..."<<endl;
	    return 1;
     }
     
	 for(ii=0; ii < pIter->second->producers.size(); ii++)  	  
	 		out_list << pIter->second->producers[ii] << endl;
	 
	 out_list.close();
    
   }//end of for
   
    out << endl << "--" << endl;
    out << "IN_ML -> Total number of bytes read by this function that a function in the monitor list is responsible for producing the value(s) of the byte(s)" << endl;
    out << "IN_ML_UMA -> Total number of unique memory addresses used corresponding to 'IN_ML'" << endl;
    out << "OUT_ML -> Total number of bytes read by a function in the monitor list that this function is responsible for producing the value(s) of the byte(s)" << endl;
    out << "OUT_ML_UMA -> Total number of unique memory addresses used corresponding to 'OUT_ML'" << endl;
    
    out << "IN_ALL -> Total number of bytes read by this function that a function in the application is responsible for producing the value(s) of the byte(s)" << endl;
    out << "IN_ALL_UMA -> Total number of unique memory addresses used corresponding to 'IN_ALL'" << endl;
    out << "OUT_ALL -> Total number of bytes read by a function in the application that this function is responsible for producing the value(s) of the byte(s)" << endl;
    out << "OUT_ALL_UMA -> Total number of unique memory addresses used corresponding to 'OUT_ALL'" << endl;
    
    
    out.close();
    return 0;
}	
// Things to do after a timestep
void AMRLevelPluto::postTimeStep()
{
  CH_assert(allDefined());

  // Used for conservation tests
  static Real orig_integral = 0.0;
  static Real last_integral = 0.0;
  static bool first = true;

  if (s_verbosity >= 3)
  {
    pout() << "AMRLevelPluto::postTimeStep " << m_level << endl;
  }

  if (m_hasFiner)
  {
    // Reflux
    Real scale = -1.0/m_dx; 
    m_fluxRegister.reflux(m_UNew,scale);

    // Average from finer level data
    AMRLevelPluto* amrGodFinerPtr = getFinerLevel();

    amrGodFinerPtr->m_coarseAverage.averageToCoarse(m_UNew,
                                                    amrGodFinerPtr->m_UNew);
  }

  if (s_verbosity >= 2 && m_level == 0)
  {
    int nRefFine = 1;

    pout() << "AMRLevelPluto::postTimeStep:" << endl;
    pout() << "  Sums:" << endl;
    for (int comp = 0; comp < m_numStates; comp++)
    {
      Interval curComp(comp,comp);
      Real integral = computeSum(m_UNew,NULL,nRefFine,m_dx,curComp);

      pout() << "    " << setw(23)
                       << setprecision(16)
                       << setiosflags(ios::showpoint)
                       << setiosflags(ios::scientific)
                       << integral
             << " --- " << m_ConsStateNames[comp];

      if (comp == 0 && !first) {
        pout() << " (" << setw(23)
                       << setprecision(16)
                       << setiosflags(ios::showpoint)
                       << setiosflags(ios::scientific)
                       << (integral-last_integral)/last_integral
               << " " << setw(23)
                      << setprecision(16)
                      << setiosflags(ios::showpoint)
                      << setiosflags(ios::scientific)
                      << (integral-orig_integral)/orig_integral
               << ")";
      }

      pout() << endl;

      if (comp == 0)
      {
        if (first)
        {
          orig_integral = integral;
          first = false;
        }

        last_integral = integral;
      }
    }
  }

  if (s_verbosity >= 3)
  {
    pout() << "AMRLevelPluto::postTimeStep " << m_level << " finished" << endl;
  }
}
Exemple #30
0
//***************************************************************************
// PUBLIC METHOD:
// void ossimFfRevb::print(ostream& os) const
//
// Prints data members.
//***************************************************************************
void ossimFfRevb::print(ostream& os) const
{
   os << setiosflags(ios::left | ios::fixed)
      << setw(30) << "\nimage_id:" 
      << theProductOrderNumber
      << setw(30) << "\npath_row_number:"
      << thePathRowNumber
      << setw(30) << "\nacquisition_date:"
      << theAcquisitionDate
      << setw(30) << "\nsatellite_name:"
      << theSatNumber
      << setw(30) << "\nsensor_name:"
      << theInstrumentType
      << setw(30) << "\nproduct_type:" 
      << theProductType
      << setw(30) << "\nproduct_size:" 
      << theProductSize
      << setw(30) << "\nprocessing_type:" 
      << theProcessingType 
      << setw(30) << "\nresamp_algorithm:" 
      << theResampAlgorithm;

   int i;
   for (i=0; i<NUMBER_OF_BANDS; i++)
   {
      os << "\nband" << i+1 << setw(25) << "_radiance:"
         << theBandRadiance[i];
   }

   os << setw(30) << "\ntape_volume_number:" 
      << theVolumeNumber
      << setw(30) << "\nfirst_line_in_volume:" 
      << the1stLineInVolume
      << setw(30) << "\nlines_per_volume:" 
      << theLinesPerVolume
      << setw(30) << "\norientation_angle:" 
      << setprecision(2) << theOrientationAngle
      << setw(30) << "\nprojection_type:" 
      << theMapProjName
      << setw(30) << "\nusgs_projection_number:" 
      << theUsgsProjNumber
      << setw(30) << "\nmap_zone:" 
      << theUsgsMapZone;

//    os << setprecision(15);
   os << setiosflags(ios::right);
   for (i=0; i<NUMBER_OF_PROJECTION_PARAMETERS; i++)
   {
      os << "\nprojection_parameter_" << i+1 << setw(10) << ":"
         << setw(24) << theUsgsProjParam[i];
   }
   os << resetiosflags(ios::right);
   

   os << setw(30) << "\nellipsoid:" 
      << theEllipsoid
      << setw(30) << "\nsemi_major_axis:"
      << setprecision(3) << setw(11) << theSemiMajorAxis
      << setw(30) << "\nsemi_minor_axis:"
      << setw(11) << theSemiMinorAxis
      << setw(30) << "\ngsd:" 
      << setprecision(2) << setw(5) << theGsd      
      << setw(30) << "\nnumber_samples:"
      << thePixelsPerLine
      << setw(30) << "\nnumber_lines:" 
      << theLinesPerImage
      << setprecision(3)
      << setw(30) << "\nul_longitude:" 
      << theUlLon
      << setw(30) << "\nul_latitude:" 
      << theUlLat
      << setw(30) << "\nul_easting:" 
      << setw(13) << theUlEasting
      << setw(30) << "\nul_northing:" 
      << setw(13) << theUlNorthing   
      << setw(30) << "\nur_longitude:" 
      << theUrLon
      << setw(30) << "\nur_latitude:" 
      << theUrLat
      << setw(30) << "\nur_easting:" 
      << setw(13) << theUrEasting
      << setw(30) << "\nur_northing:" 
      << setw(13) << theUrNorthing
      << setw(30) << "\nlr_longitude:" 
      << theLrLon
      << setw(30) << "\nlr_latitude:" 
      << theLrLat
      << setw(30) << "\nlr_easting:" 
      << setw(13) << theLrEasting
      << setw(30) << "\nlr_northing:" 
      << setw(13) << theLrNorthing
      << setw(30) << "\nll_longitude:" 
      << theLlLon
      << setw(30) << "\nll_latitude:" 
      << theLlLat
      << setw(30) << "\nll_easting:" 
      << setw(13) << theLlEasting
      << setw(30) << "\nll_northing:" 
      << setw(13) << theLlNorthing      
      << setw(30) << "\nbands_present_string:" 
      << theBandsPresentString
      << setw(30) << "\ntape_blocking_factor:" 
      << theBlockingFactor
      << setw(30) << "\nrecord_size:" 
      << theRecordSize
      << setw(30) << "\nillum_elevation:" 
      << theSunElevation
      << setw(30) << "\nillum_azimuth:"
      << theSunAzimuth
      << setw(30) << "\ncenter_longitude:" 
      << theCenterLon
      << setw(30) << "\ncenter_latitude:" 
      << theCenterLat
      << setw(30) << "\ncenter_easting:" 
      << setw(13) << theCenterEasting
      << setw(30) << "\ncenter_northing:" 
      << setw(13) << theCenterNorthing
      << setw(30) << "\ncenter_sample:" 
      << theCenterSample
      << setw(30) << "\ncenter_line:" 
      << theCenterLine
      << setw(30) << "\nhorizontal_offset:" 
      << theOffset
      << setw(30) << "\nformat_version:" 
      << theFormatVersion
      << std::endl;

}