Exemplo n.º 1
0
void 
PrintHelper::orderedtask_print(OrderedTask& task, const AircraftState &state) 
{
  abstracttask_print(task, state);
  if (!task.stats.task_valid)
    return;

  std::ofstream fi("results/res-isolines.txt");
  for (unsigned i=0; i<task.task_points.size(); i++) {
    fi << "## point " << i << "\n";
    if (task.task_points[i]->type == TaskPoint::AAT) {
      aatpoint_print(fi, (AATPoint&)*task.task_points[i], state,
                     task.GetTaskProjection(), 1);
    } else {
      orderedtaskpoint_print(fi,*task.task_points[i],state,1);
    }
    fi << "\n";
  }

  std::ofstream f1("results/res-task.txt");

  f1 << "#### Task points\n";
  for (unsigned i=0; i<task.task_points.size(); i++) {
    f1 << "## point " << i << " ###################\n";
    if (task.task_points[i]->type == TaskPoint::AAT) {
      aatpoint_print(f1, (AATPoint&)*task.task_points[i], state,
                     task.GetTaskProjection(), 0);
    } else {
      orderedtaskpoint_print(f1,*task.task_points[i],state,0);
    }
    f1 << "\n";
  }

  std::ofstream f5("results/res-ssample.txt");
  f5 << "#### Task sampled points\n";
  for (unsigned i=0; i<task.task_points.size(); i++) {
    f5 << "## point " << i << "\n";
    sampledtaskpoint_print_samples(f5,*task.task_points[i],state);
    f5 << "\n";
  }

  std::ofstream f2("results/res-max.txt");
  f2 << "#### Max task\n";
  for (unsigned i=0; i<task.task_points.size(); i++) {
    OrderedTaskPoint *tp = task.task_points[i];
    f2 <<  tp->GetLocationMax().longitude << " "
       <<  tp->GetLocationMax().latitude << "\n";
  }

  std::ofstream f3("results/res-min.txt");
  f3 << "#### Min task\n";
  for (unsigned i=0; i<task.task_points.size(); i++) {
    OrderedTaskPoint *tp = task.task_points[i];
    f3 <<  tp->GetLocationMin().longitude << " "
       <<  tp->GetLocationMin().latitude << "\n";
  }

  std::ofstream f4("results/res-rem.txt");
  f4 << "#### Remaining task\n";
  for (unsigned i=0; i<task.task_points.size(); i++) {
    OrderedTaskPoint *tp = task.task_points[i];
    f4 <<  tp->GetLocationRemaining().longitude << " "
       <<  tp->GetLocationRemaining().latitude << "\n";
  }
}
Exemplo n.º 2
0
void addn2() {

  // open existing f1:

  char* fn[99];
  int ni;

  // SR90 maps, mod D003

  ni = -1;
  ni++; fn[ni] = "SR90-map-00a.root";
  ni++; fn[ni] = "SR90-map-00b.root";
  ni++; fn[ni] = "SR90-map-01a.root";
  ni++; fn[ni] = "SR90-map-01b.root";
  ni++; fn[ni] = "SR90-map-02.root";
  ni++; fn[ni] = "SR90-map-03.root";
  ni++; fn[ni] = "SR90-map-05a.root";
  ni++; fn[ni] = "SR90-map-05b.root";
  ni++; fn[ni] = "SR90-map-07a.root";
  ni++; fn[ni] = "SR90-map-07b.root";
  ni++; fn[ni] = "SR90-map-07c.root";
  ni++; fn[ni] = "SR90-map-07d.root";

  // direct X-rays 9.4.2014 module D0003

  ni = -1;
  ni++; fn[ni] = "X-ray-20-modtd40000.root";
  ni++; fn[ni] = "X-ray-20-vthr60-modtd1000.root";
  ni++; fn[ni] = "X-ray-27-vthr60-modtd1000.root";
  ni++; fn[ni] = "X-ray-35-modtd40000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-close-modtd65000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-midpos-0p1mA-modtd10000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-midpos-halfcur-modtd40000.root";
  ni++; fn[ni] = "X-ray-35-vthr60-modtd40000.root";

  int nmax = ni;

  TFile f1(fn[0]);

  if( f1.IsZombie() ) {
    cout << "Error opening " << fn[0] << endl;
    return;
  }
  cout << "opened " << fn[0] << endl;

  //--------------------------------------------------------------------
  // create f0:

  TFile f0("fileA.root", "RECREATE");
  cout << "created ";
  gDirectory->pwd();

  /*
  TFile options:  
  NEW or CREATE   create a new file and open it for writing,
                  if the file already exists the file is
                  not opened.
  RECREATE        create a new file, if the file already
                  exists it will be overwritten.
  UPDATE          open an existing file for writing.
                  if no file exists, it is created.
  READ            open an existing file for reading (default).
  NET             used by derived remote file access
                  classes, not a user callable option
  WEB             used by derived remote http access
                  class, not a user callable option
  "" (default), READ is assumed.
  */

  //--------------------------------------------------------------------
  // copy f1 to f0:

  f1.cd();

  cout << "keys:\n";
  f1.GetListOfKeys()->Print();

  cout << "pwd: ";
  f1.pwd();

  cout << "ls: \n";
  f1.ls();

  // f1 has sub-dir:

  cout << "First: " << f1.GetListOfKeys()->First()->GetName() << endl;
  cout << "First: " << f1.GetListOfKeys()->First()->ClassName() << endl;
  char* dir1 = f1.GetListOfKeys()->First()->GetName();
  cout << "cd to " << dir1 << endl;
  f1.cd( dir1 );
  cout << "we are in ";
  gDirectory->pwd();

  gDirectory->ReadAll(); // load histos

  TList * lst = gDirectory->GetList();
  cout << lst->GetName() << endl;
  cout << lst->GetTitle() << endl;
  cout << "size    " << lst->GetSize() << endl;
  cout << "entries " << lst->GetEntries() << endl;
  cout << "last    " << lst->LastIndex() << endl;

  TIterator *iter = lst->MakeIterator();
  int ii = 0;
  TObject *obj;
  TH1D *h;
  TH1D *h0;
  TH2D *H;
  TH2D *H0;

  while( obj = iter->Next() ){
    ii++;
    cout << setw(4) << ii << ": ";
    cout << obj->ClassName() << " ";
    cout << obj->InheritsFrom("TH1D") << " ";
    cout << obj->GetName() << " \"";
    cout << obj->GetTitle() << "\"";
    cout << endl;
    //    if( obj->ClassName() == "TH1D" ){
    if( obj->InheritsFrom("TH1D") ){
      h = (TH1D*) obj;
      cout << "       1D";
      cout << h->GetNbinsX() << " bins, ";
      cout << h->GetEntries() << " entries, ";
      cout << h->GetSumOfWeights() << " inside, ";
      cout << h->GetBinContent(0) << " under, ";
      cout << h->GetBinContent(h->GetNbinsX()+1) << " over";
      cout << endl;

      f0.cd(); // output file

      //      TH1D* h0 = (TH1D*) h->Clone();
      h0 = h; // copy
      h0->Write(); // write to file f0
      
      f1.cd(); // back to file 1 for the loop
    }
    else{

      if( obj->InheritsFrom("TH2D") ){

	H = (TH2D*) obj;
	cout << "       2D";
	cout << H->GetNbinsX() << " bins, ";
	cout << H->GetEntries() << " entries, ";
	cout << H->GetSumOfWeights() << " inside, ";
	cout << H->GetBinContent(0) << " under, ";
	cout << H->GetBinContent(H->GetNbinsX()+1) << " over";
	cout << endl;
	
	f0.cd(); // output file
	
	H0 = H; // copy
	H0->Write(); // write to file f0
	
	f1.cd(); // back to file 1 for the loop
      }
      else cout << "other class " << obj->ClassName() << endl;
    }
  }
  cout << "copied " << ii << endl;
  cout << "f1 " << f1.GetName() << " close = " << f1.Close() << endl;
    
  f0.cd();
  cout << "we are in ";
  gDirectory->pwd();

  cout << "f0 " << f0.GetName() << " size  = " << f0.GetSize() << endl;

  cout << "f0 " << f0.GetName() << " write = " << f0.Write() << endl;

  cout << "f0 " << f0.GetName() << " size  = " << f0.GetSize() << endl;

  cout << "f0 " << f0.GetName() << " close = " << f0.Close() << endl;

  f0.Delete();

  //--------------------------------------------------------------------
  // list of files 2:

  bool lAB = true;

  for( int nn = 1; nn <= nmax; ++nn ){

    cout << "\n\n";
    cout << "loop " << nn << ": fn = " << fn[nn] << endl;
    cout << "lAB = " << lAB << endl;

    if( lAB ) { // A+2 -> B
      char* fn3 = "fileA.root";
      char* fn4 = "fileB.root";
    }
    else{ // B+2 -> A
      char* fn3 = "fileB.root";
      char* fn4 = "fileA.root";
    }

    // create f4:

    TFile f4( fn4, "recreate" );
    if( f4.IsZombie() ) {
      cout << "Error creating f4\n";
      return;
    }
    cout << "created f4   = " << f4.GetName() << endl;

    // re-open as f3:

    TFile f3( fn3 );
    if( f3.IsZombie() ) {
      cout << "Error opening f3\n";
      return;
    }
    cout << "re-opened f3 = " << f3.GetName() << endl;

    lAB = !lAB;
    cout << "lAB = " << lAB << " for next loop\n";

    cout << "f4 = " << f4.GetName() << endl;
    cout << "f3 = " << f3.GetName() << endl;

    f3.cd();
    gDirectory->ReadAll(); // load histos into f3 memory

    //    cout << "f3 list size = " << gDirectory->GetList()->GetSize() << endl;
    cout << "f3 list size = " << gDirectory->GetList()->GetSize() << endl;

    TFile f2(fn[nn]);
    //    TFile *f2 = new TFile(fn[nn]);

    if( f2.IsZombie() ) {
    //    if( f2 == NULL ) {
      cout << "Error opening " << fn[nn] << endl;
      return;
    }
    cout << "opened " << fn[nn] << endl;

    // f2 has sub-dir:

    f2.cd( f2.GetListOfKeys()->First()->GetName() );
    cout << "we are in ";
    gDirectory->pwd();

    gDirectory->ReadAll(); // load histos into f2 memory

    // loop over f2:

    cout << "f2 list size = " << gDirectory->GetList()->GetSize() << endl;

    int jj = 0;
    TObject *ob2;
    TH1D *h2;
    TH1D *h3;
    TH2D *H2;
    TH2D *H3;

    TIterator *ite2 = gDirectory->GetList()->MakeIterator();

    while( ob2 = ite2->Next() ){

      jj++;

      //      if( jj > 9 ) continue;

      cout << jj << ". ";
      cout << "ob2 is ";
      cout << ob2->GetName() << " ";
      cout << ob2->ClassName() << " ";
      cout << ob2->GetTitle();
      cout << endl;

      if( ob2->InheritsFrom("TH1D") ) {

	h2 = (TH1D*) ob2;
	cout << "h2 " << h2->GetName() << "  " << h2->GetNbinsX() << " bins\n";
	cout << "h2 " << h2->GetName() << "  " << h2->GetEntries() << " entries\n";
	char* hnm2 = h2->GetName();

	// search in f3:

	cout << "search for " << hnm2 << " in f3\n";
	f3.cd();
	cout << "we are in ";
	gDirectory->pwd();
	
	h3 = (TH1D*) gDirectory->GetList()->FindObject(hnm2);
	if( h3 == NULL ) {
	  cout << "h3 is null\n" ;
	  continue;
	}
	
	cout << "found h3 = ";
	cout << h3->GetName() << "  ";
	cout << h3->ClassName() << "  ";
	cout << h3->GetTitle();
	cout << endl;
	cout << "h3  " << h3->GetName() << "  " << h3->GetNbinsX() << " bins\n";
	cout << "h3  " << h3->GetName() << "  " << h3->GetEntries() << " entries\n";

	// add:

	f4.cd();
	cout << "we are in ";
	gDirectory->pwd();
	//TH1D h4 = *h3 + *h2;
	TH1D* h4 = (TH1D*) h3->Clone();
	h4->Add(h2);
	
	cout << "h4  " << h4->GetEntries() << " entries\n";
	cout << "h4  ";
	cout << h4->GetName() << " ";
	cout << h4->ClassName() << " ";
	cout << h4->GetTitle();
	cout << endl;
	cout << "h4 dir " << h4->GetDirectory()->GetName() << endl;
	cout << "f4 size " << f4.GetSize() << endl;

	// back to f2 for next iter:

	f2.cd( f2.GetListOfKeys()->First()->GetName() );

      }//1D

      if( ob2->InheritsFrom("TH2D") ) {

	H2 = (TH2D*) ob2;
	cout << "H2 " << H2->GetName() << "  " << H2->GetNbinsX() << " bins\n";
	cout << "H2 " << H2->GetName() << "  " << H2->GetEntries() << " entries\n";
	char* Hnm2 = H2->GetName();

	// search in f3:

	cout << "search for " << Hnm2 << " in f3\n";
	f3.cd();
	cout << "we are in ";
	gDirectory->pwd();
	
	H3 = (TH2D*) gDirectory->GetList()->FindObject(Hnm2);
	if( H3 == NULL ) {
	  cout << "H3 is null\n" ;
	  continue;
	}
	
	cout << "found H3 = ";
	cout << H3->GetName() << "  ";
	cout << H3->ClassName() << "  ";
	cout << H3->GetTitle();
	cout << endl;
	cout << "H3  " << H3->GetName() << "  " << H3->GetNbinsX() << " bins\n";
	cout << "H3  " << H3->GetName() << "  " << H3->GetEntries() << " entries\n";

	// add:

	f4.cd();
	cout << "we are in ";
	gDirectory->pwd();

	TH2D* H4 = (TH2D*) H3->Clone();
	H4->Add(H2);
	
	cout << "H4  " << H4->GetEntries() << " entries\n";
	cout << "H4  ";
	cout << H4->GetName() << " ";
	cout << H4->ClassName() << " ";
	cout << H4->GetTitle();
	cout << endl;
	cout << "H4 dir " << H4->GetDirectory()->GetName() << endl;
	cout << "f4 size " << f4.GetSize() << endl;

	// back to f2 for next iter:

	f2.cd( f2.GetListOfKeys()->First()->GetName() );
      }//2D

    } //while

    cout << "processed " << jj << endl;
    cout << "f4 " << f4.GetName() << " size " << f4.GetSize() << endl;

    //  cout << "f4 map:\n";
    //  f4.Map();

    cout << "f4 " << f4.GetName() << " write = " << f4.Write() << endl;

    cout << "f4 " << f4.GetName() << " size  = " << f4.GetSize() << endl;
    
  }// loop over files 2

  cout << endl;
  cout << "combined " << nmax + 1 << " files\n";
  cout << "Final file is " << f4.GetName() << endl;

  f2.Close();
  f3.Close();
  f4.Close();

}
Exemplo n.º 3
0
 int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
Exemplo n.º 4
0
int f2(unsigned char val, Buffer *buf) 
{ 
  f3(val, buf);
  return 0;
}
Exemplo n.º 5
0
void 
PrintHelper::orderedtask_print(const OrderedTask &task,
                               const AircraftState &state)
{
  abstracttask_print(task, state);
  if (!task.CheckTask())
    return;

  std::ofstream fi("output/results/res-isolines.txt");
  for (unsigned i = 0; i < task.TaskSize(); ++i) {
    const OrderedTaskPoint &tp = task.GetPoint(i);
    fi << "## point " << i << "\n";
    if (tp.GetType() == TaskPointType::AAT) {
      aatpoint_print(fi, (const AATPoint &)tp, state,
                     task.GetTaskProjection(), 1);
    } else {
      orderedtaskpoint_print(fi, tp, state, 1);
    }
    fi << "\n";
  }

  std::ofstream f1("output/results/res-task.txt");

  f1 << "#### Task points\n";
  for (unsigned i = 0; i < task.TaskSize(); ++i) {
    f1 << "## point " << i << " ###################\n";
    const OrderedTaskPoint &tp = task.GetPoint(i);
    if (tp.GetType() == TaskPointType::AAT) {
      aatpoint_print(f1, (const AATPoint &)tp, state,
                     task.GetTaskProjection(), 0);
    } else {
      orderedtaskpoint_print(f1, tp, state, 0);
    }
    f1 << "\n";
  }

  std::ofstream f5("output/results/res-ssample.txt");
  f5 << "#### Task sampled points\n";
  for (unsigned i =0 ; i < task.TaskSize(); ++i) {
    const OrderedTaskPoint &tp = task.GetPoint(i);
    f5 << "## point " << i << "\n";
    sampledtaskpoint_print_samples(f5, tp, state);
    f5 << "\n";
  }

  std::ofstream f2("output/results/res-max.txt");
  f2 << "#### Max task\n";
  for (unsigned i = 0; i < task.TaskSize(); ++i) {
    const OrderedTaskPoint &tp = task.GetPoint(i);
    f2 << tp.GetLocationMax().longitude << " "
       << tp.GetLocationMax().latitude << "\n";
  }

  std::ofstream f3("output/results/res-min.txt");
  f3 << "#### Min task\n";
  for (unsigned i = 0; i < task.TaskSize(); ++i) {
    const OrderedTaskPoint &tp = task.GetPoint(i);
    f3 << tp.GetLocationMin().longitude << " "
       << tp.GetLocationMin().latitude << "\n";
  }

  std::ofstream f4("output/results/res-rem.txt");
  f4 << "#### Remaining task\n";
  for (unsigned i = 0; i < task.TaskSize(); ++i) {
    const OrderedTaskPoint &tp = task.GetPoint(i);
    f4 << tp.GetLocationRemaining().longitude << " "
       << tp.GetLocationRemaining().latitude << "\n";
  }
}
Exemplo n.º 6
0
void r9Test(){

  // Filling plots, opening files, stuff like that...

  TFile *_fileg93 = TFile::Open("file:/gpfs/cms/data/2011/r9test/g93_zfilt.root");
  _fileg93->cd("demo");
  TH1D *g93= new TH1D("g93","g93",28,0,0.07);
  treeVJ_->Draw("IsoEcalEB_PUR>>g93","","goff");
  //TFile *_fileg94 = TFile::Open("../test/G94testnozfilt/res/g94.root");
  //_fileg94->cd("demo");
  //TH1D *g94= new TH1D("g94","g94",28,0,0.07);
  //treeVJ_->Draw("IsoEcalEB_PUR>>g94","","goff");
  TFile *_filegp2 = TFile::Open("file:/gpfs/cms/data/2011/r9test/p2_zfilt.root");
  _filegp2->cd("demo");
  TH1D *p2= new TH1D("p2","p2",28,0,0.07);
  treeVJ_->Draw("IsoEcalEB_PUR>>p2","","goff");
  //g94->SetLineColor(kRed);
  //g94->SetMarkerColor(kRed);
  //g94->SetMarkerSize(.5);
  //g94->Draw("E1");

  TCanvas *c1 = new TCanvas("c1","ratio GEANT",600,700);
  setTDRStyle();
  g93->SetLineColor(kBlue);
  g93->SetMarkerColor(kBlue);
  g93->SetMarkerSize(.5);
  p2->SetLineColor(kBlack);
  p2->SetMarkerColor(kBlack);
  p2->SetMarkerSize(.5);
  p2->SetMarkerStyle(3);
  g93->SetMarkerStyle(3);
  TLegend* legend_d = new TLegend(0.626506,0.19494,0.916667,0.447917);
  legend_d->SetFillColor(0);
  legend_d->SetFillStyle(0);
  legend_d->SetBorderSize(0);
  legend_d->AddEntry(g93,"g93","LE");
  //legend_d->AddEntry(g94,"g94","LE");
  legend_d->AddEntry(p2,"patch2","LE");
  //Plot the first canvas and pad
  TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1);
  pad1->SetBottomMargin(1);
  pad1->Draw();
  pad1->cd();
  g93->Draw("E1");
  p2->Draw("E1SAME");
  legend_d->Draw("same");

  c1->cd();
  TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);
  TH1D *ratiog= new TH1D("ratiog","ratiog",28,0,0.07);
  ratiog->Sumw2();
  g93->Sumw2();
  p2->Sumw2();
  ratiog->SetMarkerSize(.5);
  ratiog->SetLineColor(kRed);
  ratiog->SetMarkerColor(kRed);
  ratiog->SetMarkerSize(.5);
  ratiog->SetMarkerStyle(3);
  ratiog->Divide(g93,p2,1.,1.);
  pad2->SetTopMargin(1);
  pad2->Draw();
  pad2->cd();
  ratiog->Draw("E1");
  TF1 *myfit = new TF1("myfit","1", 0, 0.07);
  myfit->SetLineColor(kBlack);
  myfit->Draw("SAMES");

  ///// Other canvas
  TCanvas *c2 = new TCanvas("c2","ratio GEANT",600,700);
  c2->cd();
  setTDRStyle();
  TFile *_fileg93 = TFile::Open("/gpfs/cms/data/2011/r9test/pythiaD6Ttunesroot/D6T_zfilt.root");
  _fileg93->cd("demo");
  TH1D *g93= new TH1D("g93","g93",28,0,0.07);
  treeVJ_->Draw("IsoEcalEB_PUR>>g93");
  TFile *_fileg94 = TFile::Open("/gpfs/cms/data/2011/r9test/pythiaZ2tunesroot/Z2_zfilt.root");
  _fileg94->cd("demo");
  TH1D *g94= new TH1D("g94","g94",28,0,0.07);
  treeVJ_->Draw("IsoEcalEB_PUR>>g94");
  g94->Sumw2();
  g93->Sumw2();
  g94->SetLineColor(kRed);
  g94->SetMarkerColor(kRed);
  g94->SetMarkerSize(.5);
  TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1);
  pad1->SetBottomMargin(1);
  pad1->Draw();
  pad1->cd();
  g94->Draw("E1");
  g93->SetLineColor(kBlue);
  g93->SetMarkerColor(kBlue);
  g93->SetMarkerSize(.5);
  double ratio=(double)g94->GetEntries()/(double)g93->GetEntries();
  cout<<ratio;
  cout<<"IF YOU READ TIHS LINE THE MANUAL RATIO IS ON...."<<endl;
  ratio=112919./178795;
  g93->Scale(ratio);
  g93->Draw("E1SAMES");
  TLegend* legend_d = new TLegend(0.626506,0.19494,0.916667,0.447917);
  legend_d->SetFillColor(0);
  legend_d->SetFillStyle(0);
  legend_d->SetBorderSize(0);
  legend_d->AddEntry(g93,"PythiaD6T","LE");
  legend_d->AddEntry(g94,"PythiaZ2","LE");
  legend_d->Draw("same");
  c2->cd();
  
  TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);
  TH1D *ratiot= new TH1D("ratiot","ratiot",28,0,0.07);
  ratiot->Sumw2();
  ratiot->SetMarkerSize(.5);
  ratiot->SetMarkerColor(kRed);
  ratiot->Divide(g93,g94,1,1);
  pad2->SetTopMargin(1);
  pad2->Draw();
  pad2->cd();
  ratiot->Draw("E1");
  ratiot->SetLineColor(kRed);
  TF1 *myfit = new TF1("myfit","1", 0, 0.07);
  myfit->SetLineColor(kBlack);
  myfit->Draw("SAMES");

  TFile f3("corrections.root","UPDATE");
  f3.cd();
  //TH1D *correctionFactors= new TH1D("correctionFactors","correctionFactors",28,0,0.07);
  //correctionFactors=MH1clone("correctionFactors", "correctionFactors", ratiog);  
  ratiog->Multiply(ratiot);
  ratiog->Write();
  return;

  
}
Exemplo n.º 7
0
/// process 64 bytes
void SHA1::processBlock(const void* data)
{
  // get last hash
  uint32_t a = m_hash[0];
  uint32_t b = m_hash[1];
  uint32_t c = m_hash[2];
  uint32_t d = m_hash[3];
  uint32_t e = m_hash[4];

  // data represented as 16x 32-bit words
  const uint32_t* input = (uint32_t*) data;
  // convert to big endian
  uint32_t words[80];
  for (int i = 0; i < 16; i++)
#if defined(__BYTE_ORDER) && (__BYTE_ORDER != 0) && (__BYTE_ORDER == __BIG_ENDIAN)
    words[i] = input[i];
#else
    words[i] = swap(input[i]);
#endif

  // extend to 80 words
  for (int i = 16; i < 80; i++)
    words[i] = rotate(words[i-3] ^ words[i-8] ^ words[i-14] ^ words[i-16], 1);

  // first round
  for (int i = 0; i < 4; i++)
  {
    int offset = 5*i;
    e += rotate(a,5) + f1(b,c,d) + words[offset  ] + 0x5a827999; b = rotate(b,30);
    d += rotate(e,5) + f1(a,b,c) + words[offset+1] + 0x5a827999; a = rotate(a,30);
    c += rotate(d,5) + f1(e,a,b) + words[offset+2] + 0x5a827999; e = rotate(e,30);
    b += rotate(c,5) + f1(d,e,a) + words[offset+3] + 0x5a827999; d = rotate(d,30);
    a += rotate(b,5) + f1(c,d,e) + words[offset+4] + 0x5a827999; c = rotate(c,30);
  }

  // second round
  for (int i = 4; i < 8; i++)
  {
    int offset = 5*i;
    e += rotate(a,5) + f2(b,c,d) + words[offset  ] + 0x6ed9eba1; b = rotate(b,30);
    d += rotate(e,5) + f2(a,b,c) + words[offset+1] + 0x6ed9eba1; a = rotate(a,30);
    c += rotate(d,5) + f2(e,a,b) + words[offset+2] + 0x6ed9eba1; e = rotate(e,30);
    b += rotate(c,5) + f2(d,e,a) + words[offset+3] + 0x6ed9eba1; d = rotate(d,30);
    a += rotate(b,5) + f2(c,d,e) + words[offset+4] + 0x6ed9eba1; c = rotate(c,30);
  }

  // third round
  for (int i = 8; i < 12; i++)
  {
    int offset = 5*i;
    e += rotate(a,5) + f3(b,c,d) + words[offset  ] + 0x8f1bbcdc; b = rotate(b,30);
    d += rotate(e,5) + f3(a,b,c) + words[offset+1] + 0x8f1bbcdc; a = rotate(a,30);
    c += rotate(d,5) + f3(e,a,b) + words[offset+2] + 0x8f1bbcdc; e = rotate(e,30);
    b += rotate(c,5) + f3(d,e,a) + words[offset+3] + 0x8f1bbcdc; d = rotate(d,30);
    a += rotate(b,5) + f3(c,d,e) + words[offset+4] + 0x8f1bbcdc; c = rotate(c,30);
  }

  // fourth round
  for (int i = 12; i < 16; i++)
  {
    int offset = 5*i;
    e += rotate(a,5) + f2(b,c,d) + words[offset  ] + 0xca62c1d6; b = rotate(b,30);
    d += rotate(e,5) + f2(a,b,c) + words[offset+1] + 0xca62c1d6; a = rotate(a,30);
    c += rotate(d,5) + f2(e,a,b) + words[offset+2] + 0xca62c1d6; e = rotate(e,30);
    b += rotate(c,5) + f2(d,e,a) + words[offset+3] + 0xca62c1d6; d = rotate(d,30);
    a += rotate(b,5) + f2(c,d,e) + words[offset+4] + 0xca62c1d6; c = rotate(c,30);
  }

  // update hash
  m_hash[0] += a;
  m_hash[1] += b;
  m_hash[2] += c;
  m_hash[3] += d;
  m_hash[4] += e;
}
Exemplo n.º 8
0
int main() {
  const int j = f3(); // Works fine
  int k = f4(); // But this works fine too!
} ///:~
Exemplo n.º 9
0
void tst_QContactDetail::classHierarchy()
{
    QContactDetail f1;
    QContactDetail f2;

    QVERIFY(f1.isEmpty());
    QVERIFY(f2.isEmpty());

    QContactPhoneNumber p1;
    p1.setNumber("123456");
    QVERIFY(!p1.isEmpty());
    QVERIFY(p1.definitionName() == QContactPhoneNumber::DefinitionName);

    QContactName m1;
    m1.setFirstName("Bob");
    QVERIFY(!m1.isEmpty());
    QVERIFY(m1.definitionName() == QContactName::DefinitionName);

    QVERIFY(p1 != m1);
    QVERIFY(f1 == f2);

    f1 = p1; // f1 is a phonenumber
    QVERIFY(f1 == p1);

    f1 = f1; // assign to itself
    QVERIFY(f1 == f1);
    QVERIFY(f1 == p1);
    QVERIFY(f1 != f2);
    QVERIFY(p1 != f2);

    p1 = p1; // assign leaf class to itself
    QVERIFY(p1 == p1);
    QVERIFY(f1 == p1);
    QVERIFY(p1 == f1);

    f2 = f1; // f2 = f1 = phonenumber
    QVERIFY(f1 == f2);
    QVERIFY(f2 == f1);
    QVERIFY(f2 == p1);
    QVERIFY(f1 == p1);

    f1 = m1; // f1 = name, f2 = phonenumber
    QVERIFY(f1 == m1);
    QVERIFY(f1 != f2);
    QVERIFY(f2 == p1);

    QContactPhoneNumber p2(f2); // p2 = f2 = phonenumber
    QVERIFY(p1 == p2);
    QVERIFY(p1 == f2);
    QCOMPARE(p2.number(), p1.number());
    QCOMPARE(p2.number(), QString("123456"));

    p2 = p1; // phone number to phone number
    QVERIFY(p1 == p2);
    QVERIFY(p1 == f2);
    QCOMPARE(p2.number(), p1.number());
    QCOMPARE(p2.number(), QString("123456"));

    p2.setNumber("5678"); // NOTE: implicitly shared, this has caused a detach so p1 != 2
    QVERIFY(p1 != p2);
    QVERIFY(p1 == f2);
    QVERIFY(p2 != f2);
    QCOMPARE(p2.number(), QString("5678"));
    QCOMPARE(p1.number(), QString("123456"));

    /* Bad assignment */
    p2 = m1; // assign a name to a phone number
    QVERIFY(p2 != m1);
    QVERIFY(p2.definitionName() == QContactPhoneNumber::DefinitionName); // should still be a phone number though
    QVERIFY(p2.isEmpty());

    /* copy ctor */
    QContactName m2(m1);
    QVERIFY(m2 == m1);

    /* another bad assignment */
    m2 = p2; // phone number to a name
    QVERIFY(m2 != m1);
    QVERIFY(m2.definitionName() == QContactName::DefinitionName);
    QVERIFY(m2.isEmpty());

    /* Check contexts are considered for equality */
    p2 = QContactPhoneNumber(); // new id / detach
    p2.setNumber(p1.number());
    p2.setContexts(QContactDetail::ContextHome);
    QVERIFY(p1 != p2);
    p2.removeValue(QContactDetail::FieldContext); // note, context is a value.
    QVERIFY(p1 == p2); // different ids but same values should be equal

    /* Copy ctor from valid type */
    QContactDetail f3(p2);
    QVERIFY(f3 == p2);
    QVERIFY(f3.definitionName() == QContactPhoneNumber::DefinitionName);

    /* Copy ctor from invalid type */
    QContactPhoneNumber p3(m1);
    QVERIFY(p3 != m1);
    QVERIFY(p3.definitionName() == QContactPhoneNumber::DefinitionName);
    QVERIFY(p3.isEmpty());

    /* Copy ctore from invalid type, through base type */
    f3 = m1;
    QContactPhoneNumber p4(f3);
    QVERIFY(p4 != f3);
    QVERIFY(p4.definitionName() == QContactPhoneNumber::DefinitionName);
    QVERIFY(p4.isEmpty());

    /* Try a reference */
    p1.setNumber("123456");
    QContactDetail& ref = p1;
    QVERIFY(p1.number() == "123456");
    QVERIFY(p1.value(QContactPhoneNumber::FieldNumber) == "123456");
    QVERIFY(ref.value(QContactPhoneNumber::FieldNumber) == "123456");
    QVERIFY(p1 == ref);
    QVERIFY(ref == p1);

    /* Try changing the original */
    p1.setNumber("56789");
    QVERIFY(p1.number() == "56789");
    QVERIFY(p1.value(QContactPhoneNumber::FieldNumber) == "56789");
    QVERIFY(ref.value(QContactPhoneNumber::FieldNumber) == "56789");
    QVERIFY(p1 == ref);
    QVERIFY(ref == p1);

    /* Try changing the reference */
    ref.setValue(QContactPhoneNumber::FieldNumber, "654321");
    QVERIFY(p1.number() == "654321");
    QVERIFY(p1.value(QContactPhoneNumber::FieldNumber) == "654321");
    QVERIFY(ref.value(QContactPhoneNumber::FieldNumber) == "654321");
    QVERIFY(p1 == ref);
    QVERIFY(ref == p1);

    /* Random other test */
    NonMacroCustomDetail md;
    QVERIFY(md.definitionName() == "malicious");
    QVERIFY(md.setValue("key", "value"));
    QVERIFY(!md.isEmpty());
    md.doAssign(md); // self assignment
    QVERIFY(!md.isEmpty());
    QVERIFY(md.value("key") == "value");

    QContactDetail mdv;
    mdv = md;
    QVERIFY(mdv.definitionName() == "malicious");
    QVERIFY(mdv.value("key") == "value");

    md = mdv;
    QVERIFY(md.definitionName() == "malicious");
    QVERIFY(md.value("key") == "value");

    NonMacroCustomDetail2 md2;
    QVERIFY(md2.setValue("key", "value"));
    QVERIFY(md2.definitionName() == "malicious");
    QVERIFY(md2.value("key") == "value");
    md2.doAssign(md);
    QVERIFY(md2 == md);
    md2 = md;
    QVERIFY(md.definitionName() == "malicious");
    QVERIFY(md.value("key") == "value");

    // Self assignment
    md2.doAssign(md2);
    QVERIFY(md2.definitionName() == "malicious");
    QVERIFY(md2.value("key") == "value");

    md.doAssign(md2);
    QVERIFY(md == md2);

    // Assigning something else
    QContactPhoneNumber pn;
    pn.setNumber("12345");
    md2.doAssign(pn);
    QVERIFY(md2.isEmpty());
    QVERIFY(md2.definitionName() == "malicious");

    NonMacroCustomDetail mdb(pn);
    QVERIFY(mdb.isEmpty());
    QVERIFY(mdb.definitionName() == "malicious");

    NonMacroCustomDetail2 md2b(pn);
    QVERIFY(md2b.isEmpty());
    QVERIFY(md2b.definitionName() == "malicious");
}
Exemplo n.º 10
0
VTL_API void export_spoints_XML(std::string const &filename,
                                     int step,
                                     SPoints const &grid, SPoints const &mygrid,
                                     Zip zip, bool verb)
{
#if !defined(USE_ZLIB)
    if (zip == Zip::ZIPPED)
    {
        if(verb)
            std::cout << "INFO: zlib not present - vtk file will not be compressed!\n";
        zip = Zip::UNZIPPED;
    }
#endif

    // build file name (+rankno) + stepno + vtk extension
    std::stringstream s;
    s << filename;
    if (mygrid.id >= 0)
        s << "_r" << mygrid.id;
    s << '_' << std::setw(8) << std::setfill('0') << step << ".vti";
    std::stringstream s2;
    s2 << filename;
    if (mygrid.id >= 0)
        s2 << "r_" << mygrid.id;
    s2 << '_' << std::setw(8) << std::setfill('0') << step << ".vti.tmp";

    // open file
    if(verb)
        std::cout << "writing results to " << s.str() << '\n';
    std::ofstream f(s.str().c_str(), std::ios::binary | std::ios::out);
    std::ofstream f2(s2.str().c_str(), std::ios::binary | std::ios::out); // temp binary file
    f << std::scientific;

    size_t offset = 0;
    // header
    f << "<?xml version=\"1.0\"?>\n";

    f << "<VTKFile type=\"ImageData\" version=\"0.1\" byte_order=\"";
    f << (isCpuLittleEndian() ? "LittleEndian" : "BigEndian") << "\" ";
    f << "header_type=\"UInt32\" "; // UInt64 could be better (?)
    if (zip == Zip::ZIPPED)
        f << "compressor=\"vtkZLibDataCompressor\" ";
    f << ">\n";

    f << "  <ImageData ";
    f << "WholeExtent=\""
      << grid.np1[0] << ' ' << grid.np2[0] << ' '
      << grid.np1[1] << ' ' << grid.np2[1] << ' '
      << grid.np1[2] << ' ' << grid.np2[2] << "\" ";
    f << "Origin=\"" << grid.o[0] << ' ' << grid.o[1] << ' ' << grid.o[2] << "\" ";
    f << "Spacing=\"" << grid.dx[0] << ' ' << grid.dx[1] << ' ' << grid.dx[2] << "\">\n";

    f << "    <Piece ";
    f << "Extent=\""
      << mygrid.np1[0] << ' ' << mygrid.np2[0] << ' '
      << mygrid.np1[1] << ' ' << mygrid.np2[1] << ' '
      << mygrid.np1[2] << ' ' << mygrid.np2[2] << "\">\n";

    // ------------------------------------------------------------------------------------
    // POINT DATA

    f << "      <PointData>\n";
    // scalar fields
    for (auto const &p : mygrid.scalars)
    {
        //assert(it->second->size() == nbp); // TODO
        f << "        <DataArray type=\"Float32\" ";
        f << " Name=\"" << p.first << "\" ";
        f << " format=\"appended\" ";
        f << " RangeMin=\"0\" ";
        f << " RangeMax=\"1\" ";
        f << " offset=\"" << offset << "\" />\n";
        offset += write_vectorXML(f2, *p.second, (zip == Zip::ZIPPED));
    }

    // vector fields
    for (auto const &p : mygrid.vectors)
    {
        //assert(it->second->size() == 3 * nbp); // TODO
        f << "        <DataArray type=\"Float32\" ";
        f << " Name=\"" << p.first << "\" ";
        f << " NumberOfComponents=\"3\" ";
        f << " format=\"appended\" ";
        f << " RangeMin=\"0\" ";
        f << " RangeMax=\"1\" ";
        f << " offset=\"" << offset << "\" />\n";
        offset += write_vectorXML(f2, *p.second, (zip == Zip::ZIPPED));
    }
    f << "      </PointData>\n";

    // ------------------------------------------------------------------------------------
    // CELL DATA

    f << "      <CellData>\n";
    // scalar fields
    for (auto const &p : mygrid.cscalars)
    {
        //assert(it->second->size() == nbc); // TODO
        f << "        <DataArray type=\"Float32\" ";
        f << " Name=\"" << p.first << "\" ";
        f << " format=\"appended\" ";
        f << " RangeMin=\"0\" ";
        f << " RangeMax=\"1\" ";
        f << " offset=\"" << offset << "\" />\n";
        offset += write_vectorXML(f2, *p.second, (zip == Zip::ZIPPED));
    }

    // vector fields
    for (auto const &p : mygrid.cvectors)
    {
        //assert(it->second->size() == 3 * nbc); // TODO
        f << "        <DataArray type=\"Float32\" ";
        f << " Name=\"" << p.first << "\" ";
        f << " NumberOfComponents=\"3\" ";
        f << " format=\"appended\" ";
        f << " RangeMin=\"0\" ";
        f << " RangeMax=\"1\" ";
        f << " offset=\"" << offset << "\" />\n";
        offset += write_vectorXML(f2, *p.second, (zip == Zip::ZIPPED));
    }
    f << "      </CellData>\n";

    f2.close();

    // ------------------------------------------------------------------------------------
    f << "    </Piece>\n";
    f << "  </ImageData>\n";
    // ------------------------------------------------------------------------------------
    f << "  <AppendedData encoding=\"raw\">\n";
    f << "    _";

    // copy temp binary file as "appended" data
    std::ifstream f3(s2.str().c_str(), std::ios::binary | std::ios::in);
    f << f3.rdbuf();
    f3.close();
    // remove temp file
    std::remove(s2.str().c_str());

    f << "  </AppendedData>\n";
    f << "</VTKFile>\n";

    f.close();
}
Exemplo n.º 11
0
int main()
{
    printf("%d\n", f1(10));
    printf("%d\n", f2(10));
    printf("%d\n", f3(10));
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
    //Check that asserts are actually on.
    {
        int checkAsserts = 0;
        assert(checkAsserts = 1);
        if (!checkAsserts)
        {
            printf("Error, the code was not compiled with asserts.\n");
            exit(1);
        }
    }


    //Leak some memory on purpose to check that
    //a memory leak detection tool is working.
    char* leak = new char[12345];
    leak = 0;

    std::printf("Begin.\n");

    Test test;
    Test test2;

    {
        cb::Callback0<int> a;
        assert(!a.IsSet());

        //Test callback.
        a.Reset(&test, &Test::Return1);
        assert(a.IsSet());
        assert(a() == 1);

        //Test reseting callback.
        a.Reset(&test, &Test::Return2);
        assert(a() == 2);

        //Test equality with generated callbacks.
        assert(a == cb::Make0(&test, &Test::Return2)); //same func, same obj
        assert(a != cb::Make0(&test2, &Test::Return2)); //same func, diff obj
        assert(a != cb::Make0(&test, &Test::Return1)); //diff func, same obj
        assert(a != cb::Make0(Free3)); //Free function.
        assert(cb::Make0(Free3) == cb::Make0(Free3));

        //Test equality.
        cb::Callback0<int> b(&test, &Test::Return2);
        assert(b.IsSet());
        assert(a == b);

        b.Reset(Free3);
        assert(a != b);

        b.Reset(&test, &Test::Return1);
        assert(a != b);

        //Test equality with unset callbacks.
        b.Reset();
        assert(!b.IsSet());
        assert(a != b);

        a.Reset();
        assert(!a.IsSet());
        assert(a == b);
    }

    {
        //Test copy constructor.
        cb::Callback0<int> a(&test, &Test::Return1);
        cb::Callback0<int> b(a);
        assert(a == b);
        assert(a() == b());
        assert(b() == 1);

        cb::Callback0<int> c(Free1);
        cb::Callback0<int> d(c);
        assert(c == d);
        assert(c() == d());
        assert(d() == 1);
    }

    {
        //Test less than and equality some more.
        Test test;
        Test test2;
        X s;

        cb::Callback0<int> f1(Free1);
        cb::Callback0<int> f3(Free3);
        cb::Callback0<int> a(&test, &Test::Return1);
        cb::Callback0<int> aa(&test, &Test::Return1);
        cb::Callback0<int> b(&test2, &Test::Return1);
        cb::Callback0<int> c(&test, &Test::Return2);
        cb::Callback0<int> d(&s, &X::Return1);

        assert(d != a);
        assert(d() == a());

        assert((f1 < f3) ^ (f3 < f1));

        assert((f1 < a) && !(a < f1));
        assert((f1 < aa) && !(aa < f1));
        assert((f1 < b) && !(b < f1));
        assert((f1 < c) && !(c < f1));
        assert((f1 < d) && !(d < f1));

        assert(!(aa < a) && !(a < aa));

        assert((a < b) ^ (b < a));
        assert((a < c) ^ (c < a));
        assert((c < b) ^ (b < c));

        assert((a < d) ^ (d < a));

        f1 = f3 = a = aa = b = c = d;
        assert(f1 == f3);
        assert(a == aa);
        assert(b == c);
        assert(f1 == a && f1 == b && b == d);
    }

    {
        //Test free function callback.
        cb::Callback0<int> a(Free3);
        assert(a() == 3);
        assert(a == cb::Make0(Free3));
        assert(a != cb::Make0(Free1));

        cb::Callback1<int, int> b(FreeX2);
        assert(b(5) == 10);
    }

    {
        //Test reference parameters.
        cb::Callback1<void, int&> a(&test, &Test::Turn1);
        int i = 1000;
        a(i);
        assert(i == 1);
    }

    {
        //Test errors by calling unset callback.
        try
        {
            cb::Callback0<int> a;
            a.Call();
            assert(false);
        }
        catch (std::runtime_error err)
        {
            assert(err.what() == cb::unset_call_error);
        }
    }

    {
        //Test self assignment.
        cb::Callback0<int> a(&test, &Test::Return1);
        a = a;
        assert(a() == 1);

        cb::Callback0<int> b(Free3);
        b = b;
        assert(b() == 3);
    }

    {
        //Test container storage.
        std::set<cb::Callback0<int> > set;
        std::multiset<cb::Callback0<int> > mset;

        for (int i = 0; i < 10; ++i)
            if (i % 2)
                set.insert(cb::Make0(&test, &Test::Return1));
            else
                set.insert(cb::Make0(Free1));

        assert(set.size() == 2);

        for (std::set<cb::Callback0<int> >::const_iterator it = set.begin(); it != set.end(); ++it)
            assert(it->Call() == 1);



        for (int i = 0; i < 100; ++i)
            if (i % 2)
                mset.insert(cb::Make0(&test, &Test::Return1));
            else
                mset.insert(cb::Make0(Free1));
        assert(mset.size() == 100);
    }

    std::printf("End.\n");
}
Exemplo n.º 13
0
void
sha1_core(const uint32_t M[16], uint32_t hash_value[5]) {
  uint32_t H0;
  uint32_t H1;
  uint32_t H2;
  uint32_t H3;
  uint32_t H4;
  uint32_t W[80];
  uint32_t A, B, C, D, E, TEMP;
  int t;

  /* copy hash_value into H0, H1, H2, H3, H4 */
  H0 = hash_value[0];
  H1 = hash_value[1];
  H2 = hash_value[2];
  H3 = hash_value[3];
  H4 = hash_value[4];

  /* copy/xor message into array */
    
  W[0]  = bswap_32(M[0]);
  W[1]  = bswap_32(M[1]);
  W[2]  = bswap_32(M[2]);
  W[3]  = bswap_32(M[3]);
  W[4]  = bswap_32(M[4]);
  W[5]  = bswap_32(M[5]);
  W[6]  = bswap_32(M[6]);
  W[7]  = bswap_32(M[7]);
  W[8]  = bswap_32(M[8]);
  W[9]  = bswap_32(M[9]);
  W[10] = bswap_32(M[10]);
  W[11] = bswap_32(M[11]);
  W[12] = bswap_32(M[12]);
  W[13] = bswap_32(M[13]);
  W[14] = bswap_32(M[14]);
  W[15] = bswap_32(M[15]);
  TEMP = W[13] ^ W[8]  ^ W[2]  ^ W[0];  W[16] = S1(TEMP);
  TEMP = W[14] ^ W[9]  ^ W[3]  ^ W[1];  W[17] = S1(TEMP);
  TEMP = W[15] ^ W[10] ^ W[4]  ^ W[2];  W[18] = S1(TEMP);
  TEMP = W[16] ^ W[11] ^ W[5]  ^ W[3];  W[19] = S1(TEMP);
  TEMP = W[17] ^ W[12] ^ W[6]  ^ W[4];  W[20] = S1(TEMP);
  TEMP = W[18] ^ W[13] ^ W[7]  ^ W[5];  W[21] = S1(TEMP);
  TEMP = W[19] ^ W[14] ^ W[8]  ^ W[6];  W[22] = S1(TEMP);
  TEMP = W[20] ^ W[15] ^ W[9]  ^ W[7];  W[23] = S1(TEMP);
  TEMP = W[21] ^ W[16] ^ W[10] ^ W[8];  W[24] = S1(TEMP);
  TEMP = W[22] ^ W[17] ^ W[11] ^ W[9];  W[25] = S1(TEMP);
  TEMP = W[23] ^ W[18] ^ W[12] ^ W[10]; W[26] = S1(TEMP);
  TEMP = W[24] ^ W[19] ^ W[13] ^ W[11]; W[27] = S1(TEMP);
  TEMP = W[25] ^ W[20] ^ W[14] ^ W[12]; W[28] = S1(TEMP);
  TEMP = W[26] ^ W[21] ^ W[15] ^ W[13]; W[29] = S1(TEMP);
  TEMP = W[27] ^ W[22] ^ W[16] ^ W[14]; W[30] = S1(TEMP);
  TEMP = W[28] ^ W[23] ^ W[17] ^ W[15]; W[31] = S1(TEMP);

  /* process the remainder of the array */
  for (t=32; t < 80; t++) {
    TEMP = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16];
    W[t] = S1(TEMP);      
  }

  A = H0; B = H1; C = H2; D = H3; E = H4;

  for (t=0; t < 20; t++) {
    TEMP = S5(A) + f0(B,C,D) + E + W[t] + SHA_K0;
    E = D; D = C; C = S30(B); B = A; A = TEMP;
  }
  for (   ; t < 40; t++) {
    TEMP = S5(A) + f1(B,C,D) + E + W[t] + SHA_K1;
    E = D; D = C; C = S30(B); B = A; A = TEMP;
  }
  for (   ; t < 60; t++) {
    TEMP = S5(A) + f2(B,C,D) + E + W[t] + SHA_K2;
    E = D; D = C; C = S30(B); B = A; A = TEMP;
  }
  for (   ; t < 80; t++) {
    TEMP = S5(A) + f3(B,C,D) + E + W[t] + SHA_K3;
    E = D; D = C; C = S30(B); B = A; A = TEMP;
  }

  hash_value[0] = H0 + A;
  hash_value[1] = H1 + B;
  hash_value[2] = H2 + C;
  hash_value[3] = H3 + D;
  hash_value[4] = H4 + E;

  return;
}
Exemplo n.º 14
0
void
sha1_final(sha1_ctx_t *ctx, uint32_t *output) {
  uint32_t A, B, C, D, E, TEMP;
  uint32_t W[80];  
  int i, t;

  /*
   * process the remaining octets_in_buffer, padding and terminating as
   * necessary
   */
  {
    int tail = ctx->octets_in_buffer % 4;
    
    /* copy/xor message into array */
    for (i=0; i < (ctx->octets_in_buffer+3)/4; i++) 
      W[i]  = bswap_32(ctx->M[i]);  /* why no bswap_32() here?   - DAM */

    /* set the high bit of the octet immediately following the message */
    switch (tail) {
    case (3):
      W[i-1] = (bswap_32(ctx->M[i-1]) & 0xffffff00) | 0x80;
      W[i] = 0x0;
      break;
    case (2):      
      W[i-1] = (bswap_32(ctx->M[i-1]) & 0xffff0000) | 0x8000;
      W[i] = 0x0;
      break;
    case (1):
      W[i-1] = (bswap_32(ctx->M[i-1]) & 0xff000000) | 0x800000;
      W[i] = 0x0;
      break;
    case (0):
      W[i] = 0x80000000;
      break;
    }
    
    /* zeroize remaining words */
    for (i++   ; i < 15; i++)
      W[i] = 0x0;

    /* 
     * if there is room at the end of the word array, then set the
     * last word to the bit-length of the message; otherwise, set that
     * word to zero and then we need to do one more run of the
     * compression algo.
     */
    if (ctx->octets_in_buffer < 56) 
      W[15] = ctx->num_bits_in_msg;
    else
      W[15] = 0x0;

    /* process the word array */
    for (t=16; t < 80; t++) {
      TEMP = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16];
      W[t] = S1(TEMP);
    }

    A = ctx->H[0]; 
    B = ctx->H[1]; 
    C = ctx->H[2]; 
    D = ctx->H[3]; 
    E = ctx->H[4];

    for (t=0; t < 20; t++) {
      TEMP = S5(A) + f0(B,C,D) + E + W[t] + SHA_K0;
      E = D; D = C; C = S30(B); B = A; A = TEMP;
    }
    for (   ; t < 40; t++) {
      TEMP = S5(A) + f1(B,C,D) + E + W[t] + SHA_K1;
      E = D; D = C; C = S30(B); B = A; A = TEMP;
    }
    for (   ; t < 60; t++) {
      TEMP = S5(A) + f2(B,C,D) + E + W[t] + SHA_K2;
      E = D; D = C; C = S30(B); B = A; A = TEMP;
    }
    for (   ; t < 80; t++) {
      TEMP = S5(A) + f3(B,C,D) + E + W[t] + SHA_K3;
      E = D; D = C; C = S30(B); B = A; A = TEMP;
    }

    ctx->H[0] += A;
    ctx->H[1] += B;
    ctx->H[2] += C;
    ctx->H[3] += D;
    ctx->H[4] += E;

  }

  debug_print(mod_sha1, "(final) running sha1_core()", NULL);

  if (ctx->octets_in_buffer >= 56) {

    debug_print(mod_sha1, "(final) running sha1_core() again", NULL);

    /* we need to do one final run of the compression algo */

    /* 
     * set initial part of word array to zeros, and set the 
     * final part to the number of bits in the message
     */
    for (i=0; i < 15; i++)
      W[i] = 0x0;
    W[15] = ctx->num_bits_in_msg;

    /* process the word array */
    for (t=16; t < 80; t++) {
      TEMP = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16];
      W[t] = S1(TEMP);
    }

    A = ctx->H[0]; 
    B = ctx->H[1]; 
    C = ctx->H[2]; 
    D = ctx->H[3]; 
    E = ctx->H[4];

    for (t=0; t < 20; t++) {
      TEMP = S5(A) + f0(B,C,D) + E + W[t] + SHA_K0;
      E = D; D = C; C = S30(B); B = A; A = TEMP;
    }
    for (   ; t < 40; t++) {
      TEMP = S5(A) + f1(B,C,D) + E + W[t] + SHA_K1;
      E = D; D = C; C = S30(B); B = A; A = TEMP;
    }
    for (   ; t < 60; t++) {
      TEMP = S5(A) + f2(B,C,D) + E + W[t] + SHA_K2;
      E = D; D = C; C = S30(B); B = A; A = TEMP;
    }
    for (   ; t < 80; t++) {
      TEMP = S5(A) + f3(B,C,D) + E + W[t] + SHA_K3;
      E = D; D = C; C = S30(B); B = A; A = TEMP;
    }

    ctx->H[0] += A;
    ctx->H[1] += B;
    ctx->H[2] += C;
    ctx->H[3] += D;
    ctx->H[4] += E;
  }

  /* copy result into output buffer */
  output[0] = bswap_32(ctx->H[0]);
  output[1] = bswap_32(ctx->H[1]);
  output[2] = bswap_32(ctx->H[2]);
  output[3] = bswap_32(ctx->H[3]);
  output[4] = bswap_32(ctx->H[4]);

  /* indicate that message buffer in context is empty */
  ctx->octets_in_buffer = 0;

  return;
}
Exemplo n.º 15
0
TH2D* offlineCycEnNc(const char* filename) {
    gROOT->SetBatch(kTRUE);

    string qq;
    string baseN = "NaI-Output-EvC-NaI";
    string filetypeN = ".png";


    TFile *f = new TFile(filename);
    TTree *t = (TTree*) f->Get("gammas");

    stringstream ssss;
    ssss<<"FULL-NaIOutput-"<<filename;
    TFile f3(ssss.str().c_str(),"UPDATE");

    TCanvas *cTnc1 = new TCanvas("cTobyN1","NaI vs Cycle (1 of 3)",2000,2000);
    TCanvas *cTnc2 = new TCanvas("cTobyN2","NaI vs Cycle (2 of 3)",2000,2000);
    TCanvas *cTnc3 = new TCanvas("cTobyN3","NaI vs Cycle (3 of 3)",2000,2000);
    cout <<"Opening 3 Canvases, with 3,3,4 for the NaI crystals"<<endl;
    gStyle->SetOptLogz(1);

    cTnc1->Divide(2,2,0.001,0.001);
    cTnc2->Divide(2,2,0.001,0.001);
    cTnc3->Divide(2,2,0.001,0.001);

    TH2D* hNc0 = new TH2D("hNc0","NaI[0] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc1 = new TH2D("hNc1","NaI[1] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc2 = new TH2D("hNc2","NaI[2] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc3 = new TH2D("hNc3","NaI[3] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc4 = new TH2D("hNc4","NaI[4] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc5 = new TH2D("hNc5","NaI[5] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc6 = new TH2D("hNc6","NaI[6] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc7 = new TH2D("hNc7","NaI[7] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc8 = new TH2D("hNc8","NaI[8] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);
    TH2D* hNc9 = new TH2D("hNc9","NaI[9] vs cycle", 8000.,0.,8000.,1700.,0.,1700.);

    //set minimum for logz
    hNc0->SetMinimum(1);
    hNc1->SetMinimum(1);
    hNc2->SetMinimum(1);
    hNc3->SetMinimum(1);
    hNc4->SetMinimum(1);
    hNc5->SetMinimum(1);
    hNc6->SetMinimum(1);
    hNc7->SetMinimum(1);
    hNc8->SetMinimum(1);
    hNc9->SetMinimum(1);

    //set zoom range
    // hNc0->GetXaxis()->SetRangeUser(1200,1600);
    // hNc1->GetXaxis()->SetRangeUser(1300,1600);
    // hNc2->GetXaxis()->SetRangeUser(1300,1600);
    // hNc3->GetXaxis()->SetRangeUser(1300,1600);
    // hNc4->GetXaxis()->SetRangeUser(1300,1600);
    // hNc5->GetXaxis()->SetRangeUser(1300,1600);
    // hNc6->GetXaxis()->SetRangeUser(1300,1600);
    // hNc7->GetXaxis()->SetRangeUser(1300,1600);
    // hNc8->GetXaxis()->SetRangeUser(1300,1600);
    // hNc9->GetXaxis()->SetRangeUser(1300,1600);

    cout<<"Base name for pictures= "<<baseN<<endl<<"Filetype for Pictures= "<<filetypeN<<endl;

    cTnc1->cd(1);
    t->Draw("calgam.cycle:calgam.NaI[0]>>hNc0","","COLZ");
    qq = baseN + "0" + filetypeN;
    //  cTnc1->cd(1)->SaveAs(qq.c_str());

    cTnc1->cd(2);
    t->Draw("calgam.cycle:calgam.NaI[1]>>hNc1","","COLZ");
    qq = baseN + "1" + filetypeN;
    //cTnc1->cd(2)->SaveAs(qq.c_str());

    cTnc1->cd(3);
    t->Draw("calgam.cycle:calgam.NaI[2]>>hNc2","","COLZ");
    qq = baseN + "2" + filetypeN;
    //cTnc1->cd(3)->SaveAs(qq.c_str());

    cout<<"   First canvas fill complete. Moving on"<<endl;

    cTnc2->cd(1);
    t->Draw("calgam.cycle:calgam.NaI[3]>>hNc3","","COLZ");
    qq = baseN + "3" + filetypeN;
    //cTnc2->cd(1)->SaveAs(qq.c_str());

    cTnc2->cd(2);
    t->Draw("calgam.cycle:calgam.NaI[4]>>hNc4","","COLZ");
    qq = baseN + "4" + filetypeN;
    //cTnc2->cd(2)->SaveAs(qq.c_str());

    cTnc2->cd(3);
    t->Draw("calgam.cycle:calgam.NaI[5]>>hNc5","","COLZ");
    qq = baseN + "5" + filetypeN;
    //  cTnc2->cd(3)->SaveAs(qq.c_str());

    cout<<"   Second canvas fill complete. Moving on"<<endl;

    cTnc3->cd(1);
    t->Draw("calgam.cycle:calgam.NaI[6]>>hNc6","","COLZ");
    qq = baseN + "6" + filetypeN;
    //cTnc3->cd(1)->SaveAs(qq.c_str());

    cTnc3->cd(2);
    t->Draw("calgam.cycle:calgam.NaI[7]>>hNc7","","COLZ");
    qq = baseN + "7" + filetypeN;
    //cTnc3->cd(2)->SaveAs(qq.c_str());

    cTnc3->cd(3);
    t->Draw("calgam.cycle:calgam.NaI[8]>>hNc8","","COLZ");
    qq = baseN + "8" + filetypeN;
    //cTnc3->cd(3)->SaveAs(qq.c_str());

    cTnc3->cd(4);
    t->Draw("calgam.cycle:calgam.NaI[9]>>hNc9","","COLZ");
    qq = baseN + "9" + filetypeN;
    //cTnc3->cd(4)->SaveAs(qq.c_str());

    f3.Write();

    //  gApplication->Terminate();
}
Exemplo n.º 16
0
int P3P::computePoses(const Eigen::Matrix3d & feature_vectors, const Eigen::Matrix3d & world_points,
                      Eigen::Matrix<Eigen::Matrix<double, 3, 4>, 4, 1> & solutions)
{
  // Extraction of world points
  Eigen::Vector3d P1 = world_points.col(0);
  Eigen::Vector3d P2 = world_points.col(1);
  Eigen::Vector3d P3 = world_points.col(2);

  // Verification that world points are not colinear
  Eigen::Vector3d temp1 = P2 - P1;
  Eigen::Vector3d temp2 = P3 - P1;

  if (temp1.cross(temp2).norm() == 0)
  {
    return -1;
  }

  // Extraction of feature vectors
  Eigen::Vector3d f1 = feature_vectors.col(0);
  Eigen::Vector3d f2 = feature_vectors.col(1);
  Eigen::Vector3d f3 = feature_vectors.col(2);

  // Creation of intermediate camera frame
  Eigen::Vector3d e1 = f1;
  Eigen::Vector3d e3 = f1.cross(f2);
  e3 = e3 / e3.norm();
  Eigen::Vector3d e2 = e3.cross(e1);

  Eigen::Matrix3d T;
  T.row(0) = e1.transpose();
  T.row(1) = e2.transpose();
  T.row(2) = e3.transpose();

  f3 = T * f3;

  // Reinforce that f3(2,0) > 0 for having theta in [0;pi]
  if (f3(2, 0) > 0)
  {
    f1 = feature_vectors.col(1);
    f2 = feature_vectors.col(0);
    f3 = feature_vectors.col(2);

    e1 = f1;
    e3 = f1.cross(f2);
    e3 = e3 / e3.norm();
    e2 = e3.cross(e1);

    T.row(0) = e1.transpose();
    T.row(1) = e2.transpose();
    T.row(2) = e3.transpose();

    f3 = T * f3;

    P1 = world_points.col(1);
    P2 = world_points.col(0);
    P3 = world_points.col(2);
  }

  // Creation of intermediate world frame
  Eigen::Vector3d n1 = P2 - P1;
  n1 = n1 / n1.norm();
  Eigen::Vector3d n3 = n1.cross(P3 - P1);
  n3 = n3 / n3.norm();
  Eigen::Vector3d n2 = n3.cross(n1);

  Eigen::Matrix3d N;
  N.row(0) = n1.transpose();
  N.row(1) = n2.transpose();
  N.row(2) = n3.transpose();

  // Extraction of known parameters
  P3 = N * (P3 - P1);

  double d_12 = (P2 - P1).norm();
  double f_1 = f3(0, 0) / f3(2, 0);
  double f_2 = f3(1, 0) / f3(2, 0);
  double p_1 = P3(0, 0);
  double p_2 = P3(1, 0);

  double cos_beta = f1.dot(f2);
  double b = 1 / (1 - pow(cos_beta, 2)) - 1;

  if (cos_beta < 0)
  {
    b = -sqrt(b);
  }
  else
  {
    b = sqrt(b);
  }

  // Definition of temporary variables for avoiding multiple computation
  double f_1_pw2 = pow(f_1, 2);
  double f_2_pw2 = pow(f_2, 2);
  double p_1_pw2 = pow(p_1, 2);
  double p_1_pw3 = p_1_pw2 * p_1;
  double p_1_pw4 = p_1_pw3 * p_1;
  double p_2_pw2 = pow(p_2, 2);
  double p_2_pw3 = p_2_pw2 * p_2;
  double p_2_pw4 = p_2_pw3 * p_2;
  double d_12_pw2 = pow(d_12, 2);
  double b_pw2 = pow(b, 2);

  // Computation of factors of 4th degree polynomial
  Eigen::Matrix<double, 5, 1> factors;

  factors(0) = -f_2_pw2 * p_2_pw4 - p_2_pw4 * f_1_pw2 - p_2_pw4;

  factors(1) = 2 * p_2_pw3 * d_12 * b + 2 * f_2_pw2 * p_2_pw3 * d_12 * b - 2 * f_2 * p_2_pw3 * f_1 * d_12;

  factors(2) = -f_2_pw2 * p_2_pw2 * p_1_pw2 - f_2_pw2 * p_2_pw2 * d_12_pw2 * b_pw2 - f_2_pw2 * p_2_pw2 * d_12_pw2
      + f_2_pw2 * p_2_pw4 + p_2_pw4 * f_1_pw2 + 2 * p_1 * p_2_pw2 * d_12 + 2 * f_1 * f_2 * p_1 * p_2_pw2 * d_12 * b
      - p_2_pw2 * p_1_pw2 * f_1_pw2 + 2 * p_1 * p_2_pw2 * f_2_pw2 * d_12 - p_2_pw2 * d_12_pw2 * b_pw2
      - 2 * p_1_pw2 * p_2_pw2;

  factors(3) = 2 * p_1_pw2 * p_2 * d_12 * b + 2 * f_2 * p_2_pw3 * f_1 * d_12 - 2 * f_2_pw2 * p_2_pw3 * d_12 * b
      - 2 * p_1 * p_2 * d_12_pw2 * b;

  factors(4) = -2 * f_2 * p_2_pw2 * f_1 * p_1 * d_12 * b + f_2_pw2 * p_2_pw2 * d_12_pw2 + 2 * p_1_pw3 * d_12
      - p_1_pw2 * d_12_pw2 + f_2_pw2 * p_2_pw2 * p_1_pw2 - p_1_pw4 - 2 * f_2_pw2 * p_2_pw2 * p_1 * d_12
      + p_2_pw2 * f_1_pw2 * p_1_pw2 + f_2_pw2 * p_2_pw2 * d_12_pw2 * b_pw2;

  // Computation of roots
  Eigen::Matrix<double, 4, 1> realRoots;

  P3P::solveQuartic(factors, realRoots);

  // Backsubstitution of each solution
  for (int i = 0; i < 4; ++i)
  {
    double cot_alpha = (-f_1 * p_1 / f_2 - realRoots(i) * p_2 + d_12 * b)
        / (-f_1 * realRoots(i) * p_2 / f_2 + p_1 - d_12);

    double cos_theta = realRoots(i);
    double sin_theta = sqrt(1 - pow((double)realRoots(i), 2));
    double sin_alpha = sqrt(1 / (pow(cot_alpha, 2) + 1));
    double cos_alpha = sqrt(1 - pow(sin_alpha, 2));

    if (cot_alpha < 0)
    {
      cos_alpha = -cos_alpha;
    }

    Eigen::Vector3d C;
    C(0) = d_12 * cos_alpha * (sin_alpha * b + cos_alpha);
    C(1) = cos_theta * d_12 * sin_alpha * (sin_alpha * b + cos_alpha);
    C(2) = sin_theta * d_12 * sin_alpha * (sin_alpha * b + cos_alpha);

    C = P1 + N.transpose() * C;

    Eigen::Matrix3d R;
    R(0, 0) = -cos_alpha;
    R(0, 1) = -sin_alpha * cos_theta;
    R(0, 2) = -sin_alpha * sin_theta;
    R(1, 0) = sin_alpha;
    R(1, 1) = -cos_alpha * cos_theta;
    R(1, 2) = -cos_alpha * sin_theta;
    R(2, 0) = 0;
    R(2, 1) = -sin_theta;
    R(2, 2) = cos_theta;

    R = N.transpose() * R.transpose() * T;

    Eigen::Matrix<double, 3, 4> solution;
    solution.block<3, 3>(0, 0) = R;
    solution.col(3) = C;

    solutions(i) = solution;
  }

  return 0;
}
Exemplo n.º 17
0
int main(void) {
        f0();
    f1();
    f2();
    f3();
    f4();
    f5();
    f6();
    f7();
    f8();
    f9();
    f10();
    f11();
    f12();
    f13();
    f14();
    f15();
    f16();
    f17();
    f18();
    f19();
    f20();
    f21();
    f22();
    f23();
    f24();
    f25();
    f26();
    f27();
    f28();
    f29();
    f30();
    f31();
    f32();
    f33();
    f34();
    f35();
    f36();
    f37();
    f38();
    f39();
    f40();
    f41();
    f42();
    f43();
    f44();
    f45();
    f46();
    f47();
    f48();
    f49();
    f50();
    f51();
    f52();
    f53();
    f54();
    f55();
    f56();
    f57();
    f58();
    f59();
    f60();
    f61();


    return 0;
}
Exemplo n.º 18
0
/*
  Hashes 'data', which should be a pointer to 512 bits of data (sixteen
  32 bit ints), into the ongoing 160 bit hash value (five 32 bit ints)
  'hash'
*/
int
sha_hash(int *data, int *hash)
{
  int W[80];
  unsigned int A=hash[0], B=hash[1], C=hash[2], D=hash[3], E=hash[4];
  unsigned int t, x, TEMP;

  for (t=0; t<16; t++)
    {
#ifndef WORDS_BIGENDIAN
      W[t]=switch_endianness(data[t]);
#else
      W[t]=data[t];
#endif
    }


  /* SHA1 Data expansion */
  for (t=16; t<80; t++)
    {
      x=W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16];
      W[t]=rol1(x);
    }

  /* SHA1 main loop (t=0 to 79)
   This is broken down into four subloops in order to use
   the correct round function and constant */
  for (t=0; t<20; t++)
    {
      TEMP=rol5(A) + f1(B,C,D) + E + W[t] + K1;
      E=D;
      D=C;
      C=rol30(B);
      B=A;
      A=TEMP;
    }
  for (; t<40; t++)
    {
      TEMP=rol5(A) + f2(B,C,D) + E + W[t] + K2;
      E=D;
      D=C;
      C=rol30(B);
      B=A;
      A=TEMP;
    }
  for (; t<60; t++)
    {
      TEMP=rol5(A) + f3(B,C,D) + E + W[t] + K3;
      E=D;
      D=C;
      C=rol30(B);
      B=A;
      A=TEMP;
    }
  for (; t<80; t++)
    {
      TEMP=rol5(A) + f2(B,C,D) + E + W[t] + K4;
      E=D;
      D=C;
      C=rol30(B);
      B=A;
      A=TEMP;
    }
  hash[0]+=A;
  hash[1]+=B;
  hash[2]+=C;
  hash[3]+=D;
  hash[4]+=E;
  return 0;
}
Exemplo n.º 19
0
void Partitioner::call_RAY_MASTER_MODE_COUNT_FILE_ENTRIES(){
	/** tell every peer to count entries in files in parallel */
	if(!m_initiatedMaster){
		m_initiatedMaster=true;
		m_ranksDoneCounting=0;
		m_ranksDoneSending=0;
		for(int destination=0;destination<m_parameters->getSize();destination++){
			Message aMessage(NULL,0,destination,RAY_MPI_TAG_COUNT_FILE_ENTRIES,m_parameters->getRank());
			m_outbox->push_back(aMessage);
		}
	/** a peer rank finished counting the entries in its files */
	}else if(m_inbox->size()>0 && m_inbox->at(0)->getTag()== RAY_MPI_TAG_COUNT_FILE_ENTRIES_REPLY){
		m_ranksDoneCounting++;
		/** all peers have finished */
		if(m_ranksDoneCounting==m_parameters->getSize()){
			for(int destination=0;destination<m_parameters->getSize();destination++){
				Message aMessage(NULL,0,destination,RAY_MPI_TAG_REQUEST_FILE_ENTRY_COUNTS,m_parameters->getRank());
				m_outbox->push_back(aMessage);
			}
		}
	/** a peer send the count for one file */
	}else if(m_inbox->size()>0 && m_inbox->at(0)->getTag()== RAY_MPI_TAG_FILE_ENTRY_COUNT){
		MessageUnit*buffer=m_inbox->at(0)->getBuffer();
		int file=buffer[0];
		LargeCount count=buffer[1];
		m_masterCounts[file]=count;

		if(m_parameters->hasOption("-debug-partitioner"))
			cout<<"Rank "<<m_parameters->getRank()<<" received from "<<m_inbox->at(0)->getSource()<<" File "<<file<<" Entries "<<count<<endl;
		/** reply to the peer */
		Message aMessage(NULL,0,m_inbox->at(0)->getSource(),RAY_MPI_TAG_FILE_ENTRY_COUNT_REPLY,m_parameters->getRank());
		m_outbox->push_back(aMessage);
	/** a peer finished sending file counts */
	}else if(m_inbox->size()>0 && m_inbox->at(0)->getTag()== RAY_MPI_TAG_REQUEST_FILE_ENTRY_COUNTS_REPLY){
		m_ranksDoneSending++;
		/** all peers have finished */
		if(m_ranksDoneSending==m_parameters->getSize()){

			for(int i=0;i<(int)m_masterCounts.size();i++){
				if(m_parameters->hasOption("-debug-partitioner"))
					cout<<"Rank "<<m_parameters->getRank()<< " File "<<i<<" Count "<<m_masterCounts[i]<<endl;
				m_parameters->setNumberOfSequences(i,m_masterCounts[i]);
			}
			m_masterCounts.clear();

			/* write the number of sequences */
			ostringstream fileName;
			fileName<<m_parameters->getPrefix();
			fileName<<"NumberOfSequences.txt";
			ofstream f2(fileName.str().c_str());

/* Write a sequence partition too,
 * it contains the number of entries in each file.
 */
			ostringstream fileNameForFiles;
			fileNameForFiles<<m_parameters->getPrefix();
			fileNameForFiles<<"FilePartition.txt";
			ofstream partitionStream(fileNameForFiles.str().c_str());

			f2<<"Files: "<<m_parameters->getNumberOfFiles()<<endl;
			f2<<endl;

			partitionStream<<"#File	Name	FirstSequence	LastSequence	NumberOfSequences"<<endl;

			LargeCount totalSequences=0;
			for(int i=0;i<(int)m_parameters->getNumberOfFiles();i++){
				f2<<"FileNumber: "<<i<<endl;
				f2<<"	FilePath: "<<m_parameters->getFile(i)<<endl;

				LargeCount entries=m_parameters->getNumberOfSequences(i);
				f2<<" 	NumberOfSequences: "<<entries<<endl;

				if(entries>0){
					f2<<"	FirstSequence: "<<totalSequences<<endl;
					f2<<"	LastSequence: "<<totalSequences+entries-1<<endl;
				}

				f2<<endl;

				if(entries>0){
					partitionStream<<i<<"	"<<m_parameters->getFile(i);
					partitionStream<<"	"<<totalSequences;
					partitionStream<<"	"<<totalSequences+entries-1;
					partitionStream<<"	"<<entries<<endl;
				}

				totalSequences+=entries;
			}
			
			partitionStream.close();

			f2<<endl;
			f2<<"Summary"<<endl;
			f2<<"	NumberOfSequences: "<<totalSequences<<endl;
			f2<<"	FirstSequence: 0"<<endl;
			f2<<"	LastSequence: "<<totalSequences-1<<endl;
			f2.close();
			cout<<"Rank "<<m_parameters->getRank()<<" wrote "<<fileName.str()<<endl;


			/* write the partition */
			ostringstream fileName2;
			fileName2<<m_parameters->getPrefix();
			fileName2<<"SequencePartition.txt";
			ofstream f3(fileName2.str().c_str());

			LargeCount perRank=totalSequences/m_parameters->getSize();
			f3<<"#Rank	FirstSequence	LastSequence	NumberOfSequences"<<endl;
			for(int i=0;i<m_parameters->getSize();i++){
				LargeIndex first=i*perRank;
				LargeIndex last=first+perRank-1;

				if(i==m_parameters->getSize()-1){
					last=totalSequences-1;
				}
				
				LargeCount count=last-first+1;

				f3<<i<<"\t"<<first<<"\t"<<last<<"\t"<<count<<endl;
			}
			f3.close();
			cout<<"Rank "<<m_parameters->getRank()<<" wrote "<<fileName2.str()<<endl;

			m_switchMan->closeMasterMode();
		}
	}
}
int f3_Skel(int *argTypes, void **args) {
  f3((long *)(*args));
  return 0;
}
void TabulatorTri<Scalar,ArrayScalar,0>::tabulate(ArrayScalar &outputValues ,
                                                  const int deg ,
                                                  const ArrayScalar &z )
{
  const int np = z.dimension( 0 );
  
  // each point needs to be transformed from Pavel's element
  // z(i,0) --> (2.0 * z(i,0) - 1.0)
  // z(i,1) --> (2.0 * z(i,1) - 1.0)
  
  // set up constant term
  int idx_cur = TabulatorTri<Scalar,ArrayScalar,0>::idx(0,0);
  int idx_curp1,idx_curm1;
  
  // set D^{0,0} = 1.0
  for (int i=0;i<np;i++) {
    outputValues(idx_cur,i) = Scalar( 1.0 ) + z(i,0) - z(i,0) + z(i,1) - z(i,1);
  }
  

  if (deg > 0) {
    Teuchos::Array<Scalar> f1(np),f2(np),f3(np);
    
    for (int i=0;i<np;i++) {
      f1[i] = 0.5 * (1.0+2.0*(2.0*z(i,0)-1.0)+(2.0*z(i,1)-1.0));
      f2[i] = 0.5 * (1.0-(2.0*z(i,1)-1.0));
      f3[i] = f2[i] * f2[i];
    }
    
    // set D^{1,0} = f1
    idx_cur = TabulatorTri<Scalar,ArrayScalar,0>::idx(1,0);
    for (int i=0;i<np;i++) {
      outputValues(idx_cur,i) = f1[i];
    }
    
    // recurrence in p
    for (int p=1;p<deg;p++) {
      idx_cur = TabulatorTri<Scalar,ArrayScalar,0>::idx(p,0);
      idx_curp1 = TabulatorTri<Scalar,ArrayScalar,0>::idx(p+1,0);
      idx_curm1 = TabulatorTri<Scalar,ArrayScalar,0>::idx(p-1,0);
      Scalar a = (2.0*p+1.0)/(1.0+p);
      Scalar b = p / (p+1.0);
      
      for (int i=0;i<np;i++) {
        outputValues(idx_curp1,i) = a * f1[i] * outputValues(idx_cur,i)
          - b * f3[i] * outputValues(idx_curm1,i);
      }
    }
    
    // D^{p,1}
    for (int p=0;p<deg;p++) {
      int idxp0 = TabulatorTri<Scalar,ArrayScalar,0>::idx(p,0);
      int idxp1 = TabulatorTri<Scalar,ArrayScalar,0>::idx(p,1);
      for (int i=0;i<np;i++) {
        outputValues(idxp1,i) = outputValues(idxp0,i)
          *0.5*(1.0+2.0*p+(3.0+2.0*p)*(2.0*z(i,1)-1.0));
      }
    }
    
    
    // recurrence in q
    for (int p=0;p<deg-1;p++) {
      for (int q=1;q<deg-p;q++) {
        int idxpqp1=TabulatorTri<Scalar,ArrayScalar,0>::idx(p,q+1);
        int idxpq=TabulatorTri<Scalar,ArrayScalar,0>::idx(p,q);
        int idxpqm1=TabulatorTri<Scalar,ArrayScalar,0>::idx(p,q-1);
        Scalar a,b,c;
        TabulatorTri<Scalar,ArrayScalar,0>::jrc((Scalar)(2*p+1),(Scalar)0,q,a,b,c);
        for (int i=0;i<np;i++) {
          outputValues(idxpqp1,i)
            = (a*(2.0*z(i,1)-1.0)+b)*outputValues(idxpq,i)
            - c*outputValues(idxpqm1,i);
        }
      }
    }
  }    
  
  // orthogonalize
  for (int p=0;p<=deg;p++) {
    for (int q=0;q<=deg-p;q++) {
      for (int i=0;i<np;i++) {
        outputValues(TabulatorTri<Scalar,ArrayScalar,0>::idx(p,q),i) *= sqrt( (p+0.5)*(p+q+1.0));
      }
    }
  }
  
  return;
}
Exemplo n.º 22
0
void __attribute__((thiscall)) f6(void) {
// CHECK: define x86_thiscallcc void @f6()
  f3();
// CHECK: call x86_thiscallcc void @f3()
}
Exemplo n.º 23
0
int main ()
{
    try
    {
        saga::filesystem::directory d ("file://localhost/tmp/");

        std::cout << " ~~~ " << d.get_url () << std::endl;

        d.change_dir ("file://localhost/tmp/");

        std::cout << " ~~~ " << d.get_url () << std::endl;

        d.change_dir ("file://localhost/Users/");

        std::cout << " ~~~ " << d.get_url () << std::endl;

        d.change_dir ("file://localhost/etc/xgrid");

        std::cout << " ~~~ " << d.get_url () << std::endl;

        d.change_dir ("..");

        std::cout << " ~~~ " << d.get_url () << std::endl;

        saga::filesystem::file f = d.open ("passwd");

        std::cout << " ~~~ " << f.get_url ()
                  << ": " << f.get_size () << std::endl;

        std::cout << " ~~~ is_file 1: " << d.is_file ("syslog.conf") << std::endl;
        std::cout << " ~~~ is_file 2: " << d.is_file ("syslog.cfg")  << std::endl;
        std::cout << " ~~~ is_file 3: " << d.is_file ("file://localhost/etc/syslog.conf") << std::endl;
        std::cout << " ~~~ is_file 4: " << d.is_file ("file://localhost/etc/syslog.cfg")  << std::endl;

        d.change_dir ("../tmp/");

        std::cout << " ~~~ " << d.get_url () << std::endl;

        d.copy ("t1", "t2", saga::filesystem::Overwrite);

        std::cout << " ~~~ copy t1 t2" << std::endl;

        saga::filesystem::file f2 ("file://localhost/tmp/t1", saga::filesystem::Create);

        f2.copy ("t3", saga::filesystem::Overwrite);

        std::cout << " ~~~ copy t1 t3" << std::endl;

        std::cout << " ~~~ " << d.get_url () << std::endl;

        saga::filesystem::file f3 ("ssh://localhost/does/not/exist",
                                   saga::filesystem::Read);

        std::cout << " ~~~ " << f3.get_url () << ": " << f3.get_size () << std::endl;
    }
    catch ( const saga::exception & e )
    {
        std::cerr << " --- what ----------------------" << std::endl;
        std::cerr << e.what ();
        std::cerr << " -------------------------------" << std::endl;
        std::cerr << " --- get_message ---------------" << std::endl;
        std::cerr << e.get_message ();
        std::cerr << " -------------------------------" << std::endl;
    }
}
Exemplo n.º 24
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    
    if (argc <= 3) {
        qWarning() << "Error, no output file loaded";
        return 0;
    }
    
    QFile f1(argv[1]);
    f1.open(QIODevice::ReadOnly);
    QTextStream cin(&f1);
    
    QFile f2(argv[2]);
    f2.open(QIODevice::WriteOnly);
    QTextStream out1(&f2);
    
    QFile f3(argv[3]);
    f3.open(QIODevice::WriteOnly);
    QTextStream out2(&f3);
    
    QString dat0;
    QString dat1;
    
    while(not cin.atEnd()) {
        cin >> dat0;
        cin >> dat1;
        dat0 += " " + dat1;
        
        QDateTime d = QDateTime::fromString(dat0, "dd/MM/yyyy hh:mm:ss");
        dat0 = d.toString("dd/MM/yyyy hh:mm:ss");
        
        int day = d.date().day();
        
        bool found = false;
        for (int i = 0; i < 7 and not found; ++i) found = day == days[i];
        
        int n;
        cin >> n;        
        uint nClasse = 0;
        uint sClasse = 0;
        
        uint nTot = 0;
        uint sTot = 0;
        
        
        for (int i = 0; i < n; ++i) {
            cin >> dat1;
            int temp;
            cin >> temp;
            int classe;
            cin >> classe;
            
            if (classe)  {
                sClasse += temp;
                sTot += tot[i];
            }
            else {
                nClasse += temp;
                nTot += tot[i];
            }
        }
        if (found) continue;
        out1 << dat0 << "\t" << nClasse/double(nTot) << endl;
        if (sTot != 0) out2 << dat0 << "\t" << sClasse/double(sTot) << endl;
    }
    
    return 0;
}
Exemplo n.º 25
0
void ImproperElem::computeForce(BigReal *reduction,
                                BigReal *pressureProfileData)
{
    DebugM(3, "::computeForce() localIndex = " << localIndex[0] << " "
           << localIndex[1] << " " << localIndex[2] << " " <<
           localIndex[3] << std::endl);

    // Vector r12, r23, r34;	// vector between atoms
    Vector A,B,C;		// cross products
    BigReal rA, rB, rC;	// length of vectors A, B, and C
    BigReal energy=0;	// energy from the angle
    BigReal phi;		// angle between the plans
    double cos_phi;	// cos(phi)
    double sin_phi;	// sin(phi)
    Vector dcosdA;	// Derivative d(cos(phi))/dA
    Vector dcosdB;	// Derivative d(cos(phi))/dB
    Vector dsindC;	// Derivative d(sin(phi))/dC
    Vector dsindB;	// Derivative d(sin(phi))/dB
    BigReal K,K1;		// energy constants
    BigReal diff;		// for periodicity
    Force f1(0,0,0),f2(0,0,0),f3(0,0,0);	// force components

    //DebugM(3, "::computeForce() -- starting with improper type " << improperType << std::endl);

    // get the improper information
    int multiplicity = value->multiplicity;

    //  Calculate the vectors between atoms
    const Position & pos0 = p[0]->x[localIndex[0]].position;
    const Position & pos1 = p[1]->x[localIndex[1]].position;
    const Position & pos2 = p[2]->x[localIndex[2]].position;
    const Position & pos3 = p[3]->x[localIndex[3]].position;
    const Lattice & lattice = p[0]->p->lattice;
    const Vector r12 = lattice.delta(pos0,pos1);
    const Vector r23 = lattice.delta(pos1,pos2);
    const Vector r34 = lattice.delta(pos2,pos3);

    //  Calculate the cross products
    A = cross(r12,r23);
    B = cross(r23,r34);
    C = cross(r23,A);

    //  Calculate the distances
    rA = A.length();
    rB = B.length();
    rC = C.length();

    //  Calculate the sin and cos
    cos_phi = A*B/(rA*rB);
    sin_phi = C*B/(rC*rB);

    //  Normalize B
    rB = 1.0/rB;
    B *= rB;

    phi= -atan2(sin_phi,cos_phi);

    if (fabs(sin_phi) > 0.1)
    {
        //  Normalize A
        rA = 1.0/rA;
        A *= rA;
        dcosdA = rA*(cos_phi*A-B);
        dcosdB = rB*(cos_phi*B-A);
    }
    else
    {
        //  Normalize C
        rC = 1.0/rC;
        C *= rC;
        dsindC = rC*(sin_phi*C-B);
        dsindB = rB*(sin_phi*B-C);
    }

    //  Loop through the multiple parameter sets for this
    //  bond.  We will only loop more than once if this
    //  has multiple parameter sets from Charmm22
    for (int mult_num=0; mult_num<multiplicity; mult_num++)
    {
        /* get angle information */
        Real k = value->values[mult_num].k * scale;
        Real delta = value->values[mult_num].delta;
        int n = value->values[mult_num].n;

        //  Calculate the energy
        if (n)
        {
            //  Periodicity is greater than 0, so use cos form
            K = k*(1+cos(n*phi - delta));
            K1 = -n*k*sin(n*phi - delta);
        }
        else
        {
            //  Periodicity is 0, so just use the harmonic form
            diff = phi-delta;
            if (diff < -PI)           diff += TWOPI;
            else if (diff > PI)       diff -= TWOPI;

            K = k*diff*diff;
            K1 = 2.0*k*diff;
        }

        //  Add the energy from this improper to the total energy
        energy += K;

        //  Next, we want to calculate the forces.  In order
        //  to do that, we first need to figure out whether the
        //  sin or cos form will be more stable.  For this,
        //  just look at the value of phi
        if (fabs(sin_phi) > 0.1)
        {
            //  use the sin version to avoid 1/cos terms
            K1 = K1/sin_phi;

            f1.x += K1*(r23.y*dcosdA.z - r23.z*dcosdA.y);
            f1.y += K1*(r23.z*dcosdA.x - r23.x*dcosdA.z);
            f1.z += K1*(r23.x*dcosdA.y - r23.y*dcosdA.x);

            f3.x += K1*(r23.z*dcosdB.y - r23.y*dcosdB.z);
            f3.y += K1*(r23.x*dcosdB.z - r23.z*dcosdB.x);
            f3.z += K1*(r23.y*dcosdB.x - r23.x*dcosdB.y);

            f2.x += K1*(r12.z*dcosdA.y - r12.y*dcosdA.z
                        + r34.y*dcosdB.z - r34.z*dcosdB.y);
            f2.y += K1*(r12.x*dcosdA.z - r12.z*dcosdA.x
                        + r34.z*dcosdB.x - r34.x*dcosdB.z);
            f2.z += K1*(r12.y*dcosdA.x - r12.x*dcosdA.y
                        + r34.x*dcosdB.y - r34.y*dcosdB.x);
        }
        else
        {
            //  This angle is closer to 0 or 180 than it is to
            //  90, so use the cos version to avoid 1/sin terms
            K1 = -K1/cos_phi;

            f1.x += K1*((r23.y*r23.y + r23.z*r23.z)*dsindC.x
                        - r23.x*r23.y*dsindC.y
                        - r23.x*r23.z*dsindC.z);
            f1.y += K1*((r23.z*r23.z + r23.x*r23.x)*dsindC.y
                        - r23.y*r23.z*dsindC.z
                        - r23.y*r23.x*dsindC.x);
            f1.z += K1*((r23.x*r23.x + r23.y*r23.y)*dsindC.z
                        - r23.z*r23.x*dsindC.x
                        - r23.z*r23.y*dsindC.y);

            f3 += cross(K1,dsindB,r23);

            f2.x += K1*(-(r23.y*r12.y + r23.z*r12.z)*dsindC.x
                        +(2.0*r23.x*r12.y - r12.x*r23.y)*dsindC.y
                        +(2.0*r23.x*r12.z - r12.x*r23.z)*dsindC.z
                        +dsindB.z*r34.y - dsindB.y*r34.z);
            f2.y += K1*(-(r23.z*r12.z + r23.x*r12.x)*dsindC.y
                        +(2.0*r23.y*r12.z - r12.y*r23.z)*dsindC.z
                        +(2.0*r23.y*r12.x - r12.y*r23.x)*dsindC.x
                        +dsindB.x*r34.z - dsindB.z*r34.x);
            f2.z += K1*(-(r23.x*r12.x + r23.y*r12.y)*dsindC.z
                        +(2.0*r23.z*r12.x - r12.z*r23.x)*dsindC.x
                        +(2.0*r23.z*r12.y - r12.z*r23.y)*dsindC.y
                        +dsindB.y*r34.x - dsindB.x*r34.y);
        }
    } /* for multiplicity */

    /* store the forces */
    p[0]->f[localIndex[0]] += f1;
    p[1]->f[localIndex[1]] += f2 - f1;
    p[2]->f[localIndex[2]] += f3 - f2;
    p[3]->f[localIndex[3]] += -f3;

    DebugM(3, "::computeForce() -- ending with delta energy " << energy << std::endl);
    reduction[improperEnergyIndex] += energy;
    reduction[virialIndex_XX] += ( f1.x * r12.x + f2.x * r23.x + f3.x * r34.x );
    reduction[virialIndex_XY] += ( f1.x * r12.y + f2.x * r23.y + f3.x * r34.y );
    reduction[virialIndex_XZ] += ( f1.x * r12.z + f2.x * r23.z + f3.x * r34.z );
    reduction[virialIndex_YX] += ( f1.y * r12.x + f2.y * r23.x + f3.y * r34.x );
    reduction[virialIndex_YY] += ( f1.y * r12.y + f2.y * r23.y + f3.y * r34.y );
    reduction[virialIndex_YZ] += ( f1.y * r12.z + f2.y * r23.z + f3.y * r34.z );
    reduction[virialIndex_ZX] += ( f1.z * r12.x + f2.z * r23.x + f3.z * r34.x );
    reduction[virialIndex_ZY] += ( f1.z * r12.y + f2.z * r23.y + f3.z * r34.y );
    reduction[virialIndex_ZZ] += ( f1.z * r12.z + f2.z * r23.z + f3.z * r34.z );

    if (pressureProfileData) {
        BigReal z1 = p[0]->x[localIndex[0]].position.z;
        BigReal z2 = p[1]->x[localIndex[1]].position.z;
        BigReal z3 = p[2]->x[localIndex[2]].position.z;
        BigReal z4 = p[3]->x[localIndex[3]].position.z;
        int n1 = (int)floor((z1-pressureProfileMin)/pressureProfileThickness);
        int n2 = (int)floor((z2-pressureProfileMin)/pressureProfileThickness);
        int n3 = (int)floor((z3-pressureProfileMin)/pressureProfileThickness);
        int n4 = (int)floor((z4-pressureProfileMin)/pressureProfileThickness);
        pp_clamp(n1, pressureProfileSlabs);
        pp_clamp(n2, pressureProfileSlabs);
        pp_clamp(n3, pressureProfileSlabs);
        pp_clamp(n4, pressureProfileSlabs);
        int p1 = p[0]->x[localIndex[0]].partition;
        int p2 = p[1]->x[localIndex[1]].partition;
        int p3 = p[2]->x[localIndex[2]].partition;
        int p4 = p[3]->x[localIndex[3]].partition;
        int pn = pressureProfileAtomTypes;
        pp_reduction(pressureProfileSlabs, n1, n2,
                     p1, p2, pn,
                     f1.x * r12.x, f1.y * r12.y, f1.z * r12.z,
                     pressureProfileData);
        pp_reduction(pressureProfileSlabs, n2, n3,
                     p2, p3, pn,
                     f2.x * r23.x, f2.y * r23.y, f2.z * r23.z,
                     pressureProfileData);
        pp_reduction(pressureProfileSlabs, n3, n4,
                     p3, p4, pn,
                     f3.x * r34.x, f3.y * r34.y, f3.z * r34.z,
                     pressureProfileData);
    }
}
Exemplo n.º 26
0
Arquivo: p3.cpp Projeto: 4ntoine/clang
void test_f3(int ***ip, volatile int ***vip) {
  A<int> a0 = f3(ip);
  A<volatile int> a1 = f3(vip);
}
Exemplo n.º 27
0
int main(void) {
        f0();
    f1();
    f2();
    f3();
    f4();
    f5();
    f6();
    f7();
    f8();
    f9();
    f10();
    f11();
    f12();
    f13();
    f14();
    f15();
    f16();
    f17();
    f18();
    f19();
    f20();
    f21();
    f22();
    f23();
    f24();
    f25();
    f26();
    f27();
    f28();
    f29();
    f30();
    f31();
    f32();
    f33();
    f34();
    f35();
    f36();
    f37();
    f38();
    f39();
    f40();
    f41();
    f42();
    f43();
    f44();
    f45();
    f46();
    f47();
    f48();
    f49();
    f50();
    f51();
    f52();
    f53();
    f54();
    f55();
    f56();
    f57();
    f58();
    f59();
    f60();
    f61();
    f62();
    f63();
    f64();
    f65();
    f66();
    f67();
    f68();
    f69();
    f70();
    f71();
    f72();
    f73();
    f74();
    f75();
    f76();
    f77();
    f78();
    f79();
    f80();
    f81();
    f82();
    f83();
    f84();
    f85();
    f86();
    f87();
    f88();
    f89();
    f90();
    f91();
    f92();
    f93();
    f94();
    f95();
    f96();
    f97();
    f98();
    f99();
    f100();
    f101();
    f102();
    f103();
    f104();
    f105();
    f106();
    f107();
    f108();
    f109();
    f110();
    f111();
    f112();
    f113();
    f114();
    f115();
    f116();
    f117();
    f118();
    f119();
    f120();
    f121();
    f122();
    f123();
    f124();
    f125();
    f126();
    f127();
    f128();
    f129();
    f130();
    f131();
    f132();
    f133();
    f134();
    f135();
    f136();
    f137();
    f138();
    f139();
    f140();
    f141();
    f142();
    f143();
    f144();
    f145();
    f146();
    f147();
    f148();
    f149();
    f150();
    f151();
    f152();
    f153();
    f154();
    f155();
    f156();
    f157();
    f158();
    f159();
    f160();
    f161();
    f162();
    f163();
    f164();
    f165();
    f166();
    f167();
    f168();
    f169();
    f170();
    f171();
    f172();
    f173();
    f174();
    f175();
    f176();
    f177();
    f178();
    f179();
    f180();
    f181();


    return 0;
}
Exemplo n.º 28
0
unsigned int f4 ()
{
    return f1 () + f1 () + f1 () + f1 ()
           + f2 () + f2 () + f2 () + f2 ()
           + f3 () + f3 () + f3 () + f3 ();
}
Exemplo n.º 29
0
int main (void)
{
    f1 (::new D);
    f2 (::new D);     
    f3 (::new D);
}
Exemplo n.º 30
0
double lab3_1_newt::polynom::f4(int i, int j, int k, int z)
{
    return (f3(i, j, k) - f3(j, k, z)) / ((*(this->t))[i].first - (*(this->t))[z].first);
}