Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Clear n-th bit: bit_fld &= ~(1 << n)

Toggle (swap 0<->1) n-th bit: bit_fld ^= (1 << n)

Check if the element is in the vector or list

...

Code Block
#include <string>
#include <iostream>
#include <stdio.h>

std::string exec(char* cmd) {
    FILE* pipe = popen(cmd, "r");
    if (!pipe) return "ERROR";
    char buffer[128];
    std::string result = "";
    while(!feof(pipe)) {
    	if(fgets(buffer, 128, pipe) != NULL)
    		result += buffer;
    }
    pclose(pipe);
    return result;
}

 

 

 

 

 

 

 

...

Valgrind - analysis of job memory consumption

Code Block
valgrind --tool=massif --time-unit=B psana -n 1 -m ImgAlgos.PixCoordsProducer exp=cxi86415:run=62

this command runs the job and produces the file like massif.out.23864, which can be printed by command:

Code Block
ms_print massif.out.23864

Building C/C++ library using  distutils.core  setup, Extension

http://stackoverflow.com/questions/16854066/using-distutils-and-build-clib-to-build-c-library

Instead of passing a library name as a string, pass a tuple with the sources to compile:

Code Block
# setup.py
#__________

import sys
from distutils.core import setup
from distutils.command.build_clib import build_clib
from distutils.extension import Extension
from Cython.Distutils import build_ext

libhello = ('hello', {'sources': ['hello.c']})  # <<<<==============

ext_modules=[
    Extension("demo", ["demo.pyx"])
]

setup(
        name = 'demo',
        libraries = [libhello],
        cmdclass = {'build_clib': build_clib, 'build_ext': build_ext},
        ext_modules = ext_modules
)
#__________

Using C++ in Cython