C++

From DUNE
Jump to navigation Jump to search

String Comparison

// comparing apples with apples
#include <iostream>
#include <string>

int main ()
{
  std::string str1 ("green apple");
  std::string str2 ("red apple");

  if (str1.compare(str2) != 0)
    std::cout << str1 << " is not " << str2 << '\n';

  if (str1.compare(6,5,"apple") == 0)
    std::cout << "still, " << str1 << " is an apple\n";

  if (str2.compare(str2.size()-5,5,"apple") == 0)
    std::cout << "and " << str2 << " is also an apple\n";

  if (str1.compare(6,5,str2,4,5) == 0)
    std::cout << "therefore, both are apples\n";

  return 0;
}

BOOST

https://askubuntu.com/questions/263461/where-is-my-boost-lib-file

install libboost-all-dev

ROOT

Installation

ROOT can be built with XRootD included. When building from source, the user might need to install certain packages depending on what's reported missing in the error log. For example,

sudo apt-get install libx11-dev
sudo apt-get install libpthread-stubs0-dev
sudo apt-get install libxpm-dev
sudo apt-get install libxft-dev
sudo apt-get install libxext-dev
sudo apt-get install libxml2-dev

File modes

  • 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).

Terminating a program

In a ROOT macro, to exit gracefully:

gApplication->Terminate().

In a standalone program this becomes simply "return 0;"

Fixing GL problems at CERN

There may be complicated problems when using ROOT which can be traced to certain drivers and/or configuration error. At CERN (lxplus) the following fix usually works and allows to run ROOT remotely via X11:

source /afs/cern.ch/sw/lcg/external/gcc/4.9/x86_64-slc6-gcc49-opt/setup.sh
source /afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.08/x86_64-slc6-gcc49-opt/root/bin/thisroot.sh