<commit_before>// Copyright (c) 2016, Matthew Malensek.
// Distributed under the BSD 2-Clause License (see LICENSE.txt for details)

#include "DriveInfo.h"

#include "Logger.h"
#include "StringUtils.h"

DriveInfo::DriveInfo(wchar_t driveLetter) :
_letter(driveLetter) {
    std::wstring driveFileName = DriveFileName(driveLetter);
    _devHandle = CreateFile(
        driveFileName.c_str(),
        FILE_READ_ATTRIBUTES,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        0,
        NULL);

    if (_devHandle == INVALID_HANDLE_VALUE) {
        // TODO perhaps this should throw an error?
        CLOG(L"Failed to get device handle");
        return;
    }

    PopulateDeviceId();
    PopulateDeviceInfo();
    PopulateHotplugInfo();
    PopulateVolumeInfo();

    CloseHandle(_devHandle);
}

const wchar_t DriveInfo::DriveLetter() {
    return _letter;
}

bool DriveInfo::HasRemovableMedia() {
    return _hasRemovableMedia;
}

bool DriveInfo::IsHotPluggable() {
    return _isHotplug;
}

const std::wstring &DriveInfo::ProductID() {
    return _productId;
}

DWORD DriveInfo::SerialNumber() {
    return _serial;
}

const std::wstring &DriveInfo::VendorID() {
    return _vendorId;
}

const std::wstring &DriveInfo::VolumeLabel() {
    return _volumeName;
}

void DriveInfo::PopulateDeviceId() {
    STORAGE_DEVICE_NUMBER sdn = { 0 };
    DWORD bytesOut;

    BOOL result = DeviceIoControl(
        _devHandle,
        IOCTL_STORAGE_GET_DEVICE_NUMBER,
        NULL,
        0,
        &sdn,
        sizeof(sdn),
        &bytesOut,
        NULL);

    if (result == 0) {
        Logger::LogLastError();
        return;
    }

    _devId = sdn.DeviceNumber;
}

void DriveInfo::PopulateDeviceInfo() {
    STORAGE_PROPERTY_QUERY propertyQuery;
    propertyQuery.PropertyId = StorageDeviceProperty;
    propertyQuery.QueryType = PropertyStandardQuery;

    STORAGE_DESCRIPTOR_HEADER storageHeader = { 0 };

    DWORD bytesOut;
    BOOL result;

    result = DeviceIoControl(
        _devHandle,
        IOCTL_STORAGE_QUERY_PROPERTY,
        &propertyQuery,
        sizeof(propertyQuery),
        &storageHeader,
        sizeof(storageHeader),
        &bytesOut,
        NULL);

    if (!result) {
        Logger::LogLastError();
        return;
    }

    unsigned char *descriptorData = new unsigned char[storageHeader.Size];

    result = DeviceIoControl(
        _devHandle,
        IOCTL_STORAGE_QUERY_PROPERTY,
        &propertyQuery,
        sizeof(propertyQuery),
        descriptorData,
        storageHeader.Size,
        &bytesOut,
        NULL);

    if (!result) {
        delete[] descriptorData;
        Logger::LogLastError();
        return;
    }

    STORAGE_DEVICE_DESCRIPTOR *sdd
        = (STORAGE_DEVICE_DESCRIPTOR *) descriptorData;

    if (sdd->ProductIdOffset) {
        _productId = StringUtils::Widen(
            (const char *) ((unsigned char *) sdd + sdd->ProductIdOffset));
    }

    if (sdd->VendorIdOffset) {
        _vendorId = StringUtils::Widen(
            (const char *) ((unsigned char *) sdd + sdd->VendorIdOffset));
    }

    if (sdd->RemovableMedia) {
        _hasRemovableMedia = true;
    }

    CLOG("ProductID: '%s'\nVendor ID: '%s'",
        _productId.c_str(), _vendorId.c_str());

    delete[] descriptorData;
}

void DriveInfo::PopulateHotplugInfo() {
    STORAGE_HOTPLUG_INFO shi = { 0 };
    DWORD bytesOut;

    BOOL result = DeviceIoControl(
        _devHandle,
        IOCTL_STORAGE_GET_HOTPLUG_INFO,
        NULL,
        0,
        &shi,
        sizeof(shi),
        &bytesOut,
        NULL);

    if (result == 0) {
        Logger::LogLastError();
        return;
    }

    if (shi.DeviceHotplug) {
        _isHotplug = true;
    }

    if (shi.MediaRemovable) {
        _hasRemovableMedia = true;
    }
}

void DriveInfo::PopulateVolumeInfo() {
    wchar_t drivePath[] = L" :\\";
    drivePath[0] = _letter;
    wchar_t volName[MAX_PATH] = { 0 };
    DWORD serial = 0;

    BOOL result = GetVolumeInformation(
        drivePath,
        volName, MAX_PATH,
        &serial,
        NULL, NULL, NULL, NULL);

    if (result == FALSE) {
        _volumeName = L"";
        _serial = 0;
    }
    CLOG(L"NAME: %s", volName);

    _volumeName = std::wstring(volName);
    _serial = serial;
}

std::wstring DriveInfo::DriveFileName(wchar_t &driveLetter) {
    return DriveFileName(std::wstring(1, driveLetter));
}

std::wstring DriveInfo::DriveFileName(const std::wstring &driveLetter) {
    return L"\\\\.\\" + driveLetter + L":";
}

<commit_msg>Trim drive ID strings<commit_after>// Copyright (c) 2016, Matthew Malensek.
// Distributed under the BSD 2-Clause License (see LICENSE.txt for details)

#include "DriveInfo.h"

#include "Logger.h"
#include "StringUtils.h"

DriveInfo::DriveInfo(wchar_t driveLetter) :
_letter(driveLetter) {
    std::wstring driveFileName = DriveFileName(driveLetter);
    _devHandle = CreateFile(
        driveFileName.c_str(),
        FILE_READ_ATTRIBUTES,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        0,
        NULL);

    if (_devHandle == INVALID_HANDLE_VALUE) {
        // TODO perhaps this should throw an error?
        CLOG(L"Failed to get device handle");
        return;
    }

    PopulateDeviceId();
    PopulateDeviceInfo();
    PopulateHotplugInfo();
    PopulateVolumeInfo();

    CloseHandle(_devHandle);
}

const wchar_t DriveInfo::DriveLetter() {
    return _letter;
}

bool DriveInfo::HasRemovableMedia() {
    return _hasRemovableMedia;
}

bool DriveInfo::IsHotPluggable() {
    return _isHotplug;
}

const std::wstring &DriveInfo::ProductID() {
    return _productId;
}

DWORD DriveInfo::SerialNumber() {
    return _serial;
}

const std::wstring &DriveInfo::VendorID() {
    return _vendorId;
}

const std::wstring &DriveInfo::VolumeLabel() {
    return _volumeName;
}

void DriveInfo::PopulateDeviceId() {
    STORAGE_DEVICE_NUMBER sdn = { 0 };
    DWORD bytesOut;

    BOOL result = DeviceIoControl(
        _devHandle,
        IOCTL_STORAGE_GET_DEVICE_NUMBER,
        NULL,
        0,
        &sdn,
        sizeof(sdn),
        &bytesOut,
        NULL);

    if (result == 0) {
        Logger::LogLastError();
        return;
    }

    _devId = sdn.DeviceNumber;
}

void DriveInfo::PopulateDeviceInfo() {
    STORAGE_PROPERTY_QUERY propertyQuery;
    propertyQuery.PropertyId = StorageDeviceProperty;
    propertyQuery.QueryType = PropertyStandardQuery;

    STORAGE_DESCRIPTOR_HEADER storageHeader = { 0 };

    DWORD bytesOut;
    BOOL result;

    result = DeviceIoControl(
        _devHandle,
        IOCTL_STORAGE_QUERY_PROPERTY,
        &propertyQuery,
        sizeof(propertyQuery),
        &storageHeader,
        sizeof(storageHeader),
        &bytesOut,
        NULL);

    if (!result) {
        Logger::LogLastError();
        return;
    }

    unsigned char *descriptorData = new unsigned char[storageHeader.Size];

    result = DeviceIoControl(
        _devHandle,
        IOCTL_STORAGE_QUERY_PROPERTY,
        &propertyQuery,
        sizeof(propertyQuery),
        descriptorData,
        storageHeader.Size,
        &bytesOut,
        NULL);

    if (!result) {
        delete[] descriptorData;
        Logger::LogLastError();
        return;
    }

    STORAGE_DEVICE_DESCRIPTOR *sdd
        = (STORAGE_DEVICE_DESCRIPTOR *) descriptorData;

    if (sdd->ProductIdOffset) {
        _productId = StringUtils::Widen(
            (const char *) ((unsigned char *) sdd + sdd->ProductIdOffset));
        _productId = StringUtils::Trim(_productId);
    }

    if (sdd->VendorIdOffset) {
        _vendorId = StringUtils::Widen(
            (const char *) ((unsigned char *) sdd + sdd->VendorIdOffset));
        _vendorId = StringUtils::Trim(_vendorId);
    }

    if (sdd->RemovableMedia) {
        _hasRemovableMedia = true;
    }

    CLOG("ProductID: '%s'\nVendor ID: '%s'",
        _productId.c_str(), _vendorId.c_str());

    delete[] descriptorData;
}

void DriveInfo::PopulateHotplugInfo() {
    STORAGE_HOTPLUG_INFO shi = { 0 };
    DWORD bytesOut;

    BOOL result = DeviceIoControl(
        _devHandle,
        IOCTL_STORAGE_GET_HOTPLUG_INFO,
        NULL,
        0,
        &shi,
        sizeof(shi),
        &bytesOut,
        NULL);

    if (result == 0) {
        Logger::LogLastError();
        return;
    }

    if (shi.DeviceHotplug) {
        _isHotplug = true;
    }

    if (shi.MediaRemovable) {
        _hasRemovableMedia = true;
    }
}

void DriveInfo::PopulateVolumeInfo() {
    wchar_t drivePath[] = L" :\\";
    drivePath[0] = _letter;
    wchar_t volName[MAX_PATH] = { 0 };
    DWORD serial = 0;

    BOOL result = GetVolumeInformation(
        drivePath,
        volName, MAX_PATH,
        &serial,
        NULL, NULL, NULL, NULL);

    if (result == FALSE) {
        _volumeName = L"";
        _serial = 0;
    }

    _volumeName = StringUtils::Trim(volName);
    _serial = serial;
}

std::wstring DriveInfo::DriveFileName(wchar_t &driveLetter) {
    return DriveFileName(std::wstring(1, driveLetter));
}

std::wstring DriveInfo::DriveFileName(const std::wstring &driveLetter) {
    return L"\\\\.\\" + driveLetter + L":";
}

<|endoftext|>


<commit_before>/*
 * Copyright (c) 2012, 2013 Aldebaran Robotics. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the COPYING file.
 */

#pragma once
#ifndef _LIBQI_QI_OS_HPP_
#define _LIBQI_QI_OS_HPP_

# include <cstdio>
# include <string>
# include <map>
# include <vector>
# include <qi/api.hpp>
# include <qi/types.hpp>

struct stat;

namespace qi {

  namespace os {

    QI_API FILE* fopen(const char *filename, const char *mode);
    QI_API int stat(const char *filename, struct stat *pstat);
    QI_API int checkdbg();
    QI_API std::string home();
    QI_API std::string mktmpdir(const char *prefix = "");
    QI_API std::string tmp();
    QI_API std::string gethostname();

    // lib C
    QI_API char* strdup(const char *src);
    QI_API int snprintf(char *str, size_t size, const char *format, ...);

    // env
    QI_API std::string getenv(const char *var);
    QI_API int setenv(const char *var, const char *value);

    // time
    QI_API void sleep(unsigned int seconds);
    QI_API void msleep(unsigned int milliseconds);
    struct QI_API timeval {
      long tv_sec;
      long tv_usec;
    };
    QI_API int gettimeofday(qi::os::timeval *tp);
    QI_API qi::int64_t ustime();
    QI_API qi::os::timeval operator+(const qi::os::timeval &lhs,
                                     const qi::os::timeval &rhs);
    QI_API qi::os::timeval operator+(const qi::os::timeval &lhs,
                                     long                   us);
    QI_API qi::os::timeval operator-(const qi::os::timeval &lhs,
                                     const qi::os::timeval &rhs);
    QI_API qi::os::timeval operator-(const qi::os::timeval &lhs,
                                     long                   us);

    // shared library
    QI_API void *dlopen(const char *filename, int flag = -1);
    QI_API int dlclose(void *handle);
    QI_API void *dlsym(void *handle, const char *symbol);
    QI_API const char *dlerror(void);

    // process management
    QI_API int spawnvp(char *const argv[]);
    QI_API int spawnlp(const char* argv, ...);
    QI_API int system(const char *command);
    QI_API int getpid();
    QI_API int gettid();
    QI_API int waitpid(int pid, int* status);
    QI_API int kill(int pid, int sig);

    // trad
    QI_API std::string gettext(const std::string &msgid);
    QI_API std::string dgettext(const std::string &domainname,
                                const std::string &msgid);

    QI_API unsigned short findAvailablePort(unsigned short port);
    QI_API std::map<std::string, std::vector<std::string> > hostIPAddrs(bool ipv6Addr = false);

    QI_API void setCurrentThreadName(const std::string &name);

    QI_API std::string getMachineId();

    //since 1.12.1
    QI_API_DEPRECATED QI_API std::string tmpdir(const char *prefix = "");
  }
}

#endif  // _LIBQI_QI_OS_HPP_
<commit_msg>qi::os::timeval: use long long instead of long<commit_after>/*
 * Copyright (c) 2012, 2013 Aldebaran Robotics. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the COPYING file.
 */

#pragma once
#ifndef _LIBQI_QI_OS_HPP_
#define _LIBQI_QI_OS_HPP_

# include <cstdio>
# include <string>
# include <map>
# include <vector>
# include <qi/api.hpp>
# include <qi/types.hpp>

struct stat;

namespace qi {

  namespace os {

    QI_API FILE* fopen(const char *filename, const char *mode);
    QI_API int stat(const char *filename, struct stat *pstat);
    QI_API int checkdbg();
    QI_API std::string home();
    QI_API std::string mktmpdir(const char *prefix = "");
    QI_API std::string tmp();
    QI_API std::string gethostname();

    // lib C
    QI_API char* strdup(const char *src);
    QI_API int snprintf(char *str, size_t size, const char *format, ...);

    // env
    QI_API std::string getenv(const char *var);
    QI_API int setenv(const char *var, const char *value);

    // time
    QI_API void sleep(unsigned int seconds);
    QI_API void msleep(unsigned int milliseconds);
    struct QI_API timeval {
      qi::int64_t tv_sec;
      qi::int64_t tv_usec;
    };
    QI_API int gettimeofday(qi::os::timeval *tp);
    QI_API qi::int64_t ustime();
    QI_API qi::os::timeval operator+(const qi::os::timeval &lhs,
                                     const qi::os::timeval &rhs);
    QI_API qi::os::timeval operator+(const qi::os::timeval &lhs,
                                     long                   us);
    QI_API qi::os::timeval operator-(const qi::os::timeval &lhs,
                                     const qi::os::timeval &rhs);
    QI_API qi::os::timeval operator-(const qi::os::timeval &lhs,
                                     long                   us);

    // shared library
    QI_API void *dlopen(const char *filename, int flag = -1);
    QI_API int dlclose(void *handle);
    QI_API void *dlsym(void *handle, const char *symbol);
    QI_API const char *dlerror(void);

    // process management
    QI_API int spawnvp(char *const argv[]);
    QI_API int spawnlp(const char* argv, ...);
    QI_API int system(const char *command);
    QI_API int getpid();
    QI_API int gettid();
    QI_API int waitpid(int pid, int* status);
    QI_API int kill(int pid, int sig);

    // trad
    QI_API std::string gettext(const std::string &msgid);
    QI_API std::string dgettext(const std::string &domainname,
                                const std::string &msgid);

    QI_API unsigned short findAvailablePort(unsigned short port);
    QI_API std::map<std::string, std::vector<std::string> > hostIPAddrs(bool ipv6Addr = false);

    QI_API void setCurrentThreadName(const std::string &name);

    QI_API std::string getMachineId();

    //since 1.12.1
    QI_API_DEPRECATED QI_API std::string tmpdir(const char *prefix = "");
  }
}

#endif  // _LIBQI_QI_OS_HPP_
<|endoftext|>


<commit_before>#pragma once

#ifndef INCLUDE_OCVG_DARKLIGHT
#define INCLUDE_OCVG_DARKLIGHT

#include "..\stdafx.h"

using namespace cv;
using namespace cuda;
using namespace std;

namespace openCVGraph
{
    // Brightfield / Darkfield correction
    // Corrected = (Image - Darkfield) / (Brightfield - Darkfield) * 2**16 (for 16 bit data)

    class BrightDarkFieldCorrection : public Filter
    {
    public:

        static void BrightDarkFieldCorrection::SliderCallback(int pos, void * userData) {
            BrightDarkFieldCorrection* filter = (BrightDarkFieldCorrection *)userData;
            filter->FieldToView(pos);
        }

        BrightDarkFieldCorrection::BrightDarkFieldCorrection(std::string name, GraphData& graphData,
            int width = 512, int height = 512)
            : Filter(name, graphData, width, height)
        {

        }

        bool BrightDarkFieldCorrection::init(GraphData& graphData) override
        {
            Filter::init(graphData);

            graphData.m_NeedCV_16UC1 = true;
            // Need 8 bit if we're viewing it
            if (m_showView) {
                graphData.m_NeedCV_8UC1 = true;
            }

            // get the Bright Dark images from file

            Mat img = imread(m_BrightFieldPath, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_GRAYSCALE);
            if (!img.empty()) {
                m_imBrightFieldGpu16U.upload(img);
            }
            else {
                assert(false);
            }

            img = imread(m_DarkFieldPath, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_GRAYSCALE);
            if (!img.empty()) {
                m_imDarkFieldGpu16U.upload(img);
            }
            else {
                assert(false);
            }

            // Bright - Dark as 32F
            cuda::subtract(m_imBrightFieldGpu16U, m_imDarkFieldGpu16U, m_imTemp16UGpu);
            m_imTemp16UGpu.convertTo(m_imBrightMinusDarkFieldGpu32F, CV_32F);

            if (m_showView) {
                // To write on the overlay, you must allocate it.
                // This indicates to the renderer the need to merge it with the final output image.
                // m_imViewTextOverlay = Mat(m_width, m_height, CV_8U);

                if (m_showSlider) {
                    createTrackbar("BrightDarkFieldCorrection", m_CombinedName, &m_FieldToView, 4, SliderCallback, this);
                }
            }

            return true;
        }

        ProcessResult BrightDarkFieldCorrection::process(GraphData& graphData) override
        {
            if (graphData.m_UseCuda) {
                // sub darkfield
                cuda::subtract(graphData.m_imCapGpu16UC1, m_imDarkFieldGpu16U, m_imTemp16UGpu);
                // make 32F
                m_imTemp16UGpu.convertTo(m_imTemp32FGpu, CV_32F);
                // image - dark / bright - dark
                cuda::divide(m_imTemp32FGpu, m_imBrightMinusDarkFieldGpu32F, m_imTemp16UGpu);

                m_imTemp16UGpu.convertTo(graphData.m_imOutGpu16UC1, CV_16U, 65536);

                if (graphData.m_NeedCV_8UC1) {
                    graphData.m_imOutGpu16UC1.convertTo(graphData.m_imOutGpu8UC1, CV_8U, 1.0 / 256);
                }
            }
            else {
                //todo
                assert(false);

            }

            return ProcessResult::OK;  // if you return false, the graph stops
        }

        void BrightDarkFieldCorrection::processView(GraphData & graphData) override
        {
            if (m_showView) {
                switch (m_FieldToView) {
                case 0:
                    graphData.m_imOutGpu8UC1.download(m_imView);
                    break;
                case 1:
                    graphData.m_imCapGpu16UC1.convertTo(graphData.m_imOutGpu8UC1, CV_8U, 1.0 / 256);
                    graphData.m_imOutGpu8UC1.download(m_imView);
                    break;
                case 2:
                    m_imBrightFieldGpu16U.convertTo(graphData.m_imOutGpu8UC1, CV_8U, 1.0 / 256);
                    graphData.m_imOutGpu8UC1.download(m_imView);
                    break;
                case 3:
                    m_imDarkFieldGpu16U.convertTo(graphData.m_imOutGpu8UC1, CV_8U, 1.0 / 256);
                    graphData.m_imOutGpu8UC1.download(m_imView);
                    break;

                }
                Filter::processView(graphData);
            }
        }

        void BrightDarkFieldCorrection::FieldToView(int n) {
            m_FieldToView = n;
        }

        void  BrightDarkFieldCorrection::saveConfig(FileStorage& fs, GraphData& data)
        {
            Filter::saveConfig(fs, data);
            fs <<"bright_field_path" << m_BrightFieldPath.c_str();
            fs <<"dark_field_path" << m_DarkFieldPath.c_str();
            fs << "show_slider" << m_showSlider;
        }

        void  BrightDarkFieldCorrection::loadConfig(FileNode& fs, GraphData& data)
        {
            Filter::loadConfig(fs, data);
            fs["bright_field_path"] >> m_BrightFieldPath;
            fs["dark_field_path"] >> m_DarkFieldPath;
            fs["show_slider"] >> m_showSlider;
        }

    private:
        cv::cuda::GpuMat m_imTemp16UGpu;                     // 32F
        cv::cuda::GpuMat m_imTemp32FGpu;                     // 32F
        cv::cuda::GpuMat m_imBrightFieldGpu16U;           // 16U
        cv::cuda::GpuMat m_imDarkFieldGpu16U;             // 16U
        cv::cuda::GpuMat m_imBrightMinusDarkFieldGpu32F;  // 32F

        std::string m_BrightFieldPath = "config/BrightField.tif";
        std::string m_DarkFieldPath = "config/DarkField.tif";

        int m_FieldToView = 0;      // 0 is processed, 1 is unprocessed, 2 is darkfield, 3 is brightfield
        bool m_showSlider = true;

    };
}
#endif<commit_msg>Logging BrightDarkfield<commit_after>#pragma once

#ifndef INCLUDE_OCVG_DARKLIGHT
#define INCLUDE_OCVG_DARKLIGHT

#include "..\stdafx.h"

using namespace cv;
using namespace cuda;
using namespace std;

namespace openCVGraph
{
    // Brightfield / Darkfield correction
    // Corrected = (Image - Darkfield) / (Brightfield - Darkfield) * 2**16 (for 16 bit data)

    class BrightDarkFieldCorrection : public Filter
    {
    public:

        static void BrightDarkFieldCorrection::SliderCallback(int pos, void * userData) {
            BrightDarkFieldCorrection* filter = (BrightDarkFieldCorrection *)userData;
            filter->FieldToView(pos);
        }

        BrightDarkFieldCorrection::BrightDarkFieldCorrection(std::string name, GraphData& graphData,
            int width = 512, int height = 512)
            : Filter(name, graphData, width, height)
        {

        }

        bool BrightDarkFieldCorrection::init(GraphData& graphData) override
        {
            Filter::init(graphData);

            graphData.m_NeedCV_16UC1 = true;
            // Need 8 bit if we're viewing it
            if (m_showView) {
                graphData.m_NeedCV_8UC1 = true;
            }

            // get the Bright Dark images from file

            Mat img = imread(m_BrightFieldPath, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_GRAYSCALE);
            if (!img.empty()) {
                m_imBrightFieldGpu16U.upload(img);
            }
            else {
                graphData.m_Logger->error ("Unable to load BrightField: " + m_BrightFieldPath);
                return false;
            }

            img = imread(m_DarkFieldPath, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_GRAYSCALE);
            if (!img.empty()) {
                m_imDarkFieldGpu16U.upload(img);
            }
            else {
                graphData.m_Logger->error("Unable to load DarkField: " + m_DarkFieldPath);
                return false;
            }

            // Bright - Dark as 32F
            cuda::subtract(m_imBrightFieldGpu16U, m_imDarkFieldGpu16U, m_imTemp16UGpu);
            m_imTemp16UGpu.convertTo(m_imBrightMinusDarkFieldGpu32F, CV_32F);

            if (m_showView) {
                // To write on the overlay, you must allocate it.
                // This indicates to the renderer the need to merge it with the final output image.
                // m_imViewTextOverlay = Mat(m_width, m_height, CV_8U);

                if (m_showSlider) {
                    createTrackbar("BrightDarkFieldCorrection", m_CombinedName, &m_FieldToView, 4, SliderCallback, this);
                }
            }

            return true;
        }

        ProcessResult BrightDarkFieldCorrection::process(GraphData& graphData) override
        {
            if (graphData.m_UseCuda) {
                // sub darkfield
                cuda::subtract(graphData.m_imCapGpu16UC1, m_imDarkFieldGpu16U, m_imTemp16UGpu);
                // make 32F
                m_imTemp16UGpu.convertTo(m_imTemp32FGpu, CV_32F);
                // image - dark / bright - dark
                cuda::divide(m_imTemp32FGpu, m_imBrightMinusDarkFieldGpu32F, m_imTemp16UGpu);

                m_imTemp16UGpu.convertTo(graphData.m_imOutGpu16UC1, CV_16U, 65536);

                if (graphData.m_NeedCV_8UC1) {
                    graphData.m_imOutGpu16UC1.convertTo(graphData.m_imOutGpu8UC1, CV_8U, 1.0 / 256);
                }
            }
            else {
                //todo
                assert(false);

            }

            return ProcessResult::OK;  // if you return false, the graph stops
        }

        void BrightDarkFieldCorrection::processView(GraphData & graphData) override
        {
            if (m_showView) {
                switch (m_FieldToView) {
                case 0:
                    graphData.m_imOutGpu8UC1.download(m_imView);
                    break;
                case 1:
                    graphData.m_imCapGpu16UC1.convertTo(graphData.m_imOutGpu8UC1, CV_8U, 1.0 / 256);
                    graphData.m_imOutGpu8UC1.download(m_imView);
                    break;
                case 2:
                    m_imBrightFieldGpu16U.convertTo(graphData.m_imOutGpu8UC1, CV_8U, 1.0 / 256);
                    graphData.m_imOutGpu8UC1.download(m_imView);
                    break;
                case 3:
                    m_imDarkFieldGpu16U.convertTo(graphData.m_imOutGpu8UC1, CV_8U, 1.0 / 256);
                    graphData.m_imOutGpu8UC1.download(m_imView);
                    break;

                }
                Filter::processView(graphData);
            }
        }

        void BrightDarkFieldCorrection::FieldToView(int n) {
            m_FieldToView = n;
        }

        void  BrightDarkFieldCorrection::saveConfig(FileStorage& fs, GraphData& data)
        {
            Filter::saveConfig(fs, data);
            fs <<"bright_field_path" << m_BrightFieldPath.c_str();
            fs <<"dark_field_path" << m_DarkFieldPath.c_str();
            fs << "show_slider" << m_showSlider;
        }

        void  BrightDarkFieldCorrection::loadConfig(FileNode& fs, GraphData& data)
        {
            Filter::loadConfig(fs, data);
            fs["bright_field_path"] >> m_BrightFieldPath;
            fs["dark_field_path"] >> m_DarkFieldPath;
            fs["show_slider"] >> m_showSlider;
        }

    private:
        cv::cuda::GpuMat m_imTemp16UGpu;                     // 32F
        cv::cuda::GpuMat m_imTemp32FGpu;                     // 32F
        cv::cuda::GpuMat m_imBrightFieldGpu16U;           // 16U
        cv::cuda::GpuMat m_imDarkFieldGpu16U;             // 16U
        cv::cuda::GpuMat m_imBrightMinusDarkFieldGpu32F;  // 32F

        std::string m_BrightFieldPath = "config/BrightField.tif";
        std::string m_DarkFieldPath = "config/DarkField.tif";

        int m_FieldToView = 0;      // 0 is processed, 1 is unprocessed, 2 is darkfield, 3 is brightfield
        bool m_showSlider = true;

    };
}
#endif<|endoftext|>


<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/window.h"
#include "chrome/common/extensions/extension.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/layout/layout_constants.h"
#include "views/view.h"
#include "views/widget/widget.h"
#include "views/window/dialog_delegate.h"

namespace {

const int kRightColumnWidth = 210;
const int kIconSize = 69;

class ExtensionUninstallDialogDelegateView;

// Views implementation of the uninstall dialog.
class ExtensionUninstallDialogViews : public ExtensionUninstallDialog {
 public:
  ExtensionUninstallDialogViews(Profile* profile,
                                ExtensionUninstallDialog::Delegate* delegate);
  virtual ~ExtensionUninstallDialogViews();

  // Forwards the accept and cancels to the delegate.
  void ExtensionUninstallAccepted();
  void ExtensionUninstallCanceled();

  ExtensionUninstallDialogDelegateView* view() { return view_; }

 private:
  void Show() OVERRIDE;

  ExtensionUninstallDialogDelegateView* view_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews);
};

// The dialog's view, owned by the views framework.
class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
 public:
  ExtensionUninstallDialogDelegateView(
      ExtensionUninstallDialogViews* dialog_view,
      const Extension* extension,
      SkBitmap* icon);
  virtual ~ExtensionUninstallDialogDelegateView();

  // Called when the ExtensionUninstallDialog has been destroyed to make sure
  // we invalidate pointers.
  void DialogDestroyed() { dialog_ = NULL; }

 private:
  // views::DialogDelegate:
  virtual std::wstring GetDialogButtonLabel(
      MessageBoxFlags::DialogButton button) const OVERRIDE;

  virtual int GetDefaultDialogButton() const OVERRIDE {
    return MessageBoxFlags::DIALOGBUTTON_CANCEL;
  }

  virtual bool Accept() OVERRIDE;
  virtual bool Cancel() OVERRIDE;

  // views::WidgetDelegate:
  virtual bool IsModal() const OVERRIDE { return true; }
  virtual views::View* GetContentsView() OVERRIDE { return this; }
  virtual std::wstring GetWindowTitle() const OVERRIDE;

  // views::View:
  virtual gfx::Size GetPreferredSize() OVERRIDE;

  virtual void Layout() OVERRIDE;

  ExtensionUninstallDialogViews* dialog_;

  views::ImageView* icon_;
  views::Label* heading_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
};

ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
    Profile* profile, ExtensionUninstallDialog::Delegate* delegate)
    : ExtensionUninstallDialog(profile, delegate) {}

ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
  // Close the widget (the views framework will delete view_).
  if (view_) {
    view_->DialogDestroyed();
    view_->GetWidget()->CloseNow();
  }
}

void ExtensionUninstallDialogViews::Show() {
  Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
  if (!browser) {
    delegate_->ExtensionUninstallCanceled();
    return;
  }

  BrowserWindow* window = browser->window();
  if (!window) {
    delegate_->ExtensionUninstallCanceled();
    return;
  }

  view_ = new ExtensionUninstallDialogDelegateView(this, extension_, &icon_);
  browser::CreateViewsWindow(window->GetNativeHandle(), view_)->Show();
}

void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
  // The widget gets destroyed when the dialog is accepted.
  view_ = NULL;
  delegate_->ExtensionUninstallAccepted();
}

void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
  // The widget gets destroyed when the dialog is canceled.
  view_ = NULL;
  delegate_->ExtensionUninstallCanceled();
}

ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView(
    ExtensionUninstallDialogViews* dialog_view,
    const Extension* extension,
    SkBitmap* icon)
    : dialog_(dialog_view) {
  // Scale down to icon size, but allow smaller icons (don't scale up).
  gfx::Size size(icon->width(), icon->height());
  if (size.width() > kIconSize || size.height() > kIconSize)
    size = gfx::Size(kIconSize, kIconSize);
  icon_ = new views::ImageView();
  icon_->SetImageSize(size);
  icon_->SetImage(*icon);
  AddChildView(icon_);

  heading_ = new views::Label(UTF16ToWide(
      l10n_util::GetStringFUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
                                 UTF8ToUTF16(extension->name()))));
  heading_->SetMultiLine(true);
  AddChildView(heading_);
}

ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() {
}

std::wstring ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
    MessageBoxFlags::DialogButton button) const {
  switch (button) {
    case MessageBoxFlags::DIALOGBUTTON_OK:
      return UTF16ToWide(
          l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON));
    case MessageBoxFlags::DIALOGBUTTON_CANCEL:
      return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
    default:
      NOTREACHED();
      return L"";
  }
}

bool ExtensionUninstallDialogDelegateView::Accept() {
  if (dialog_)
    dialog_->ExtensionUninstallAccepted();
  return true;
}

bool ExtensionUninstallDialogDelegateView::Cancel() {
  if (dialog_)
    dialog_->ExtensionUninstallCanceled();
  return true;
}

std::wstring ExtensionUninstallDialogDelegateView::GetWindowTitle() const {
  return UTF16ToWide(
      l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE));
}

gfx::Size ExtensionUninstallDialogDelegateView::GetPreferredSize() {
  int width = kRightColumnWidth;
  width += kIconSize;
  width += views::kPanelHorizMargin * 3;

  int height = views::kPanelVertMargin * 2;
  height += heading_->GetHeightForWidth(kRightColumnWidth);

  return gfx::Size(width,
                   std::max(height, kIconSize + views::kPanelVertMargin * 2));
}

void ExtensionUninstallDialogDelegateView::Layout() {
  int x = views::kPanelHorizMargin;
  int y = views::kPanelVertMargin;

  heading_->SizeToFit(kRightColumnWidth);

  if (heading_->height() <= kIconSize) {
    icon_->SetBounds(x, y, kIconSize, kIconSize);
    x += kIconSize;
    x += views::kPanelHorizMargin;

    heading_->SetX(x);
    heading_->SetY(y + (kIconSize - heading_->height()) / 2);
  } else {
    icon_->SetBounds(x,
                     y + (heading_->height() - kIconSize) / 2,
                     kIconSize,
                     kIconSize);
    x += kIconSize;
    x += views::kPanelHorizMargin;

    heading_->SetX(x);
    heading_->SetY(y);
  }
}

}  // namespace

// static
ExtensionUninstallDialog* ExtensionUninstallDialog::Create(
    Profile* profile, Delegate* delegate) {
  return new ExtensionUninstallDialogViews(profile, delegate);
}
<commit_msg>Remove executable permission from extension_uninstall_dialog_view.cc<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/window.h"
#include "chrome/common/extensions/extension.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/layout/layout_constants.h"
#include "views/view.h"
#include "views/widget/widget.h"
#include "views/window/dialog_delegate.h"

namespace {

const int kRightColumnWidth = 210;
const int kIconSize = 69;

class ExtensionUninstallDialogDelegateView;

// Views implementation of the uninstall dialog.
class ExtensionUninstallDialogViews : public ExtensionUninstallDialog {
 public:
  ExtensionUninstallDialogViews(Profile* profile,
                                ExtensionUninstallDialog::Delegate* delegate);
  virtual ~ExtensionUninstallDialogViews();

  // Forwards the accept and cancels to the delegate.
  void ExtensionUninstallAccepted();
  void ExtensionUninstallCanceled();

  ExtensionUninstallDialogDelegateView* view() { return view_; }

 private:
  void Show() OVERRIDE;

  ExtensionUninstallDialogDelegateView* view_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews);
};

// The dialog's view, owned by the views framework.
class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
 public:
  ExtensionUninstallDialogDelegateView(
      ExtensionUninstallDialogViews* dialog_view,
      const Extension* extension,
      SkBitmap* icon);
  virtual ~ExtensionUninstallDialogDelegateView();

  // Called when the ExtensionUninstallDialog has been destroyed to make sure
  // we invalidate pointers.
  void DialogDestroyed() { dialog_ = NULL; }

 private:
  // views::DialogDelegate:
  virtual std::wstring GetDialogButtonLabel(
      MessageBoxFlags::DialogButton button) const OVERRIDE;

  virtual int GetDefaultDialogButton() const OVERRIDE {
    return MessageBoxFlags::DIALOGBUTTON_CANCEL;
  }

  virtual bool Accept() OVERRIDE;
  virtual bool Cancel() OVERRIDE;

  // views::WidgetDelegate:
  virtual bool IsModal() const OVERRIDE { return true; }
  virtual views::View* GetContentsView() OVERRIDE { return this; }
  virtual std::wstring GetWindowTitle() const OVERRIDE;

  // views::View:
  virtual gfx::Size GetPreferredSize() OVERRIDE;

  virtual void Layout() OVERRIDE;

  ExtensionUninstallDialogViews* dialog_;

  views::ImageView* icon_;
  views::Label* heading_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
};

ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
    Profile* profile, ExtensionUninstallDialog::Delegate* delegate)
    : ExtensionUninstallDialog(profile, delegate) {}

ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
  // Close the widget (the views framework will delete view_).
  if (view_) {
    view_->DialogDestroyed();
    view_->GetWidget()->CloseNow();
  }
}

void ExtensionUninstallDialogViews::Show() {
  Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
  if (!browser) {
    delegate_->ExtensionUninstallCanceled();
    return;
  }

  BrowserWindow* window = browser->window();
  if (!window) {
    delegate_->ExtensionUninstallCanceled();
    return;
  }

  view_ = new ExtensionUninstallDialogDelegateView(this, extension_, &icon_);
  browser::CreateViewsWindow(window->GetNativeHandle(), view_)->Show();
}

void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
  // The widget gets destroyed when the dialog is accepted.
  view_ = NULL;
  delegate_->ExtensionUninstallAccepted();
}

void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
  // The widget gets destroyed when the dialog is canceled.
  view_ = NULL;
  delegate_->ExtensionUninstallCanceled();
}

ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView(
    ExtensionUninstallDialogViews* dialog_view,
    const Extension* extension,
    SkBitmap* icon)
    : dialog_(dialog_view) {
  // Scale down to icon size, but allow smaller icons (don't scale up).
  gfx::Size size(icon->width(), icon->height());
  if (size.width() > kIconSize || size.height() > kIconSize)
    size = gfx::Size(kIconSize, kIconSize);
  icon_ = new views::ImageView();
  icon_->SetImageSize(size);
  icon_->SetImage(*icon);
  AddChildView(icon_);

  heading_ = new views::Label(UTF16ToWide(
      l10n_util::GetStringFUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
                                 UTF8ToUTF16(extension->name()))));
  heading_->SetMultiLine(true);
  AddChildView(heading_);
}

ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() {
}

std::wstring ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
    MessageBoxFlags::DialogButton button) const {
  switch (button) {
    case MessageBoxFlags::DIALOGBUTTON_OK:
      return UTF16ToWide(
          l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON));
    case MessageBoxFlags::DIALOGBUTTON_CANCEL:
      return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
    default:
      NOTREACHED();
      return L"";
  }
}

bool ExtensionUninstallDialogDelegateView::Accept() {
  if (dialog_)
    dialog_->ExtensionUninstallAccepted();
  return true;
}

bool ExtensionUninstallDialogDelegateView::Cancel() {
  if (dialog_)
    dialog_->ExtensionUninstallCanceled();
  return true;
}

std::wstring ExtensionUninstallDialogDelegateView::GetWindowTitle() const {
  return UTF16ToWide(
      l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE));
}

gfx::Size ExtensionUninstallDialogDelegateView::GetPreferredSize() {
  int width = kRightColumnWidth;
  width += kIconSize;
  width += views::kPanelHorizMargin * 3;

  int height = views::kPanelVertMargin * 2;
  height += heading_->GetHeightForWidth(kRightColumnWidth);

  return gfx::Size(width,
                   std::max(height, kIconSize + views::kPanelVertMargin * 2));
}

void ExtensionUninstallDialogDelegateView::Layout() {
  int x = views::kPanelHorizMargin;
  int y = views::kPanelVertMargin;

  heading_->SizeToFit(kRightColumnWidth);

  if (heading_->height() <= kIconSize) {
    icon_->SetBounds(x, y, kIconSize, kIconSize);
    x += kIconSize;
    x += views::kPanelHorizMargin;

    heading_->SetX(x);
    heading_->SetY(y + (kIconSize - heading_->height()) / 2);
  } else {
    icon_->SetBounds(x,
                     y + (heading_->height() - kIconSize) / 2,
                     kIconSize,
                     kIconSize);
    x += kIconSize;
    x += views::kPanelHorizMargin;

    heading_->SetX(x);
    heading_->SetY(y);
  }
}

}  // namespace

// static
ExtensionUninstallDialog* ExtensionUninstallDialog::Create(
    Profile* profile, Delegate* delegate) {
  return new ExtensionUninstallDialogViews(profile, delegate);
}
<|endoftext|>


<commit_before>// Copyright 2015 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <chrono>
#include <memory>
#include <sstream>

#include "rclcpp/rclcpp.hpp"

using namespace std::chrono_literals;

void on_parameter_event(
  const rcl_interfaces::msg::ParameterEvent::SharedPtr event, rclcpp::Logger logger)
{
  // TODO(wjwwood): The message should have an operator<<, which would replace all of this.
  std::stringstream ss;
  ss << "\nParameter event:\n new parameters:";
  for (auto & new_parameter : event->new_parameters) {
    ss << "\n  " << new_parameter.name;
  }
  ss << "\n changed parameters:";
  for (auto & changed_parameter : event->changed_parameters) {
    ss << "\n  " << changed_parameter.name;
  }
  ss << "\n deleted parameters:";
  for (auto & deleted_parameter : event->deleted_parameters) {
    ss << "\n  " << deleted_parameter.name;
  }
  ss << "\n";
  RCLCPP_INFO(logger, ss.str().c_str());
}

int main(int argc, char ** argv)
{
  // Force flush of the stdout buffer.
  setvbuf(stdout, NULL, _IONBF, BUFSIZ);

  rclcpp::init(argc, argv);

  auto node = rclcpp::Node::make_shared("parameter_events");

  auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(node);
  while (!parameters_client->wait_for_service(1s)) {
    if (!rclcpp::ok()) {
      RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting.");
      return 0;
    }
    RCLCPP_INFO(node->get_logger(), "service not available, waiting again...");
  }

  // Setup callback for changes to parameters.
  auto sub = parameters_client->on_parameter_event(
    [node](const rcl_interfaces::msg::ParameterEvent::SharedPtr event) -> void
    {
      on_parameter_event(event, node->get_logger());
    });

  // Declare parameters that may be set on this node
  node->declare_parameter("foo");
  node->declare_parameter("bar");
  node->declare_parameter("baz");
  node->declare_parameter("foobar");

  // Set several different types of parameters.
  auto set_parameters_results = parameters_client->set_parameters({
    rclcpp::Parameter("foo", 2),
    rclcpp::Parameter("bar", "hello"),
    rclcpp::Parameter("baz", 1.45),
    rclcpp::Parameter("foobar", true),
  });

  // Change the value of some of them.
  set_parameters_results = parameters_client->set_parameters({
    rclcpp::Parameter("foo", 3),
    rclcpp::Parameter("bar", "world"),
  });

  // TODO(wjwwood): Create and use delete_parameter

  // TODO(hidmic): Fast-RTPS takes a significant amount of time to deliver
  //               requests and response, thus the rather long sleep. Reduce
  //               once that's resolved.
  rclcpp::sleep_for(3s);

  rclcpp::spin_some(node);

  rclcpp::shutdown();

  return 0;
}
<commit_msg>Use `spin_until_future_complete` instead of `spin_some` in parameters_event demo (#427)<commit_after>// Copyright 2015 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <chrono>
#include <future>
#include <memory>
#include <sstream>
#include <utility>

#include "rclcpp/rclcpp.hpp"

using namespace std::chrono_literals;

void on_parameter_event(
  const rcl_interfaces::msg::ParameterEvent::SharedPtr event, rclcpp::Logger logger)
{
  // TODO(wjwwood): The message should have an operator<<, which would replace all of this.
  std::stringstream ss;
  ss << "\nParameter event:\n new parameters:";
  for (auto & new_parameter : event->new_parameters) {
    ss << "\n  " << new_parameter.name;
  }
  ss << "\n changed parameters:";
  for (auto & changed_parameter : event->changed_parameters) {
    ss << "\n  " << changed_parameter.name;
  }
  ss << "\n deleted parameters:";
  for (auto & deleted_parameter : event->deleted_parameters) {
    ss << "\n  " << deleted_parameter.name;
  }
  ss << "\n";
  RCLCPP_INFO(logger, ss.str().c_str());
}

int main(int argc, char ** argv)
{
  // Force flush of the stdout buffer.
  setvbuf(stdout, NULL, _IONBF, BUFSIZ);

  rclcpp::init(argc, argv);

  auto node = rclcpp::Node::make_shared("parameter_events");

  auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(node);
  while (!parameters_client->wait_for_service(1s)) {
    if (!rclcpp::ok()) {
      RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting.");
      return 0;
    }
    RCLCPP_INFO(node->get_logger(), "service not available, waiting again...");
  }

  auto events_received_promise = std::make_shared<std::promise<void>>();
  auto events_received_future = events_received_promise->get_future();

  // Setup callback for changes to parameters.
  auto sub = parameters_client->on_parameter_event(
    [node, promise = std::move(events_received_promise)](
      const rcl_interfaces::msg::ParameterEvent::SharedPtr event) -> void
    {
      static size_t n_times_called = 0u;
      on_parameter_event(event, node->get_logger());
      if (10u == ++n_times_called) {
        // This callback will be called 10 times, set the promise when that happens.
        promise->set_value();
      }
    });

  // Declare parameters that may be set on this node
  node->declare_parameter("foo");
  node->declare_parameter("bar");
  node->declare_parameter("baz");
  node->declare_parameter("foobar");

  // Set several different types of parameters.
  auto set_parameters_results = parameters_client->set_parameters({
    rclcpp::Parameter("foo", 2),
    rclcpp::Parameter("bar", "hello"),
    rclcpp::Parameter("baz", 1.45),
    rclcpp::Parameter("foobar", true),
  });

  // Change the value of some of them.
  set_parameters_results = parameters_client->set_parameters({
    rclcpp::Parameter("foo", 3),
    rclcpp::Parameter("bar", "world"),
  });

  // TODO(wjwwood): Create and use delete_parameter

  rclcpp::spin_until_future_complete(node, events_received_future.share());
  rclcpp::shutdown();

  return 0;
}
<|endoftext|>


<commit_before>#include "LogobotText.h"

namespace LogobotText
{
	// Namespace containing private functions
	namespace
	{
		float fontSize;  // =em, equal to line spacing (between baselines), text sizes derived from this
		float capHeight;
		float letterSpacing;
		float w;

		CommandQueue * _cmdQ;

		void pushCmd(String cmd)
		{
			_cmdQ->enqueue(cmd, 0xff);
		}

		void pushTo(float x, float y)
		{
			String s = "TO ";
			s += x;
			s += " ";
			s += y;
			pushCmd(s);
		}

		// Alphabet
		void writeA(float x, float y)
		{
			pushCmd("PD");
			pushTo(x + w/2, y + capHeight);
			pushTo(x + w, y);
			pushCmd("PU");
			pushTo(x + w / 4, y + capHeight / 2);
			pushCmd("PD");
			pushTo(x + 3 * w / 4, y + capHeight / 2 );
		}

		void writeB(float x, float y)
		{
			pushCmd("PD");
			pushTo(x + 2 * w / 3, y);
			pushTo(x + w, y + capHeight / 4);
			pushTo(x + 2 * w / 3, y + capHeight / 2);
			pushTo(x + w, y + 3 * capHeight / 4);
			pushTo(x + 2 * w / 3, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x, y);
		}

		void writeC(float x, float y)
		{
			pushTo(x + w, y + capHeight);
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushTo(x, y);
			pushTo(x + w, y);
		}

		void writeD(float x, float y)
		{
			pushCmd("PD");
			pushTo(x + 3 * w / 4, y);
			pushTo(x + w, y + capHeight / 4);
			pushTo(x + w, y + 3 * capHeight / 4);
			pushTo(x + 3 * w / 4, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x, y);
		}

		void writeE(float x, float y)
		{
			writeC(x, y);
			pushCmd("PU");
			pushTo(x, y + capHeight / 2);
			pushCmd("PD");
			pushTo(x + w, y + capHeight /2);
		}

		void writeF(float x, float y)
		{
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushTo(x + w, y + capHeight);
			pushCmd("PU");
			pushTo(x + w, y + capHeight / 2);
			pushCmd("PD");
			pushTo(x, y + capHeight / 2);
		}

		void writeG(float x, float y)
		{
			pushTo(x + w, y + capHeight);
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushTo(x, y);
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight/3);
			pushTo(x + w/3, y + capHeight/3);
		}

		void writeH(float x, float y)
		{
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushTo(x, y + capHeight / 2);
			pushTo(x + w, y + capHeight / 2);
			pushTo(x + w, y + capHeight);
			pushTo(x + w, y);
		}

		void writeI(float x, float y)
		{
			pushTo(x + w / 2, y);
			pushCmd("PD");
			pushTo(x + w / 2, y + capHeight);
		}

		void writeJ(float x, float y)
		{
			pushTo(x, y + capHeight / 4);
			pushCmd("PD");
			pushTo(x, y);
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight);
		}

		void writeK(float x, float y)
		{
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushCmd("PU");
			pushTo(x + w, y + capHeight);
			pushCmd("PD");
			pushTo(x, y + capHeight / 2);
			pushTo(x + w, y);
		}

		void writeL(float x, float y)
		{
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushTo(x,y);
			pushTo(x + w, y);
		}

		void writeM(float x, float y)
		{
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushTo(x + w / 2, y + capHeight / 2);
			pushTo(x + w, y + capHeight);
			pushTo(x + w, y);
		}

		void writeN(float x, float y)
		{
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight);

		}

		void writeO(float x, float y)
		{
			pushCmd("PD");
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x, y);
		}

		void writeP(float x, float y)
		{
			pushCmd("PD");
			pushTo(x, y + capHeight);
			pushTo(x + w, y + capHeight);
			pushTo(x + w, y + capHeight / 2);
			pushTo(x, y + capHeight / 2);
		}

		void writeQ(float x, float y)
		{
			pushCmd("PD");
			pushTo(x + w / 2, y);
			pushTo(x + w, y + capHeight / 2);
			pushTo(x + w, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x, y);
			pushCmd("PU");
			pushTo(x + w / 2, y + capHeight / 2);
			pushCmd("PD");
			pushTo(x + w, y);
		}

		void writeR(float x, float y)
		{
			writeP(x, y);
			pushTo(x + w, y);
		}

		void writeS(float x, float y)
		{
			pushCmd("PD");
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight / 2);
			pushTo(x, y + capHeight / 2);
			pushTo(x, y + capHeight);
			pushTo(x + w, y + capHeight);
		}

		void writeT(float x, float y)
		{
			pushTo(x + w/2, y);
			pushCmd("PD");
			pushTo(x + w/2, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x + w, y + capHeight);
		}

		void writeU(float x, float y)
		{
			pushTo(x, y + capHeight);
			pushCmd("PD");
			pushTo(x, y);
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight);
		}

		void writeV(float x, float y)
		{
			pushTo(x, y + capHeight);
			pushCmd("PD");
			pushTo(x + w / 2, y);
			pushTo(x + w, y + capHeight);
		}

		void writeW(float x, float y)
		{
			pushTo(x, y + capHeight);
			pushCmd("PD");
			pushTo(x + w / 4, y);
			pushTo(x + w / 2, y + capHeight / 2);
			pushTo(x + 3 * w / 4, y);
			pushTo(x + w, y + capHeight);
		}

		void writeX(float x, float y)
		{
			pushCmd("PD");
			pushTo(x + w, y + capHeight);
			pushCmd("PU");
			pushTo(x, y + capHeight);
			pushCmd("PD");
			pushTo(x + w, y);
		}

		void writeY(float x, float y)
		{
			pushCmd("PD");
			pushTo(x + w, y + capHeight);
			pushCmd("PU");
			pushTo(x, y + capHeight);
			pushCmd("PD");
			pushTo(x + w / 2, y + capHeight / 2);
		}

		void writeZ(float x, float y)
		{
			pushTo(x, y + capHeight);
			pushCmd("PD");
			pushTo(x + w, y + capHeight);
			pushTo(x, y);
			pushTo(x + w, y);
		}

		void writeColon(float x, float y)
		{
			pushTo(x + w/3, y + capHeight/3);
			pushCmd("PD");
			pushTo(x + 2*w/3, y + capHeight/3);
			pushCmd("PU");
			pushTo(x + 2*w/3, y + 2*capHeight/3);
			pushCmd("PD");
			pushTo(x + w/3, y + 2*capHeight/3);
		}

		void writeCloseBracket(float x, float y)
		{
			pushTo(x + w/3, y);
			pushCmd("PD");
			pushTo(x + 2*w/3, y + capHeight/4);
			pushTo(x + w, y + capHeight/2);
			pushTo(x + 2*w/3, y + 3*capHeight/4);
			pushTo(x + w/3, y + capHeight);
		}

		void writeHash(float x, float y)
		{
			pushTo(x, y + capHeight/3);
			pushCmd("PD");
			pushTo(x + w, y + capHeight/3);
			pushCmd("PU");
			pushTo(x + w, y + 2*capHeight/3);
			pushCmd("PD");
			pushTo(x, y + 2*capHeight/3);
			pushCmd("PU");

			pushTo(x + w/3, y + capHeight);
			pushCmd("PD");
			pushTo(x + w/3, y);
			pushCmd("PU");
			pushTo(x + 2*w/3, y);
			pushCmd("PD");
			pushTo(x + 2*w/3, y + capHeight);
		}
	}
	// End private namespace functions

	// Logobot text public functions
	void begin(CommandQueue& cmdQ)
	{
		_cmdQ = &cmdQ;
		setFontSize(20);
	}

	void setFontSize(float size)
	{
		fontSize = size;
		capHeight = fontSize * 0.7;
		letterSpacing = fontSize * 0.1;
		w = fontSize * 0.5;
	}

	void writeChar(char c, float x, float y)
	{
		switch (c) {
			case 'A':
				writeA(x, y);
				break;
			case 'B':
				writeB(x, y);
				break;
			case 'C':
				writeC(x, y);
				break;
			case 'D':
				writeD(x, y);
				break;
			case 'E':
				writeE(x, y);
				break;
			case 'F':
				writeF(x, y);
				break;
			case 'G':
				writeG(x, y);
				break;
			case 'H':
				writeH(x, y);
				break;
			case 'I':
				writeI(x, y);
				break;
			case 'J':
				writeJ(x, y);
				break;
			case 'K':
				writeK(x, y);
				break;
			case 'L':
				writeL(x, y);
				break;
			case 'M':
				writeM(x, y);
				break;
			case 'N':
				writeN(x, y);
				break;
			case 'O':
				writeO(x, y);
				break;
			case 'P':
				writeP(x, y);
				break;
			case 'Q':
				writeQ(x, y);
				break;
			case 'R':
				writeR(x, y);
				break;
			case 'S':
				writeS(x, y);
				break;
			case 'T':
				writeT(x, y);
				break;
			case 'U':
				writeU(x, y);
				break;
			case 'V':
				writeV(x, y);
				break;
			case 'W':
				writeW(x, y);
				break;
			case 'X':
				writeX(x, y);
				break;
			case 'Y':
				writeY(x, y);
				break;
			case 'Z':
				writeZ(x, y);
				break;
			case ' ':
				// nothing to do, just move to next letter
				break;
			case ':':
				writeColon(x,y);
				break;
			case ')':
				writeCloseBracket(x,y);
				break;
			case '#':
				writeHash(x,y);
				break;

			default:
				pushCmd("BZ 500");
				return;
		}

		pushCmd("PU");
		pushTo(x + w + letterSpacing, y);
	}
}
<commit_msg>Space optimisation<commit_after>#include "LogobotText.h"

// local copy of critical command defines - for space optimisation
#define LOGO_CMD_BZ			8
#define LOGO_CMD_PU			9
#define LOGO_CMD_PD			10

namespace LogobotText
{
	// Namespace containing private functions
	namespace
	{
		float fontSize;  // =em, equal to line spacing (between baselines), text sizes derived from this
		float capHeight;
		float letterSpacing;
		float w;

		CommandQueue * _cmdQ;

		void pushCmd(String cmd)
		{
			_cmdQ->enqueue(cmd, 0xff);
		}

		void pushPU() {
			_cmdQ->enqueue("", LOGO_CMD_PU);
		}

		void pushPD() {
			_cmdQ->enqueue("", LOGO_CMD_PD);
		}

		void pushTo(float x, float y)
		{
			String s = "TO ";
			s += x;
			s += " ";
			s += y;
			pushCmd(s);
		}

		// Alphabet
		void writeA(float x, float y)
		{
			pushPD();
			pushTo(x + w/2, y + capHeight);
			pushTo(x + w, y);
			pushPU();
			pushTo(x + w / 4, y + capHeight / 2);
			pushPD();
			pushTo(x + 3 * w / 4, y + capHeight / 2 );
		}

		void writeB(float x, float y)
		{
			pushPD();
			pushTo(x + 2 * w / 3, y);
			pushTo(x + w, y + capHeight / 4);
			pushTo(x + 2 * w / 3, y + capHeight / 2);
			pushTo(x + w, y + 3 * capHeight / 4);
			pushTo(x + 2 * w / 3, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x, y);
		}

		void writeC(float x, float y)
		{
			pushTo(x + w, y + capHeight);
			pushPD();
			pushTo(x, y + capHeight);
			pushTo(x, y);
			pushTo(x + w, y);
		}

		void writeD(float x, float y)
		{
			pushPD();
			pushTo(x + 3 * w / 4, y);
			pushTo(x + w, y + capHeight / 4);
			pushTo(x + w, y + 3 * capHeight / 4);
			pushTo(x + 3 * w / 4, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x, y);
		}

		void writeE(float x, float y)
		{
			writeC(x, y);
			pushPU();
			pushTo(x, y + capHeight / 2);
			pushPD();
			pushTo(x + w, y + capHeight /2);
		}

		void writeF(float x, float y)
		{
			pushPD();
			pushTo(x, y + capHeight);
			pushTo(x + w, y + capHeight);
			pushPU();
			pushTo(x + w, y + capHeight / 2);
			pushPD();
			pushTo(x, y + capHeight / 2);
		}

		void writeG(float x, float y)
		{
			pushTo(x + w, y + capHeight);
			pushPD();
			pushTo(x, y + capHeight);
			pushTo(x, y);
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight/3);
			pushTo(x + w/3, y + capHeight/3);
		}

		void writeH(float x, float y)
		{
			pushPD();
			pushTo(x, y + capHeight);
			pushTo(x, y + capHeight / 2);
			pushTo(x + w, y + capHeight / 2);
			pushTo(x + w, y + capHeight);
			pushTo(x + w, y);
		}

		void writeI(float x, float y)
		{
			pushTo(x + w / 2, y);
			pushPD();
			pushTo(x + w / 2, y + capHeight);
		}

		void writeJ(float x, float y)
		{
			pushTo(x, y + capHeight / 4);
			pushPD();
			pushTo(x, y);
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight);
		}

		void writeK(float x, float y)
		{
			pushPD();
			pushTo(x, y + capHeight);
			pushPU();
			pushTo(x + w, y + capHeight);
			pushPD();
			pushTo(x, y + capHeight / 2);
			pushTo(x + w, y);
		}

		void writeL(float x, float y)
		{
			pushPD();
			pushTo(x, y + capHeight);
			pushTo(x,y);
			pushTo(x + w, y);
		}

		void writeM(float x, float y)
		{
			pushPD();
			pushTo(x, y + capHeight);
			pushTo(x + w / 2, y + capHeight / 2);
			pushTo(x + w, y + capHeight);
			pushTo(x + w, y);
		}

		void writeN(float x, float y)
		{
			pushPD();
			pushTo(x, y + capHeight);
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight);

		}

		void writeO(float x, float y)
		{
			pushPD();
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x, y);
		}

		void writeP(float x, float y)
		{
			pushPD();
			pushTo(x, y + capHeight);
			pushTo(x + w, y + capHeight);
			pushTo(x + w, y + capHeight / 2);
			pushTo(x, y + capHeight / 2);
		}

		void writeQ(float x, float y)
		{
			pushPD();
			pushTo(x + w / 2, y);
			pushTo(x + w, y + capHeight / 2);
			pushTo(x + w, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x, y);
			pushPU();
			pushTo(x + w / 2, y + capHeight / 2);
			pushPD();
			pushTo(x + w, y);
		}

		void writeR(float x, float y)
		{
			writeP(x, y);
			pushTo(x + w, y);
		}

		void writeS(float x, float y)
		{
			pushPD();
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight / 2);
			pushTo(x, y + capHeight / 2);
			pushTo(x, y + capHeight);
			pushTo(x + w, y + capHeight);
		}

		void writeT(float x, float y)
		{
			pushTo(x + w/2, y);
			pushPD();
			pushTo(x + w/2, y + capHeight);
			pushTo(x, y + capHeight);
			pushTo(x + w, y + capHeight);
		}

		void writeU(float x, float y)
		{
			pushTo(x, y + capHeight);
			pushPD();
			pushTo(x, y);
			pushTo(x + w, y);
			pushTo(x + w, y + capHeight);
		}

		void writeV(float x, float y)
		{
			pushTo(x, y + capHeight);
			pushPD();
			pushTo(x + w / 2, y);
			pushTo(x + w, y + capHeight);
		}

		void writeW(float x, float y)
		{
			pushTo(x, y + capHeight);
			pushPD();
			pushTo(x + w / 4, y);
			pushTo(x + w / 2, y + capHeight / 2);
			pushTo(x + 3 * w / 4, y);
			pushTo(x + w, y + capHeight);
		}

		void writeX(float x, float y)
		{
			pushPD();
			pushTo(x + w, y + capHeight);
			pushPU();
			pushTo(x, y + capHeight);
			pushPD();
			pushTo(x + w, y);
		}

		void writeY(float x, float y)
		{
			pushPD();
			pushTo(x + w, y + capHeight);
			pushPU();
			pushTo(x, y + capHeight);
			pushPD();
			pushTo(x + w / 2, y + capHeight / 2);
		}

		void writeZ(float x, float y)
		{
			pushTo(x, y + capHeight);
			pushPD();
			pushTo(x + w, y + capHeight);
			pushTo(x, y);
			pushTo(x + w, y);
		}

		void writeColon(float x, float y)
		{
			pushTo(x + w/3, y + capHeight/3);
			pushPD();
			pushTo(x + 2*w/3, y + capHeight/3);
			pushPU();
			pushTo(x + 2*w/3, y + 2*capHeight/3);
			pushPD();
			pushTo(x + w/3, y + 2*capHeight/3);
		}

		void writeCloseBracket(float x, float y)
		{
			pushTo(x + w/3, y);
			pushPD();
			pushTo(x + 2*w/3, y + capHeight/4);
			pushTo(x + w, y + capHeight/2);
			pushTo(x + 2*w/3, y + 3*capHeight/4);
			pushTo(x + w/3, y + capHeight);
		}

		void writeHash(float x, float y)
		{
			pushTo(x, y + capHeight/3);
			pushPD();
			pushTo(x + w, y + capHeight/3);
			pushPU();
			pushTo(x + w, y + 2*capHeight/3);
			pushPD();
			pushTo(x, y + 2*capHeight/3);
			pushPU();

			pushTo(x + w/3, y + capHeight);
			pushPD();
			pushTo(x + w/3, y);
			pushPU();
			pushTo(x + 2*w/3, y);
			pushPD();
			pushTo(x + 2*w/3, y + capHeight);
		}
	}
	// End private namespace functions

	// Logobot text public functions
	void begin(CommandQueue& cmdQ)
	{
		_cmdQ = &cmdQ;
		setFontSize(20);
	}

	void setFontSize(float size)
	{
		fontSize = size;
		capHeight = fontSize * 0.7;
		letterSpacing = fontSize * 0.1;
		w = fontSize * 0.5;
	}

	void writeChar(char c, float x, float y)
	{
		switch (c) {
			case 'A':
				writeA(x, y);
				break;
			case 'B':
				writeB(x, y);
				break;
			case 'C':
				writeC(x, y);
				break;
			case 'D':
				writeD(x, y);
				break;
			case 'E':
				writeE(x, y);
				break;
			case 'F':
				writeF(x, y);
				break;
			case 'G':
				writeG(x, y);
				break;
			case 'H':
				writeH(x, y);
				break;
			case 'I':
				writeI(x, y);
				break;
			case 'J':
				writeJ(x, y);
				break;
			case 'K':
				writeK(x, y);
				break;
			case 'L':
				writeL(x, y);
				break;
			case 'M':
				writeM(x, y);
				break;
			case 'N':
				writeN(x, y);
				break;
			case 'O':
				writeO(x, y);
				break;
			case 'P':
				writeP(x, y);
				break;
			case 'Q':
				writeQ(x, y);
				break;
			case 'R':
				writeR(x, y);
				break;
			case 'S':
				writeS(x, y);
				break;
			case 'T':
				writeT(x, y);
				break;
			case 'U':
				writeU(x, y);
				break;
			case 'V':
				writeV(x, y);
				break;
			case 'W':
				writeW(x, y);
				break;
			case 'X':
				writeX(x, y);
				break;
			case 'Y':
				writeY(x, y);
				break;
			case 'Z':
				writeZ(x, y);
				break;
			case ' ':
				// nothing to do, just move to next letter
				break;
			case ':':
				writeColon(x,y);
				break;
			case ')':
				writeCloseBracket(x,y);
				break;
			case '#':
				writeHash(x,y);
				break;

			default:
				_cmdQ->enqueue("500",LOGO_CMD_BZ);
				//pushCmd("BZ 500");
				return;
		}

		pushPU();
		pushTo(x + w + letterSpacing, y);
	}
}
<|endoftext|>


<commit_before>AliAnalysisTaskCharmFraction* AddTaskCharmFraction(
         const char* fileout="d0D0.root",
	 Bool_t sideband=kFALSE,
	 Bool_t setD0usecuts=kTRUE,
	 Bool_t setcheckMC=kTRUE,
	 Bool_t setcheckMC_prompt=kTRUE,
	 Bool_t setcheckMC_fromB=kFALSE,
	 Bool_t setcheckMC_D0=kTRUE,
	 Bool_t setcheckMC_2prongs=kTRUE,
	 Bool_t setSkipD0star=kTRUE,
	 Bool_t setStudyPureBack=kFALSE)
{
  //
  // Configuration macro for the task to analyze the fraction of prompt charm
  // using the D0 impact parameter
  // andrea.rossi@ts.infn.it
  //
  //==========================================================================
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskCharmFraction", "No analysis manager to connect to.");
    return NULL;
  }

  TString str=fileout,containername;
  str.ReplaceAll(".root","");
  str.Prepend("_");

  AliAnalysisTaskCharmFraction *hfTask;
  if(!sideband) {
    hfTask = new AliAnalysisTaskCharmFraction("CharmFraction",10);
  } else {
    hfTask= new AliAnalysisTaskCharmFraction("CharmFractionSideB",10);
    hfTask->SetSideBands(-2.);
  }

  hfTask->SetUseCuts(setD0usecuts);
  hfTask->SetCheckMC(setcheckMC);
  hfTask->SetCheckMC_D0(setcheckMC_D0);
  hfTask->SetCheckMC_2prongs(setcheckMC_2prongs);
  hfTask->SetCheckMC_prompt(setcheckMC_prompt);
  hfTask->SetCheckMC_fromB(setcheckMC_fromB);
  hfTask->SetCheckMC_fromDstar(setSkipD0star);
  hfTask->SetStudyPureBackground(setStudyPureBack);
  //  hfTask->SetSideBands(0);
  //  hfTask->SetDebugLevel(2);
  mgr->AddTask(hfTask);

  //Now the same for sidebands
  /*AliAnalysisTaskCharmFraction *hfTaskSideB

  hfTaskSideB->SetUseCuts(fD0usecuts);
  hfTaskSideB->SetCheckMC(fcheckMC);
  hfTaskSideB->SetCheckMC_D0(fcheckMC_D0);
  hfTaskSideB->SetCheckMC_2prongs(fcheckMC_2prongs);
  hfTaskSideB->SetCheckMC_prompt(fcheckMC_prompt);
  hfTaskSideB->SetCheckMC_fromB(fcheckMC_fromB);
  hfTaskSideB->SetCheckMC_fromDstar(fSkipD0star);
  hfTaskSideB->SetStudyPureBackground(fStudyPureBack);

  //  hfTaskSideB->SetDebugLevel(2);
  mgr->AddTask(hfTaskSideB);
  */

  // Create containers for input/output
  AliAnalysisDataContainer *cinput =   mgr->GetCommonInputContainer();//mgr->CreateContainer("cinput",TChain::Class(),AliAnalysisManager::kInputContainer);
  mgr->ConnectInput(hfTask,0,cinput);
  //  mgr->ConnectInput(hfTaskSideB,0,cinput);

  //Now container for general properties histograms
  containername="coutputCptd0d0";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputCptd0d0 = mgr->CreateContainer(containername.Data(),TH2::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,0,coutputCptd0d0);

  containername="coutputSecVtxXY";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSecVtxXY = mgr->CreateContainer(containername.Data(),TH2::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,1,coutputSecVtxXY);

  containername="coutputd0d0";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputd0d0 = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,2,coutputd0d0);

  containername="coutputCpt";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputCpt = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,3,coutputCpt);

  containername="coutputSecVtxZ";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSecVtxZ = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,4,coutputSecVtxZ);

  containername="coutputSecVtxX";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSecVtxX = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,5,coutputSecVtxX);

  containername="coutputSecVtxY";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSecVtxY = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,6,coutputSecVtxY);

  containername="coutputSecVtxPhi";
  containername.Append(str.Data());
 AliAnalysisDataContainer *coutputSecVtxPhi = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,7,coutputSecVtxPhi);

  //Now container for d0D0
  AliAnalysisDataContainer **coutput=new AliAnalysisDataContainer*[10];
  containername="coutputAll";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputAll = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);

  TString name="coutput";
  for(Int_t j=0;j<10;j++){
    containername=name;
    containername+=j;
    containername.Append(str.Data());
    coutput[j] = mgr->CreateContainer(containername.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      fileout);

    mgr->ConnectOutput(hfTask,j+8,coutput[j]);
  }
  mgr->ConnectOutput(hfTask,18,coutputAll);
  //Now container for MC d0D0
  AliAnalysisDataContainer **coutputMC=new AliAnalysisDataContainer*[10];
  containername="coutputAllMC";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputAllMC = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);

  name="coutputMC";
  for(Int_t j=0;j<10;j++){
    containername=name;
    containername+=j;
    containername.Append(str.Data());
    coutputMC[j] = mgr->CreateContainer(containername.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      fileout);

    mgr->ConnectOutput(hfTask,j+19,coutputMC[j]);
  }
  mgr->ConnectOutput(hfTask,29,coutputAllMC);

  //Now container for histo with d0 with respect to True Vtx
  AliAnalysisDataContainer **coutputd0VtxTrue=new AliAnalysisDataContainer*[10];
  containername="coutputd0VtxTrueAll";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputd0VtxTrueAll = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);

  name="coutputd0VtxTrue";
  for(Int_t j=0;j<10;j++){
    containername=name;
    containername+=j;
    containername.Append(str.Data());
    coutputd0VtxTrue[j] = mgr->CreateContainer(containername.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      fileout);

    mgr->ConnectOutput(hfTask,j+30,coutputd0VtxTrue[j]);
  }
  mgr->ConnectOutput(hfTask,40,coutputd0VtxTrueAll);
  //INV MASS
  containername="coutputD0InvMassAll";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputD0InvMassAll = mgr->CreateContainer(containername.Data(),TH1::Class(),
								       AliAnalysisManager::kOutputContainer,
								       fileout);
  mgr->ConnectOutput(hfTask,41,coutputD0InvMassAll);
  containername="coutputD0MCInvMassAll";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputD0MCInvMassAll = mgr->CreateContainer(containername.Data(),TH1::Class(),
									 AliAnalysisManager::kOutputContainer,
									 fileout);
  mgr->ConnectOutput(hfTask,42,coutputD0MCInvMassAll);

 ////////
 //NOW THE SAME FOR SIDE BANDS
 /*
 //Now container for general properties histograms

 AliAnalysisDataContainer *coutputSBCptd0d0 = mgr->CreateContainer("coutputSBCptd0d0",TH2::Class(),
								   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
 mgr->ConnectOutput(hfTaskSideB,0,coutputSBCptd0d0);

  AliAnalysisDataContainer *coutputSBSecVtxXY = mgr->CreateContainer("coutputSBSecVtxXY",TH2::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,1,coutputSBSecVtxXY);

  AliAnalysisDataContainer *coutputSBd0d0 = mgr->CreateContainer("coutputSBd0d0",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,2,coutputSBd0d0);

  AliAnalysisDataContainer *coutputSBCpt = mgr->CreateContainer("coutputSBCpt",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,3,coutputSBCpt);

  AliAnalysisDataContainer *coutputSBSecVtxZ = mgr->CreateContainer("coutputSBSecVtxZ",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,4,coutputSBSecVtxZ);

  AliAnalysisDataContainer *coutputSBSecVtxX = mgr->CreateContainer("coutputSBSecVtxX",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,5,coutputSBSecVtxX);

  AliAnalysisDataContainer *coutputSBSecVtxY = mgr->CreateContainer("coutputSBSecVtxY",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,6,coutputSBSecVtxY);

 AliAnalysisDataContainer *coutputSBSecVtxPhi = mgr->CreateContainer("coutputSBSecVtxPhi",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,7,coutputSBSecVtxPhi);

  //Now container for d0D0SideB
  AliAnalysisDataContainer **coutputSB=new AliAnalysisDataContainer*[10];
  AliAnalysisDataContainer *coutputSBAll = mgr->CreateContainer("coutputSBAll",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");

  TString name="coutputSB",strname;
  for(Int_t j=0;j<10;j++){
    strname=name;
    strname+=j;
    coutputSB[j] = mgr->CreateContainer(strname.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      "d0D0SideB.root");

    mgr->ConnectOutput(hfTaskSideB,j+8,coutputSB[j]);
  }
  mgr->ConnectOutput(hfTaskSideB,18,coutputSBAll);
  //Now container for MC d0D0SideB
  AliAnalysisDataContainer **coutputSBMC=new AliAnalysisDataContainer*[10];
  AliAnalysisDataContainer *coutputSBAllMC = mgr->CreateContainer("coutputSBAllMC",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");

  name="coutputSBMC";
  for(Int_t j=0;j<10;j++){
    strname=name;
    strname+=j;
    coutputSBMC[j] = mgr->CreateContainer(strname.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      "d0D0SideB.root");

    mgr->ConnectOutput(hfTaskSideB,j+19,coutputSBMC[j]);
  }
  mgr->ConnectOutput(hfTaskSideB,29,coutputSBAllMC);

  //Now container for histo with d0 with respect to True Vtx
  AliAnalysisDataContainer **coutputSBd0VtxTrue=new AliAnalysisDataContainer*[10];
  AliAnalysisDataContainer *coutputSBd0VtxTrueAll = mgr->CreateContainer("coutputSBd0VtxTrueAll",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");

  name="coutputSBd0VtxTrue";
  for(Int_t j=0;j<10;j++){
    strname=name;
    strname+=j;
    coutputSBd0VtxTrue[j] = mgr->CreateContainer(strname.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      "d0D0SideB.root");

    mgr->ConnectOutput(hfTaskSideB,j+30,coutputSBd0VtxTrue[j]);
  }
  mgr->ConnectOutput(hfTaskSideB,40,coutputSBd0VtxTrueAll);

//INV MASS
 AliAnalysisDataContainer *coutputSBD0InvMassAll = mgr->CreateContainer("coutputSBD0InvMassAll",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
 mgr->ConnectOutput(hfTaskSideB,41,coutputSBD0InvMassAll);

 AliAnalysisDataContainer *coutputSBD0MCInvMassAll = mgr->CreateContainer("coutputSBD0MCInvMassAll",TH1::Class(),
								      AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
 mgr->ConnectOutput(hfTaskSideB,42,coutputSBD0MCInvMassAll);

 */

  return hfTask;
}
<commit_msg>Changed default value (no D*+ rejection) Andrea R<commit_after>AliAnalysisTaskCharmFraction* AddTaskCharmFraction(
         const char* fileout="d0D0.root",
	 Bool_t sideband=kFALSE,
	 Bool_t setD0usecuts=kTRUE,
	 Bool_t setcheckMC=kTRUE,
	 Bool_t setcheckMC_prompt=kTRUE,
	 Bool_t setcheckMC_fromB=kFALSE,
	 Bool_t setcheckMC_D0=kTRUE,
	 Bool_t setcheckMC_2prongs=kTRUE,
	 Bool_t setSkipD0star=kFALSE,
	 Bool_t setStudyPureBack=kFALSE)
{
  //
  // Configuration macro for the task to analyze the fraction of prompt charm
  // using the D0 impact parameter
  // andrea.rossi@ts.infn.it
  //
  //==========================================================================
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskCharmFraction", "No analysis manager to connect to.");
    return NULL;
  }

  TString str=fileout,containername;
  str.ReplaceAll(".root","");
  str.Prepend("_");

  AliAnalysisTaskCharmFraction *hfTask;
  if(!sideband) {
    hfTask = new AliAnalysisTaskCharmFraction("CharmFraction",10);
  } else {
    hfTask= new AliAnalysisTaskCharmFraction("CharmFractionSideB",10);
    hfTask->SetSideBands(-2.);
  }

  hfTask->SetUseCuts(setD0usecuts);
  hfTask->SetCheckMC(setcheckMC);
  hfTask->SetCheckMC_D0(setcheckMC_D0);
  hfTask->SetCheckMC_2prongs(setcheckMC_2prongs);
  hfTask->SetCheckMC_prompt(setcheckMC_prompt);
  hfTask->SetCheckMC_fromB(setcheckMC_fromB);
  hfTask->SetCheckMC_fromDstar(setSkipD0star);
  hfTask->SetStudyPureBackground(setStudyPureBack);
  //  hfTask->SetSideBands(0);
  //  hfTask->SetDebugLevel(2);
  mgr->AddTask(hfTask);

  //Now the same for sidebands
  /*AliAnalysisTaskCharmFraction *hfTaskSideB

  hfTaskSideB->SetUseCuts(fD0usecuts);
  hfTaskSideB->SetCheckMC(fcheckMC);
  hfTaskSideB->SetCheckMC_D0(fcheckMC_D0);
  hfTaskSideB->SetCheckMC_2prongs(fcheckMC_2prongs);
  hfTaskSideB->SetCheckMC_prompt(fcheckMC_prompt);
  hfTaskSideB->SetCheckMC_fromB(fcheckMC_fromB);
  hfTaskSideB->SetCheckMC_fromDstar(fSkipD0star);
  hfTaskSideB->SetStudyPureBackground(fStudyPureBack);

  //  hfTaskSideB->SetDebugLevel(2);
  mgr->AddTask(hfTaskSideB);
  */

  // Create containers for input/output
  AliAnalysisDataContainer *cinput =   mgr->GetCommonInputContainer();//mgr->CreateContainer("cinput",TChain::Class(),AliAnalysisManager::kInputContainer);
  mgr->ConnectInput(hfTask,0,cinput);
  //  mgr->ConnectInput(hfTaskSideB,0,cinput);

  //Now container for general properties histograms
  containername="coutputCptd0d0";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputCptd0d0 = mgr->CreateContainer(containername.Data(),TH2::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,0,coutputCptd0d0);

  containername="coutputSecVtxXY";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSecVtxXY = mgr->CreateContainer(containername.Data(),TH2::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,1,coutputSecVtxXY);

  containername="coutputd0d0";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputd0d0 = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,2,coutputd0d0);

  containername="coutputCpt";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputCpt = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,3,coutputCpt);

  containername="coutputSecVtxZ";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSecVtxZ = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,4,coutputSecVtxZ);

  containername="coutputSecVtxX";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSecVtxX = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,5,coutputSecVtxX);

  containername="coutputSecVtxY";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSecVtxY = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,6,coutputSecVtxY);

  containername="coutputSecVtxPhi";
  containername.Append(str.Data());
 AliAnalysisDataContainer *coutputSecVtxPhi = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);
  mgr->ConnectOutput(hfTask,7,coutputSecVtxPhi);

  //Now container for d0D0
  AliAnalysisDataContainer **coutput=new AliAnalysisDataContainer*[10];
  containername="coutputAll";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputAll = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);

  TString name="coutput";
  for(Int_t j=0;j<10;j++){
    containername=name;
    containername+=j;
    containername.Append(str.Data());
    coutput[j] = mgr->CreateContainer(containername.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      fileout);

    mgr->ConnectOutput(hfTask,j+8,coutput[j]);
  }
  mgr->ConnectOutput(hfTask,18,coutputAll);
  //Now container for MC d0D0
  AliAnalysisDataContainer **coutputMC=new AliAnalysisDataContainer*[10];
  containername="coutputAllMC";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputAllMC = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);

  name="coutputMC";
  for(Int_t j=0;j<10;j++){
    containername=name;
    containername+=j;
    containername.Append(str.Data());
    coutputMC[j] = mgr->CreateContainer(containername.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      fileout);

    mgr->ConnectOutput(hfTask,j+19,coutputMC[j]);
  }
  mgr->ConnectOutput(hfTask,29,coutputAllMC);

  //Now container for histo with d0 with respect to True Vtx
  AliAnalysisDataContainer **coutputd0VtxTrue=new AliAnalysisDataContainer*[10];
  containername="coutputd0VtxTrueAll";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputd0VtxTrueAll = mgr->CreateContainer(containername.Data(),TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   fileout);

  name="coutputd0VtxTrue";
  for(Int_t j=0;j<10;j++){
    containername=name;
    containername+=j;
    containername.Append(str.Data());
    coutputd0VtxTrue[j] = mgr->CreateContainer(containername.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      fileout);

    mgr->ConnectOutput(hfTask,j+30,coutputd0VtxTrue[j]);
  }
  mgr->ConnectOutput(hfTask,40,coutputd0VtxTrueAll);
  //INV MASS
  containername="coutputD0InvMassAll";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputD0InvMassAll = mgr->CreateContainer(containername.Data(),TH1::Class(),
								       AliAnalysisManager::kOutputContainer,
								       fileout);
  mgr->ConnectOutput(hfTask,41,coutputD0InvMassAll);
  containername="coutputD0MCInvMassAll";
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputD0MCInvMassAll = mgr->CreateContainer(containername.Data(),TH1::Class(),
									 AliAnalysisManager::kOutputContainer,
									 fileout);
  mgr->ConnectOutput(hfTask,42,coutputD0MCInvMassAll);

 ////////
 //NOW THE SAME FOR SIDE BANDS
 /*
 //Now container for general properties histograms

 AliAnalysisDataContainer *coutputSBCptd0d0 = mgr->CreateContainer("coutputSBCptd0d0",TH2::Class(),
								   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
 mgr->ConnectOutput(hfTaskSideB,0,coutputSBCptd0d0);

  AliAnalysisDataContainer *coutputSBSecVtxXY = mgr->CreateContainer("coutputSBSecVtxXY",TH2::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,1,coutputSBSecVtxXY);

  AliAnalysisDataContainer *coutputSBd0d0 = mgr->CreateContainer("coutputSBd0d0",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,2,coutputSBd0d0);

  AliAnalysisDataContainer *coutputSBCpt = mgr->CreateContainer("coutputSBCpt",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,3,coutputSBCpt);

  AliAnalysisDataContainer *coutputSBSecVtxZ = mgr->CreateContainer("coutputSBSecVtxZ",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,4,coutputSBSecVtxZ);

  AliAnalysisDataContainer *coutputSBSecVtxX = mgr->CreateContainer("coutputSBSecVtxX",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,5,coutputSBSecVtxX);

  AliAnalysisDataContainer *coutputSBSecVtxY = mgr->CreateContainer("coutputSBSecVtxY",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,6,coutputSBSecVtxY);

 AliAnalysisDataContainer *coutputSBSecVtxPhi = mgr->CreateContainer("coutputSBSecVtxPhi",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
  mgr->ConnectOutput(hfTaskSideB,7,coutputSBSecVtxPhi);

  //Now container for d0D0SideB
  AliAnalysisDataContainer **coutputSB=new AliAnalysisDataContainer*[10];
  AliAnalysisDataContainer *coutputSBAll = mgr->CreateContainer("coutputSBAll",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");

  TString name="coutputSB",strname;
  for(Int_t j=0;j<10;j++){
    strname=name;
    strname+=j;
    coutputSB[j] = mgr->CreateContainer(strname.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      "d0D0SideB.root");

    mgr->ConnectOutput(hfTaskSideB,j+8,coutputSB[j]);
  }
  mgr->ConnectOutput(hfTaskSideB,18,coutputSBAll);
  //Now container for MC d0D0SideB
  AliAnalysisDataContainer **coutputSBMC=new AliAnalysisDataContainer*[10];
  AliAnalysisDataContainer *coutputSBAllMC = mgr->CreateContainer("coutputSBAllMC",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");

  name="coutputSBMC";
  for(Int_t j=0;j<10;j++){
    strname=name;
    strname+=j;
    coutputSBMC[j] = mgr->CreateContainer(strname.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      "d0D0SideB.root");

    mgr->ConnectOutput(hfTaskSideB,j+19,coutputSBMC[j]);
  }
  mgr->ConnectOutput(hfTaskSideB,29,coutputSBAllMC);

  //Now container for histo with d0 with respect to True Vtx
  AliAnalysisDataContainer **coutputSBd0VtxTrue=new AliAnalysisDataContainer*[10];
  AliAnalysisDataContainer *coutputSBd0VtxTrueAll = mgr->CreateContainer("coutputSBd0VtxTrueAll",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");

  name="coutputSBd0VtxTrue";
  for(Int_t j=0;j<10;j++){
    strname=name;
    strname+=j;
    coutputSBd0VtxTrue[j] = mgr->CreateContainer(strname.Data(),TH1::Class(),
				      AliAnalysisManager::kOutputContainer,
				      "d0D0SideB.root");

    mgr->ConnectOutput(hfTaskSideB,j+30,coutputSBd0VtxTrue[j]);
  }
  mgr->ConnectOutput(hfTaskSideB,40,coutputSBd0VtxTrueAll);

//INV MASS
 AliAnalysisDataContainer *coutputSBD0InvMassAll = mgr->CreateContainer("coutputSBD0InvMassAll",TH1::Class(),
							   AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
 mgr->ConnectOutput(hfTaskSideB,41,coutputSBD0InvMassAll);

 AliAnalysisDataContainer *coutputSBD0MCInvMassAll = mgr->CreateContainer("coutputSBD0MCInvMassAll",TH1::Class(),
								      AliAnalysisManager::kOutputContainer,
							   "d0D0SideB.root");
 mgr->ConnectOutput(hfTaskSideB,42,coutputSBD0MCInvMassAll);

 */

  return hfTask;
}
<|endoftext|>