<commit_before>/* libs/graphics/effects/SkBlurMask.cpp
**
** Copyright 2006, The Android Open Source Project
**
** 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 "SkBlurMask.h"
#include "SkTemplates.h"

static void build_sum_buffer(uint32_t dst[], int w, int h, const uint8_t src[], int srcRB)
{
    SkASSERT(srcRB >= w);
    // mod srcRB so we can apply it after each row
    srcRB -= w;

    int x, y;

    // special case first row
    uint32_t X = 0;
    for (x = w - 1; x >= 0; --x)
    {
        X = *src++ + X;
        *dst++ = X;
    }
    src += srcRB;

    // now do the rest of the rows
    for (y = h - 1; y > 0; --y)
    {
        uint32_t L = 0;
        uint32_t C = 0;
        for (x = w - 1; x >= 0; --x)
        {
            uint32_t T = dst[-w];
            X = *src++ + L + T - C;
            *dst++ = X;
            L = X;
            C = T;
        }
        src += srcRB;
    }
}

static void apply_kernel(uint8_t dst[], int rx, int ry, const uint32_t src[], int sw, int sh)
{
    uint32_t scale = (1 << 24) / ((2*rx + 1)*(2*ry + 1));

    int rowBytes = sw;

    int dw = sw + 2*rx;
    int dh = sh + 2*ry;

    sw -= 1;    // now it is max_x
    sh -= 1;    // now it is max_y

    int prev_y = -ry - 1    -ry;
    int next_y = ry         -ry;

    for (int y = 0; y < dh; y++)
    {
        int py = SkClampPos(prev_y) * rowBytes;
        int ny = SkFastMin32(next_y, sh) * rowBytes;

        int prev_x = -rx - 1    -rx;
        int next_x = rx         -rx;

        for (int x = 0; x < dw; x++)
        {
            int px = SkClampPos(prev_x);
            int nx = SkFastMin32(next_x, sw);

            uint32_t sum = src[px+py] + src[nx+ny] - src[nx+py] - src[px+ny];
            *dst++ = SkToU8(sum * scale >> 24);

            prev_x += 1;
            next_x += 1;
        }
        prev_y += 1;
        next_y += 1;
    }
}

static void apply_kernel_interp(uint8_t dst[], int rx, int ry, const uint32_t src[], int sw, int sh, U8CPU outer_weight)
{
    SkASSERT(rx > 0 && ry > 0);
    SkASSERT(outer_weight <= 255);

    int inner_weight = 255 - outer_weight;

    // round these guys up if they're bigger than 127
    outer_weight += outer_weight >> 7;
    inner_weight += inner_weight >> 7;

    uint32_t outer_scale = (outer_weight << 16) / ((2*rx + 1)*(2*ry + 1));
    uint32_t inner_scale = (inner_weight << 16) / ((2*rx - 1)*(2*ry - 1));

    int rowBytes = sw;

    int dw = sw + 2*rx;
    int dh = sh + 2*ry;

    sw -= 1;    // now it is max_x
    sh -= 1;    // now it is max_y

    int prev_y = -ry - 1    -ry;
    int next_y = ry         -ry;

    for (int y = 0; y < dh; y++)
    {
        int py = SkClampPos(prev_y) * rowBytes;
        int ny = SkFastMin32(next_y, sh) * rowBytes;

        int ipy = SkClampPos(prev_y + 1) * rowBytes;
        int iny = SkClampMax(next_y - 1, sh) * rowBytes;

        int prev_x = -rx - 1    -rx;
        int next_x = rx         -rx;

        for (int x = 0; x < dw; x++)
        {
            int px = SkClampPos(prev_x);
            int nx = SkFastMin32(next_x, sw);

            int ipx = SkClampPos(prev_x + 1);
            int inx = SkClampMax(next_x - 1, sw);

            uint32_t outer_sum = src[px+py] + src[nx+ny] - src[nx+py] - src[px+ny];
            uint32_t inner_sum = src[ipx+ipy] + src[inx+iny] - src[inx+ipy] - src[ipx+iny];
            *dst++ = SkToU8((outer_sum * outer_scale + inner_sum * inner_scale) >> 24);

            prev_x += 1;
            next_x += 1;
        }
        prev_y += 1;
        next_y += 1;
    }
}

#include "SkColorPriv.h"

static void merge_src_with_blur(uint8_t dst[], int dstRB,
                                const uint8_t src[], int srcRB,
                                const uint8_t blur[], int blurRB,
                                int sw, int sh) {
    dstRB -= sw;
    srcRB -= sw;
    blurRB -= sw;
    while (--sh >= 0) {
        for (int x = sw - 1; x >= 0; --x) {
            *dst = SkToU8(SkAlphaMul(*blur, SkAlpha255To256(*src)));
            dst += 1;
            src += 1;
            blur += 1;
        }
        dst += dstRB;
        src += srcRB;
        blur += blurRB;
    }
}

static void clamp_with_orig(uint8_t dst[], int dstRowBytes,
                            const uint8_t src[], int srcRowBytes,
                            int sw, int sh,
                            SkBlurMask::Style style)
{
    int x;
    while (--sh >= 0) {
        switch (style) {
        case SkBlurMask::kSolid_Style:
            for (x = sw - 1; x >= 0; --x) {
                int s = *src;
                int d = *dst;
                *dst = SkToU8(s + d - SkMulDiv255Round(s, d));
                dst += 1;
                src += 1;
            }
            break;
        case SkBlurMask::kOuter_Style:
            for (x = sw - 1; x >= 0; --x) {
                if (*src) {
                    *dst = SkToU8(SkAlphaMul(*dst, SkAlpha255To256(255 - *src)));
                }
                dst += 1;
                src += 1;
            }
            break;
        default:
            SkASSERT(!"Unexpected blur style here");
            break;
        }
        dst += dstRowBytes - sw;
        src += srcRowBytes - sw;
    }
}

////////////////////////////////////////////////////////////////////////

// we use a local funciton to wrap the class static method to work around
// a bug in gcc98
void SkMask_FreeImage(uint8_t* image);
void SkMask_FreeImage(uint8_t* image)
{
    SkMask::FreeImage(image);
}

bool SkBlurMask::Blur(SkMask* dst, const SkMask& src,
                      SkScalar radius, Style style)
{
    if (src.fFormat != SkMask::kA8_Format)
        return false;

    int rx = SkScalarCeil(radius);
    int outer_weight = 255 - SkScalarRound((SkIntToScalar(rx) - radius) * 255);

    SkASSERT(rx >= 0);
    SkASSERT((unsigned)outer_weight <= 255);
    if (rx <= 0) {
        return false;
    }

    int ry = rx;    // only do square blur for now

    dst->fBounds.set(src.fBounds.fLeft - rx, src.fBounds.fTop - ry,
                        src.fBounds.fRight + rx, src.fBounds.fBottom + ry);
    dst->fRowBytes = dst->fBounds.width();
    dst->fFormat = SkMask::kA8_Format;
    dst->fImage = NULL;

    if (src.fImage) {
        size_t dstSize = dst->computeImageSize();
        if (0 == dstSize) {
            return false;   // too big to allocate, abort
        }

        int             sw = src.fBounds.width();
        int             sh = src.fBounds.height();
        const uint8_t*  sp = src.fImage;
        uint8_t*        dp = SkMask::AllocImage(dstSize);

        SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp);

        // build the blurry destination
        {
            SkAutoTMalloc<uint32_t> storage(sw * sh);
            uint32_t*               sumBuffer = storage.get();

            build_sum_buffer(sumBuffer, sw, sh, sp, src.fRowBytes);
            if (outer_weight == 255)
                apply_kernel(dp, rx, ry, sumBuffer, sw, sh);
            else
                apply_kernel_interp(dp, rx, ry, sumBuffer, sw, sh, outer_weight);
        }

        dst->fImage = dp;
        // if need be, alloc the "real" dst (same size as src) and copy/merge
        // the blur into it (applying the src)
        if (style == kInner_Style) {
            // now we allocate the "real" dst, mirror the size of src
            size_t srcSize = src.computeImageSize();
            if (0 == srcSize) {
                return false;   // too big to allocate, abort
            }
            dst->fImage = SkMask::AllocImage(srcSize);
            merge_src_with_blur(dst->fImage, src.fRowBytes,
                                sp, src.fRowBytes,
                                dp + rx + ry*dst->fRowBytes, dst->fRowBytes,
                                sw, sh);
            SkMask::FreeImage(dp);
        } else if (style != kNormal_Style) {
            clamp_with_orig(dp + rx + ry*dst->fRowBytes, dst->fRowBytes,
                            sp, src.fRowBytes, sw, sh,
                            style);
        }
        (void)autoCall.detach();
    }

    if (style == kInner_Style) {
        dst->fBounds = src.fBounds; // restore trimmed bounds
        dst->fRowBytes = src.fRowBytes;
    }

#if 0
    if (gamma && dst->fImage) {
        uint8_t*    image = dst->fImage;
        uint8_t*    stop = image + dst->computeImageSize();

        for (; image < stop; image += 1) {
            *image = gamma[*image];
        }
    }
#endif
    return true;
}

#if 0
void SkBlurMask::BuildSqrtGamma(uint8_t gamma[256], SkScalar percent)
{
    SkASSERT(gamma);
    SkASSERT(percent >= 0 && percent <= SK_Scalar1);

    int scale = SkScalarRound(percent * 256);

    for (int i = 0; i < 256; i++)
    {
        SkFixed n = i * 257;
        n += n >> 15;
        SkASSERT(n >= 0 && n <= SK_Fixed1);
        n = SkFixedSqrt(n);
        n = n * 255 >> 16;
        n = SkAlphaBlend(n, i, scale);
        gamma[i] = SkToU8(n);
    }
}

void SkBlurMask::BuildSqrGamma(uint8_t gamma[256], SkScalar percent)
{
    SkASSERT(gamma);
    SkASSERT(percent >= 0 && percent <= SK_Scalar1);

    int     scale = SkScalarRound(percent * 256);
    SkFixed div255 = SK_Fixed1 / 255;

    for (int i = 0; i < 256; i++)
    {
        int square = i * i;
        int linear = i * 255;
        int n = SkAlphaBlend(square, linear, scale);
        gamma[i] = SkToU8(n * div255 >> 16);
    }
}
#endif
<commit_msg>fix sumbuffer to initialize its top and left colum/row with zeros. Without this fix we were effectively chopping off the top row of pixels when we computed a blur.<commit_after>/* libs/graphics/effects/SkBlurMask.cpp
**
** Copyright 2006, The Android Open Source Project
**
** 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 "SkBlurMask.h"
#include "SkTemplates.h"

#if 0
static void dump_sum_buffer(const uint32_t sum[], const int w, const int h) {
    printf("---- sum buffer\n");
    for (int y = 0; y <= h; y++) {
        for (int x = 0; x <= w; x++) {
            printf(" %5d", sum[x]);
        }
        printf("\n");
        sum += w+1;
    }
}
#else
#define dump_sum_buffer(sum, w, h)
#endif

/** The sum buffer is an array of u32 to hold the accumulated sum of all of the
    src values at their position, plus all values above and to the left.
    When we sample into this buffer, we need an initial row and column of 0s,
    so we have an index correspondence as follows:

    src[i, j] == sum[i+1, j+1]
    sum[0, j] == sum[i, 0] == 0

    We assume that the sum buffer's stride == its width
 */
static void build_sum_buffer(uint32_t sum[], int srcW, int srcH, const uint8_t src[], int srcRB) {
    int sumW = srcW + 1;

    SkASSERT(srcRB >= srcW);
    // mod srcRB so we can apply it after each row
    srcRB -= srcW;

    int x, y;

    // zero out the top row and column
    memset(sum, 0, sumW * sizeof(sum[0]));
    sum += sumW;

    // special case first row
    uint32_t X = 0;
    *sum++ = 0; // initialze the first column to 0
    for (x = srcW - 1; x >= 0; --x)
    {
        X = *src++ + X;
        *sum++ = X;
    }
    src += srcRB;

    // now do the rest of the rows
    for (y = srcH - 1; y > 0; --y)
    {
        uint32_t L = 0;
        uint32_t C = 0;
        *sum++ = 0; // initialze the first column to 0
        for (x = srcW - 1; x >= 0; --x)
        {
            uint32_t T = sum[-sumW];
            X = *src++ + L + T - C;
            *sum++ = X;
            L = X;
            C = T;
        }
        src += srcRB;
    }
}

/*  sw and sh are the width and height of the src. Since the sum buffer
    matches that, but has an extra row and col at the beginning (with zeros),
    we can just use sw and sh as our "max" values for pinning coordinates
    when sampling into sum[][]
 */
static void apply_kernel(uint8_t dst[], int rx, int ry, const uint32_t sum[],
                         int sw, int sh) {
    uint32_t scale = (1 << 24) / ((2*rx + 1)*(2*ry + 1));

    int sumStride = sw + 1;

    int dw = sw + 2*rx;
    int dh = sh + 2*ry;

    int prev_y = -2*ry;
    int next_y = 1;

    for (int y = 0; y < dh; y++) {
        int py = SkClampPos(prev_y) * sumStride;
        int ny = SkFastMin32(next_y, sh) * sumStride;

        int prev_x = -2*rx;
        int next_x = 1;

        for (int x = 0; x < dw; x++) {
            int px = SkClampPos(prev_x);
            int nx = SkFastMin32(next_x, sw);

            uint32_t tmp = sum[px+py] + sum[nx+ny] - sum[nx+py] - sum[px+ny];
            *dst++ = SkToU8(tmp * scale >> 24);

            prev_x += 1;
            next_x += 1;
        }
        prev_y += 1;
        next_y += 1;
    }
}

/*  sw and sh are the width and height of the src. Since the sum buffer
 matches that, but has an extra row and col at the beginning (with zeros),
 we can just use sw and sh as our "max" values for pinning coordinates
 when sampling into sum[][]
 */
static void apply_kernel_interp(uint8_t dst[], int rx, int ry,
                const uint32_t sum[], int sw, int sh, U8CPU outer_weight) {
    SkASSERT(rx > 0 && ry > 0);
    SkASSERT(outer_weight <= 255);

    int inner_weight = 255 - outer_weight;

    // round these guys up if they're bigger than 127
    outer_weight += outer_weight >> 7;
    inner_weight += inner_weight >> 7;

    uint32_t outer_scale = (outer_weight << 16) / ((2*rx + 1)*(2*ry + 1));
    uint32_t inner_scale = (inner_weight << 16) / ((2*rx - 1)*(2*ry - 1));

    int sumStride = sw + 1;

    int dw = sw + 2*rx;
    int dh = sh + 2*ry;

    int prev_y = -2*ry;
    int next_y = 1;

    for (int y = 0; y < dh; y++) {
        int py = SkClampPos(prev_y) * sumStride;
        int ny = SkFastMin32(next_y, sh) * sumStride;

        int ipy = SkClampPos(prev_y + 1) * sumStride;
        int iny = SkClampMax(next_y - 1, sh) * sumStride;

        int prev_x = -2*rx;
        int next_x = 1;

        for (int x = 0; x < dw; x++) {
            int px = SkClampPos(prev_x);
            int nx = SkFastMin32(next_x, sw);

            int ipx = SkClampPos(prev_x + 1);
            int inx = SkClampMax(next_x - 1, sw);

            uint32_t outer_sum = sum[px+py] + sum[nx+ny] - sum[nx+py] - sum[px+ny];
            uint32_t inner_sum = sum[ipx+ipy] + sum[inx+iny] - sum[inx+ipy] - sum[ipx+iny];
            *dst++ = SkToU8((outer_sum * outer_scale + inner_sum * inner_scale) >> 24);

            prev_x += 1;
            next_x += 1;
        }
        prev_y += 1;
        next_y += 1;
    }
}

#include "SkColorPriv.h"

static void merge_src_with_blur(uint8_t dst[], int dstRB,
                                const uint8_t src[], int srcRB,
                                const uint8_t blur[], int blurRB,
                                int sw, int sh) {
    dstRB -= sw;
    srcRB -= sw;
    blurRB -= sw;
    while (--sh >= 0) {
        for (int x = sw - 1; x >= 0; --x) {
            *dst = SkToU8(SkAlphaMul(*blur, SkAlpha255To256(*src)));
            dst += 1;
            src += 1;
            blur += 1;
        }
        dst += dstRB;
        src += srcRB;
        blur += blurRB;
    }
}

static void clamp_with_orig(uint8_t dst[], int dstRowBytes,
                            const uint8_t src[], int srcRowBytes,
                            int sw, int sh,
                            SkBlurMask::Style style) {
    int x;
    while (--sh >= 0) {
        switch (style) {
        case SkBlurMask::kSolid_Style:
            for (x = sw - 1; x >= 0; --x) {
                int s = *src;
                int d = *dst;
                *dst = SkToU8(s + d - SkMulDiv255Round(s, d));
                dst += 1;
                src += 1;
            }
            break;
        case SkBlurMask::kOuter_Style:
            for (x = sw - 1; x >= 0; --x) {
                if (*src) {
                    *dst = SkToU8(SkAlphaMul(*dst, SkAlpha255To256(255 - *src)));
                }
                dst += 1;
                src += 1;
            }
            break;
        default:
            SkASSERT(!"Unexpected blur style here");
            break;
        }
        dst += dstRowBytes - sw;
        src += srcRowBytes - sw;
    }
}

////////////////////////////////////////////////////////////////////////

// we use a local funciton to wrap the class static method to work around
// a bug in gcc98
void SkMask_FreeImage(uint8_t* image);
void SkMask_FreeImage(uint8_t* image)
{
    SkMask::FreeImage(image);
}

bool SkBlurMask::Blur(SkMask* dst, const SkMask& src,
                      SkScalar radius, Style style)
{
    if (src.fFormat != SkMask::kA8_Format)
        return false;

    int rx = SkScalarCeil(radius);
    int outer_weight = 255 - SkScalarRound((SkIntToScalar(rx) - radius) * 255);

    SkASSERT(rx >= 0);
    SkASSERT((unsigned)outer_weight <= 255);
    if (rx <= 0) {
        return false;
    }

    int ry = rx;    // only do square blur for now

    dst->fBounds.set(src.fBounds.fLeft - rx, src.fBounds.fTop - ry,
                        src.fBounds.fRight + rx, src.fBounds.fBottom + ry);
    dst->fRowBytes = dst->fBounds.width();
    dst->fFormat = SkMask::kA8_Format;
    dst->fImage = NULL;

    if (src.fImage) {
        size_t dstSize = dst->computeImageSize();
        if (0 == dstSize) {
            return false;   // too big to allocate, abort
        }

        int             sw = src.fBounds.width();
        int             sh = src.fBounds.height();
        const uint8_t*  sp = src.fImage;
        uint8_t*        dp = SkMask::AllocImage(dstSize);

        SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp);

        // build the blurry destination
        {
            SkAutoTMalloc<uint32_t> storage((sw + 1) * (sh + 1));
            uint32_t*               sumBuffer = storage.get();

            build_sum_buffer(sumBuffer, sw, sh, sp, src.fRowBytes);
            dump_sum_buffer(sumBuffer, sw, sh);
            if (outer_weight == 255)
                apply_kernel(dp, rx, ry, sumBuffer, sw, sh);
            else
                apply_kernel_interp(dp, rx, ry, sumBuffer, sw, sh, outer_weight);
        }

        dst->fImage = dp;
        // if need be, alloc the "real" dst (same size as src) and copy/merge
        // the blur into it (applying the src)
        if (style == kInner_Style) {
            // now we allocate the "real" dst, mirror the size of src
            size_t srcSize = src.computeImageSize();
            if (0 == srcSize) {
                return false;   // too big to allocate, abort
            }
            dst->fImage = SkMask::AllocImage(srcSize);
            merge_src_with_blur(dst->fImage, src.fRowBytes,
                                sp, src.fRowBytes,
                                dp + rx + ry*dst->fRowBytes, dst->fRowBytes,
                                sw, sh);
            SkMask::FreeImage(dp);
        } else if (style != kNormal_Style) {
            clamp_with_orig(dp + rx + ry*dst->fRowBytes, dst->fRowBytes,
                            sp, src.fRowBytes, sw, sh,
                            style);
        }
        (void)autoCall.detach();
    }

    if (style == kInner_Style) {
        dst->fBounds = src.fBounds; // restore trimmed bounds
        dst->fRowBytes = src.fRowBytes;
    }

#if 0
    if (gamma && dst->fImage) {
        uint8_t*    image = dst->fImage;
        uint8_t*    stop = image + dst->computeImageSize();

        for (; image < stop; image += 1) {
            *image = gamma[*image];
        }
    }
#endif
    return true;
}

#if 0
void SkBlurMask::BuildSqrtGamma(uint8_t gamma[256], SkScalar percent)
{
    SkASSERT(gamma);
    SkASSERT(percent >= 0 && percent <= SK_Scalar1);

    int scale = SkScalarRound(percent * 256);

    for (int i = 0; i < 256; i++)
    {
        SkFixed n = i * 257;
        n += n >> 15;
        SkASSERT(n >= 0 && n <= SK_Fixed1);
        n = SkFixedSqrt(n);
        n = n * 255 >> 16;
        n = SkAlphaBlend(n, i, scale);
        gamma[i] = SkToU8(n);
    }
}

void SkBlurMask::BuildSqrGamma(uint8_t gamma[256], SkScalar percent)
{
    SkASSERT(gamma);
    SkASSERT(percent >= 0 && percent <= SK_Scalar1);

    int     scale = SkScalarRound(percent * 256);
    SkFixed div255 = SK_Fixed1 / 255;

    for (int i = 0; i < 256; i++)
    {
        int square = i * i;
        int linear = i * 255;
        int n = SkAlphaBlend(square, linear, scale);
        gamma[i] = SkToU8(n * div255 >> 16);
    }
}
#endif
<|endoftext|>


<commit_before>
/**************************************************************************
 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

//-----------------------------------------------------------------
//         AliSpectraAODTrackCuts class
//-----------------------------------------------------------------

#include "TChain.h"
#include "TTree.h"
#include "TLegend.h"
#include "TH1F.h"
#include "TH1I.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "AliAnalysisTask.h"
#include "AliAnalysisManager.h"
#include "AliAODTrack.h"
#include "AliExternalTrackParam.h"
#include "AliAODMCParticle.h"
#include "AliAODEvent.h"
#include "AliAODInputHandler.h"
#include "AliAnalysisTaskESDfilter.h"
#include "AliAnalysisDataContainer.h"
#include "AliSpectraAODTrackCuts.h"
//#include "AliSpectraAODHistoManager.h"
#include <iostream>

using namespace std;

const char * AliSpectraAODTrackCuts::kBinLabel[] ={"TrkBit",
						   "TrkCuts",
						   "TrkEta",
						   "TrkDCA",
						   "TrkP",
						   "TrkPt",
						   "TrkPtTOF",
						   "TOFMatching",
						   "kTOFout",
						   "kTIME",
						   "kTOFpid",
						   "Accepted"};

ClassImp(AliSpectraAODTrackCuts)

AliSpectraAODTrackCuts::AliSpectraAODTrackCuts(const char *name) : TNamed(name, "AOD Track Cuts"), fIsSelected(0), fTrackBits(0), fMinTPCcls(0), fEtaCutMin(0), fEtaCutMax(0), fDCACut(0), fPCut(0), fPtCut(0), fYCut(0),
  fPtCutTOFMatching(0), fHistoCuts(0), fHistoNSelectedPos(0), fHistoNSelectedNeg(0), fHistoNMatchedPos(0), fHistoNMatchedNeg(0), fHistoEtaPhiHighPt(0), fTrack(0)

{
  // Constructor
  fHistoCuts = new TH1I("fTrkCuts", "Track Cuts", kNTrkCuts, -0.5, kNTrkCuts - 0.5);
  for(Int_t ibin=1;ibin<=kNTrkCuts;ibin++)fHistoCuts->GetXaxis()->SetBinLabel(ibin,kBinLabel[ibin-1]);
  //standard histo
  const Double_t templBins[] = {0.05,0.1,0.12,0.14,0.16,0.18,0.20,0.25,0.30,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.2,3.4,3.6,3.8,4.0,4.2,4.4,4.6,4.8,5.0};
  Int_t nbinsTempl=52;

  fHistoNSelectedPos=new TH1F("fHistoNSelectedPos","fHistoNSelectedPos",nbinsTempl,templBins);
  fHistoNSelectedPos->GetXaxis()->SetTitle("P_{T} (GeV / c)");
  fHistoNSelectedNeg=new TH1F("fHistoNSelectedNeg","fHistoNSelectedNeg",nbinsTempl,templBins);
  fHistoNSelectedNeg->GetXaxis()->SetTitle("P_{T} (GeV / c)");
  fHistoNMatchedPos=new TH1F("fHistoNMatchedPos","fHistoNMatchedPos",nbinsTempl,templBins);
  fHistoNMatchedPos->GetXaxis()->SetTitle("P_{T} (GeV / c)");
  fHistoNMatchedNeg=new TH1F("fHistoNMatchedNeg","fHistoNMatchedNeg",nbinsTempl,templBins);
  fHistoNMatchedNeg->GetXaxis()->SetTitle("P_{T} (GeV / c)");
  fHistoEtaPhiHighPt=new TH2F("fHistoEtaPhiHighPt","fHistoEtaPhiHighPt",200,-1,1,400,0,7);
  fHistoEtaPhiHighPt->SetXTitle("eta");
  fHistoEtaPhiHighPt->SetYTitle("phi");

  fEtaCutMin = -100000.0; // default value of eta cut ~ no cut
  fEtaCutMax = 100000.0; // default value of eta cut ~ no cut
  fDCACut = 100000.0; // default value of dca cut ~ no cut
  fPCut = 100000.0; // default value of p cut ~ no cut
  fPtCut = 100000.0; // default value of pt cut ~ no cut
  fPtCutTOFMatching=0.6; //default value fot matching with TOF
  fYCut       = 100000.0; // default value of y cut ~ no cut
  fMinTPCcls=70; // ncls in TPC
}

//_______________________________________________________
Bool_t AliSpectraAODTrackCuts::IsSelected(AliAODTrack * track,Bool_t FillHistStat)
{
  // Returns true if Track Cuts are selected and applied
  if (!track)
    {
      printf("ERROR: Could not receive track");
      return kFALSE;
    }
  fTrack = track;

  if(!CheckTrackType()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkBit);

  if(!CheckTrackCuts()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkCuts);
  if(!CheckEtaCut()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkEta);
  if(!CheckDCACut()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkDCA);
  if(!CheckPCut()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkP);
  if(!CheckPtCut()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkPt);
  if(!CheckTOFMatching(FillHistStat)){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kAccepted);
  //Printf("-------- %d,%d",kTOFMatching,kAccepted);
  return kTRUE;
}
//_________________________________________________________

Bool_t AliSpectraAODTrackCuts::CheckTrackType()
{
  // Check track Type
  if (fTrack->TestFilterBit(fTrackBits)) return kTRUE;
  return kFALSE;
}
//_________________________________________________________

Bool_t AliSpectraAODTrackCuts::CheckTrackCuts()
{
  // Check additional track Cuts
  Bool_t PassTrackCuts=kTRUE;
  if (!fTrack->HasPointOnITSLayer(0) && !fTrack->HasPointOnITSLayer(1))PassTrackCuts=kFALSE; //FIXME 1 SPD for the moment
  if (fTrack->GetTPCNcls()<fMinTPCcls)PassTrackCuts=kFALSE;
  return PassTrackCuts;
}
//________________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckEtaCut()
{
   // Check eta cut
   if (fTrack->Eta() < fEtaCutMax && fTrack->Eta() > fEtaCutMin) return kTRUE;
    return kFALSE;
}

Bool_t AliSpectraAODTrackCuts::CheckYCut(AODParticleSpecies_t species)
{
  // check if the rapidity is within the set range
  Double_t y;
  if (species == kSpProton) { y = fTrack->Y(9.38271999999999995e-01); }
  if ( species == kSpKaon ) { y = fTrack->Y(4.93676999999999977e-01); }
  if ( species == kSpPion)  { y = fTrack->Y(1.39570000000000000e-01); }
  if (TMath::Abs(y) > fYCut || y < -998.) return kFALSE;
  return kTRUE;
}
//_______________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckDCACut()
{
   // Check DCA cut
  if (TMath::Abs(fTrack->DCA()) < fDCACut) return kTRUE; //FIXME for newest AOD fTrack->DCA() always gives -999
   return kFALSE;
}
//________________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckPCut()
{
   // Check P cut
   if (fTrack->P() < fPCut) return kTRUE;
   return kFALSE;
}
//_______________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckPtCut()
{
    // check Pt cut
//    if ((fTrack->Pt() < fPtCut) && (fTrack->Pt() > 0.3 )) return kTRUE;
   if (fTrack->Pt() < fPtCut) return kTRUE;
    return kFALSE;
}

//_______________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckTOFMatching(Bool_t FillHistStat)
{
  // check Pt cut
  //    if ((fTrack->Pt() < fPtCut) && (fTrack->Pt() > 0.3 )) return kTRUE;

  if (fTrack->Pt() < fPtCutTOFMatching) return kTRUE;
  else{
    if(FillHistStat)fHistoCuts->Fill(kTrkPtTOF);
    if(fTrack->Charge()>0)fHistoNSelectedPos->Fill(fTrack->Pt());
    else fHistoNSelectedNeg->Fill(fTrack->Pt());
    UInt_t status;
    status=fTrack->GetStatus();
    if((status&AliAODTrack::kTOFout)&&FillHistStat)fHistoCuts->Fill(kTrTOFout);
    if((status&AliAODTrack::kTIME)&&FillHistStat)fHistoCuts->Fill(kTrTIME);
    if((status&AliAODTrack::kTOFpid)&&FillHistStat)fHistoCuts->Fill(kTrTOFpid);

    if((status&AliAODTrack::kTOFout)==0 || (status&AliAODTrack::kTIME)==0){//kTOFout and kTIME
      return kFALSE;
    }
    if(FillHistStat)fHistoCuts->Fill(kTOFMatching);
    if(fTrack->Charge()>0)fHistoNMatchedPos->Fill(fTrack->Pt());
    else fHistoNMatchedNeg->Fill(fTrack->Pt());
    if(fTrack->Pt()>1.5){
      //fHistoEtaPhiHighPt->Fill(fTrack->GetOuterParam()->Eta(),fTrack->GetOuterParam()->Phi());
      //Printf("AliExternalTrackParam * extpar=(AliExternalTrackParam*)fTrack->GetOuterParam();");
      //AliExternalTrackParam * extpar=(AliExternalTrackParam*)fTrack->GetOuterParam();
      fHistoEtaPhiHighPt->Fill(fTrack->Eta(),fTrack->Phi());
      //Printf("fHistoEtaPhiHighPt->Fill(extpar->Eta(),extpar->Phi());");
      //fHistoEtaPhiHighPt->Fill(extpar->Eta(),extpar->Phi());
      //delete extpar;
    }
    return kTRUE;
  }
}
//_______________________________________________________
void AliSpectraAODTrackCuts::PrintCuts() const
{
  // Print cuts
    cout << "Track Cuts" << endl;
    cout << " > TrackBit\t" << fTrackBits << endl;
    cout << " > Eta cut\t" << fEtaCutMin <<","<< fEtaCutMax << endl;
    cout << " > DCA cut\t" << fDCACut << endl;
    cout << " > P cut\t" << fPCut << endl;
    cout << " > Pt cut \t" << fPtCut << endl;
    cout << " > TPC cls \t" << fMinTPCcls << endl;
}
//_______________________________________________________
void AliSpectraAODTrackCuts::SetTrackType(UInt_t bit)
{
   // Set the type of track to be used. The argument should be the bit number. The mask is produced automatically.
   fTrackBits = (0x1 << (bit - 1));
}
//_______________________________________________________

Long64_t AliSpectraAODTrackCuts::Merge(TCollection* list)
{
  // Merge a list of AliSpectraAODTrackCuts objects with this.
  // Returns the number of merged objects (including this).

  //  AliInfo("Merging");

  if (!list)
    return 0;

  if (list->IsEmpty())
    return 1;

  TIterator* iter = list->MakeIterator();
  TObject* obj;

  // collections of all histograms
  TList collections;//FIXME we should only 1 collection
  TList collections_histoNSelectedPos;
  TList collections_histoNSelectedNeg;
  TList collections_histoNMatchedPos;
  TList collections_histoNMatchedNeg;
  TList collections_histoEtaPhiHighPt;

  Int_t count = 0;

  while ((obj = iter->Next())) {
    AliSpectraAODTrackCuts* entry = dynamic_cast<AliSpectraAODTrackCuts*> (obj);
    if (entry == 0)
      continue;

    TH1I * histo = entry->GetHistoCuts();
    collections.Add(histo);
    TH1F * histoNSelectedPos = entry->GetHistoNSelectedPos();
    collections_histoNSelectedPos.Add(histoNSelectedPos);
    TH1F * histoNSelectedNeg = entry->GetHistoNSelectedNeg();
    collections_histoNSelectedNeg.Add(histoNSelectedNeg);
    TH1F * histoNMatchedPos = entry->GetHistoNMatchedPos();
    collections_histoNMatchedPos.Add(histoNMatchedPos);
    TH1F * histoNMatchedNeg = entry->GetHistoNMatchedNeg();
    collections_histoNMatchedNeg.Add(histoNMatchedNeg);
    TH2F * histoEtaPhiHighPt = entry->GetHistoEtaPhiHighPt();
    collections_histoEtaPhiHighPt.Add(histoEtaPhiHighPt);
    count++;
  }

  fHistoCuts->Merge(&collections);
  fHistoNSelectedPos->Merge(&collections_histoNSelectedPos);
  fHistoNSelectedNeg->Merge(&collections_histoNSelectedNeg);
  fHistoNMatchedPos->Merge(&collections_histoNMatchedPos);
  fHistoNMatchedNeg->Merge(&collections_histoNMatchedNeg);
  fHistoEtaPhiHighPt->Merge(&collections_histoEtaPhiHighPt);

  delete iter;

  return count+1;
}

<commit_msg>Coverity fix<commit_after>
/**************************************************************************
 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

//-----------------------------------------------------------------
//         AliSpectraAODTrackCuts class
//-----------------------------------------------------------------

#include "TChain.h"
#include "TTree.h"
#include "TLegend.h"
#include "TH1F.h"
#include "TH1I.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "AliAnalysisTask.h"
#include "AliAnalysisManager.h"
#include "AliAODTrack.h"
#include "AliExternalTrackParam.h"
#include "AliAODMCParticle.h"
#include "AliAODEvent.h"
#include "AliAODInputHandler.h"
#include "AliAnalysisTaskESDfilter.h"
#include "AliAnalysisDataContainer.h"
#include "AliSpectraAODTrackCuts.h"
//#include "AliSpectraAODHistoManager.h"
#include <iostream>

using namespace std;

const char * AliSpectraAODTrackCuts::kBinLabel[] ={"TrkBit",
						   "TrkCuts",
						   "TrkEta",
						   "TrkDCA",
						   "TrkP",
						   "TrkPt",
						   "TrkPtTOF",
						   "TOFMatching",
						   "kTOFout",
						   "kTIME",
						   "kTOFpid",
						   "Accepted"};

ClassImp(AliSpectraAODTrackCuts)

AliSpectraAODTrackCuts::AliSpectraAODTrackCuts(const char *name) : TNamed(name, "AOD Track Cuts"), fIsSelected(0), fTrackBits(0), fMinTPCcls(0), fEtaCutMin(0), fEtaCutMax(0), fDCACut(0), fPCut(0), fPtCut(0), fYCut(0),
  fPtCutTOFMatching(0), fHistoCuts(0), fHistoNSelectedPos(0), fHistoNSelectedNeg(0), fHistoNMatchedPos(0), fHistoNMatchedNeg(0), fHistoEtaPhiHighPt(0), fTrack(0)

{
  // Constructor
  fHistoCuts = new TH1I("fTrkCuts", "Track Cuts", kNTrkCuts, -0.5, kNTrkCuts - 0.5);
  for(Int_t ibin=1;ibin<=kNTrkCuts;ibin++)fHistoCuts->GetXaxis()->SetBinLabel(ibin,kBinLabel[ibin-1]);
  //standard histo
  const Double_t templBins[] = {0.05,0.1,0.12,0.14,0.16,0.18,0.20,0.25,0.30,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.2,3.4,3.6,3.8,4.0,4.2,4.4,4.6,4.8,5.0};
  Int_t nbinsTempl=52;

  fHistoNSelectedPos=new TH1F("fHistoNSelectedPos","fHistoNSelectedPos",nbinsTempl,templBins);
  fHistoNSelectedPos->GetXaxis()->SetTitle("P_{T} (GeV / c)");
  fHistoNSelectedNeg=new TH1F("fHistoNSelectedNeg","fHistoNSelectedNeg",nbinsTempl,templBins);
  fHistoNSelectedNeg->GetXaxis()->SetTitle("P_{T} (GeV / c)");
  fHistoNMatchedPos=new TH1F("fHistoNMatchedPos","fHistoNMatchedPos",nbinsTempl,templBins);
  fHistoNMatchedPos->GetXaxis()->SetTitle("P_{T} (GeV / c)");
  fHistoNMatchedNeg=new TH1F("fHistoNMatchedNeg","fHistoNMatchedNeg",nbinsTempl,templBins);
  fHistoNMatchedNeg->GetXaxis()->SetTitle("P_{T} (GeV / c)");
  fHistoEtaPhiHighPt=new TH2F("fHistoEtaPhiHighPt","fHistoEtaPhiHighPt",200,-1,1,400,0,7);
  fHistoEtaPhiHighPt->SetXTitle("eta");
  fHistoEtaPhiHighPt->SetYTitle("phi");

  fEtaCutMin = -100000.0; // default value of eta cut ~ no cut
  fEtaCutMax = 100000.0; // default value of eta cut ~ no cut
  fDCACut = 100000.0; // default value of dca cut ~ no cut
  fPCut = 100000.0; // default value of p cut ~ no cut
  fPtCut = 100000.0; // default value of pt cut ~ no cut
  fPtCutTOFMatching=0.6; //default value fot matching with TOF
  fYCut       = 100000.0; // default value of y cut ~ no cut
  fMinTPCcls=70; // ncls in TPC
}

//_______________________________________________________
Bool_t AliSpectraAODTrackCuts::IsSelected(AliAODTrack * track,Bool_t FillHistStat)
{
  // Returns true if Track Cuts are selected and applied
  if (!track)
    {
      printf("ERROR: Could not receive track");
      return kFALSE;
    }
  fTrack = track;

  if(!CheckTrackType()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkBit);

  if(!CheckTrackCuts()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkCuts);
  if(!CheckEtaCut()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkEta);
  if(!CheckDCACut()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkDCA);
  if(!CheckPCut()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkP);
  if(!CheckPtCut()){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kTrkPt);
  if(!CheckTOFMatching(FillHistStat)){
    return kFALSE;
  }
  if(FillHistStat)fHistoCuts->Fill(kAccepted);
  //Printf("-------- %d,%d",kTOFMatching,kAccepted);
  return kTRUE;
}
//_________________________________________________________

Bool_t AliSpectraAODTrackCuts::CheckTrackType()
{
  // Check track Type
  if (fTrack->TestFilterBit(fTrackBits)) return kTRUE;
  return kFALSE;
}
//_________________________________________________________

Bool_t AliSpectraAODTrackCuts::CheckTrackCuts()
{
  // Check additional track Cuts
  Bool_t PassTrackCuts=kTRUE;
  if (!fTrack->HasPointOnITSLayer(0) && !fTrack->HasPointOnITSLayer(1))PassTrackCuts=kFALSE; //FIXME 1 SPD for the moment
  if (fTrack->GetTPCNcls()<fMinTPCcls)PassTrackCuts=kFALSE;
  return PassTrackCuts;
}
//________________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckEtaCut()
{
   // Check eta cut
   if (fTrack->Eta() < fEtaCutMax && fTrack->Eta() > fEtaCutMin) return kTRUE;
    return kFALSE;
}

Bool_t AliSpectraAODTrackCuts::CheckYCut(AODParticleSpecies_t species)
{
  // check if the rapidity is within the set range
  Double_t y = 0.;
  if (species == kSpProton) { y = fTrack->Y(9.38271999999999995e-01); }
  if ( species == kSpKaon ) { y = fTrack->Y(4.93676999999999977e-01); }
  if ( species == kSpPion)  { y = fTrack->Y(1.39570000000000000e-01); }
  if (TMath::Abs(y) > fYCut || y < -998.) return kFALSE;
  return kTRUE;
}
//_______________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckDCACut()
{
   // Check DCA cut
  if (TMath::Abs(fTrack->DCA()) < fDCACut) return kTRUE; //FIXME for newest AOD fTrack->DCA() always gives -999
   return kFALSE;
}
//________________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckPCut()
{
   // Check P cut
   if (fTrack->P() < fPCut) return kTRUE;
   return kFALSE;
}
//_______________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckPtCut()
{
    // check Pt cut
//    if ((fTrack->Pt() < fPtCut) && (fTrack->Pt() > 0.3 )) return kTRUE;
   if (fTrack->Pt() < fPtCut) return kTRUE;
    return kFALSE;
}

//_______________________________________________________
Bool_t AliSpectraAODTrackCuts::CheckTOFMatching(Bool_t FillHistStat)
{
  // check Pt cut
  //    if ((fTrack->Pt() < fPtCut) && (fTrack->Pt() > 0.3 )) return kTRUE;

  if (fTrack->Pt() < fPtCutTOFMatching) return kTRUE;
  else{
    if(FillHistStat)fHistoCuts->Fill(kTrkPtTOF);
    if(fTrack->Charge()>0)fHistoNSelectedPos->Fill(fTrack->Pt());
    else fHistoNSelectedNeg->Fill(fTrack->Pt());
    UInt_t status;
    status=fTrack->GetStatus();
    if((status&AliAODTrack::kTOFout)&&FillHistStat)fHistoCuts->Fill(kTrTOFout);
    if((status&AliAODTrack::kTIME)&&FillHistStat)fHistoCuts->Fill(kTrTIME);
    if((status&AliAODTrack::kTOFpid)&&FillHistStat)fHistoCuts->Fill(kTrTOFpid);

    if((status&AliAODTrack::kTOFout)==0 || (status&AliAODTrack::kTIME)==0){//kTOFout and kTIME
      return kFALSE;
    }
    if(FillHistStat)fHistoCuts->Fill(kTOFMatching);
    if(fTrack->Charge()>0)fHistoNMatchedPos->Fill(fTrack->Pt());
    else fHistoNMatchedNeg->Fill(fTrack->Pt());
    if(fTrack->Pt()>1.5){
      //fHistoEtaPhiHighPt->Fill(fTrack->GetOuterParam()->Eta(),fTrack->GetOuterParam()->Phi());
      //Printf("AliExternalTrackParam * extpar=(AliExternalTrackParam*)fTrack->GetOuterParam();");
      //AliExternalTrackParam * extpar=(AliExternalTrackParam*)fTrack->GetOuterParam();
      fHistoEtaPhiHighPt->Fill(fTrack->Eta(),fTrack->Phi());
      //Printf("fHistoEtaPhiHighPt->Fill(extpar->Eta(),extpar->Phi());");
      //fHistoEtaPhiHighPt->Fill(extpar->Eta(),extpar->Phi());
      //delete extpar;
    }
    return kTRUE;
  }
}
//_______________________________________________________
void AliSpectraAODTrackCuts::PrintCuts() const
{
  // Print cuts
    cout << "Track Cuts" << endl;
    cout << " > TrackBit\t" << fTrackBits << endl;
    cout << " > Eta cut\t" << fEtaCutMin <<","<< fEtaCutMax << endl;
    cout << " > DCA cut\t" << fDCACut << endl;
    cout << " > P cut\t" << fPCut << endl;
    cout << " > Pt cut \t" << fPtCut << endl;
    cout << " > TPC cls \t" << fMinTPCcls << endl;
}
//_______________________________________________________
void AliSpectraAODTrackCuts::SetTrackType(UInt_t bit)
{
   // Set the type of track to be used. The argument should be the bit number. The mask is produced automatically.
   fTrackBits = (0x1 << (bit - 1));
}
//_______________________________________________________

Long64_t AliSpectraAODTrackCuts::Merge(TCollection* list)
{
  // Merge a list of AliSpectraAODTrackCuts objects with this.
  // Returns the number of merged objects (including this).

  //  AliInfo("Merging");

  if (!list)
    return 0;

  if (list->IsEmpty())
    return 1;

  TIterator* iter = list->MakeIterator();
  TObject* obj;

  // collections of all histograms
  TList collections;//FIXME we should only 1 collection
  TList collections_histoNSelectedPos;
  TList collections_histoNSelectedNeg;
  TList collections_histoNMatchedPos;
  TList collections_histoNMatchedNeg;
  TList collections_histoEtaPhiHighPt;

  Int_t count = 0;

  while ((obj = iter->Next())) {
    AliSpectraAODTrackCuts* entry = dynamic_cast<AliSpectraAODTrackCuts*> (obj);
    if (entry == 0)
      continue;

    TH1I * histo = entry->GetHistoCuts();
    collections.Add(histo);
    TH1F * histoNSelectedPos = entry->GetHistoNSelectedPos();
    collections_histoNSelectedPos.Add(histoNSelectedPos);
    TH1F * histoNSelectedNeg = entry->GetHistoNSelectedNeg();
    collections_histoNSelectedNeg.Add(histoNSelectedNeg);
    TH1F * histoNMatchedPos = entry->GetHistoNMatchedPos();
    collections_histoNMatchedPos.Add(histoNMatchedPos);
    TH1F * histoNMatchedNeg = entry->GetHistoNMatchedNeg();
    collections_histoNMatchedNeg.Add(histoNMatchedNeg);
    TH2F * histoEtaPhiHighPt = entry->GetHistoEtaPhiHighPt();
    collections_histoEtaPhiHighPt.Add(histoEtaPhiHighPt);
    count++;
  }

  fHistoCuts->Merge(&collections);
  fHistoNSelectedPos->Merge(&collections_histoNSelectedPos);
  fHistoNSelectedNeg->Merge(&collections_histoNSelectedNeg);
  fHistoNMatchedPos->Merge(&collections_histoNMatchedPos);
  fHistoNMatchedNeg->Merge(&collections_histoNMatchedNeg);
  fHistoEtaPhiHighPt->Merge(&collections_histoEtaPhiHighPt);

  delete iter;

  return count+1;
}

<|endoftext|>


<commit_before>/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * 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
 * OpenSceneGraph Public License for more details.
*/
#include <osgUtil/GLObjectsVisitor>
#include <osg/Drawable>
#include <osg/Notify>

using namespace osg;
using namespace osgUtil;

GLObjectsVisitor::GLObjectsVisitor(Mode mode)
{
    setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);

    _mode = mode;

}

void GLObjectsVisitor::apply(osg::Node& node)
{
    if (node.getStateSet())
    {
        apply(*(node.getStateSet()));
    }

    traverse(node);
}

void GLObjectsVisitor::apply(osg::Geode& node)
{
    if (node.getStateSet())
    {
        apply(*(node.getStateSet()));
    }

    for(unsigned int i=0;i<node.getNumDrawables();++i)
    {
        Drawable* drawable = node.getDrawable(i);
        if (drawable)
        {
            apply(*drawable);
            if (drawable->getStateSet())
            {
                apply(*(drawable->getStateSet()));
            }
        }
    }
}

void GLObjectsVisitor::apply(osg::Drawable& drawable)
{
    if (_drawablesAppliedSet.count(&drawable)!=0) return;

    _drawablesAppliedSet.insert(&drawable);

    if (_mode&SWITCH_OFF_DISPLAY_LISTS)
    {
        drawable.setUseDisplayList(false);
    }

    if (_mode&SWITCH_ON_DISPLAY_LISTS)
    {
        drawable.setUseDisplayList(true);
    }

    if (_mode&COMPILE_DISPLAY_LISTS && _renderInfo.getState())
    {
        drawable.compileGLObjects(_renderInfo);
    }

    if (_mode&RELEASE_DISPLAY_LISTS)
    {
        drawable.releaseGLObjects(_renderInfo.getState());
    }

    if (_mode&SWITCH_ON_VERTEX_BUFFER_OBJECTS)
    {
        drawable.setUseVertexBufferObjects(true);
    }

    if (_mode&SWITCH_OFF_VERTEX_BUFFER_OBJECTS)
    {
        drawable.setUseVertexBufferObjects(false);
    }
}

void GLObjectsVisitor::apply(osg::StateSet& stateset)
{
    if (_stateSetAppliedSet.count(&stateset)!=0) return;

    _stateSetAppliedSet.insert(&stateset);

    if (_mode & COMPILE_STATE_ATTRIBUTES && _renderInfo.getState())
    {
        stateset.compileGLObjects(*_renderInfo.getState());

        osg::Program* program = dynamic_cast<osg::Program*>(stateset.getAttribute(osg::StateAttribute::PROGRAM));
        if (program) _lastCompiledProgram = program;

        if (_lastCompiledProgram.valid() && !stateset.getUniformList().empty())
        {
            osg::Program::PerContextProgram* pcp = _lastCompiledProgram->getPCP(_renderInfo.getState()->getContextID());
            if (pcp)
            {
                pcp->useProgram();

                _renderInfo.getState()->setLastAppliedProgramObject(pcp);

                osg::StateSet::UniformList& ul = stateset.getUniformList();
                for(osg::StateSet::UniformList::iterator itr = ul.begin();
                    itr != ul.end();
                    ++itr)
                {
                    pcp->apply(*(itr->second.first));
                }
            }
        }

    }

    if (_mode & RELEASE_STATE_ATTRIBUTES)
    {
        stateset.releaseGLObjects(_renderInfo.getState());
    }

    if (_mode & CHECK_BLACK_LISTED_MODES)
    {
        stateset.checkValidityOfAssociatedModes(*_renderInfo.getState());
    }
}

GLObjectsOperation::GLObjectsOperation(osg::Node* subgraph, GLObjectsVisitor::Mode mode):
    osg::GraphicsOperation("GLObjectOperation",false),
    _subgraph(subgraph),
    _mode(mode)
{
}

void GLObjectsOperation::operator () (osg::GraphicsContext* context)
{
    GLObjectsVisitor glObjectsVisitor(_mode);

    glObjectsVisitor.setState(context->getState());

    _subgraph->accept(glObjectsVisitor);
}
<commit_msg>Commented out debug messages<commit_after>/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * 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
 * OpenSceneGraph Public License for more details.
*/
#include <osgUtil/GLObjectsVisitor>
#include <osg/Drawable>
#include <osg/Notify>

using namespace osg;
using namespace osgUtil;

GLObjectsVisitor::GLObjectsVisitor(Mode mode)
{
    setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);

    _mode = mode;

}

void GLObjectsVisitor::apply(osg::Node& node)
{
    if (node.getStateSet())
    {
        apply(*(node.getStateSet()));
    }

    traverse(node);
}

void GLObjectsVisitor::apply(osg::Geode& node)
{
    if (node.getStateSet())
    {
        apply(*(node.getStateSet()));
    }

    for(unsigned int i=0;i<node.getNumDrawables();++i)
    {
        Drawable* drawable = node.getDrawable(i);
        if (drawable)
        {
            apply(*drawable);
            if (drawable->getStateSet())
            {
                apply(*(drawable->getStateSet()));
            }
        }
    }
}

void GLObjectsVisitor::apply(osg::Drawable& drawable)
{
    if (_drawablesAppliedSet.count(&drawable)!=0) return;

    _drawablesAppliedSet.insert(&drawable);

    if (_mode&SWITCH_OFF_DISPLAY_LISTS)
    {
        drawable.setUseDisplayList(false);
    }

    if (_mode&SWITCH_ON_DISPLAY_LISTS)
    {
        drawable.setUseDisplayList(true);
    }

    if (_mode&COMPILE_DISPLAY_LISTS && _renderInfo.getState())
    {
        drawable.compileGLObjects(_renderInfo);
    }

    if (_mode&RELEASE_DISPLAY_LISTS)
    {
        drawable.releaseGLObjects(_renderInfo.getState());
    }

    if (_mode&SWITCH_ON_VERTEX_BUFFER_OBJECTS)
    {
        drawable.setUseVertexBufferObjects(true);
    }

    if (_mode&SWITCH_OFF_VERTEX_BUFFER_OBJECTS)
    {
        drawable.setUseVertexBufferObjects(false);
    }
}

void GLObjectsVisitor::apply(osg::StateSet& stateset)
{
    if (_stateSetAppliedSet.count(&stateset)!=0) return;

    _stateSetAppliedSet.insert(&stateset);

    if (_mode & COMPILE_STATE_ATTRIBUTES && _renderInfo.getState())
    {
        stateset.compileGLObjects(*_renderInfo.getState());

        osg::Program* program = dynamic_cast<osg::Program*>(stateset.getAttribute(osg::StateAttribute::PROGRAM));
        if (program) _lastCompiledProgram = program;

        if (_lastCompiledProgram.valid() && !stateset.getUniformList().empty())
        {
            osg::Program::PerContextProgram* pcp = _lastCompiledProgram->getPCP(_renderInfo.getState()->getContextID());
            if (pcp)
            {
                pcp->useProgram();

                _renderInfo.getState()->setLastAppliedProgramObject(pcp);

                osg::StateSet::UniformList& ul = stateset.getUniformList();
                for(osg::StateSet::UniformList::iterator itr = ul.begin();
                    itr != ul.end();
                    ++itr)
                {
                    pcp->apply(*(itr->second.first));
                }
            }
        }

    }

    if (_mode & RELEASE_STATE_ATTRIBUTES)
    {
        stateset.releaseGLObjects(_renderInfo.getState());
    }

    if (_mode & CHECK_BLACK_LISTED_MODES)
    {
        stateset.checkValidityOfAssociatedModes(*_renderInfo.getState());
    }
}

GLObjectsOperation::GLObjectsOperation(osg::Node* subgraph, GLObjectsVisitor::Mode mode):
    osg::GraphicsOperation("GLObjectOperation",false),
    _subgraph(subgraph),
    _mode(mode)
{
}

void GLObjectsOperation::operator () (osg::GraphicsContext* context)
{
    GLObjectsVisitor glObjectsVisitor(_mode);

    glObjectsVisitor.setState(context->getState());

    // osg::notify(osg::NOTICE)<<"GLObjectsOperation::before <<<<<<<<<<<"<<std::endl;
    _subgraph->accept(glObjectsVisitor);
    // osg::notify(osg::NOTICE)<<"GLObjectsOperation::after >>>>>>>>>>> "<<std::endl;
}
<|endoftext|>


<commit_before>#ifndef ENTT_ENTITY_ENTITY_HPP
#define ENTT_ENTITY_ENTITY_HPP

#include <cstddef>
#include <cstdint>
#include <type_traits>
#include "../config/config.h"
#include "fwd.hpp"

namespace entt {

/**
 * @cond TURN_OFF_DOXYGEN
 * Internal details not to be documented.
 */

namespace internal {

template<typename, typename = void>
struct entt_traits;

template<typename Type>
struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
    : entt_traits<std::underlying_type_t<Type>> {};

template<typename Type>
struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
    : entt_traits<typename Type::entity_type> {};

template<>
struct entt_traits<std::uint32_t> {
    using entity_type = std::uint32_t;
    using version_type = std::uint16_t;

    static constexpr entity_type entity_mask = 0xFFFFF;
    static constexpr entity_type version_mask = 0xFFF;
    static constexpr std::size_t entity_shift = 20u;
};

template<>
struct entt_traits<std::uint64_t> {
    using entity_type = std::uint64_t;
    using version_type = std::uint32_t;

    static constexpr entity_type entity_mask = 0xFFFFFFFF;
    static constexpr entity_type version_mask = 0xFFFFFFFF;
    static constexpr std::size_t entity_shift = 32u;
};

} // namespace internal

/**
 * Internal details not to be documented.
 * @endcond
 */

/**
 * @brief Entity traits.
 * @tparam Type Type of identifier.
 */
template<typename Type>
class entt_traits: internal::entt_traits<Type> {
    using base_type = internal::entt_traits<Type>;

public:
    /*! @brief Value type. */
    using value_type = Type;
    /*! @brief Underlying entity type. */
    using entity_type = typename base_type::entity_type;
    /*! @brief Underlying version type. */
    using version_type = typename base_type::version_type;
    /*! @brief Reserved identifier. */
    static constexpr entity_type reserved = base_type::entity_mask | (base_type::version_mask << base_type::entity_shift);

    /**
     * @brief Converts an entity to its underlying type.
     * @param value The value to convert.
     * @return The integral representation of the given value.
     */
    [[nodiscard]] static constexpr entity_type to_integral(const value_type value) ENTT_NOEXCEPT {
        return static_cast<entity_type>(value);
    }

    /**
     * @brief Returns the entity part once converted to the underlying type.
     * @param value The value to convert.
     * @return The integral representation of the entity part.
     */
    [[nodiscard]] static constexpr entity_type to_entity(const value_type value) ENTT_NOEXCEPT {
        return (to_integral(value) & base_type::entity_mask);
    }

    /**
     * @brief Returns the version part once converted to the underlying type.
     * @param value The value to convert.
     * @return The integral representation of the version part.
     */
    [[nodiscard]] static constexpr version_type to_version(const value_type value) ENTT_NOEXCEPT {
        constexpr auto mask = (base_type::version_mask << base_type::entity_shift);
        return ((to_integral(value) & mask) >> base_type::entity_shift);
    }

    /**
     * @brief Constructs an identifier from its parts.
     *
     * If the version part is not provided, a tombstone is returned.

     * If the entity part is not provided, a null identifier is returned.
     *
     * @param entity The entity part of the identifier.
     * @param version The version part of the identifier.
     * @return A properly constructed identifier.
     */
    [[nodiscard]] static constexpr value_type construct(const entity_type entity, const version_type version) ENTT_NOEXCEPT {
        return value_type{(entity & base_type::entity_mask) | (static_cast<entity_type>(version) << base_type::entity_shift)};
    }

    /**
     * @brief Combines two identifiers in a single one.
     *
     * The returned identifier is a copy of the first element except for its
     * version, which is taken from the second element.
     *
     * @param lhs The identifier from which to take the entity part.
     * @param rhs The identifier from which to take the version part.
     * @return A properly constructed identifier.
     */
    [[nodiscard]] static constexpr value_type combine(const entity_type lhs, const entity_type rhs) ENTT_NOEXCEPT {
        constexpr auto mask = (base_type::version_mask << base_type::entity_shift);
        return value_type{(lhs & base_type::entity_mask) | (rhs & mask)};
    }
};

/**
 * @copydoc entt_traits<Entity>::to_integral
 * @tparam Entity The value type.
 */
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::entity_type to_integral(const Entity value) ENTT_NOEXCEPT {
    return entt_traits<Entity>::to_integral(value);
}

/**
 * @copydoc entt_traits<Entity>::to_entity
 * @tparam Entity The value type.
 */
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::entity_type to_entity(const Entity value) ENTT_NOEXCEPT {
    return entt_traits<Entity>::to_entity(value);
}

/**
 * @copydoc entt_traits<Entity>::to_version
 * @tparam Entity The value type.
 */
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::version_type to_version(const Entity value) ENTT_NOEXCEPT {
    return entt_traits<Entity>::to_version(value);
}

/*! @brief Null object for all identifiers.  */
struct null_t {
    /**
     * @brief Converts the null object to identifiers of any type.
     * @tparam Entity Type of identifier.
     * @return The null representation for the given type.
     */
    template<typename Entity>
    [[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
        using entity_traits = entt_traits<Entity>;
        return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
    }

    /**
     * @brief Compares two null objects.
     * @param other A null object.
     * @return True in all cases.
     */
    [[nodiscard]] constexpr bool operator==([[maybe_unused]] const null_t other) const ENTT_NOEXCEPT {
        return true;
    }

    /**
     * @brief Compares two null objects.
     * @param other A null object.
     * @return False in all cases.
     */
    [[nodiscard]] constexpr bool operator!=([[maybe_unused]] const null_t other) const ENTT_NOEXCEPT {
        return false;
    }

    /**
     * @brief Compares a null object and an identifier of any type.
     * @tparam Entity Type of identifier.
     * @param entity Identifier with which to compare.
     * @return False if the two elements differ, true otherwise.
     */
    template<typename Entity>
    [[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
        using entity_traits = entt_traits<Entity>;
        return entity_traits::to_entity(entity) == entity_traits::to_entity(*this);
    }

    /**
     * @brief Compares a null object and an identifier of any type.
     * @tparam Entity Type of identifier.
     * @param entity Identifier with which to compare.
     * @return True if the two elements differ, false otherwise.
     */
    template<typename Entity>
    [[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
        return !(entity == *this);
    }
};

/**
 * @brief Compares a null object and an identifier of any type.
 * @tparam Entity Type of identifier.
 * @param entity Identifier with which to compare.
 * @param other A null object yet to be converted.
 * @return False if the two elements differ, true otherwise.
 */
template<typename Entity>
[[nodiscard]] constexpr bool operator==(const Entity entity, const null_t other) ENTT_NOEXCEPT {
    return other.operator==(entity);
}

/**
 * @brief Compares a null object and an identifier of any type.
 * @tparam Entity Type of identifier.
 * @param entity Identifier with which to compare.
 * @param other A null object yet to be converted.
 * @return True if the two elements differ, false otherwise.
 */
template<typename Entity>
[[nodiscard]] constexpr bool operator!=(const Entity entity, const null_t other) ENTT_NOEXCEPT {
    return !(other == entity);
}

/*! @brief Tombstone object for all identifiers.  */
struct tombstone_t {
    /**
     * @brief Converts the tombstone object to identifiers of any type.
     * @tparam Entity Type of identifier.
     * @return The tombstone representation for the given type.
     */
    template<typename Entity>
    [[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
        using entity_traits = entt_traits<Entity>;
        return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
    }

    /**
     * @brief Compares two tombstone objects.
     * @param other A tombstone object.
     * @return True in all cases.
     */
    [[nodiscard]] constexpr bool operator==([[maybe_unused]] const tombstone_t other) const ENTT_NOEXCEPT {
        return true;
    }

    /**
     * @brief Compares two tombstone objects.
     * @param other A tombstone object.
     * @return False in all cases.
     */
    [[nodiscard]] constexpr bool operator!=([[maybe_unused]] const tombstone_t other) const ENTT_NOEXCEPT {
        return false;
    }

    /**
     * @brief Compares a tombstone object and an identifier of any type.
     * @tparam Entity Type of identifier.
     * @param entity Identifier with which to compare.
     * @return False if the two elements differ, true otherwise.
     */
    template<typename Entity>
    [[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
        using entity_traits = entt_traits<Entity>;
        return entity_traits::to_version(entity) == entity_traits::to_version(*this);
    }

    /**
     * @brief Compares a tombstone object and an identifier of any type.
     * @tparam Entity Type of identifier.
     * @param entity Identifier with which to compare.
     * @return True if the two elements differ, false otherwise.
     */
    template<typename Entity>
    [[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
        return !(entity == *this);
    }
};

/**
 * @brief Compares a tombstone object and an identifier of any type.
 * @tparam Entity Type of identifier.
 * @param entity Identifier with which to compare.
 * @param other A tombstone object yet to be converted.
 * @return False if the two elements differ, true otherwise.
 */
template<typename Entity>
[[nodiscard]] constexpr bool operator==(const Entity entity, const tombstone_t other) ENTT_NOEXCEPT {
    return other.operator==(entity);
}

/**
 * @brief Compares a tombstone object and an identifier of any type.
 * @tparam Entity Type of identifier.
 * @param entity Identifier with which to compare.
 * @param other A tombstone object yet to be converted.
 * @return True if the two elements differ, false otherwise.
 */
template<typename Entity>
[[nodiscard]] constexpr bool operator!=(const Entity entity, const tombstone_t other) ENTT_NOEXCEPT {
    return !(other == entity);
}

/**
 * @brief Compile-time constant for null entities.
 *
 * There exist implicit conversions from this variable to identifiers of any
 * allowed type. Similarly, there exist comparision operators between the null
 * entity and any other identifier.
 */
inline constexpr null_t null{};

/**
 * @brief Compile-time constant for tombstone entities.
 *
 * There exist implicit conversions from this variable to identifiers of any
 * allowed type. Similarly, there exist comparision operators between the
 * tombstone entity and any other identifier.
 */
inline constexpr tombstone_t tombstone{};

} // namespace entt

#endif
<commit_msg>entity: simplified to_version<commit_after>#ifndef ENTT_ENTITY_ENTITY_HPP
#define ENTT_ENTITY_ENTITY_HPP

#include <cstddef>
#include <cstdint>
#include <type_traits>
#include "../config/config.h"
#include "fwd.hpp"

namespace entt {

/**
 * @cond TURN_OFF_DOXYGEN
 * Internal details not to be documented.
 */

namespace internal {

template<typename, typename = void>
struct entt_traits;

template<typename Type>
struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
    : entt_traits<std::underlying_type_t<Type>> {};

template<typename Type>
struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
    : entt_traits<typename Type::entity_type> {};

template<>
struct entt_traits<std::uint32_t> {
    using entity_type = std::uint32_t;
    using version_type = std::uint16_t;

    static constexpr entity_type entity_mask = 0xFFFFF;
    static constexpr entity_type version_mask = 0xFFF;
    static constexpr std::size_t entity_shift = 20u;
};

template<>
struct entt_traits<std::uint64_t> {
    using entity_type = std::uint64_t;
    using version_type = std::uint32_t;

    static constexpr entity_type entity_mask = 0xFFFFFFFF;
    static constexpr entity_type version_mask = 0xFFFFFFFF;
    static constexpr std::size_t entity_shift = 32u;
};

} // namespace internal

/**
 * Internal details not to be documented.
 * @endcond
 */

/**
 * @brief Entity traits.
 * @tparam Type Type of identifier.
 */
template<typename Type>
class entt_traits: internal::entt_traits<Type> {
    using base_type = internal::entt_traits<Type>;

public:
    /*! @brief Value type. */
    using value_type = Type;
    /*! @brief Underlying entity type. */
    using entity_type = typename base_type::entity_type;
    /*! @brief Underlying version type. */
    using version_type = typename base_type::version_type;
    /*! @brief Reserved identifier. */
    static constexpr entity_type reserved = base_type::entity_mask | (base_type::version_mask << base_type::entity_shift);

    /**
     * @brief Converts an entity to its underlying type.
     * @param value The value to convert.
     * @return The integral representation of the given value.
     */
    [[nodiscard]] static constexpr entity_type to_integral(const value_type value) ENTT_NOEXCEPT {
        return static_cast<entity_type>(value);
    }

    /**
     * @brief Returns the entity part once converted to the underlying type.
     * @param value The value to convert.
     * @return The integral representation of the entity part.
     */
    [[nodiscard]] static constexpr entity_type to_entity(const value_type value) ENTT_NOEXCEPT {
        return (to_integral(value) & base_type::entity_mask);
    }

    /**
     * @brief Returns the version part once converted to the underlying type.
     * @param value The value to convert.
     * @return The integral representation of the version part.
     */
    [[nodiscard]] static constexpr version_type to_version(const value_type value) ENTT_NOEXCEPT {
        return (to_integral(value) >> base_type::entity_shift);
    }

    /**
     * @brief Constructs an identifier from its parts.
     *
     * If the version part is not provided, a tombstone is returned.

     * If the entity part is not provided, a null identifier is returned.
     *
     * @param entity The entity part of the identifier.
     * @param version The version part of the identifier.
     * @return A properly constructed identifier.
     */
    [[nodiscard]] static constexpr value_type construct(const entity_type entity, const version_type version) ENTT_NOEXCEPT {
        return value_type{(entity & base_type::entity_mask) | (static_cast<entity_type>(version) << base_type::entity_shift)};
    }

    /**
     * @brief Combines two identifiers in a single one.
     *
     * The returned identifier is a copy of the first element except for its
     * version, which is taken from the second element.
     *
     * @param lhs The identifier from which to take the entity part.
     * @param rhs The identifier from which to take the version part.
     * @return A properly constructed identifier.
     */
    [[nodiscard]] static constexpr value_type combine(const entity_type lhs, const entity_type rhs) ENTT_NOEXCEPT {
        constexpr auto mask = (base_type::version_mask << base_type::entity_shift);
        return value_type{(lhs & base_type::entity_mask) | (rhs & mask)};
    }
};

/**
 * @copydoc entt_traits<Entity>::to_integral
 * @tparam Entity The value type.
 */
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::entity_type to_integral(const Entity value) ENTT_NOEXCEPT {
    return entt_traits<Entity>::to_integral(value);
}

/**
 * @copydoc entt_traits<Entity>::to_entity
 * @tparam Entity The value type.
 */
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::entity_type to_entity(const Entity value) ENTT_NOEXCEPT {
    return entt_traits<Entity>::to_entity(value);
}

/**
 * @copydoc entt_traits<Entity>::to_version
 * @tparam Entity The value type.
 */
template<typename Entity>
[[nodiscard]] constexpr typename entt_traits<Entity>::version_type to_version(const Entity value) ENTT_NOEXCEPT {
    return entt_traits<Entity>::to_version(value);
}

/*! @brief Null object for all identifiers.  */
struct null_t {
    /**
     * @brief Converts the null object to identifiers of any type.
     * @tparam Entity Type of identifier.
     * @return The null representation for the given type.
     */
    template<typename Entity>
    [[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
        using entity_traits = entt_traits<Entity>;
        return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
    }

    /**
     * @brief Compares two null objects.
     * @param other A null object.
     * @return True in all cases.
     */
    [[nodiscard]] constexpr bool operator==([[maybe_unused]] const null_t other) const ENTT_NOEXCEPT {
        return true;
    }

    /**
     * @brief Compares two null objects.
     * @param other A null object.
     * @return False in all cases.
     */
    [[nodiscard]] constexpr bool operator!=([[maybe_unused]] const null_t other) const ENTT_NOEXCEPT {
        return false;
    }

    /**
     * @brief Compares a null object and an identifier of any type.
     * @tparam Entity Type of identifier.
     * @param entity Identifier with which to compare.
     * @return False if the two elements differ, true otherwise.
     */
    template<typename Entity>
    [[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
        using entity_traits = entt_traits<Entity>;
        return entity_traits::to_entity(entity) == entity_traits::to_entity(*this);
    }

    /**
     * @brief Compares a null object and an identifier of any type.
     * @tparam Entity Type of identifier.
     * @param entity Identifier with which to compare.
     * @return True if the two elements differ, false otherwise.
     */
    template<typename Entity>
    [[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
        return !(entity == *this);
    }
};

/**
 * @brief Compares a null object and an identifier of any type.
 * @tparam Entity Type of identifier.
 * @param entity Identifier with which to compare.
 * @param other A null object yet to be converted.
 * @return False if the two elements differ, true otherwise.
 */
template<typename Entity>
[[nodiscard]] constexpr bool operator==(const Entity entity, const null_t other) ENTT_NOEXCEPT {
    return other.operator==(entity);
}

/**
 * @brief Compares a null object and an identifier of any type.
 * @tparam Entity Type of identifier.
 * @param entity Identifier with which to compare.
 * @param other A null object yet to be converted.
 * @return True if the two elements differ, false otherwise.
 */
template<typename Entity>
[[nodiscard]] constexpr bool operator!=(const Entity entity, const null_t other) ENTT_NOEXCEPT {
    return !(other == entity);
}

/*! @brief Tombstone object for all identifiers.  */
struct tombstone_t {
    /**
     * @brief Converts the tombstone object to identifiers of any type.
     * @tparam Entity Type of identifier.
     * @return The tombstone representation for the given type.
     */
    template<typename Entity>
    [[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
        using entity_traits = entt_traits<Entity>;
        return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
    }

    /**
     * @brief Compares two tombstone objects.
     * @param other A tombstone object.
     * @return True in all cases.
     */
    [[nodiscard]] constexpr bool operator==([[maybe_unused]] const tombstone_t other) const ENTT_NOEXCEPT {
        return true;
    }

    /**
     * @brief Compares two tombstone objects.
     * @param other A tombstone object.
     * @return False in all cases.
     */
    [[nodiscard]] constexpr bool operator!=([[maybe_unused]] const tombstone_t other) const ENTT_NOEXCEPT {
        return false;
    }

    /**
     * @brief Compares a tombstone object and an identifier of any type.
     * @tparam Entity Type of identifier.
     * @param entity Identifier with which to compare.
     * @return False if the two elements differ, true otherwise.
     */
    template<typename Entity>
    [[nodiscard]] constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
        using entity_traits = entt_traits<Entity>;
        return entity_traits::to_version(entity) == entity_traits::to_version(*this);
    }

    /**
     * @brief Compares a tombstone object and an identifier of any type.
     * @tparam Entity Type of identifier.
     * @param entity Identifier with which to compare.
     * @return True if the two elements differ, false otherwise.
     */
    template<typename Entity>
    [[nodiscard]] constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
        return !(entity == *this);
    }
};

/**
 * @brief Compares a tombstone object and an identifier of any type.
 * @tparam Entity Type of identifier.
 * @param entity Identifier with which to compare.
 * @param other A tombstone object yet to be converted.
 * @return False if the two elements differ, true otherwise.
 */
template<typename Entity>
[[nodiscard]] constexpr bool operator==(const Entity entity, const tombstone_t other) ENTT_NOEXCEPT {
    return other.operator==(entity);
}

/**
 * @brief Compares a tombstone object and an identifier of any type.
 * @tparam Entity Type of identifier.
 * @param entity Identifier with which to compare.
 * @param other A tombstone object yet to be converted.
 * @return True if the two elements differ, false otherwise.
 */
template<typename Entity>
[[nodiscard]] constexpr bool operator!=(const Entity entity, const tombstone_t other) ENTT_NOEXCEPT {
    return !(other == entity);
}

/**
 * @brief Compile-time constant for null entities.
 *
 * There exist implicit conversions from this variable to identifiers of any
 * allowed type. Similarly, there exist comparision operators between the null
 * entity and any other identifier.
 */
inline constexpr null_t null{};

/**
 * @brief Compile-time constant for tombstone entities.
 *
 * There exist implicit conversions from this variable to identifiers of any
 * allowed type. Similarly, there exist comparision operators between the
 * tombstone entity and any other identifier.
 */
inline constexpr tombstone_t tombstone{};

} // namespace entt

#endif
<|endoftext|>


<commit_before>#include "j1App.h"
#include "j1Render.h"
#include "S_InGameMenu.h"
#include "j1Player.h"
#include "j1Window.h"
#include "j1Camera.h"
#include "j1HUD.h"
#include "j1Pathfinding.h"
#include "Gui.h"
#include "GuiButton.h"
#include "j1GameStartMenuBack.h"
#include "j1Audio.h"

S_InGameMenu::S_InGameMenu()
{
	scene_str = "InGameMenu";
}

S_InGameMenu::~S_InGameMenu()
{
}

bool S_InGameMenu::Awake(pugi::xml_node& conf)
{
	IngamemenuLabel = App->gui->CreateButton(iPoint(40,40), &std::string(conf.child("IngamemenuLabel").attribute("value").as_string("In-Game menu")), ButtonType::idle_only, &label_title_rec, false);
	IngamemenuLabel->SetFont(App->font->Triforce48);
	((Gui*)IngamemenuLabel)->SetListener(this);
	IngamemenuLabel->SetVisible(false);
	int X_pos = App->win->GetWindowWHalf() - (int)(idle_button_rect.w * 0.5f);
	resume = App->gui->CreateButton(iPoint(X_pos, 160), &std::string(conf.child("resume").attribute("value").as_string("Resume")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	resume->SetFont(App->font->Sherwood20);
	((Gui*)resume)->SetListener(this);
	resume->SetVisible(false);
	resume->Focusable(true);
	loadcheckpoint = App->gui->CreateButton(iPoint(X_pos, 270), &std::string(conf.child("loadcheckpoint").attribute("value").as_string("Load Last Checkpoint")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	loadcheckpoint->SetFont(App->font->Sherwood20);
	((Gui*)loadcheckpoint)->SetListener(this);
	loadcheckpoint->SetVisible(false);
	loadcheckpoint->Focusable(true);
	options = App->gui->CreateButton(iPoint(X_pos, 380), &std::string(conf.child("options").attribute("value").as_string("Options")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	options->SetFont(App->font->Sherwood20);
	((Gui*)options)->SetListener(this);
	options->SetVisible(false);
	options->Focusable(true);
	mainmenu = App->gui->CreateButton(iPoint(X_pos, 490), &std::string(conf.child("mainmenu").attribute("value").as_string("Main Menu")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	mainmenu->SetFont(App->font->Sherwood20);
	((Gui*)mainmenu)->SetListener(this);
	mainmenu->SetVisible(false);
	mainmenu->Focusable(true);
	quit = App->gui->CreateButton(iPoint(X_pos, 600), &std::string(conf.child("quit").attribute("value").as_string("Quit")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	quit->SetFont(App->font->Sherwood20);
	((Gui*)quit)->SetListener(this);
	quit->SetVisible(false);
	quit->Focusable(true);

	buttons.push_back(resume);
	buttons.push_back(loadcheckpoint);
	buttons.push_back(options);
	buttons.push_back(mainmenu);
	buttons.push_back(quit);
	return true;
};

bool S_InGameMenu::Start()
{
	IngamemenuLabel->SetVisible(true);
	resume->SetVisible(true);
	loadcheckpoint->SetVisible(true);
	options->SetVisible(true);
	mainmenu->SetVisible(true);
	quit->SetVisible(true);

	App->gui->SetFocus(buttons.front());

	active = true;

	return true;
}

bool S_InGameMenu::Update()
{
	/*
	//Blit title
	if (visibility)
	{
		int Title_X_pos = App->win->GetWindowWHalf() - (int)(title.w * 0.5f);
		App->render->Blit(App->gui->GetAtlas(), -App->render->camera.x + Title_X_pos, -App->render->camera.y + 40, &title, 1.0f, 0, INT_MAX, INT_MAX, false, titleopacity);
	}
	*/
	MenuInput(&buttons);
	return true;
}

bool S_InGameMenu::Clean()
{
	IngamemenuLabel->SetVisible(false);
	resume->SetVisible(false);
	loadcheckpoint->SetVisible(false);
	options->SetVisible(false);
	mainmenu->SetVisible(false);
	quit->SetVisible(false);
	App->gui->SetFocus(nullptr);

	active = false;

	return true;
}

void S_InGameMenu::OnGui(Gui* ui, GuiEvent event)
{
	if ((ui == (Gui*)resume) && (event == GuiEvent::mouse_lclk_down))
	{
		App->player->paused = !App->player->paused;
		App->enemy->paused = !App->enemy->paused;
		App->collision->paused = !App->collision->paused;
		App->pathfinding->paused = !App->pathfinding->paused;
		App->scene->Hide();
		App->startmenuback->Freeze(true);
	}
	if ((ui == (Gui*)loadcheckpoint) && (event == GuiEvent::mouse_lclk_down))
	{
		//By now this do nothing
	}
	if ((ui == (Gui*)options) && (event == GuiEvent::mouse_lclk_down))
	{
		App->scene->Show(Scene_ID::options);
	}
	if ((ui == (Gui*)mainmenu) && (event == GuiEvent::mouse_lclk_down))
	{
		App->audio->VolumeMusic(0);
		App->player->Disable();
		App->enemy->Disable();
		App->map->Disable();
		App->collision->Disable();
		App->hud->Disable();
		App->object->Disable();
		App->scene->ChangeScene(Scene_ID::mainmenu);
		App->scene->Hide();
		active = false;
	}
	if ((ui == (Gui*)quit) && (event == GuiEvent::mouse_lclk_down))
	{
		App->scene->Show(Scene_ID::quitgame);
	}
}<commit_msg>Crash fix<commit_after>#include "j1App.h"
#include "j1Render.h"
#include "S_InGameMenu.h"
#include "j1Player.h"
#include "j1Window.h"
#include "j1Camera.h"
#include "j1HUD.h"
#include "j1Pathfinding.h"
#include "Gui.h"
#include "GuiButton.h"
#include "j1GameStartMenuBack.h"
#include "j1Audio.h"

S_InGameMenu::S_InGameMenu()
{
	scene_str = "InGameMenu";
}

S_InGameMenu::~S_InGameMenu()
{
}

bool S_InGameMenu::Awake(pugi::xml_node& conf)
{
	IngamemenuLabel = App->gui->CreateButton(iPoint(40,40), &std::string(conf.child("IngamemenuLabel").attribute("value").as_string("In-Game menu")), ButtonType::idle_only, &label_title_rec, false);
	IngamemenuLabel->SetFont(App->font->Triforce48);
	((Gui*)IngamemenuLabel)->SetListener(this);
	IngamemenuLabel->SetVisible(false);
	int X_pos = App->win->GetWindowWHalf() - (int)(idle_button_rect.w * 0.5f);
	resume = App->gui->CreateButton(iPoint(X_pos, 160), &std::string(conf.child("resume").attribute("value").as_string("Resume")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	resume->SetFont(App->font->Sherwood20);
	((Gui*)resume)->SetListener(this);
	resume->SetVisible(false);
	resume->Focusable(true);
	loadcheckpoint = App->gui->CreateButton(iPoint(X_pos, 270), &std::string(conf.child("loadcheckpoint").attribute("value").as_string("Load Last Checkpoint")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	loadcheckpoint->SetFont(App->font->Sherwood20);
	((Gui*)loadcheckpoint)->SetListener(this);
	loadcheckpoint->SetVisible(false);
	loadcheckpoint->Focusable(true);
	options = App->gui->CreateButton(iPoint(X_pos, 380), &std::string(conf.child("options").attribute("value").as_string("Options")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	options->SetFont(App->font->Sherwood20);
	((Gui*)options)->SetListener(this);
	options->SetVisible(false);
	options->Focusable(true);
	mainmenu = App->gui->CreateButton(iPoint(X_pos, 490), &std::string(conf.child("mainmenu").attribute("value").as_string("Main Menu")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	mainmenu->SetFont(App->font->Sherwood20);
	((Gui*)mainmenu)->SetListener(this);
	mainmenu->SetVisible(false);
	mainmenu->Focusable(true);
	quit = App->gui->CreateButton(iPoint(X_pos, 600), &std::string(conf.child("quit").attribute("value").as_string("Quit")), ButtonType::idle_hover_pressed, &idle_button_rect, &hover_button_rect, &pressed_button_rect, false);
	quit->SetFont(App->font->Sherwood20);
	((Gui*)quit)->SetListener(this);
	quit->SetVisible(false);
	quit->Focusable(true);

	buttons.push_back(resume);
	buttons.push_back(loadcheckpoint);
	buttons.push_back(options);
	buttons.push_back(mainmenu);
	buttons.push_back(quit);
	return true;
};

bool S_InGameMenu::Start()
{
	IngamemenuLabel->SetVisible(true);
	resume->SetVisible(true);
	loadcheckpoint->SetVisible(true);
	options->SetVisible(true);
	mainmenu->SetVisible(true);
	quit->SetVisible(true);

	App->gui->SetFocus(buttons.front());

	active = true;

	return true;
}

bool S_InGameMenu::Update()
{
	/*
	//Blit title
	if (visibility)
	{
		int Title_X_pos = App->win->GetWindowWHalf() - (int)(title.w * 0.5f);
		App->render->Blit(App->gui->GetAtlas(), -App->render->camera.x + Title_X_pos, -App->render->camera.y + 40, &title, 1.0f, 0, INT_MAX, INT_MAX, false, titleopacity);
	}
	*/
	MenuInput(&buttons);
	return true;
}

bool S_InGameMenu::Clean()
{
	IngamemenuLabel->SetVisible(false);
	resume->SetVisible(false);
	loadcheckpoint->SetVisible(false);
	options->SetVisible(false);
	mainmenu->SetVisible(false);
	quit->SetVisible(false);
	App->gui->SetFocus(nullptr);

	//active = false;

	return true;
}

void S_InGameMenu::OnGui(Gui* ui, GuiEvent event)
{
	if ((ui == (Gui*)resume) && (event == GuiEvent::mouse_lclk_down))
	{
		App->player->paused = !App->player->paused;
		App->enemy->paused = !App->enemy->paused;
		App->collision->paused = !App->collision->paused;
		App->pathfinding->paused = !App->pathfinding->paused;
		App->scene->Hide();
		App->startmenuback->Freeze(true);
	}
	if ((ui == (Gui*)loadcheckpoint) && (event == GuiEvent::mouse_lclk_down))
	{
		//By now this do nothing
	}
	if ((ui == (Gui*)options) && (event == GuiEvent::mouse_lclk_down))
	{
		App->scene->Show(Scene_ID::options);
	}
	if ((ui == (Gui*)mainmenu) && (event == GuiEvent::mouse_lclk_down))
	{
		App->audio->VolumeMusic(0);
		App->player->Disable();
		App->enemy->Disable();
		App->map->Disable();
		App->collision->Disable();
		App->hud->Disable();
		App->object->Disable();
		App->scene->ChangeScene(Scene_ID::mainmenu);
		App->scene->Hide();
		active = false;
	}
	if ((ui == (Gui*)quit) && (event == GuiEvent::mouse_lclk_down))
	{
		App->scene->Show(Scene_ID::quitgame);
	}
}<|endoftext|>