<commit_before>/*
This file is part of Bohrium and copyright (c) 2012 the Bohrium
team <http://www.bh107.org>.

Bohrium is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.

Bohrium is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the
GNU Lesser General Public License along with Bohrium.

If not, see <http://www.gnu.org/licenses/>.
*/

#include <string>
#include <cstring>
#include <bh.h>
#include "bh_fuse.h"
#include "bh_fuse_cache.h"
#include <fstream>
#include <exception>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/version.hpp>
#include <boost/algorithm/string/predicate.hpp> //For iequals()

using namespace std;
using namespace boost;
using namespace boost::filesystem;

namespace bohrium {

/* * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS
 * When designing an instruction hash function REMEMBER:
 * The hash string should either be of fixed length and all feilds
 * contained also be of fixed legth OR unique seperators should be
 * used for each variable length field and to seperate instruction
 * hashed. The function hashOpcodeIdShapeSweepdim may be used as
 * inspiration.
 */

static const size_t inst_sep = SIZE_MAX;
static const size_t op_sep   = SIZE_MAX-1;

static void hashOpcodeOpidShapeidSweepdim(std::ostream& os, const bh_instruction& instr,
                                        BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * <opcode> (<operant-id> <ndim> <shape> <op_sep>)[1] <sweep-dim>[2] <inst_sep>
     * 1: for each operand
     * 2: if the operation is a sweep operation
     */
    int noperands = bh_operands(instr.opcode);
    os.write((const char*)&instr.opcode, sizeof(instr.opcode));         // <opcode>
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
        os.write((char*)&view.ndim, sizeof(view.ndim));                 // <ndim>
        std::pair<size_t,bool> sidp = batchHash.shapes.insert(std::vector<bh_index>(view.shape,view.shape+view.ndim));
        os.write((char*)&sidp.first, sizeof(sidp.first));                   // <shape-id>
        os.write((char*)&op_sep, sizeof(op_sep));                       // <op_sep>
    }
    if (bh_opcode_is_sweep(instr.opcode))
        os.write((char*)&instr.constant.value.int64, sizeof(bh_int64)); // <sweep-dim>
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

static void hashOpidSweepdim(std::ostream& os, const bh_instruction& instr, BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * (<operant-id>)[1] <op_sep> (<ndim> <sweep-dim>)[2] <seperator>
     * 1: for each operand
     * 2: if the operation is a sweep operation
     */
    int noperands = bh_operands(instr.opcode);
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
    }
    os.write((char*)&op_sep, sizeof(op_sep));                           // <op_sep>
    if (bh_opcode_is_sweep(instr.opcode))
    {
        const bh_view& view = instr.operand[1];
        os.write((char*)&view.ndim, sizeof(view.ndim));                 // <ndim>
        os.write((char*)&instr.constant.value.int64, sizeof(bh_int64)); // <sweep-dim>
    }
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

static void hashScalarOpidSweepdim(std::ostream& os, const bh_instruction& instr, BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * <is_scalar> (<operant-id>)[1] <op_sep> (<ndim> <sweep-dim>)[2] <seperator>
     * 1: for each operand
     * 2: if the operation is a sweep operation
     */
    bool scalar = (bh_is_scalar(&(instr.operand[0])) ||
                   (bh_opcode_is_accumulate(instr.opcode) && instr.operand[0].ndim == 1));
    os.write((char*)&scalar, sizeof(scalar));                           // <is_scalar>
    int noperands = bh_operands(instr.opcode);
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
    }
    os.write((char*)&op_sep, sizeof(op_sep));                           // <op_sep>
    if (bh_opcode_is_sweep(instr.opcode))
    {
        const bh_view& view = instr.operand[1];
        os.write((char*)&view.ndim, sizeof(view.ndim));                 // <ndim>
        os.write((char*)&instr.constant.value.int64, sizeof(bh_int64)); // <sweep-dim>
    }
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

static void hashScalarShapeidOpidSweepdim(std::ostream& os, const bh_instruction& instr, BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * <is_scalar> <shape-id> (<operant-id>)[1] <op_sep> (<ndim> <sweep-dim>)[2] <seperator>
     * 1: for each operand
     * 2: if the operation is a sweep operation
     * NB: but ignores instructions that takes no arguments, such as BH_NONE
     */
    int noperands = bh_operands(instr.opcode);
    if(noperands == 0)
    {
        os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
        return;
    }
    bool scalar = (bh_is_scalar(&(instr.operand[0])) ||
                   (bh_opcode_is_accumulate(instr.opcode) && instr.operand[0].ndim == 1));
    os.write((char*)&scalar, sizeof(scalar));                           // <is_scalar>
    const bh_view& view = (bh_opcode_is_sweep(instr.opcode) ? instr.operand[1] : instr.operand[0]);
    std::pair<size_t,bool> sidp = batchHash.shapes.insert(std::vector<bh_index>(view.shape,view.shape+view.ndim));
    os.write((char*)&sidp.first, sizeof(sidp.first));                   // <shape-id>
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
    }
    os.write((char*)&op_sep, sizeof(op_sep));                           // <op_sep>
    if (bh_opcode_is_sweep(instr.opcode))
    {
        const bh_view& view = instr.operand[1];
        os.write((char*)&view.ndim, sizeof(view.ndim));                 // <ndim>
        os.write((char*)&instr.constant.value.int64, sizeof(bh_int64)); // <sweep-dim>
    }
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

static void hashOpid(std::ostream& os, const bh_instruction& instr, BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * (<operant-id>)[1]  <seperator>
     * 1: for each operand
     */
    int noperands = bh_operands(instr.opcode);
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
    }
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

#define __scalar(i) (bh_is_scalar(&(i)->operand[0]) || \
                     (bh_opcode_is_accumulate((i)->opcode) && (i)->operand[0].ndim == 1))

typedef void (*InstrHash)(std::ostream& os, const bh_instruction &instr, BatchHash& batchHash);

static InstrHash getInstrHash(FuseModel fuseModel)
{
    switch(fuseModel)
    {
    case BROADEST:
        return &hashOpid;
    case NO_XSWEEP:
        return &hashOpidSweepdim;
    case NO_XSWEEP_SCALAR_SEPERATE:
        return &hashScalarOpidSweepdim;
    case NO_XSWEEP_SCALAR_SEPERATE_SHAPE_MATCH:
        return &hashScalarShapeidOpidSweepdim;
    case SAME_SHAPE:
    case SAME_SHAPE_RANGE:
    case SAME_SHAPE_RANDOM:
    case SAME_SHAPE_RANGE_RANDOM:
    case SAME_SHAPE_GENERATE_1DREDUCE:
        return &hashOpcodeOpidShapeidSweepdim;
    default:
        throw runtime_error("Could not find valid hash function for fuse model.");
    }
}

//Constructor of the BatchHash class
BatchHash::BatchHash(const vector<bh_instruction> &instr_list)
{
    InstrHash hashFn = getInstrHash(fuse_get_selected_model());
    std::ostringstream data(std::ios_base::ate);
    for(const bh_instruction& instr: instr_list)
    {
        hashFn(data, instr, *this);
    }
    boost::hash<string> hasher;
    _hash = hasher(data.str());
}

InstrIndexesList &FuseCache::insert(const BatchHash &batch,
                                    const vector<bh_ir_kernel> &kernel_list)
{
    if(cache.find(batch.hash()) != cache.end())
    {
        throw runtime_error("Instruction list is already in the fuse cache!");
    }
    cache[batch.hash()] = InstrIndexesList(kernel_list, batch.hash(), fuser_name);
    return cache[batch.hash()];
}

bool FuseCache::lookup(const BatchHash &batch,
                       bh_ir &bhir,
                       vector<bh_ir_kernel> &kernel_list) const
{
    assert(kernel_list.size() == 0);
    assert(enabled);
    CacheMap::const_iterator it = cache.find(batch.hash());
    if(it == cache.end())
    {
        return false;
    }
    else
    {
        it->second.fill_kernel_list(bhir, kernel_list);
        return true;
    }
}

void FuseCache::write_to_files() const
{
    assert(enabled);
    if(dir_path == NULL or dir_path[0] == '\0')
    {
        cout << "[FUSE-CACHE] Couldn't find the 'cache_path' key in "   \
            "the configure file thus no cache files are written to disk!" << endl;
        return;
    }
    path cache_dir(dir_path);
    if(create_directories(cache_dir))
    {
        cout << "[FUSE-CACHE] Creating cache diretory " << cache_dir << endl;
#if BOOST_VERSION > 104900
            permissions(cache_dir, all_all);
#endif
    }

    path tmp_dir = cache_dir / unique_path();
    create_directories(tmp_dir);
    for(CacheMap::const_iterator it=cache.begin(); it != cache.end(); ++it)
    {
        string name;
        it->second.get_filename(name);
        path shared_name = cache_dir / name;

        if(exists(shared_name))
            continue;//No need to overwrite an existing file

        path unique_name = tmp_dir / name;
        ofstream ofs(unique_name.string().c_str());
        boost::archive::text_oarchive oa(ofs);
        oa << it->second;
        ofs.close();
#if BOOST_VERSION > 104900
        permissions(unique_name, all_all);
#endif
        rename(unique_name, shared_name);
    }
    remove(tmp_dir);
}

void FuseCache::load_from_files()
{
    assert(enabled);
    if(dir_path == NULL or dir_path[0] == '\0')
    {
        cout << "[FUSE-CACHE] Couldn't find the 'cache_path' key in "   \
            "the configure file thus no cache files are loaded from disk!" << endl;
        return;
    }
    path p(dir_path);
    if(not (exists(p) and is_directory(p)))
        return;

    string fuse_model_name;
    fuse_model_text(fuse_get_selected_model(), fuse_model_name);
    string fuse_price_name;
    fuse_price_model_text(fuse_get_selected_price_model(), fuse_price_name);

    //Iterate the 'dir_path' diretory and load each file
    directory_iterator it(p), eod;
    BOOST_FOREACH(const path &f, make_pair(it, eod))
    {
        if(is_regular_file(f))
        {
            int tries = 0;
            while(1)
            {
                try
                {
                    ifstream ifs(f.string().c_str());
                    boost::archive::text_iarchive ia(ifs);
                    InstrIndexesList t;
                    ia >> t;
                    if(iequals(t.fuser_name(), fuser_name) and
                       iequals(t.fuse_model(), fuse_model_name) and
                       iequals(t.price_model(), fuse_price_name))
                    {
                        if(cache.find(t.hash()) != cache.end())
                        {
                            throw runtime_error("Instruction list is already in the fuse cache!");
                        }
                        cache[t.hash()] = t;
                    }
                }
                catch(const std::exception &e)
                {
                    if(++tries >= 10)
                    {
                        cerr << "[FUSE-CACHE] failed to open file '" << f.string();
                        cerr << "' (" << tries << " tries): " << e.what() << endl;
                    }
                    else
                        continue;
                }
                break;
            }
        }
    }
}
} //namespace bohrium
<commit_msg>fuse-cache: fixed BUG where hashScalarOpidSweepdim() didn't handle bytecode that takes no operands (e.g. BH_NONE).<commit_after>/*
This file is part of Bohrium and copyright (c) 2012 the Bohrium
team <http://www.bh107.org>.

Bohrium is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.

Bohrium is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the
GNU Lesser General Public License along with Bohrium.

If not, see <http://www.gnu.org/licenses/>.
*/

#include <string>
#include <cstring>
#include <bh.h>
#include "bh_fuse.h"
#include "bh_fuse_cache.h"
#include <fstream>
#include <exception>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/version.hpp>
#include <boost/algorithm/string/predicate.hpp> //For iequals()

using namespace std;
using namespace boost;
using namespace boost::filesystem;

namespace bohrium {

/* * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS * OBS
 * When designing an instruction hash function REMEMBER:
 * The hash string should either be of fixed length and all feilds
 * contained also be of fixed legth OR unique seperators should be
 * used for each variable length field and to seperate instruction
 * hashed. The function hashOpcodeIdShapeSweepdim may be used as
 * inspiration.
 */

static const size_t inst_sep = SIZE_MAX;
static const size_t op_sep   = SIZE_MAX-1;

static void hashOpcodeOpidShapeidSweepdim(std::ostream& os, const bh_instruction& instr,
                                        BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * <opcode> (<operant-id> <ndim> <shape> <op_sep>)[1] <sweep-dim>[2] <inst_sep>
     * 1: for each operand
     * 2: if the operation is a sweep operation
     */
    int noperands = bh_operands(instr.opcode);
    os.write((const char*)&instr.opcode, sizeof(instr.opcode));         // <opcode>
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
        os.write((char*)&view.ndim, sizeof(view.ndim));                 // <ndim>
        std::pair<size_t,bool> sidp = batchHash.shapes.insert(std::vector<bh_index>(view.shape,view.shape+view.ndim));
        os.write((char*)&sidp.first, sizeof(sidp.first));                   // <shape-id>
        os.write((char*)&op_sep, sizeof(op_sep));                       // <op_sep>
    }
    if (bh_opcode_is_sweep(instr.opcode))
        os.write((char*)&instr.constant.value.int64, sizeof(bh_int64)); // <sweep-dim>
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

static void hashOpidSweepdim(std::ostream& os, const bh_instruction& instr, BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * (<operant-id>)[1] <op_sep> (<ndim> <sweep-dim>)[2] <seperator>
     * 1: for each operand
     * 2: if the operation is a sweep operation
     */
    int noperands = bh_operands(instr.opcode);
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
    }
    os.write((char*)&op_sep, sizeof(op_sep));                           // <op_sep>
    if (bh_opcode_is_sweep(instr.opcode))
    {
        const bh_view& view = instr.operand[1];
        os.write((char*)&view.ndim, sizeof(view.ndim));                 // <ndim>
        os.write((char*)&instr.constant.value.int64, sizeof(bh_int64)); // <sweep-dim>
    }
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

static void hashScalarOpidSweepdim(std::ostream& os, const bh_instruction& instr, BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * <is_scalar> (<operant-id>)[1] <op_sep> (<ndim> <sweep-dim>)[2] <seperator>
     * 1: for each operand
     * 2: if the operation is a sweep operation
     */
    int noperands = bh_operands(instr.opcode);
    if(noperands == 0)
    {
        os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
        return;
    }
    bool scalar = (bh_is_scalar(&(instr.operand[0])) ||
                   (bh_opcode_is_accumulate(instr.opcode) && instr.operand[0].ndim == 1));
    os.write((char*)&scalar, sizeof(scalar));                           // <is_scalar>
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
    }
    os.write((char*)&op_sep, sizeof(op_sep));                           // <op_sep>
    if (bh_opcode_is_sweep(instr.opcode))
    {
        const bh_view& view = instr.operand[1];
        os.write((char*)&view.ndim, sizeof(view.ndim));                 // <ndim>
        os.write((char*)&instr.constant.value.int64, sizeof(bh_int64)); // <sweep-dim>
    }
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

static void hashScalarShapeidOpidSweepdim(std::ostream& os, const bh_instruction& instr, BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * <is_scalar> <shape-id> (<operant-id>)[1] <op_sep> (<ndim> <sweep-dim>)[2] <seperator>
     * 1: for each operand
     * 2: if the operation is a sweep operation
     * NB: but ignores instructions that takes no arguments, such as BH_NONE
     */
    int noperands = bh_operands(instr.opcode);
    if(noperands == 0)
    {
        os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
        return;
    }
    bool scalar = (bh_is_scalar(&(instr.operand[0])) ||
                   (bh_opcode_is_accumulate(instr.opcode) && instr.operand[0].ndim == 1));
    os.write((char*)&scalar, sizeof(scalar));                           // <is_scalar>
    const bh_view& view = (bh_opcode_is_sweep(instr.opcode) ? instr.operand[1] : instr.operand[0]);
    std::pair<size_t,bool> sidp = batchHash.shapes.insert(std::vector<bh_index>(view.shape,view.shape+view.ndim));
    os.write((char*)&sidp.first, sizeof(sidp.first));                   // <shape-id>
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
    }
    os.write((char*)&op_sep, sizeof(op_sep));                           // <op_sep>
    if (bh_opcode_is_sweep(instr.opcode))
    {
        const bh_view& view = instr.operand[1];
        os.write((char*)&view.ndim, sizeof(view.ndim));                 // <ndim>
        os.write((char*)&instr.constant.value.int64, sizeof(bh_int64)); // <sweep-dim>
    }
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

static void hashOpid(std::ostream& os, const bh_instruction& instr, BatchHash& batchHash)
{
    /* The Instruction hash consists of the following fields:
     * (<operant-id>)[1]  <seperator>
     * 1: for each operand
     */
    int noperands = bh_operands(instr.opcode);
    for(int oidx=0; oidx<noperands; ++oidx) {
        const bh_view& view = instr.operand[oidx];
        if (bh_is_constant(&view))
            continue;  // Ignore constants
        std::pair<size_t,bool> vid = batchHash.views.insert(view);
        size_t id = vid.first;
        os.write((char*)&id, sizeof(id));                               // <operant-id>
    }
    os.write((char*)&inst_sep, sizeof(inst_sep));                       // <inst_sep>
}

#define __scalar(i) (bh_is_scalar(&(i)->operand[0]) || \
                     (bh_opcode_is_accumulate((i)->opcode) && (i)->operand[0].ndim == 1))

typedef void (*InstrHash)(std::ostream& os, const bh_instruction &instr, BatchHash& batchHash);

static InstrHash getInstrHash(FuseModel fuseModel)
{
    switch(fuseModel)
    {
    case BROADEST:
        return &hashOpid;
    case NO_XSWEEP:
        return &hashOpidSweepdim;
    case NO_XSWEEP_SCALAR_SEPERATE:
        return &hashScalarOpidSweepdim;
    case NO_XSWEEP_SCALAR_SEPERATE_SHAPE_MATCH:
        return &hashScalarShapeidOpidSweepdim;
    case SAME_SHAPE:
    case SAME_SHAPE_RANGE:
    case SAME_SHAPE_RANDOM:
    case SAME_SHAPE_RANGE_RANDOM:
    case SAME_SHAPE_GENERATE_1DREDUCE:
        return &hashOpcodeOpidShapeidSweepdim;
    default:
        throw runtime_error("Could not find valid hash function for fuse model.");
    }
}

//Constructor of the BatchHash class
BatchHash::BatchHash(const vector<bh_instruction> &instr_list)
{
    InstrHash hashFn = getInstrHash(fuse_get_selected_model());
    std::ostringstream data(std::ios_base::ate);
    for(const bh_instruction& instr: instr_list)
    {
        hashFn(data, instr, *this);
    }
    boost::hash<string> hasher;
    _hash = hasher(data.str());
}

InstrIndexesList &FuseCache::insert(const BatchHash &batch,
                                    const vector<bh_ir_kernel> &kernel_list)
{
    if(cache.find(batch.hash()) != cache.end())
    {
        throw runtime_error("Instruction list is already in the fuse cache!");
    }
    cache[batch.hash()] = InstrIndexesList(kernel_list, batch.hash(), fuser_name);
    return cache[batch.hash()];
}

bool FuseCache::lookup(const BatchHash &batch,
                       bh_ir &bhir,
                       vector<bh_ir_kernel> &kernel_list) const
{
    assert(kernel_list.size() == 0);
    assert(enabled);
    CacheMap::const_iterator it = cache.find(batch.hash());
    if(it == cache.end())
    {
        return false;
    }
    else
    {
        it->second.fill_kernel_list(bhir, kernel_list);
        return true;
    }
}

void FuseCache::write_to_files() const
{
    assert(enabled);
    if(dir_path == NULL or dir_path[0] == '\0')
    {
        cout << "[FUSE-CACHE] Couldn't find the 'cache_path' key in "   \
            "the configure file thus no cache files are written to disk!" << endl;
        return;
    }
    path cache_dir(dir_path);
    if(create_directories(cache_dir))
    {
        cout << "[FUSE-CACHE] Creating cache diretory " << cache_dir << endl;
#if BOOST_VERSION > 104900
            permissions(cache_dir, all_all);
#endif
    }

    path tmp_dir = cache_dir / unique_path();
    create_directories(tmp_dir);
    for(CacheMap::const_iterator it=cache.begin(); it != cache.end(); ++it)
    {
        string name;
        it->second.get_filename(name);
        path shared_name = cache_dir / name;

        if(exists(shared_name))
            continue;//No need to overwrite an existing file

        path unique_name = tmp_dir / name;
        ofstream ofs(unique_name.string().c_str());
        boost::archive::text_oarchive oa(ofs);
        oa << it->second;
        ofs.close();
#if BOOST_VERSION > 104900
        permissions(unique_name, all_all);
#endif
        rename(unique_name, shared_name);
    }
    remove(tmp_dir);
}

void FuseCache::load_from_files()
{
    assert(enabled);
    if(dir_path == NULL or dir_path[0] == '\0')
    {
        cout << "[FUSE-CACHE] Couldn't find the 'cache_path' key in "   \
            "the configure file thus no cache files are loaded from disk!" << endl;
        return;
    }
    path p(dir_path);
    if(not (exists(p) and is_directory(p)))
        return;

    string fuse_model_name;
    fuse_model_text(fuse_get_selected_model(), fuse_model_name);
    string fuse_price_name;
    fuse_price_model_text(fuse_get_selected_price_model(), fuse_price_name);

    //Iterate the 'dir_path' diretory and load each file
    directory_iterator it(p), eod;
    BOOST_FOREACH(const path &f, make_pair(it, eod))
    {
        if(is_regular_file(f))
        {
            int tries = 0;
            while(1)
            {
                try
                {
                    ifstream ifs(f.string().c_str());
                    boost::archive::text_iarchive ia(ifs);
                    InstrIndexesList t;
                    ia >> t;
                    if(iequals(t.fuser_name(), fuser_name) and
                       iequals(t.fuse_model(), fuse_model_name) and
                       iequals(t.price_model(), fuse_price_name))
                    {
                        if(cache.find(t.hash()) != cache.end())
                        {
                            throw runtime_error("Instruction list is already in the fuse cache!");
                        }
                        cache[t.hash()] = t;
                    }
                }
                catch(const std::exception &e)
                {
                    if(++tries >= 10)
                    {
                        cerr << "[FUSE-CACHE] failed to open file '" << f.string();
                        cerr << "' (" << tries << " tries): " << e.what() << endl;
                    }
                    else
                        continue;
                }
                break;
            }
        }
    }
}
} //namespace bohrium
<|endoftext|>


<commit_before>//===-- Emitter.cpp - Write machine code to executable memory -------------===//
//
// This file defines a MachineCodeEmitter object that is used by Jello to write
// machine code to memory and remember where relocatable values lie.
//
//===----------------------------------------------------------------------===//

#include "VM.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Function.h"
#include "Support/Statistic.h"

static VM *TheVM = 0;

namespace {
  Statistic<> NumBytes("jello", "Number of bytes of machine code compiled");

  class Emitter : public MachineCodeEmitter {
    // CurBlock - The start of the current block of memory.  CurByte - The
    // current byte being emitted to.
    unsigned char *CurBlock, *CurByte;

    // When outputting a function stub in the context of some other function, we
    // save CurBlock and CurByte here.
    unsigned char *SavedCurBlock, *SavedCurByte;

    // ConstantPoolAddresses - Contains the location for each entry in the
    // constant pool.
    std::vector<void*> ConstantPoolAddresses;
  public:
    Emitter(VM &vm) { TheVM = &vm; }

    virtual void startFunction(MachineFunction &F);
    virtual void finishFunction(MachineFunction &F);
    virtual void emitConstantPool(MachineConstantPool *MCP);
    virtual void startFunctionStub(const Function &F, unsigned StubSize);
    virtual void* finishFunctionStub(const Function &F);
    virtual void emitByte(unsigned char B);
    virtual void emitWord(unsigned W);

    virtual uint64_t getGlobalValueAddress(GlobalValue *V);
    virtual uint64_t getGlobalValueAddress(const std::string &Name);
    virtual uint64_t getConstantPoolEntryAddress(unsigned Entry);
    virtual uint64_t getCurrentPCValue();

    // forceCompilationOf - Force the compilation of the specified function, and
    // return its address, because we REALLY need the address now.
    //
    // FIXME: This is JIT specific!
    //
    virtual uint64_t forceCompilationOf(Function *F);
  };
}

MachineCodeEmitter *VM::createEmitter(VM &V) {
  return new Emitter(V);
}

#define _POSIX_MAPPED_FILES
#include <unistd.h>
#include <sys/mman.h>

// FIXME: This should be rewritten to support a real memory manager for
// executable memory pages!
static void *getMemory(unsigned NumPages) {
#if defined(i386) || defined(__i386__) || defined(__x86__)
  static const int fd = 0;
#elif defined(sparc) || defined(__sparc__) || defined(__sparcv9)
  static const int fd = -1;
#else
  // This is an unsupported architecture.
  static const int fd = 0;
#endif

  void *pa;
  if (NumPages == 0) return 0;
  static const long pageSize = sysconf (_SC_PAGESIZE);
  pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
            MAP_PRIVATE|MAP_ANONYMOUS, fd, 0);
  if (pa == MAP_FAILED) {
    perror("mmap");
    abort();
  }
  return pa;
}

void Emitter::startFunction(MachineFunction &F) {
  CurBlock = (unsigned char *)getMemory(16);
  CurByte = CurBlock;  // Start writing at the beginning of the fn.
  TheVM->addGlobalMapping(F.getFunction(), CurBlock);
}

void Emitter::finishFunction(MachineFunction &F) {
  ConstantPoolAddresses.clear();
  NumBytes += CurByte-CurBlock;

  DEBUG(std::cerr << "Finished CodeGen of [0x" << std::hex
                  << (unsigned)(intptr_t)CurBlock
                  << std::dec << "] Function: " << F.getFunction()->getName()
                  << ": " << CurByte-CurBlock << " bytes of text\n");
}

void Emitter::emitConstantPool(MachineConstantPool *MCP) {
  const std::vector<Constant*> &Constants = MCP->getConstants();
  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
    // For now we just allocate some memory on the heap, this can be
    // dramatically improved.
    const Type *Ty = ((Value*)Constants[i])->getType();
    void *Addr = malloc(TheVM->getTargetData().getTypeSize(Ty));
    TheVM->InitializeMemory(Constants[i], Addr);
    ConstantPoolAddresses.push_back(Addr);
  }
}

void Emitter::startFunctionStub(const Function &F, unsigned StubSize) {
  SavedCurBlock = CurBlock;  SavedCurByte = CurByte;
  // FIXME: this is a huge waste of memory.
  CurBlock = (unsigned char *)getMemory((StubSize+4095)/4096);
  CurByte = CurBlock;  // Start writing at the beginning of the fn.
}

void *Emitter::finishFunctionStub(const Function &F) {
  NumBytes += CurByte-CurBlock;
  DEBUG(std::cerr << "Finished CodeGen of [0x" << std::hex
                  << (unsigned)(intptr_t)CurBlock
                  << std::dec << "] Function stub for: " << F.getName()
                  << ": " << CurByte-CurBlock << " bytes of text\n");
  std::swap(CurBlock, SavedCurBlock);
  CurByte = SavedCurByte;
  return SavedCurBlock;
}

void Emitter::emitByte(unsigned char B) {
  *CurByte++ = B;   // Write the byte to memory
}

void Emitter::emitWord(unsigned W) {
  // FIXME: This won't work if the endianness of the host and target don't
  // agree!  (For a JIT this can't happen though.  :)
  *(unsigned*)CurByte = W;
  CurByte += sizeof(unsigned);
}

uint64_t Emitter::getGlobalValueAddress(GlobalValue *V) {
  // Try looking up the function to see if it is already compiled, if not return
  // 0.
  return (intptr_t)TheVM->getPointerToGlobalIfAvailable(V);
}
uint64_t Emitter::getGlobalValueAddress(const std::string &Name) {
  return (intptr_t)TheVM->getPointerToNamedFunction(Name);
}

// getConstantPoolEntryAddress - Return the address of the 'ConstantNum' entry
// in the constant pool that was last emitted with the 'emitConstantPool'
// method.
//
uint64_t Emitter::getConstantPoolEntryAddress(unsigned ConstantNum) {
  assert(ConstantNum < ConstantPoolAddresses.size() &&
	 "Invalid ConstantPoolIndex!");
  return (intptr_t)ConstantPoolAddresses[ConstantNum];
}

// getCurrentPCValue - This returns the address that the next emitted byte
// will be output to.
//
uint64_t Emitter::getCurrentPCValue() {
  return (intptr_t)CurByte;
}

uint64_t Emitter::forceCompilationOf(Function *F) {
  return (intptr_t)TheVM->getPointerToFunction(F);
}

<commit_msg>* Institute a hack for the Sparc call to mmap() to get our generated code to be   laid out closer to the VM so that calls to library functions (e.g. puts()) and   callback (e.g.  JITResolver::CompilationCallback) fit into 30 bits of the call   instruction. * Abort if architecture is not yet supported (not X86 or Sparc) because it   likely requires a different set of parameters to mmap() . * Stop using hard-coded values for page size; use sysconf(_SC_PAGESIZE) instead.<commit_after>//===-- Emitter.cpp - Write machine code to executable memory -------------===//
//
// This file defines a MachineCodeEmitter object that is used by Jello to write
// machine code to memory and remember where relocatable values lie.
//
//===----------------------------------------------------------------------===//

#include "VM.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Function.h"
#include "Support/Statistic.h"

static VM *TheVM = 0;

namespace {
  Statistic<> NumBytes("jello", "Number of bytes of machine code compiled");

  class Emitter : public MachineCodeEmitter {
    // CurBlock - The start of the current block of memory.  CurByte - The
    // current byte being emitted to.
    unsigned char *CurBlock, *CurByte;

    // When outputting a function stub in the context of some other function, we
    // save CurBlock and CurByte here.
    unsigned char *SavedCurBlock, *SavedCurByte;

    // ConstantPoolAddresses - Contains the location for each entry in the
    // constant pool.
    std::vector<void*> ConstantPoolAddresses;
  public:
    Emitter(VM &vm) { TheVM = &vm; }

    virtual void startFunction(MachineFunction &F);
    virtual void finishFunction(MachineFunction &F);
    virtual void emitConstantPool(MachineConstantPool *MCP);
    virtual void startFunctionStub(const Function &F, unsigned StubSize);
    virtual void* finishFunctionStub(const Function &F);
    virtual void emitByte(unsigned char B);
    virtual void emitWord(unsigned W);

    virtual uint64_t getGlobalValueAddress(GlobalValue *V);
    virtual uint64_t getGlobalValueAddress(const std::string &Name);
    virtual uint64_t getConstantPoolEntryAddress(unsigned Entry);
    virtual uint64_t getCurrentPCValue();

    // forceCompilationOf - Force the compilation of the specified function, and
    // return its address, because we REALLY need the address now.
    //
    // FIXME: This is JIT specific!
    //
    virtual uint64_t forceCompilationOf(Function *F);
  };
}

MachineCodeEmitter *VM::createEmitter(VM &V) {
  return new Emitter(V);
}

#define _POSIX_MAPPED_FILES
#include <unistd.h>
#include <sys/mman.h>

// FIXME: This should be rewritten to support a real memory manager for
// executable memory pages!
static void *getMemory(unsigned NumPages) {
  void *pa;
  if (NumPages == 0) return 0;
  static const long pageSize = sysconf(_SC_PAGESIZE);

#if defined(i386) || defined(__i386__) || defined(__x86__)
  pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
            MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);  /* fd = 0  */
#elif defined(sparc) || defined(__sparc__) || defined(__sparcv9)
  static unsigned long Counter = 0;
  pa = mmap((void*)(0x140000000UL+Counter), pageSize*NumPages,
            PROT_READ|PROT_WRITE|PROT_EXEC,
            MAP_PRIVATE|MAP_ANON|MAP_FIXED, -1, 0); /* fd = -1 */
  Counter += pageSize*NumPages;
  std::cerr << "getMemory() returning " << pa << "\n";
#else
  std::cerr << "This architecture is not supported by the JIT\n";
  abort();
#endif

  if (pa == MAP_FAILED) {
    perror("mmap");
    abort();
  }
  return pa;
}

void Emitter::startFunction(MachineFunction &F) {
  CurBlock = (unsigned char *)getMemory(16);
  CurByte = CurBlock;  // Start writing at the beginning of the fn.
  TheVM->addGlobalMapping(F.getFunction(), CurBlock);
}

void Emitter::finishFunction(MachineFunction &F) {
  ConstantPoolAddresses.clear();
  NumBytes += CurByte-CurBlock;

  DEBUG(std::cerr << "Finished CodeGen of [0x" << std::hex
                  << (unsigned)(intptr_t)CurBlock
                  << std::dec << "] Function: " << F.getFunction()->getName()
                  << ": " << CurByte-CurBlock << " bytes of text\n");
}

void Emitter::emitConstantPool(MachineConstantPool *MCP) {
  const std::vector<Constant*> &Constants = MCP->getConstants();
  for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
    // For now we just allocate some memory on the heap, this can be
    // dramatically improved.
    const Type *Ty = ((Value*)Constants[i])->getType();
    void *Addr = malloc(TheVM->getTargetData().getTypeSize(Ty));
    TheVM->InitializeMemory(Constants[i], Addr);
    ConstantPoolAddresses.push_back(Addr);
  }
}

void Emitter::startFunctionStub(const Function &F, unsigned StubSize) {
  static const long pageSize = sysconf(_SC_PAGESIZE);
  SavedCurBlock = CurBlock;  SavedCurByte = CurByte;
  // FIXME: this is a huge waste of memory.
  CurBlock = (unsigned char *)getMemory((StubSize+pageSize-1)/pageSize);
  CurByte = CurBlock;  // Start writing at the beginning of the fn.
}

void *Emitter::finishFunctionStub(const Function &F) {
  NumBytes += CurByte-CurBlock;
  DEBUG(std::cerr << "Finished CodeGen of [0x" << std::hex
                  << (unsigned)(intptr_t)CurBlock
                  << std::dec << "] Function stub for: " << F.getName()
                  << ": " << CurByte-CurBlock << " bytes of text\n");
  std::swap(CurBlock, SavedCurBlock);
  CurByte = SavedCurByte;
  return SavedCurBlock;
}

void Emitter::emitByte(unsigned char B) {
  *CurByte++ = B;   // Write the byte to memory
}

void Emitter::emitWord(unsigned W) {
  // FIXME: This won't work if the endianness of the host and target don't
  // agree!  (For a JIT this can't happen though.  :)
  *(unsigned*)CurByte = W;
  CurByte += sizeof(unsigned);
}

uint64_t Emitter::getGlobalValueAddress(GlobalValue *V) {
  // Try looking up the function to see if it is already compiled, if not return
  // 0.
  return (intptr_t)TheVM->getPointerToGlobalIfAvailable(V);
}
uint64_t Emitter::getGlobalValueAddress(const std::string &Name) {
  return (intptr_t)TheVM->getPointerToNamedFunction(Name);
}

// getConstantPoolEntryAddress - Return the address of the 'ConstantNum' entry
// in the constant pool that was last emitted with the 'emitConstantPool'
// method.
//
uint64_t Emitter::getConstantPoolEntryAddress(unsigned ConstantNum) {
  assert(ConstantNum < ConstantPoolAddresses.size() &&
	 "Invalid ConstantPoolIndex!");
  return (intptr_t)ConstantPoolAddresses[ConstantNum];
}

// getCurrentPCValue - This returns the address that the next emitted byte
// will be output to.
//
uint64_t Emitter::getCurrentPCValue() {
  return (intptr_t)CurByte;
}

uint64_t Emitter::forceCompilationOf(Function *F) {
  return (intptr_t)TheVM->getPointerToFunction(F);
}

<|endoftext|>


<commit_before>AliAnalysisTask *AddTask_mfigueredo_JPsi(TString prod="",ULong64_t triggers=AliVEvent::kEMCEGA  | AliVEvent::kEMCEJE | AliVEvent::kCentral | AliVEvent::kSemiCentral | AliVEvent::kMB){

  //get the current analysis manager
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTask_mfigueredo_JPsi", "No analysis manager found.");
    return NULL;
  }
  if (!mgr->GetInputEventHandler()) {
    ::Error("AddTask_mfigueredo_JPsi", "This task requires an input event handler");
    return NULL;
  }

    //Do we have an MC handler?
  Bool_t hasMC = kFALSE;
  TString list = gSystem->Getenv("LIST");
  if( list.IsNull()) list=prod;
  if( list.Contains("LHC10h")   || list.Contains("LHC11h")   ) hasMC=kFALSE;
  if( list.Contains("LHC11a10") || list.Contains("LHC12a17") ) hasMC=kTRUE;

  TString configFile("");
  printf("%s \n",gSystem->pwd());

  configFile="ConfigJpsi_mf_PbPb.C";

  if(!gSystem->Exec("alien_cp alien:///alice/cern.ch/user/m/mfiguere/PWGDQ/dielectron/macrosJPSI/ConfigJpsi_mf_PbPb.C ."))
    configFile=Form("%s/ConfigJpsi_mf_PbPb.C",gSystem->pwd());                        // alien config
  else
    configFile="$ALICE_ROOT/PWGDQ/dielectron/macrosJPSI/ConfigJpsi_mf_PbPb.C"; // aliroot config

  Bool_t isAOD=mgr->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();

  //create task and add it to the manager
//   AliAnalysisTaskMultiDielectron *task=new AliAnalysisTaskMultiDielectron("MultiDie");

  // trigger selection
  ULong64_t triggerSets[]={AliVEvent::kEMCEGA ,AliVEvent::kEMCEJE,AliVEvent::kCentral , AliVEvent::kSemiCentral , AliVEvent::kMB};
  const char* triggerNames[]={"EMCEGA","EMCEJE","Central","SemiCentral","MB"};

  // find out the configured triggers
  Int_t j=0;
  for(j=0; j<5; j++) {
    if(triggers!=triggerSets[j]) continue;
    else break;
  }

    // print task configuration
  printf("production: %s MC: %d \n",  list.Data(),hasMC);
  printf("triggers:   %s \n",         triggerNames[j]  );

  //load dielectron configuration file
  TString checkconfig="ConfigJpsi_mf_pp";
  if (!gROOT->GetListOfGlobalFunctions()->FindObject(checkconfig.Data()))
    gROOT->LoadMacro(configFile.Data());

  //add dielectron analysis with different cuts to the task
  for (Int_t i=0; i<nDie; ++i){ //nDie defined in config file
    AliDielectron *jpsi;
    jpsi=ConfigJpsi_mf_PbPb(i,isAOD,triggerNames[j]);

    // create unique title
  	TString unitit = Form("%s_%s",triggerNames[j],jpsi->GetName()); // as in Julian's addtask
  	task = new AliAnalysisTaskMultiDielectron(Form("MultiDieMF_%s",unitit.Data()));
    if (jpsi) task->AddDielectron(jpsi);

  //Add event filter
  AliDielectronEventCuts *eventCuts=new AliDielectronEventCuts("eventCuts","Vertex Track && |vtxZ|<10 && ncontrib>0");
  if(isAOD) eventCuts->SetVertexType(AliDielectronEventCuts::kVtxAny);
  eventCuts->SetRequireVertex();
  eventCuts->SetMinVtxContributors(1);
  eventCuts->SetVertexZ(-10.,10.);
  eventCuts->SetCentralityRange(0.0,90.0);
  // add event filter
  task->SetEventFilter(eventCuts);

  // pileup rejection
  task->SetTriggerMask(triggers);
  task->UsePhysicsSelection();

  mgr->AddTask(task);

  //----------------------
  //create data containers
  //----------------------

 	 //create output container
 	TString containerName = "JPSI.root";
  	AliAnalysisDataContainer *cOutputHist1 =
    mgr->CreateContainer(Form("mfigueredo_QA_%s",unitit.Data()),
			 TList::Class(),
			 AliAnalysisManager::kOutputContainer,
			 containerName.Data());

  	AliAnalysisDataContainer *cOutputHist2 =
   	 mgr->CreateContainer(Form("mfigueredo_CF_%s",unitit.Data()),
			 TList::Class(),
			 AliAnalysisManager::kOutputContainer,
			 containerName.Data());

 	 AliAnalysisDataContainer *cOutputHist3 =
    	mgr->CreateContainer(Form("mfigueredo_EventStat_%s",unitit.Data()),
			 TH1D::Class(),
			 AliAnalysisManager::kOutputContainer,
			 containerName.Data());

 	mgr->ConnectInput(task,  0, mgr->GetCommonInputContainer());
 	mgr->ConnectOutput(task, 1, cOutputHist1);
	mgr->ConnectOutput(task, 2, cOutputHist2);
  	mgr->ConnectOutput(task, 3, cOutputHist3);
    printf(" %s added\n",jpsi->GetName());
  }
  return task;
}
<commit_msg>addtask update marcel<commit_after>AliAnalysisTask *AddTask_mfigueredo_JPsi(TString prod="",ULong64_t triggers=AliVEvent::kEMCEGA  | AliVEvent::kEMCEJE | AliVEvent::kCentral | AliVEvent::kSemiCentral | AliVEvent::kMB){

  //get the current analysis manager
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTask_mfigueredo_JPsi", "No analysis manager found.");
    return NULL;
  }
  if (!mgr->GetInputEventHandler()) {
    ::Error("AddTask_mfigueredo_JPsi", "This task requires an input event handler");
    return NULL;
  }

    //Do we have an MC handler?
  Bool_t hasMC = kFALSE;
  TString list = gSystem->Getenv("LIST");
  if( list.IsNull()) list=prod;
  if( list.Contains("LHC10h")   || list.Contains("LHC11h")   ) hasMC=kFALSE;
  if( list.Contains("LHC11a10") || list.Contains("LHC12a17") ) hasMC=kTRUE;

  TString configFile("");
  printf("%s \n",gSystem->pwd());

  configFile="ConfigJpsi_mf_PbPb.C";

  if(!gSystem->Exec("alien_cp alien:///alice/cern.ch/user/m/mfiguere/PWGDQ/dielectron/macrosJPSI/ConfigJpsi_mf_PbPb.C ."))
    configFile=Form("%s/ConfigJpsi_mf_PbPb.C",gSystem->pwd());                        // alien config
  else
    configFile="$ALICE_ROOT/PWGDQ/dielectron/macrosJPSI/ConfigJpsi_mf_PbPb.C"; // aliroot config

  Bool_t isAOD=mgr->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();

  //create task and add it to the manager
//   AliAnalysisTaskMultiDielectron *task=new AliAnalysisTaskMultiDielectron("MultiDie");

  // trigger selection
  ULong64_t triggerSets[]={AliVEvent::kEMCEGA ,AliVEvent::kEMCEJE,AliVEvent::kCentral , AliVEvent::kSemiCentral , AliVEvent::kMB};
  const char* triggerNames[]={"EMCEGA","EMCEJE","Central","SemiCentral","MB"};

  // find out the configured triggers
  Int_t j=0;
  for(j=0; j<5; j++) {
    if(triggers!=triggerSets[j]) continue;
    else break;
  }

    // print task configuration
  printf("production: %s MC: %d \n",  list.Data(),hasMC);
  printf("triggers:   %s \n",         triggerNames[j]  );

  //load dielectron configuration file
  TString checkconfig="ConfigJpsi_mf_pp";
  if (!gROOT->GetListOfGlobalFunctions()->FindObject(checkconfig.Data()))
    gROOT->LoadMacro(configFile.Data());

  //add dielectron analysis with different cuts to the task
  for (Int_t i=0; i<nDie; ++i){ //nDie defined in config file
    AliDielectron *jpsi;
    jpsi=ConfigJpsi_mf_PbPb(i,isAOD,triggerNames[j]);

    // create unique title
  	TString unitit = Form("%s_%s",triggerNames[j],jpsi->GetName()); // as in Julian's addtask
  	task = new AliAnalysisTaskMultiDielectron(Form("MultiDieMF_%s",unitit.Data()));
    if (jpsi) task->AddDielectron(jpsi);

  //Add event filter
  AliDielectronEventCuts *eventCuts=new AliDielectronEventCuts("eventCuts","Vertex Track && |vtxZ|<10 && ncontrib>0");
  if(isAOD) eventCuts->SetVertexType(AliDielectronEventCuts::kVtxAny);
  eventCuts->SetRequireVertex();
  eventCuts->SetMinVtxContributors(1);
  eventCuts->SetVertexZ(-10.,10.);
  eventCuts->SetCentralityRange(0.0,90.0);
  // add event filter
  task->SetEventFilter(eventCuts);

  // pileup rejection
  if(!hasMC){
  	task->SetTriggerMask(triggers);
  	task->UsePhysicsSelection();
  }

  mgr->AddTask(task);

  //----------------------
  //create data containers
  //----------------------

 	 //create output container
 	TString containerName = "JPSI.root";
  	AliAnalysisDataContainer *cOutputHist1 =
    mgr->CreateContainer(Form("mfigueredo_QA_%s",unitit.Data()),
			 TList::Class(),
			 AliAnalysisManager::kOutputContainer,
			 containerName.Data());

  	AliAnalysisDataContainer *cOutputHist2 =
   	 mgr->CreateContainer(Form("mfigueredo_CF_%s",unitit.Data()),
			 TList::Class(),
			 AliAnalysisManager::kOutputContainer,
			 containerName.Data());

 	 AliAnalysisDataContainer *cOutputHist3 =
    	mgr->CreateContainer(Form("mfigueredo_EventStat_%s",unitit.Data()),
			 TH1D::Class(),
			 AliAnalysisManager::kOutputContainer,
			 containerName.Data());

 	mgr->ConnectInput(task,  0, mgr->GetCommonInputContainer());
 	mgr->ConnectOutput(task, 1, cOutputHist1);
	mgr->ConnectOutput(task, 2, cOutputHist2);
  	mgr->ConnectOutput(task, 3, cOutputHist3);
    printf(" %s added\n",jpsi->GetName());
  }
  return task;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: class2.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: hr $ $Date: 2004-09-09 11:31:29 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#include <main.hxx>

// ---------------------------------------------------------------

void CGM::ImplDoClass2()
{
    sal_uInt32  nUInteger;
    switch ( mnElementID )
    {
        case 0x01 : ComOut( CGM_LEVEL1 | CGM_DRAWING_PLUS_CONTROL_SET, "Scaling Mode" )
        {
            if ( mnElementSize )    // HACK (NASA.CGM)
            {
                switch( ImplGetUI16() )
                {
                    case 0 : pElement->eScalingMode = SM_ABSTRACT; break;
                    case 1 : pElement->eScalingMode = SM_METRIC; break;
                    default : mbStatus = sal_False; break;
                }
                pElement->nScalingFactor = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
                ImplSetMapMode();
            }
        }
        break;
        case 0x02 : ComOut( CGM_LEVEL1, "Color Selection Mode" )
        {
            nUInteger = ImplGetUI16();
            switch( nUInteger )
            {
                case 0 : pElement->eColorSelectionMode = CSM_INDEXED; break;
                case 1 : pElement->eColorSelectionMode = CSM_DIRECT; break;
                default : mbStatus = sal_False; break;
            }
        }
        break;
        case 0x03 : ComOut( CGM_LEVEL1 | CGM_DRAWING_PLUS_CONTROL_SET, "Line Width Specification Mode" )
        {
            nUInteger = ImplGetUI16();
            switch( nUInteger )
            {
                case 0 : pElement->eLineWidthSpecMode = SM_ABSOLUTE; break;
                case 1 : pElement->eLineWidthSpecMode = SM_SCALED; break;
                default : mbStatus = sal_False; break;
            }
        }
        break;
        case 0x04 : ComOut( CGM_LEVEL1 | CGM_DRAWING_PLUS_CONTROL_SET, "Marker Size Specification Mode" )
        {
            nUInteger = ImplGetUI16();
            switch( nUInteger )
            {
                case 0 : pElement->eMarkerSizeSpecMode = SM_ABSOLUTE; break;
                case 1 : pElement->eMarkerSizeSpecMode = SM_SCALED; break;
                default : mbStatus = sal_False; break;
            }
        }
        break;
        case 0x05 : ComOut( CGM_LEVEL1 | CGM_DRAWING_PLUS_CONTROL_SET, "Edge Width Specification Mode" )
        {
            nUInteger = ImplGetUI16();
            switch( nUInteger )
            {
                case 0 : pElement->eEdgeWidthSpecMode = SM_ABSOLUTE; break;
                case 1 : pElement->eEdgeWidthSpecMode = SM_SCALED; break;
                default : mbStatus = sal_False; break;
            }
        }
        break;
        case 0x06 : ComOut( CGM_LEVEL1, "VDC Extent" )
        {
            ImplGetRectangleNS( pElement->aVDCExtent );
            ImplSetMapMode();
        }
        break;
        case 0x07 : ComOut( CGM_LEVEL1, "Background Color" )
            pElement->nBackGroundColor = ImplGetBitmapColor( sal_True );
        break;
        case 0x08 : ComOut( CGM_LEVEL2, "Device Viewport" )
        {
            if ( pElement->eVDCType == VDC_INTEGER )
                ImplGetRectangle( pElement->aDeviceViewPort );
                ImplSetMapMode();
        }
        break;
        case 0x09 : ComOut( CGM_LEVEL2, "Device Viewport Specification Mode" )
        {
            nUInteger = ImplGetUI16( 8 );
            switch( nUInteger )
            {
                case 0 : pElement->eDeviceViewPortMode = DVPM_FRACTION; break;
                case 1 : pElement->eDeviceViewPortMode = DVPM_METRIC; break;
                case 2 : pElement->eDeviceViewPortMode = DVPM_DEVICE; break;
                default : mbStatus = sal_False; break;
            }
            pElement->nDeviceViewPortScale = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            ImplSetMapMode();
        }
        break;
        case 0x0a : ComOut( CGM_LEVEL2, "Device Viewport Mapping" )
        {
            switch( ImplGetUI16() )
            {
                case 0 : pElement->eDeviceViewPortMap = DVPM_NOT_FORCED; break;
                case 1 : pElement->eDeviceViewPortMap = DVPM_FORCED; break;
                default : mbStatus = sal_False; break;
            }
            switch( ImplGetUI16() )
            {
                case 0 : pElement->eDeviceViewPortMapH = DVPMH_LEFT; break;
                case 1 : pElement->eDeviceViewPortMapH = DVPMH_CENTER; break;
                case 2 : pElement->eDeviceViewPortMapH = CVPMH_RIGHT; break;
                default : mbStatus = sal_False; break;
            }
            switch( ImplGetUI16() )
            {
                case 0 : pElement->eDeviceViewPortMapV = DVPMV_BOTTOM; break;
                case 1 : pElement->eDeviceViewPortMapV = DVPMV_CENTER; break;
                case 2 : pElement->eDeviceViewPortMapV = DVPMV_TOP; break;
                default : mbStatus = sal_False; break;
            }
            ImplSetMapMode();
        }
        break;
        case 0x0b : ComOut( CGM_LEVEL2, "Line Representation" )
        {
            LineBundle  aTempLineBundle;
            aTempLineBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempLineBundle.eLineType = (LineType)ImplGetI( pElement->nIndexPrecision );
            aTempLineBundle.nLineWidth = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempLineBundle.SetColor( ImplGetBitmapColor() );
            pElement->InsertBundle( pElement->aLineList, aTempLineBundle );
        }
        break;
        case 0x0c : ComOut( CGM_LEVEL2, "Marker Representation" )
        {
            MarkerBundle aTempMarkerBundle;
            aTempMarkerBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempMarkerBundle.eMarkerType = (MarkerType)ImplGetI( pElement->nIndexPrecision );
            aTempMarkerBundle.nMarkerSize = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempMarkerBundle.SetColor( ImplGetBitmapColor() );
            pElement->InsertBundle( pElement->aMarkerList, aTempMarkerBundle );
        }
        break;
        case 0x0d : ComOut( CGM_LEVEL2, "Text Representation" )
        {
            TextBundle aTempTextBundle;
            aTempTextBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempTextBundle.nTextFontIndex = ImplGetI( pElement->nIndexPrecision );
            aTempTextBundle.eTextPrecision = (TextPrecision)ImplGetI( pElement->nIndexPrecision );
            aTempTextBundle.nCharacterSpacing = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempTextBundle.nCharacterExpansion = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempTextBundle.SetColor( ImplGetBitmapColor() );
            pElement->InsertBundle( pElement->aTextList, aTempTextBundle );
        }
        break;
        case 0x0e : ComOut( CGM_LEVEL2, "Fill Representation" )
        {
            FillBundle aTempFillBundle;
            aTempFillBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempFillBundle.eFillInteriorStyle = (FillInteriorStyle)ImplGetI( pElement->nIndexPrecision );
            aTempFillBundle.SetColor( ImplGetBitmapColor() );
            aTempFillBundle.nFillPatternIndex = ImplGetI( pElement->nIndexPrecision );
            aTempFillBundle.nFillHatchIndex = ImplGetI( pElement->nIndexPrecision );
            pElement->InsertBundle( pElement->aFillList, aTempFillBundle );
        }
        break;
        case 0x0f : ComOut( CGM_LEVEL2, "Edge Representation" )
        {
            EdgeBundle aTempEdgeBundle;
            aTempEdgeBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempEdgeBundle.eEdgeType = (EdgeType)ImplGetI( pElement->nIndexPrecision );
            aTempEdgeBundle.nEdgeWidth = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempEdgeBundle.SetColor( ImplGetBitmapColor() );
            pElement->InsertBundle( pElement->aEdgeList, aTempEdgeBundle );
        }
        break;
        case 0x10 : ComOut( CGM_LEVEL3, "Interior Style Specification Mode" ) break;    // NS
        case 0x11 : ComOut( CGM_LEVEL3, "Line and Edge Type Definition" ) break;
        case 0x12 : ComOut( CGM_LEVEL3, "Hatch Style Definition" ) break;               // NS
        case 0x13 : ComOut( CGM_LEVEL3, "Geometric Pattern Definition" ) break;         // NS
        case 0xff : ComOut( CGM_GDSF_ONLY, "inquire VDC EXTENT" ) break;
        case 0xfe : ComOut( CGM_GDSF_ONLY, "inquire Background Color" ) break;
        case 0xfd : ComOut( CGM_GDSF_ONLY, "inquire Device Viewport" ) break;
        case 0xfc : ComOut( CGM_GDSF_ONLY, "set Font Selection Mode" ) break;
        case 0xfb : ComOut( CGM_GDSF_ONLY, "inquire Color Selection Mode" ) break;
        case 0xfa : ComOut( CGM_GDSF_ONLY, "inquire Font Selection Mode" ) break;
        case 0xf9 : ComOut( CGM_GDSF_ONLY, "set Char Height Spec Mode" )
        {
            ImplGetUI16(); // -Wall is this really needed?
        }
        break;
        case 0xf8 : ComOut( CGM_GDSF_ONLY, "set Background Style" ) break;
        default: ComOut( CGM_UNKNOWN_COMMAND, "" ) break;
    }
};

<commit_msg>INTEGRATION: CWS ooo19126 (1.2.84); FILE MERGED 2005/09/05 15:12:54 rt 1.2.84.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: class2.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 02:50:47 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include <main.hxx>

// ---------------------------------------------------------------

void CGM::ImplDoClass2()
{
    sal_uInt32  nUInteger;
    switch ( mnElementID )
    {
        case 0x01 : ComOut( CGM_LEVEL1 | CGM_DRAWING_PLUS_CONTROL_SET, "Scaling Mode" )
        {
            if ( mnElementSize )    // HACK (NASA.CGM)
            {
                switch( ImplGetUI16() )
                {
                    case 0 : pElement->eScalingMode = SM_ABSTRACT; break;
                    case 1 : pElement->eScalingMode = SM_METRIC; break;
                    default : mbStatus = sal_False; break;
                }
                pElement->nScalingFactor = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
                ImplSetMapMode();
            }
        }
        break;
        case 0x02 : ComOut( CGM_LEVEL1, "Color Selection Mode" )
        {
            nUInteger = ImplGetUI16();
            switch( nUInteger )
            {
                case 0 : pElement->eColorSelectionMode = CSM_INDEXED; break;
                case 1 : pElement->eColorSelectionMode = CSM_DIRECT; break;
                default : mbStatus = sal_False; break;
            }
        }
        break;
        case 0x03 : ComOut( CGM_LEVEL1 | CGM_DRAWING_PLUS_CONTROL_SET, "Line Width Specification Mode" )
        {
            nUInteger = ImplGetUI16();
            switch( nUInteger )
            {
                case 0 : pElement->eLineWidthSpecMode = SM_ABSOLUTE; break;
                case 1 : pElement->eLineWidthSpecMode = SM_SCALED; break;
                default : mbStatus = sal_False; break;
            }
        }
        break;
        case 0x04 : ComOut( CGM_LEVEL1 | CGM_DRAWING_PLUS_CONTROL_SET, "Marker Size Specification Mode" )
        {
            nUInteger = ImplGetUI16();
            switch( nUInteger )
            {
                case 0 : pElement->eMarkerSizeSpecMode = SM_ABSOLUTE; break;
                case 1 : pElement->eMarkerSizeSpecMode = SM_SCALED; break;
                default : mbStatus = sal_False; break;
            }
        }
        break;
        case 0x05 : ComOut( CGM_LEVEL1 | CGM_DRAWING_PLUS_CONTROL_SET, "Edge Width Specification Mode" )
        {
            nUInteger = ImplGetUI16();
            switch( nUInteger )
            {
                case 0 : pElement->eEdgeWidthSpecMode = SM_ABSOLUTE; break;
                case 1 : pElement->eEdgeWidthSpecMode = SM_SCALED; break;
                default : mbStatus = sal_False; break;
            }
        }
        break;
        case 0x06 : ComOut( CGM_LEVEL1, "VDC Extent" )
        {
            ImplGetRectangleNS( pElement->aVDCExtent );
            ImplSetMapMode();
        }
        break;
        case 0x07 : ComOut( CGM_LEVEL1, "Background Color" )
            pElement->nBackGroundColor = ImplGetBitmapColor( sal_True );
        break;
        case 0x08 : ComOut( CGM_LEVEL2, "Device Viewport" )
        {
            if ( pElement->eVDCType == VDC_INTEGER )
                ImplGetRectangle( pElement->aDeviceViewPort );
                ImplSetMapMode();
        }
        break;
        case 0x09 : ComOut( CGM_LEVEL2, "Device Viewport Specification Mode" )
        {
            nUInteger = ImplGetUI16( 8 );
            switch( nUInteger )
            {
                case 0 : pElement->eDeviceViewPortMode = DVPM_FRACTION; break;
                case 1 : pElement->eDeviceViewPortMode = DVPM_METRIC; break;
                case 2 : pElement->eDeviceViewPortMode = DVPM_DEVICE; break;
                default : mbStatus = sal_False; break;
            }
            pElement->nDeviceViewPortScale = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            ImplSetMapMode();
        }
        break;
        case 0x0a : ComOut( CGM_LEVEL2, "Device Viewport Mapping" )
        {
            switch( ImplGetUI16() )
            {
                case 0 : pElement->eDeviceViewPortMap = DVPM_NOT_FORCED; break;
                case 1 : pElement->eDeviceViewPortMap = DVPM_FORCED; break;
                default : mbStatus = sal_False; break;
            }
            switch( ImplGetUI16() )
            {
                case 0 : pElement->eDeviceViewPortMapH = DVPMH_LEFT; break;
                case 1 : pElement->eDeviceViewPortMapH = DVPMH_CENTER; break;
                case 2 : pElement->eDeviceViewPortMapH = CVPMH_RIGHT; break;
                default : mbStatus = sal_False; break;
            }
            switch( ImplGetUI16() )
            {
                case 0 : pElement->eDeviceViewPortMapV = DVPMV_BOTTOM; break;
                case 1 : pElement->eDeviceViewPortMapV = DVPMV_CENTER; break;
                case 2 : pElement->eDeviceViewPortMapV = DVPMV_TOP; break;
                default : mbStatus = sal_False; break;
            }
            ImplSetMapMode();
        }
        break;
        case 0x0b : ComOut( CGM_LEVEL2, "Line Representation" )
        {
            LineBundle  aTempLineBundle;
            aTempLineBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempLineBundle.eLineType = (LineType)ImplGetI( pElement->nIndexPrecision );
            aTempLineBundle.nLineWidth = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempLineBundle.SetColor( ImplGetBitmapColor() );
            pElement->InsertBundle( pElement->aLineList, aTempLineBundle );
        }
        break;
        case 0x0c : ComOut( CGM_LEVEL2, "Marker Representation" )
        {
            MarkerBundle aTempMarkerBundle;
            aTempMarkerBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempMarkerBundle.eMarkerType = (MarkerType)ImplGetI( pElement->nIndexPrecision );
            aTempMarkerBundle.nMarkerSize = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempMarkerBundle.SetColor( ImplGetBitmapColor() );
            pElement->InsertBundle( pElement->aMarkerList, aTempMarkerBundle );
        }
        break;
        case 0x0d : ComOut( CGM_LEVEL2, "Text Representation" )
        {
            TextBundle aTempTextBundle;
            aTempTextBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempTextBundle.nTextFontIndex = ImplGetI( pElement->nIndexPrecision );
            aTempTextBundle.eTextPrecision = (TextPrecision)ImplGetI( pElement->nIndexPrecision );
            aTempTextBundle.nCharacterSpacing = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempTextBundle.nCharacterExpansion = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempTextBundle.SetColor( ImplGetBitmapColor() );
            pElement->InsertBundle( pElement->aTextList, aTempTextBundle );
        }
        break;
        case 0x0e : ComOut( CGM_LEVEL2, "Fill Representation" )
        {
            FillBundle aTempFillBundle;
            aTempFillBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempFillBundle.eFillInteriorStyle = (FillInteriorStyle)ImplGetI( pElement->nIndexPrecision );
            aTempFillBundle.SetColor( ImplGetBitmapColor() );
            aTempFillBundle.nFillPatternIndex = ImplGetI( pElement->nIndexPrecision );
            aTempFillBundle.nFillHatchIndex = ImplGetI( pElement->nIndexPrecision );
            pElement->InsertBundle( pElement->aFillList, aTempFillBundle );
        }
        break;
        case 0x0f : ComOut( CGM_LEVEL2, "Edge Representation" )
        {
            EdgeBundle aTempEdgeBundle;
            aTempEdgeBundle.SetIndex( ImplGetI( pElement->nIndexPrecision ) );
            aTempEdgeBundle.eEdgeType = (EdgeType)ImplGetI( pElement->nIndexPrecision );
            aTempEdgeBundle.nEdgeWidth = ImplGetFloat( pElement->eRealPrecision, pElement->nRealSize );
            aTempEdgeBundle.SetColor( ImplGetBitmapColor() );
            pElement->InsertBundle( pElement->aEdgeList, aTempEdgeBundle );
        }
        break;
        case 0x10 : ComOut( CGM_LEVEL3, "Interior Style Specification Mode" ) break;    // NS
        case 0x11 : ComOut( CGM_LEVEL3, "Line and Edge Type Definition" ) break;
        case 0x12 : ComOut( CGM_LEVEL3, "Hatch Style Definition" ) break;               // NS
        case 0x13 : ComOut( CGM_LEVEL3, "Geometric Pattern Definition" ) break;         // NS
        case 0xff : ComOut( CGM_GDSF_ONLY, "inquire VDC EXTENT" ) break;
        case 0xfe : ComOut( CGM_GDSF_ONLY, "inquire Background Color" ) break;
        case 0xfd : ComOut( CGM_GDSF_ONLY, "inquire Device Viewport" ) break;
        case 0xfc : ComOut( CGM_GDSF_ONLY, "set Font Selection Mode" ) break;
        case 0xfb : ComOut( CGM_GDSF_ONLY, "inquire Color Selection Mode" ) break;
        case 0xfa : ComOut( CGM_GDSF_ONLY, "inquire Font Selection Mode" ) break;
        case 0xf9 : ComOut( CGM_GDSF_ONLY, "set Char Height Spec Mode" )
        {
            ImplGetUI16(); // -Wall is this really needed?
        }
        break;
        case 0xf8 : ComOut( CGM_GDSF_ONLY, "set Background Style" ) break;
        default: ComOut( CGM_UNKNOWN_COMMAND, "" ) break;
    }
};

<|endoftext|>


<commit_before>
AliAnalysisTask* AddTask(Bool_t AnalysisMC, const Char_t* taskname, Int_t typerun, UInt_t kTriggerInt, Float_t minc, Float_t maxc, Bool_t CentFrameworkAliCen)
{

  // Creates a pid task and adds it to the analysis manager

  // Get the pointer to the existing analysis manager via the static
  // access methodh
  //=========================================================================
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    Error("AddTaskHighPtDeDx", "No analysis manager to connect to.");
    return NULL;
  }

  // Check the analysis type using the event handlers connected to the
  // analysis manager The availability of MC handler can also be
  // checked here.
  // =========================================================================
  if (!mgr->GetInputEventHandler()) {
    Error("AddTaskHighPtDeDx", "This task requires an input event handler");
    return NULL;
  }

  //
  // Add track filters, with Golden Cuts
  //

  AliAnalysisFilter* trackFilterGolden = new AliAnalysisFilter("trackFilter");

  AliESDtrackCuts* esdTrackCutsGolden = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE,1);
  esdTrackCutsGolden->SetMinNCrossedRowsTPC(120);
  esdTrackCutsGolden->SetMinRatioCrossedRowsOverFindableClustersTPC(0.8);
  esdTrackCutsGolden->SetMaxChi2PerClusterITS(36);
  esdTrackCutsGolden->SetMaxFractionSharedTPCClusters(0.4);
  esdTrackCutsGolden->SetMaxChi2TPCConstrainedGlobal(36);
  esdTrackCutsGolden->SetMaxDCAToVertexXY(3.0);

  trackFilterGolden->AddCuts(esdTrackCutsGolden);

  //old cuts without golden cut
  AliAnalysisFilter* trackFilter0 = new AliAnalysisFilter("trackFilter");
  Bool_t clusterCut = 0;
  Bool_t selPrimaries = kTRUE;
  AliESDtrackCuts* esdTrackCutsL0 = new AliESDtrackCuts;
  // TPC
  if(clusterCut == 0)  esdTrackCutsL0->SetMinNClustersTPC(70);
  else if (clusterCut == 1) {
    esdTrackCutsL0->SetMinNCrossedRowsTPC(70);
    esdTrackCutsL0->SetMinRatioCrossedRowsOverFindableClustersTPC(0.8);
  }
  else {
    AliWarningClass(Form("Wrong value of the clusterCut parameter (%d), using cut on Nclusters",clusterCut));
    esdTrackCutsL0->SetMinNClustersTPC(70);
  }

  esdTrackCutsL0->SetMaxChi2PerClusterTPC(4);
  esdTrackCutsL0->SetAcceptKinkDaughters(kFALSE);
  esdTrackCutsL0->SetRequireTPCRefit(kTRUE);
  // ITS
  esdTrackCutsL0->SetRequireITSRefit(kTRUE);
  esdTrackCutsL0->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kAny);
  if(selPrimaries) {
    esdTrackCutsL0->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01");
  }
  esdTrackCutsL0->SetMaxDCAToVertexZ(2);
  esdTrackCutsL0->SetDCAToVertex2D(kFALSE);
  esdTrackCutsL0->SetRequireSigmaToVertex(kFALSE);
  esdTrackCutsL0->SetMaxChi2PerClusterITS(1e10);
  esdTrackCutsL0->SetMaxChi2TPCConstrainedGlobal(1e10);

  trackFilter0->AddCuts(esdTrackCutsL0);

  AliAnalysisFilter* trackFilterTPC = new AliAnalysisFilter("trackFilterTPC");
  AliESDtrackCuts* esdTrackCutsTPC = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
  trackFilterTPC->AddCuts(esdTrackCutsTPC);

  // Create the task and configure it
  //========================================================================
  if(typerun==2){//pbpb: heavy ion analysis

    AliAnalysisTaskHighPtDeDx* taskHighPtDeDx;

    taskHighPtDeDx = 0;
    Char_t TaskName[256] = {0};
    sprintf(TaskName,"%s_%1.0f_%1.0f",taskname,minc,maxc);
    taskHighPtDeDx = new AliAnalysisTaskHighPtDeDx(TaskName);

    // TString type = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
    // taskHighPtDeDx->SetAnalysisType(type);
    // Run AOD even when filtered from LF_PbPb or LF_PbPb_MC

    //Set analysis details
    taskHighPtDeDx->SetAnalysisType("AOD");
    taskHighPtDeDx->SetAnalysisMC(AnalysisMC);
    taskHighPtDeDx->SetAnalysisRun2(kFALSE);
    taskHighPtDeDx->SetTrigger1(kTriggerInt);
    taskHighPtDeDx->SetTrigger2(kTriggerInt);
    taskHighPtDeDx->SetProduceVZEROBranch(kTRUE);
    taskHighPtDeDx->SetDebugLevel(0);

    //Set event details
    taskHighPtDeDx->SetCentFrameworkAliCen(CentFrameworkAliCen); //kTRUE:AliCentrality, kFALSE:AliMultSelection
    taskHighPtDeDx->SetCentDetector("V0M");
    taskHighPtDeDx->SetMinCent(minc);
    taskHighPtDeDx->SetMaxCent(maxc);
    taskHighPtDeDx->SetVtxCut(10.0);
    taskHighPtDeDx->SetContributorsVtxCut(0);
    taskHighPtDeDx->SetContributorsVtxSPDCut(0);
    taskHighPtDeDx->SetZvsSPDvtxCorrCut(999.); //Correlation between global Zvtx and SPD Zvtx: use 999. for no cut
    taskHighPtDeDx->SetVtxR2Cut(10.); //use 10. for no cut

    //Set trigger particle tracks, v0s and daughter track details
    taskHighPtDeDx->SetMinPt(5.0); //trigger tracks
    taskHighPtDeDx->SetLowPtFraction(0.0); //keep x.x% of tracks below min pt
    taskHighPtDeDx->SetEtaCut(0.8);
    taskHighPtDeDx->SetCrossedRowsCut(70.); //use 0. for no cut
    taskHighPtDeDx->SetCrossedOverFindableCut(0.8); //use 0. for no cut
    taskHighPtDeDx->SetCosPACut(0.97);
    taskHighPtDeDx->SetDecayRCut(5.);
    taskHighPtDeDx->SetMinPtV0(1.0);
    taskHighPtDeDx->SetMassCut(0.1);
    taskHighPtDeDx->SetRejectKinks(kTRUE);
    taskHighPtDeDx->SetSigmaDedxCut(kFALSE);

    //Set Filters
    taskHighPtDeDx->SetTrackFilterGolden(trackFilterGolden);
    taskHighPtDeDx->SetTrackFilter(trackFilter0);
    taskHighPtDeDx->SetTrackFilterTPC(trackFilterTPC);

    mgr->AddTask(taskHighPtDeDx);

  }

if(typerun==3){//pp analysis

  AliAnalysisTaskHighPtDeDx* taskHighPtDeDx = new AliAnalysisTaskHighPtDeDx("taskHighPtDeDx");

    //Set analysis details
    taskHighPtDeDx->SetAnalysisType("AOD");
    taskHighPtDeDx->SetAnalysisMC(AnalysisMC);
    taskHighPtDeDx->SetAnalysisRun2(kTRUE);
    taskHighPtDeDx->SetTrigger1(kTriggerInt);
    taskHighPtDeDx->SetTrigger2(kTriggerInt);
    taskHighPtDeDx->SetProduceVZEROBranch(kTRUE);
    taskHighPtDeDx->SetDebugLevel(0);

    //Set event details
    taskHighPtDeDx->SetCentFrameworkAliCen(CentFrameworkAliCen); //kTRUE:AliCentrality, kFALSE:AliMultSelection
    taskHighPtDeDx->SetCentDetector("V0M");
    taskHighPtDeDx->SetMinCent(minc);
    taskHighPtDeDx->SetMaxCent(maxc);
    taskHighPtDeDx->SetVtxCut(10.0);
    taskHighPtDeDx->SetContributorsVtxCut(0);
    taskHighPtDeDx->SetContributorsVtxSPDCut(0);
    taskHighPtDeDx->SetZvsSPDvtxCorrCut(999.); //Correlation between global Zvtx and SPD Zvtx: use 999. for no cut
    taskHighPtDeDx->SetVtxR2Cut(10.); //use 10. for no cut

    //Set trigger particle tracks, v0s and daughter track details
    taskHighPtDeDx->SetMinPt(5.0); //trigger tracks
    taskHighPtDeDx->SetLowPtFraction(0.0); //keep x.x% of tracks below min pt
    taskHighPtDeDx->SetEtaCut(0.8);
    taskHighPtDeDx->SetCrossedRowsCut(70.); //use 0. for no cut
    taskHighPtDeDx->SetCrossedOverFindableCut(0.8); //use 0. for no cut
    taskHighPtDeDx->SetCosPACut(0.97);
    taskHighPtDeDx->SetDecayRCut(0.5);
    taskHighPtDeDx->SetMinPtV0(1.0);
    taskHighPtDeDx->SetMassCut(0.1);
    taskHighPtDeDx->SetRejectKinks(kTRUE);
    taskHighPtDeDx->SetSigmaDedxCut(kFALSE);

    //Set Filters
    taskHighPtDeDx->SetTrackFilterGolden(trackFilterGolden);
    taskHighPtDeDx->SetTrackFilter(trackFilter0);
    taskHighPtDeDx->SetTrackFilterTPC(trackFilterTPC);

    mgr->AddTask(taskHighPtDeDx);

 }

if(typerun==4){//ppb analysis
  cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<    Runing pPb    <<<<<<<<<<<<<<"<<endl;

  AliAnalysisTaskHighPtDeDx* taskHighPtDeDx = new AliAnalysisTaskHighPtDeDx("taskHighPtDeDx");

    //Set analysis details
    taskHighPtDeDx->SetAnalysisType("AOD");
    taskHighPtDeDx->SetAnalysisMC(AnalysisMC);
    taskHighPtDeDx->SetAnalysisRun2(kTRUE);
    taskHighPtDeDx->SetTrigger1(kTriggerInt);
    taskHighPtDeDx->SetTrigger2(kTriggerInt);
    taskHighPtDeDx->SetProduceVZEROBranch(kTRUE);
    taskHighPtDeDx->SetDebugLevel(0);

    //Set event details
    taskHighPtDeDx->SetCentFrameworkAliCen(CentFrameworkAliCen); //kTRUE:AliCentrality, kFALSE:AliMultSelection
    taskHighPtDeDx->SetCentDetector("V0A");
    taskHighPtDeDx->SetMinCent(minc);
    taskHighPtDeDx->SetMaxCent(maxc);
    taskHighPtDeDx->SetVtxCut(10.0);
    taskHighPtDeDx->SetContributorsVtxCut(0);
    taskHighPtDeDx->SetContributorsVtxSPDCut(0);
    taskHighPtDeDx->SetZvsSPDvtxCorrCut(999.); //Correlation between global Zvtx and SPD Zvtx: use 999. for no cut
    taskHighPtDeDx->SetVtxR2Cut(10.); //use 10. for no cut

    //Set trigger particle tracks, v0s and daughter track details
    taskHighPtDeDx->SetMinPt(5.0); //trigger tracks
    taskHighPtDeDx->SetLowPtFraction(0.0); //keep x.x% of tracks below min pt
    taskHighPtDeDx->SetEtaCut(0.8);
    taskHighPtDeDx->SetCrossedRowsCut(70.); //use 0. for no cut
    taskHighPtDeDx->SetCrossedOverFindableCut(0.8); //use 0. for no cut
    taskHighPtDeDx->SetCosPACut(0.97);
    taskHighPtDeDx->SetDecayRCut(0.5);
    taskHighPtDeDx->SetMinPtV0(1.0);
    taskHighPtDeDx->SetMassCut(0.1);
    taskHighPtDeDx->SetRejectKinks(kTRUE);
    taskHighPtDeDx->SetSigmaDedxCut(kFALSE);

    //Set Filters
    taskHighPtDeDx->SetTrackFilterGolden(trackFilterGolden);
    taskHighPtDeDx->SetTrackFilter(trackFilter0);
    taskHighPtDeDx->SetTrackFilterTPC(trackFilterTPC);

    mgr->AddTask(taskHighPtDeDx);

 }

// Create ONLY the output containers for the data produced by the
// task.  Get and connect other common input/output containers via
// the manager as below
//=======================================================================

 TString outputFileName = Form("%s", AliAnalysisManager::GetCommonFileName());
 AliAnalysisDataContainer *cout_hist = mgr->CreateContainer("output", TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName);

 mgr->ConnectInput(taskHighPtDeDx, 0, mgr->GetCommonInputContainer());
 mgr->ConnectOutput(taskHighPtDeDx, 1, cout_hist);

 // Return task pointer at the end
 return taskHighPtDeDx;

}
<commit_msg>change default cosPA cut<commit_after>
AliAnalysisTask* AddTask(Bool_t AnalysisMC, const Char_t* taskname, Int_t typerun, UInt_t kTriggerInt, Float_t minc, Float_t maxc, Bool_t CentFrameworkAliCen)
{

  // Creates a pid task and adds it to the analysis manager

  // Get the pointer to the existing analysis manager via the static
  // access methodh
  //=========================================================================
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    Error("AddTaskHighPtDeDx", "No analysis manager to connect to.");
    return NULL;
  }

  // Check the analysis type using the event handlers connected to the
  // analysis manager The availability of MC handler can also be
  // checked here.
  // =========================================================================
  if (!mgr->GetInputEventHandler()) {
    Error("AddTaskHighPtDeDx", "This task requires an input event handler");
    return NULL;
  }

  //
  // Add track filters, with Golden Cuts
  //

  AliAnalysisFilter* trackFilterGolden = new AliAnalysisFilter("trackFilter");

  AliESDtrackCuts* esdTrackCutsGolden = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE,1);
  esdTrackCutsGolden->SetMinNCrossedRowsTPC(120);
  esdTrackCutsGolden->SetMinRatioCrossedRowsOverFindableClustersTPC(0.8);
  esdTrackCutsGolden->SetMaxChi2PerClusterITS(36);
  esdTrackCutsGolden->SetMaxFractionSharedTPCClusters(0.4);
  esdTrackCutsGolden->SetMaxChi2TPCConstrainedGlobal(36);
  esdTrackCutsGolden->SetMaxDCAToVertexXY(3.0);

  trackFilterGolden->AddCuts(esdTrackCutsGolden);

  //old cuts without golden cut
  AliAnalysisFilter* trackFilter0 = new AliAnalysisFilter("trackFilter");
  Bool_t clusterCut = 0;
  Bool_t selPrimaries = kTRUE;
  AliESDtrackCuts* esdTrackCutsL0 = new AliESDtrackCuts;
  // TPC
  if(clusterCut == 0)  esdTrackCutsL0->SetMinNClustersTPC(70);
  else if (clusterCut == 1) {
    esdTrackCutsL0->SetMinNCrossedRowsTPC(70);
    esdTrackCutsL0->SetMinRatioCrossedRowsOverFindableClustersTPC(0.8);
  }
  else {
    AliWarningClass(Form("Wrong value of the clusterCut parameter (%d), using cut on Nclusters",clusterCut));
    esdTrackCutsL0->SetMinNClustersTPC(70);
  }

  esdTrackCutsL0->SetMaxChi2PerClusterTPC(4);
  esdTrackCutsL0->SetAcceptKinkDaughters(kFALSE);
  esdTrackCutsL0->SetRequireTPCRefit(kTRUE);
  // ITS
  esdTrackCutsL0->SetRequireITSRefit(kTRUE);
  esdTrackCutsL0->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kAny);
  if(selPrimaries) {
    esdTrackCutsL0->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01");
  }
  esdTrackCutsL0->SetMaxDCAToVertexZ(2);
  esdTrackCutsL0->SetDCAToVertex2D(kFALSE);
  esdTrackCutsL0->SetRequireSigmaToVertex(kFALSE);
  esdTrackCutsL0->SetMaxChi2PerClusterITS(1e10);
  esdTrackCutsL0->SetMaxChi2TPCConstrainedGlobal(1e10);

  trackFilter0->AddCuts(esdTrackCutsL0);

  AliAnalysisFilter* trackFilterTPC = new AliAnalysisFilter("trackFilterTPC");
  AliESDtrackCuts* esdTrackCutsTPC = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
  trackFilterTPC->AddCuts(esdTrackCutsTPC);

  // Create the task and configure it
  //========================================================================
  if(typerun==2){//pbpb: heavy ion analysis

    AliAnalysisTaskHighPtDeDx* taskHighPtDeDx;

    taskHighPtDeDx = 0;
    Char_t TaskName[256] = {0};
    sprintf(TaskName,"%s_%1.0f_%1.0f",taskname,minc,maxc);
    taskHighPtDeDx = new AliAnalysisTaskHighPtDeDx(TaskName);

    // TString type = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
    // taskHighPtDeDx->SetAnalysisType(type);
    // Run AOD even when filtered from LF_PbPb or LF_PbPb_MC

    //Set analysis details
    taskHighPtDeDx->SetAnalysisType("AOD");
    taskHighPtDeDx->SetAnalysisMC(AnalysisMC);
    taskHighPtDeDx->SetAnalysisRun2(kFALSE);
    taskHighPtDeDx->SetTrigger1(kTriggerInt);
    taskHighPtDeDx->SetTrigger2(kTriggerInt);
    taskHighPtDeDx->SetProduceVZEROBranch(kTRUE);
    taskHighPtDeDx->SetDebugLevel(0);

    //Set event details
    taskHighPtDeDx->SetCentFrameworkAliCen(CentFrameworkAliCen); //kTRUE:AliCentrality, kFALSE:AliMultSelection
    taskHighPtDeDx->SetCentDetector("V0M");
    taskHighPtDeDx->SetMinCent(minc);
    taskHighPtDeDx->SetMaxCent(maxc);
    taskHighPtDeDx->SetVtxCut(10.0);
    taskHighPtDeDx->SetContributorsVtxCut(0);
    taskHighPtDeDx->SetContributorsVtxSPDCut(0);
    taskHighPtDeDx->SetZvsSPDvtxCorrCut(999.); //Correlation between global Zvtx and SPD Zvtx: use 999. for no cut
    taskHighPtDeDx->SetVtxR2Cut(10.); //use 10. for no cut

    //Set trigger particle tracks, v0s and daughter track details
    taskHighPtDeDx->SetMinPt(5.0); //trigger tracks
    taskHighPtDeDx->SetLowPtFraction(0.0); //keep x.x% of tracks below min pt
    taskHighPtDeDx->SetEtaCut(0.8);
    taskHighPtDeDx->SetCrossedRowsCut(70.); //use 0. for no cut
    taskHighPtDeDx->SetCrossedOverFindableCut(0.8); //use 0. for no cut
    taskHighPtDeDx->SetCosPACut(0.97);
    taskHighPtDeDx->SetDecayRCut(5.);
    taskHighPtDeDx->SetMinPtV0(1.0);
    taskHighPtDeDx->SetMassCut(0.1);
    taskHighPtDeDx->SetRejectKinks(kTRUE);
    taskHighPtDeDx->SetSigmaDedxCut(kFALSE);

    //Set Filters
    taskHighPtDeDx->SetTrackFilterGolden(trackFilterGolden);
    taskHighPtDeDx->SetTrackFilter(trackFilter0);
    taskHighPtDeDx->SetTrackFilterTPC(trackFilterTPC);

    mgr->AddTask(taskHighPtDeDx);

  }

if(typerun==3){//pp analysis

  AliAnalysisTaskHighPtDeDx* taskHighPtDeDx = new AliAnalysisTaskHighPtDeDx("taskHighPtDeDx");

    //Set analysis details
    taskHighPtDeDx->SetAnalysisType("AOD");
    taskHighPtDeDx->SetAnalysisMC(AnalysisMC);
    taskHighPtDeDx->SetAnalysisRun2(kTRUE);
    taskHighPtDeDx->SetTrigger1(kTriggerInt);
    taskHighPtDeDx->SetTrigger2(kTriggerInt);
    taskHighPtDeDx->SetProduceVZEROBranch(kTRUE);
    taskHighPtDeDx->SetDebugLevel(0);

    //Set event details
    taskHighPtDeDx->SetCentFrameworkAliCen(CentFrameworkAliCen); //kTRUE:AliCentrality, kFALSE:AliMultSelection
    taskHighPtDeDx->SetCentDetector("V0M");
    taskHighPtDeDx->SetMinCent(minc);
    taskHighPtDeDx->SetMaxCent(maxc);
    taskHighPtDeDx->SetVtxCut(10.0);
    taskHighPtDeDx->SetContributorsVtxCut(0);
    taskHighPtDeDx->SetContributorsVtxSPDCut(0);
    taskHighPtDeDx->SetZvsSPDvtxCorrCut(999.); //Correlation between global Zvtx and SPD Zvtx: use 999. for no cut
    taskHighPtDeDx->SetVtxR2Cut(10.); //use 10. for no cut

    //Set trigger particle tracks, v0s and daughter track details
    taskHighPtDeDx->SetMinPt(5.0); //trigger tracks
    taskHighPtDeDx->SetLowPtFraction(0.0); //keep x.x% of tracks below min pt
    taskHighPtDeDx->SetEtaCut(0.8);
    taskHighPtDeDx->SetCrossedRowsCut(70.); //use 0. for no cut
    taskHighPtDeDx->SetCrossedOverFindableCut(0.8); //use 0. for no cut
    taskHighPtDeDx->SetCosPACut(0.98);
    taskHighPtDeDx->SetDecayRCut(0.5);
    taskHighPtDeDx->SetMinPtV0(1.0);
    taskHighPtDeDx->SetMassCut(0.1);
    taskHighPtDeDx->SetRejectKinks(kTRUE);
    taskHighPtDeDx->SetSigmaDedxCut(kFALSE);

    //Set Filters
    taskHighPtDeDx->SetTrackFilterGolden(trackFilterGolden);
    taskHighPtDeDx->SetTrackFilter(trackFilter0);
    taskHighPtDeDx->SetTrackFilterTPC(trackFilterTPC);

    mgr->AddTask(taskHighPtDeDx);

 }

if(typerun==4){//ppb analysis
  cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<    Runing pPb    <<<<<<<<<<<<<<"<<endl;

  AliAnalysisTaskHighPtDeDx* taskHighPtDeDx = new AliAnalysisTaskHighPtDeDx("taskHighPtDeDx");

    //Set analysis details
    taskHighPtDeDx->SetAnalysisType("AOD");
    taskHighPtDeDx->SetAnalysisMC(AnalysisMC);
    taskHighPtDeDx->SetAnalysisRun2(kTRUE);
    taskHighPtDeDx->SetTrigger1(kTriggerInt);
    taskHighPtDeDx->SetTrigger2(kTriggerInt);
    taskHighPtDeDx->SetProduceVZEROBranch(kTRUE);
    taskHighPtDeDx->SetDebugLevel(0);

    //Set event details
    taskHighPtDeDx->SetCentFrameworkAliCen(CentFrameworkAliCen); //kTRUE:AliCentrality, kFALSE:AliMultSelection
    taskHighPtDeDx->SetCentDetector("V0A");
    taskHighPtDeDx->SetMinCent(minc);
    taskHighPtDeDx->SetMaxCent(maxc);
    taskHighPtDeDx->SetVtxCut(10.0);
    taskHighPtDeDx->SetContributorsVtxCut(0);
    taskHighPtDeDx->SetContributorsVtxSPDCut(0);
    taskHighPtDeDx->SetZvsSPDvtxCorrCut(999.); //Correlation between global Zvtx and SPD Zvtx: use 999. for no cut
    taskHighPtDeDx->SetVtxR2Cut(10.); //use 10. for no cut

    //Set trigger particle tracks, v0s and daughter track details
    taskHighPtDeDx->SetMinPt(5.0); //trigger tracks
    taskHighPtDeDx->SetLowPtFraction(0.0); //keep x.x% of tracks below min pt
    taskHighPtDeDx->SetEtaCut(0.8);
    taskHighPtDeDx->SetCrossedRowsCut(70.); //use 0. for no cut
    taskHighPtDeDx->SetCrossedOverFindableCut(0.8); //use 0. for no cut
    taskHighPtDeDx->SetCosPACut(0.97);
    taskHighPtDeDx->SetDecayRCut(0.5);
    taskHighPtDeDx->SetMinPtV0(1.0);
    taskHighPtDeDx->SetMassCut(0.1);
    taskHighPtDeDx->SetRejectKinks(kTRUE);
    taskHighPtDeDx->SetSigmaDedxCut(kFALSE);

    //Set Filters
    taskHighPtDeDx->SetTrackFilterGolden(trackFilterGolden);
    taskHighPtDeDx->SetTrackFilter(trackFilter0);
    taskHighPtDeDx->SetTrackFilterTPC(trackFilterTPC);

    mgr->AddTask(taskHighPtDeDx);

 }

// Create ONLY the output containers for the data produced by the
// task.  Get and connect other common input/output containers via
// the manager as below
//=======================================================================

 TString outputFileName = Form("%s", AliAnalysisManager::GetCommonFileName());
 AliAnalysisDataContainer *cout_hist = mgr->CreateContainer("output", TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName);

 mgr->ConnectInput(taskHighPtDeDx, 0, mgr->GetCommonInputContainer());
 mgr->ConnectOutput(taskHighPtDeDx, 1, cout_hist);

 // Return task pointer at the end
 return taskHighPtDeDx;

}
<|endoftext|>