<commit_before>// Author: Enrico Guiraud, Danilo Piparo CERN  09/2017

/*************************************************************************
 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_RDATASOURCE
#define ROOT_RDATASOURCE

#include "RDF/RColumnReaderBase.hxx"
#include "ROOT/RStringView.hxx"
#include "ROOT/RConfig.hxx" // R__DEPRECATED
#include "RtypesCore.h" // ULong64_t
#include "TError.h" // Warning
#include "TString.h"

#include <algorithm> // std::transform
#include <string>
#include <typeinfo>
#include <vector>

namespace ROOT {
namespace RDF {
class RDataSource;
}
}

/// Print a RDataSource at the prompt
namespace cling {
std::string printValue(ROOT::RDF::RDataSource *ds);
} // namespace cling

namespace ROOT {

namespace Internal {
namespace TDS {

/// Mother class of TTypedPointerHolder. The instances
/// of this class can be put in a container. Upon destruction,
/// the correct deletion of the pointer is performed in the
/// derived class.
class TPointerHolder {
protected:
   void *fPointer{nullptr};

public:
   TPointerHolder(void *ptr) : fPointer(ptr) {}
   void *GetPointer() { return fPointer; }
   void *GetPointerAddr() { return &fPointer; }
   virtual TPointerHolder *GetDeepCopy() = 0;
   virtual ~TPointerHolder(){};
};

/// Class to wrap a pointer and delete the memory associated to it
/// correctly
template <typename T>
class TTypedPointerHolder final : public TPointerHolder {
public:
   TTypedPointerHolder(T *ptr) : TPointerHolder((void *)ptr) {}

   virtual TPointerHolder *GetDeepCopy()
   {
      const auto typedPtr = static_cast<T *>(fPointer);
      return new TTypedPointerHolder(new T(*typedPtr));
   }

   ~TTypedPointerHolder() { delete static_cast<T *>(fPointer); }
};

} // ns TDS
} // ns Internal

namespace RDF {

// clang-format off
/**
\class ROOT::RDF::RDataSource
\ingroup dataframe
\brief RDataSource defines an API that RDataFrame can use to read arbitrary data formats.

A concrete RDataSource implementation (i.e. a class that inherits from RDataSource and implements all of its pure
methods) provides an adaptor that RDataFrame can leverage to read any kind of tabular data formats.
RDataFrame calls into RDataSource to retrieve information about the data, retrieve (thread-local) readers or "cursors"
for selected columns and to advance the readers to the desired data entry.

The sequence of calls that RDataFrame (or any other client of a RDataSource) performs is the following:

 - SetNSlots() : inform RDataSource of the desired level of parallelism
 - GetColumnReaders() : retrieve from RDataSource per-thread readers for the desired columns
 - Initialize() : inform RDataSource that an event-loop is about to start
 - GetEntryRanges() : retrieve from RDataSource a set of ranges of entries that can be processed concurrently
 - InitSlot() : inform RDataSource that a certain thread is about to start working on a certain range of entries
 - SetEntry() : inform RDataSource that a certain thread is about to start working on a certain entry
 - FinalizeSlot() : inform RDataSource that a certain thread finished working on a certain range of entries
 - Finalize() : inform RDataSource that an event-loop finished

RDataSource implementations must support running multiple event-loops consecutively (although sequentially) on the same dataset.
 - \b SetNSlots() is called once per RDataSource object, typically when it is associated to a RDataFrame.
 - \b GetColumnReaders() can be called several times, potentially with the same arguments, also in-between event-loops, but not during an event-loop.
 - \b GetEntryRanges() will be called several times, including during an event loop, as additional ranges are needed.  It will not be called concurrently.
 - \b Initialize() and \b Finalize() are called once per event-loop,  right before starting and right after finishing.
 - \b InitSlot(), \b SetEntry(), and \b FinalizeSlot() can be called concurrently from multiple threads, multiple times per event-loop.
*/
class RDataSource {
   // clang-format on
protected:
   using Record_t = std::vector<void *>;
   friend std::string cling::printValue(::ROOT::RDF::RDataSource *);

   virtual std::string AsString() { return "generic data source"; };

public:
   virtual ~RDataSource() = default;

   // clang-format off
   /// \brief Inform RDataSource of the number of processing slots (i.e. worker threads) used by the associated RDataFrame.
   /// Slots numbers are used to simplify parallel execution: RDataFrame guarantees that different threads will always
   /// pass different slot values when calling methods concurrently.
   // clang-format on
   virtual void SetNSlots(unsigned int nSlots) = 0;

   // clang-format off
   /// \brief Returns a reference to the collection of the dataset's column names
   // clang-format on
   virtual const std::vector<std::string> &GetColumnNames() const = 0;

   /// \brief Checks if the dataset has a certain column
   /// \param[in] colName The name of the column
   virtual bool HasColumn(std::string_view colName) const = 0;

   // clang-format off
   /// \brief Type of a column as a string, e.g. `GetTypeName("x") == "double"`. Required for jitting e.g. `df.Filter("x>0")`.
   /// \param[in] colName The name of the column
   // clang-format on
   virtual std::string GetTypeName(std::string_view colName) const = 0;

   // clang-format off
   /// Called at most once per column by RDF. Return vector of pointers to pointers to column values - one per slot.
   /// \tparam T The type of the data stored in the column
   /// \param[in] columnName The name of the column
   ///
   /// These pointers are veritable cursors: it's a responsibility of the RDataSource implementation that they point to
   /// the "right" memory region.
   // clang-format on
   template <typename T>
   std::vector<T **> GetColumnReaders(std::string_view columnName)
   {
      auto typeErasedVec = GetColumnReadersImpl(columnName, typeid(T));
      std::vector<T **> typedVec(typeErasedVec.size());
      std::transform(typeErasedVec.begin(), typeErasedVec.end(), typedVec.begin(),
                     [](void *p) { return static_cast<T **>(p); });
      return typedVec;
   }

   /// If the other GetColumnReaders overload returns an empty vector, this overload will be called instead.
   /// \param[in] slot The data processing slot that needs to be considered
   /// \param[in] name The name of the column for which a column reader needs to be returned
   /// \param[in] tid A type_info
   /// At least one of the two must return a non-empty/non-null value.
   virtual std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase>
   GetColumnReaders(unsigned int /*slot*/, std::string_view /*name*/, const std::type_info &)
   {
      return {};
   }

   // clang-format off
   /// \brief Return ranges of entries to distribute to tasks.
   /// They are required to be contiguous intervals with no entries skipped. Supposing a dataset with nEntries, the
   /// intervals must start at 0 and end at nEntries, e.g. [0-5],[5-10] for 10 entries.
   /// This function will be invoked repeatedly by RDataFrame as it needs additional entries to process.
   /// The same entry range should not be returned more than once.
   /// Returning an empty collection of ranges signals to RDataFrame that the processing can stop.
   // clang-format on
   virtual std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() = 0;

   // clang-format off
   /// \brief Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
   /// \param[in] slot The data processing slot that needs to be considered
   /// \param[in] entry The entry which needs to be pointed to by the reader pointers
   /// Slots are adopted to accommodate parallel data processing.
   /// Different workers will loop over different ranges and
   /// will be labelled by different "slot" values.
   /// Returns *true* if the entry has to be processed, *false* otherwise.
   // clang-format on
   virtual bool SetEntry(unsigned int slot, ULong64_t entry) = 0;

   // clang-format off
   /// \brief Convenience method called before starting an event-loop.
   /// This method might be called multiple times over the lifetime of a RDataSource, since
   /// users can run multiple event-loops with the same RDataFrame.
   /// Ideally, `Initialize` should set the state of the RDataSource so that multiple identical event-loops
   /// will produce identical results.
   // clang-format on
   virtual void Initialize() {}

   /// \cond
   // Unused deprecated struct, it's here to remind us to remove the deprecated spellings Initialise, Finalise and
   // FinaliseSlot.
   struct R__DEPRECATED(6, 30,
                        "Use Initialize, Finalize and FinalizeSlot instead of the corresponding british spellings.")
      NeverUsedJustAReminder {
   };

   virtual void Initialise() { throw 0; }

   void CallInitialize()
   {
      try {
         Initialise();
      } catch (int) {
         Initialize();
         return;
      }
      Warning("RDataSource::Initialise",
              "Initialise is deprecated. Please implement Initialize (with a z) instead of Initialise.");
   }
   /// \endcond

   // clang-format off
   /// \brief Convenience method called at the start of the data processing associated to a slot.
   /// \param[in] slot The data processing slot wihch needs to be initialized
   /// \param[in] firstEntry The first entry of the range that the task will process.
   /// This method might be called multiple times per thread per event-loop.
   // clang-format on
   virtual void InitSlot(unsigned int /*slot*/, ULong64_t /*firstEntry*/) {}

   // clang-format off
   /// \brief Convenience method called at the end of the data processing associated to a slot.
   /// \param[in] slot The data processing slot wihch needs to be finalized
   /// This method might be called multiple times per thread per event-loop.
   // clang-format on
   virtual void FinalizeSlot(unsigned int /*slot*/) {}

   /// \cond
   virtual void FinaliseSlot(unsigned int) { throw 0; }

   void CallFinalizeSlot(unsigned int slot)
   {
      try {
         FinaliseSlot(slot);
      } catch (int) {
         FinalizeSlot(slot);
         return;
      }
      Warning("RDataSource::FinaliseSlot",
              "FinaliseSlot is deprecated. Please implement FinalizeSlot (with a z) instead of FinaliseSlot.");
   }
   /// \endcond

   // clang-format off
   /// \brief Convenience method called after concluding an event-loop.
   /// See Initialize for more details.
   // clang-format on
   virtual void Finalize() {}

   /// \cond
   virtual void Finalise() { throw 0; }

   void CallFinalize()
   {
      try {
         Finalise();
      } catch (int) {
         Finalize();
         return;
      }
      Warning("RDataSource::Finalise",
              "Finalise is deprecated. Please implement Finalize (with a z) instead of Finalise.");
   }
   /// \endcond

   /// \brief Return a string representation of the datasource type.
   /// The returned string will be used by ROOT::RDF::SaveGraph() to represent
   /// the datasource in the visualization of the computation graph.
   /// Concrete datasources can override the default implementation.
   virtual std::string GetLabel() { return "Custom Datasource"; }

protected:
   /// type-erased vector of pointers to pointers to column values - one per slot
   virtual Record_t GetColumnReadersImpl(std::string_view name, const std::type_info &) = 0;
};

} // ns RDF

} // ns ROOT

/// Print a RDataSource at the prompt
namespace cling {
inline std::string printValue(ROOT::RDF::RDataSource *ds)
{
   return ds->AsString();
}
} // namespace cling

#endif // ROOT_TDATASOURCE
<commit_msg>[DF][NFC] Improve comments and warning message<commit_after>// Author: Enrico Guiraud, Danilo Piparo CERN  09/2017

/*************************************************************************
 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_RDATASOURCE
#define ROOT_RDATASOURCE

#include "RDF/RColumnReaderBase.hxx"
#include "ROOT/RStringView.hxx"
#include "ROOT/RConfig.hxx" // R__DEPRECATED
#include "RtypesCore.h" // ULong64_t
#include "TError.h" // Warning
#include "TString.h"

#include <algorithm> // std::transform
#include <string>
#include <typeinfo>
#include <vector>

namespace ROOT {
namespace RDF {
class RDataSource;
}
}

/// Print a RDataSource at the prompt
namespace cling {
std::string printValue(ROOT::RDF::RDataSource *ds);
} // namespace cling

namespace ROOT {

namespace Internal {
namespace TDS {

/// Mother class of TTypedPointerHolder. The instances
/// of this class can be put in a container. Upon destruction,
/// the correct deletion of the pointer is performed in the
/// derived class.
class TPointerHolder {
protected:
   void *fPointer{nullptr};

public:
   TPointerHolder(void *ptr) : fPointer(ptr) {}
   void *GetPointer() { return fPointer; }
   void *GetPointerAddr() { return &fPointer; }
   virtual TPointerHolder *GetDeepCopy() = 0;
   virtual ~TPointerHolder(){};
};

/// Class to wrap a pointer and delete the memory associated to it
/// correctly
template <typename T>
class TTypedPointerHolder final : public TPointerHolder {
public:
   TTypedPointerHolder(T *ptr) : TPointerHolder((void *)ptr) {}

   virtual TPointerHolder *GetDeepCopy()
   {
      const auto typedPtr = static_cast<T *>(fPointer);
      return new TTypedPointerHolder(new T(*typedPtr));
   }

   ~TTypedPointerHolder() { delete static_cast<T *>(fPointer); }
};

} // ns TDS
} // ns Internal

namespace RDF {

// clang-format off
/**
\class ROOT::RDF::RDataSource
\ingroup dataframe
\brief RDataSource defines an API that RDataFrame can use to read arbitrary data formats.

A concrete RDataSource implementation (i.e. a class that inherits from RDataSource and implements all of its pure
methods) provides an adaptor that RDataFrame can leverage to read any kind of tabular data formats.
RDataFrame calls into RDataSource to retrieve information about the data, retrieve (thread-local) readers or "cursors"
for selected columns and to advance the readers to the desired data entry.

The sequence of calls that RDataFrame (or any other client of a RDataSource) performs is the following:

 - SetNSlots() : inform RDataSource of the desired level of parallelism
 - GetColumnReaders() : retrieve from RDataSource per-thread readers for the desired columns
 - Initialize() : inform RDataSource that an event-loop is about to start
 - GetEntryRanges() : retrieve from RDataSource a set of ranges of entries that can be processed concurrently
 - InitSlot() : inform RDataSource that a certain thread is about to start working on a certain range of entries
 - SetEntry() : inform RDataSource that a certain thread is about to start working on a certain entry
 - FinalizeSlot() : inform RDataSource that a certain thread finished working on a certain range of entries
 - Finalize() : inform RDataSource that an event-loop finished

RDataSource implementations must support running multiple event-loops consecutively (although sequentially) on the same dataset.
 - \b SetNSlots() is called once per RDataSource object, typically when it is associated to a RDataFrame.
 - \b GetColumnReaders() can be called several times, potentially with the same arguments, also in-between event-loops, but not during an event-loop.
 - \b GetEntryRanges() will be called several times, including during an event loop, as additional ranges are needed.  It will not be called concurrently.
 - \b Initialize() and \b Finalize() are called once per event-loop,  right before starting and right after finishing.
 - \b InitSlot(), \b SetEntry(), and \b FinalizeSlot() can be called concurrently from multiple threads, multiple times per event-loop.
*/
class RDataSource {
   // clang-format on
protected:
   using Record_t = std::vector<void *>;
   friend std::string cling::printValue(::ROOT::RDF::RDataSource *);

   virtual std::string AsString() { return "generic data source"; };

public:
   virtual ~RDataSource() = default;

   // clang-format off
   /// \brief Inform RDataSource of the number of processing slots (i.e. worker threads) used by the associated RDataFrame.
   /// Slots numbers are used to simplify parallel execution: RDataFrame guarantees that different threads will always
   /// pass different slot values when calling methods concurrently.
   // clang-format on
   virtual void SetNSlots(unsigned int nSlots) = 0;

   // clang-format off
   /// \brief Returns a reference to the collection of the dataset's column names
   // clang-format on
   virtual const std::vector<std::string> &GetColumnNames() const = 0;

   /// \brief Checks if the dataset has a certain column
   /// \param[in] colName The name of the column
   virtual bool HasColumn(std::string_view colName) const = 0;

   // clang-format off
   /// \brief Type of a column as a string, e.g. `GetTypeName("x") == "double"`. Required for jitting e.g. `df.Filter("x>0")`.
   /// \param[in] colName The name of the column
   // clang-format on
   virtual std::string GetTypeName(std::string_view colName) const = 0;

   // clang-format off
   /// Called at most once per column by RDF. Return vector of pointers to pointers to column values - one per slot.
   /// \tparam T The type of the data stored in the column
   /// \param[in] columnName The name of the column
   ///
   /// These pointers are veritable cursors: it's a responsibility of the RDataSource implementation that they point to
   /// the "right" memory region.
   // clang-format on
   template <typename T>
   std::vector<T **> GetColumnReaders(std::string_view columnName)
   {
      auto typeErasedVec = GetColumnReadersImpl(columnName, typeid(T));
      std::vector<T **> typedVec(typeErasedVec.size());
      std::transform(typeErasedVec.begin(), typeErasedVec.end(), typedVec.begin(),
                     [](void *p) { return static_cast<T **>(p); });
      return typedVec;
   }

   /// If the other GetColumnReaders overload returns an empty vector, this overload will be called instead.
   /// \param[in] slot The data processing slot that needs to be considered
   /// \param[in] name The name of the column for which a column reader needs to be returned
   /// \param[in] tid A type_info
   /// At least one of the two must return a non-empty/non-null value.
   virtual std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase>
   GetColumnReaders(unsigned int /*slot*/, std::string_view /*name*/, const std::type_info &)
   {
      return {};
   }

   // clang-format off
   /// \brief Return ranges of entries to distribute to tasks.
   /// They are required to be contiguous intervals with no entries skipped. Supposing a dataset with nEntries, the
   /// intervals must start at 0 and end at nEntries, e.g. [0-5],[5-10] for 10 entries.
   /// This function will be invoked repeatedly by RDataFrame as it needs additional entries to process.
   /// The same entry range should not be returned more than once.
   /// Returning an empty collection of ranges signals to RDataFrame that the processing can stop.
   // clang-format on
   virtual std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() = 0;

   // clang-format off
   /// \brief Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
   /// \param[in] slot The data processing slot that needs to be considered
   /// \param[in] entry The entry which needs to be pointed to by the reader pointers
   /// Slots are adopted to accommodate parallel data processing.
   /// Different workers will loop over different ranges and
   /// will be labelled by different "slot" values.
   /// Returns *true* if the entry has to be processed, *false* otherwise.
   // clang-format on
   virtual bool SetEntry(unsigned int slot, ULong64_t entry) = 0;

   // clang-format off
   /// \brief Convenience method called before starting an event-loop.
   /// This method might be called multiple times over the lifetime of a RDataSource, since
   /// users can run multiple event-loops with the same RDataFrame.
   /// Ideally, `Initialize` should set the state of the RDataSource so that multiple identical event-loops
   /// will produce identical results.
   // clang-format on
   virtual void Initialize() {}

   /// \cond
   // Unused deprecated struct, it's here to remind us to remove the deprecated spellings Initialise, Finalise and
   // FinaliseSlot. PR that removes the deprecated code: https://github.com/root-project/root/pull/9521 .
   struct R__DEPRECATED(6, 30,
                        "Use Initialize, Finalize and FinalizeSlot instead of the corresponding british spellings.")
      NeverUsedJustAReminder {
   };

   virtual void Initialise() { throw 0; }

   void CallInitialize()
   {
      try {
         Initialise();
      } catch (int) {
         // `Initialise()` was not overridden and threw, the data source uses the new spelling: good!
         Initialize();
         return;
      }
      Warning("RDataSource::Initialise",
              "Initialise is deprecated. Please rename it to \"Initialize\" (with a z).");
   }
   /// \endcond

   // clang-format off
   /// \brief Convenience method called at the start of the data processing associated to a slot.
   /// \param[in] slot The data processing slot wihch needs to be initialized
   /// \param[in] firstEntry The first entry of the range that the task will process.
   /// This method might be called multiple times per thread per event-loop.
   // clang-format on
   virtual void InitSlot(unsigned int /*slot*/, ULong64_t /*firstEntry*/) {}

   // clang-format off
   /// \brief Convenience method called at the end of the data processing associated to a slot.
   /// \param[in] slot The data processing slot wihch needs to be finalized
   /// This method might be called multiple times per thread per event-loop.
   // clang-format on
   virtual void FinalizeSlot(unsigned int /*slot*/) {}

   /// \cond
   virtual void FinaliseSlot(unsigned int) { throw 0; }

   void CallFinalizeSlot(unsigned int slot)
   {
      try {
         FinaliseSlot(slot);
      } catch (int) {
         FinalizeSlot(slot);
         return;
      }
      Warning("RDataSource::FinaliseSlot",
              "FinaliseSlot is deprecated. Please implement FinalizeSlot (with a z) instead of FinaliseSlot.");
   }
   /// \endcond

   // clang-format off
   /// \brief Convenience method called after concluding an event-loop.
   /// See Initialize for more details.
   // clang-format on
   virtual void Finalize() {}

   /// \cond
   virtual void Finalise() { throw 0; }

   void CallFinalize()
   {
      try {
         Finalise();
      } catch (int) {
         Finalize();
         return;
      }
      Warning("RDataSource::Finalise",
              "Finalise is deprecated. Please implement Finalize (with a z) instead of Finalise.");
   }
   /// \endcond

   /// \brief Return a string representation of the datasource type.
   /// The returned string will be used by ROOT::RDF::SaveGraph() to represent
   /// the datasource in the visualization of the computation graph.
   /// Concrete datasources can override the default implementation.
   virtual std::string GetLabel() { return "Custom Datasource"; }

protected:
   /// type-erased vector of pointers to pointers to column values - one per slot
   virtual Record_t GetColumnReadersImpl(std::string_view name, const std::type_info &) = 0;
};

} // ns RDF

} // ns ROOT

/// Print a RDataSource at the prompt
namespace cling {
inline std::string printValue(ROOT::RDF::RDataSource *ds)
{
   return ds->AsString();
}
} // namespace cling

#endif // ROOT_TDATASOURCE
<|endoftext|>


<commit_before>/*******************************************************
 * Copyright (c) 2014, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#include <gtest/gtest.h>
#include <arrayfire.h>
#include <af/dim4.hpp>
#include <af/traits.hpp>
#include <vector>
#include <iostream>
#include <string>
#include <testHelpers.hpp>

using std::vector;
using std::string;
using std::cout;
using std::endl;
using af::af_cfloat;
using af::af_cdouble;

template<typename T>
class Rotate : public ::testing::Test
{
    public:
        virtual void SetUp() {
            subMat0.push_back({0, 4, 1});
            subMat0.push_back({2, 6, 1});
            subMat0.push_back({0, 2, 1});
        }
        vector<af_seq> subMat0;
};

// create a list of types to be tested
typedef ::testing::Types<float, double> TestTypes;

// register the type list
TYPED_TEST_CASE(Rotate, TestTypes);

#define PI 3.1415926535897931f

template<typename T>
void rotateTest(string pTestFile, const unsigned resultIdx, const float angle, const bool crop, const bool recenter, bool isSubRef = false, const vector<af_seq> * seqv = nullptr)
{
    vector<af::dim4> numDims;
    vector<vector<T>>   in;
    vector<vector<T>>   tests;
    readTests<T, T, float>(pTestFile,numDims,in,tests);

    af::dim4 dims = numDims[0];

    af_array inArray = 0;
    af_array outArray = 0;
    af_array tempArray = 0;

    float theta = angle * PI / 180.0f;

    if (isSubRef) {

        ASSERT_EQ(AF_SUCCESS, af_create_array(&tempArray, &(in[0].front()), dims.ndims(), dims.get(), (af_dtype) af::dtype_traits<T>::af_type));

        ASSERT_EQ(AF_SUCCESS, af_index(&inArray, tempArray, seqv->size(), &seqv->front()));
    } else {
        ASSERT_EQ(AF_SUCCESS, af_create_array(&inArray, &(in[0].front()), dims.ndims(), dims.get(), (af_dtype) af::dtype_traits<T>::af_type));
    }

    ASSERT_EQ(AF_SUCCESS, af_rotate(&outArray, inArray, theta, AF_INTERP_BILINEAR, crop, recenter));

    // Get result
    T* outData = new T[tests[resultIdx].size()];
    ASSERT_EQ(AF_SUCCESS, af_get_data_ptr((void*)outData, outArray));

    // Compare result
    size_t nElems = tests[resultIdx].size();

    // This is a temporary solution. The reason we need this is because of
    // floating point error in the index computations on CPU/GPU, some
    // elements of GPU(CUDA/OpenCL) versions are different from the CPU version.
    // That is, the input index of CPU/GPU may differ by 1 (rounding error) on
    // x or y, hence a different value is copied.
    // We expect 99.99% values to be same between the CPU/GPU versions and
    // ASSERT_EQ (in comments below) to pass for CUDA & OpenCL backends
    size_t fail_count = 0;
    for(size_t i = 0; i < nElems; i++) {
        if(abs((double)(tests[resultIdx][i] - outData[i])) > 0.0001)
            fail_count++;
    }
    ASSERT_EQ(true, ((fail_count / (float)nElems) < 0.01));

    //for (size_t elIter = 0; elIter < nElems; ++elIter) {
    //    ASSERT_EQ(tests[resultIdx][elIter], outData[elIter]) << "at: " << elIter << std::endl;
    //}

    // Delete
    delete[] outData;

    if(inArray   != 0) af_destroy_array(inArray);
    if(outArray  != 0) af_destroy_array(outArray);
    if(tempArray != 0) af_destroy_array(tempArray);
}

#define ROTATE_INIT(desc, file, resultIdx, angle, crop, recenter)                               \
    TYPED_TEST(Rotate, desc)                                                                    \
    {                                                                                \
        rotateTest<TypeParam>(string(TEST_DIR"/rotate/"#file".test"), resultIdx, angle, crop, recenter);\
    }

    ROTATE_INIT(Square180NoCropRecenter     , rotatelinear1,  0, 180, false, true);
    ROTATE_INIT(Square180CropRecenter       , rotatelinear1,  1, 180, true , true);
    ROTATE_INIT(Square90NoCropRecenter      , rotatelinear1,  2, 90 , false, true);
    ROTATE_INIT(Square90CropRecenter        , rotatelinear1,  3, 90 , true , true);
    ROTATE_INIT(Square45NoCropRecenter      , rotatelinear1,  4, 45 , false, true);
    ROTATE_INIT(Square45CropRecenter        , rotatelinear1,  5, 45 , true , true);
    ROTATE_INIT(Squarem45NoCropRecenter     , rotatelinear1,  6,-45 , false, true);
    ROTATE_INIT(Squarem45CropRecenter       , rotatelinear1,  7,-45 , true , true);
    ROTATE_INIT(Square60NoCropRecenter      , rotatelinear1,  8, 60 , false, true);
    ROTATE_INIT(Square60CropRecenter        , rotatelinear1,  9, 60 , true , true);
    ROTATE_INIT(Square30NoCropRecenter      , rotatelinear1, 10, 30 , false, true);
    ROTATE_INIT(Square30CropRecenter        , rotatelinear1, 11, 30 , true , true);
    ROTATE_INIT(Square15NoCropRecenter      , rotatelinear1, 12, 15 , false, true);
    ROTATE_INIT(Square15CropRecenter        , rotatelinear1, 13, 15 , true , true);
    ROTATE_INIT(Square10NoCropRecenter      , rotatelinear1, 14, 10 , false, true);
    ROTATE_INIT(Square10CropRecenter        , rotatelinear1, 15, 10 , true , true);
    ROTATE_INIT(Square01NoCropRecenter      , rotatelinear1, 16,  1 , false, true);
    ROTATE_INIT(Square01CropRecenter        , rotatelinear1, 17,  1 , true , true);
    ROTATE_INIT(Square360NoCropRecenter     , rotatelinear1, 18, 360, false, true);
    ROTATE_INIT(Square360CropRecenter       , rotatelinear1, 19, 360, true , true);
    ROTATE_INIT(Squarem180NoCropRecenter    , rotatelinear1, 20,-180, false, true);
    ROTATE_INIT(Squarem180CropRecenter      , rotatelinear1, 21,-180, false, true);
    ROTATE_INIT(Square00NoCropRecenter      , rotatelinear1, 22,  0 , false, true);
    ROTATE_INIT(Square00CropRecenter        , rotatelinear1, 23,  0 , true , true);
    ROTATE_INIT(Square45NoCropNoRecenter    , rotatelinear1, 24, 45 , false, false);
    ROTATE_INIT(Square45CropNoRecenter      , rotatelinear1, 25, 45 , true , false);

    ROTATE_INIT(Rectangle180NoCropRecenter     , rotatelinear2,  0, 180, false, true);
    ROTATE_INIT(Rectangle180CropRecenter       , rotatelinear2,  1, 180, true , true);
    ROTATE_INIT(Rectangle90NoCropRecenter      , rotatelinear2,  2, 90 , false, true);
  //ROTATE_INIT(Rectangle90CropRecenter        , rotatelinear2,  3, 90 , true , true);
    ROTATE_INIT(Rectangle45NoCropRecenter      , rotatelinear2,  4, 45 , false, true);
    ROTATE_INIT(Rectangle45CropRecenter        , rotatelinear2,  5, 45 , true , true);
    ROTATE_INIT(Rectanglem45NoCropRecenter     , rotatelinear2,  6,-45 , false, true);
    ROTATE_INIT(Rectanglem45CropRecenter       , rotatelinear2,  7,-45 , true , true);
    ROTATE_INIT(Rectangle60NoCropRecenter      , rotatelinear2,  8, 60 , false, true);
    ROTATE_INIT(Rectangle60CropRecenter        , rotatelinear2,  9, 60 , true , true);
    ROTATE_INIT(Rectangle30NoCropRecenter      , rotatelinear2, 10, 30 , false, true);
    ROTATE_INIT(Rectangle30CropRecenter        , rotatelinear2, 11, 30 , true , true);
    ROTATE_INIT(Rectangle15NoCropRecenter      , rotatelinear2, 12, 15 , false, true);
    ROTATE_INIT(Rectangle15CropRecenter        , rotatelinear2, 13, 15 , true , true);
    ROTATE_INIT(Rectangle10NoCropRecenter      , rotatelinear2, 14, 10 , false, true);
    ROTATE_INIT(Rectangle10CropRecenter        , rotatelinear2, 15, 10 , true , true);
    ROTATE_INIT(Rectangle01NoCropRecenter      , rotatelinear2, 16,  1 , false, true);
    ROTATE_INIT(Rectangle01CropRecenter        , rotatelinear2, 17,  1 , true , true);
    ROTATE_INIT(Rectangle360NoCropRecenter     , rotatelinear2, 18, 360, false, true);
    ROTATE_INIT(Rectangle360CropRecenter       , rotatelinear2, 19, 360, true , true);
    ROTATE_INIT(Rectanglem180NoCropRecenter    , rotatelinear2, 20,-180, false, true);
    ROTATE_INIT(Rectanglem180CropRecenter      , rotatelinear2, 21,-180, false, true);
    ROTATE_INIT(Rectangle00NoCropRecenter      , rotatelinear2, 22,  0 , false, true);
    ROTATE_INIT(Rectangle00CropRecenter        , rotatelinear2, 23,  0 , true , true);
    ROTATE_INIT(Rectangle45NoCropNoRecenter    , rotatelinear2, 24, 45 , false, false);
    ROTATE_INIT(Rectangle45CropNoRecenter      , rotatelinear2, 25, 45 , true , false);

////////////////////////////////// CPP //////////////////////////////////////

TEST(Rotate, CPP)
{
    const unsigned resultIdx = 0;
    const float angle = 180;
    const bool crop = false;
    const bool recenter =true;

    vector<af::dim4> numDims;
    vector<vector<float>>   in;
    vector<vector<float>>   tests;
    readTests<float, float, float>(string(TEST_DIR"/rotate/rotatelinear1.test"),numDims,in,tests);

    af::dim4 dims = numDims[0];
    float theta = angle * PI / 180.0f;

    af::array input(dims, &(in[0].front()));
    af::array output = af::rotate(input, theta, AF_INTERP_BILINEAR, crop, recenter);

    // Get result
    float* outData = new float[tests[resultIdx].size()];
    output.host((void*)outData);

    // Compare result
    size_t nElems = tests[resultIdx].size();

    // This is a temporary solution. The reason we need this is because of
    // floating point error in the index computations on CPU/GPU, some
    // elements of GPU(CUDA/OpenCL) versions are different from the CPU version.
    // That is, the input index of CPU/GPU may differ by 1 (rounding error) on
    // x or y, hence a different value is copied.
    // We expect 99.99% values to be same between the CPU/GPU versions and
    // ASSERT_EQ (in comments below) to pass for CUDA & OpenCL backends
    size_t fail_count = 0;
    for(size_t i = 0; i < nElems; i++) {
        if(abs(tests[resultIdx][i] - outData[i]) > 0.0001)
            fail_count++;
    }
    ASSERT_EQ(true, ((fail_count / (float)nElems) < 0.01));

    // Delete
    delete[] outData;
}
<commit_msg>Fixes for rotate bilinear tests<commit_after>/*******************************************************
 * Copyright (c) 2014, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#include <gtest/gtest.h>
#include <arrayfire.h>
#include <af/dim4.hpp>
#include <af/traits.hpp>
#include <vector>
#include <iostream>
#include <string>
#include <testHelpers.hpp>

using std::vector;
using std::string;
using std::cout;
using std::endl;
using af::af_cfloat;
using af::af_cdouble;

template<typename T>
class Rotate : public ::testing::Test
{
    public:
        virtual void SetUp() {
            subMat0.push_back({0, 4, 1});
            subMat0.push_back({2, 6, 1});
            subMat0.push_back({0, 2, 1});
        }
        vector<af_seq> subMat0;
};

// create a list of types to be tested
typedef ::testing::Types<float, double> TestTypes;

// register the type list
TYPED_TEST_CASE(Rotate, TestTypes);

#define PI 3.1415926535897931f

template<typename T>
void rotateTest(string pTestFile, const unsigned resultIdx, const float angle, const bool crop, const bool recenter, bool isSubRef = false, const vector<af_seq> * seqv = nullptr)
{
    vector<af::dim4> numDims;
    vector<vector<T>>   in;
    vector<vector<T>>   tests;
    readTests<T, T, float>(pTestFile,numDims,in,tests);

    af::dim4 dims = numDims[0];

    af_array inArray = 0;
    af_array outArray = 0;
    af_array tempArray = 0;

    float theta = angle * PI / 180.0f;

    if (isSubRef) {

        ASSERT_EQ(AF_SUCCESS, af_create_array(&tempArray, &(in[0].front()), dims.ndims(), dims.get(), (af_dtype) af::dtype_traits<T>::af_type));

        ASSERT_EQ(AF_SUCCESS, af_index(&inArray, tempArray, seqv->size(), &seqv->front()));
    } else {
        ASSERT_EQ(AF_SUCCESS, af_create_array(&inArray, &(in[0].front()), dims.ndims(), dims.get(), (af_dtype) af::dtype_traits<T>::af_type));
    }

    ASSERT_EQ(AF_SUCCESS, af_rotate(&outArray, inArray, theta, AF_INTERP_BILINEAR, crop, recenter));

    // Get result
    T* outData = new T[tests[resultIdx].size()];
    ASSERT_EQ(AF_SUCCESS, af_get_data_ptr((void*)outData, outArray));

    // Compare result
    size_t nElems = tests[resultIdx].size();

    // This is a temporary solution. The reason we need this is because of
    // floating point error in the index computations on CPU/GPU, some
    // elements of GPU(CUDA/OpenCL) versions are different from the CPU version.
    // That is, the input index of CPU/GPU may differ by 1 (rounding error) on
    // x or y, hence a different value is copied.
    // We expect 99.99% values to be same between the CPU/GPU versions and
    // ASSERT_EQ (in comments below) to pass for CUDA & OpenCL backends
    size_t fail_count = 0;
    for(size_t i = 0; i < nElems; i++) {
        if(abs((double)(tests[resultIdx][i] - outData[i])) > 0.0001)
            fail_count++;
    }
    ASSERT_EQ(true, ((fail_count / (float)nElems) < 0.02));

    //for (size_t elIter = 0; elIter < nElems; ++elIter) {
    //    ASSERT_EQ(tests[resultIdx][elIter], outData[elIter]) << "at: " << elIter << std::endl;
    //}

    // Delete
    delete[] outData;

    if(inArray   != 0) af_destroy_array(inArray);
    if(outArray  != 0) af_destroy_array(outArray);
    if(tempArray != 0) af_destroy_array(tempArray);
}

#define ROTATE_INIT(desc, file, resultIdx, angle, crop, recenter)                               \
    TYPED_TEST(Rotate, desc)                                                                    \
    {                                                                                \
        rotateTest<TypeParam>(string(TEST_DIR"/rotate/"#file".test"), resultIdx, angle, crop, recenter);\
    }

    ROTATE_INIT(Square180NoCropRecenter     , rotatelinear1,  0, 180, false, true);
    ROTATE_INIT(Square180CropRecenter       , rotatelinear1,  1, 180, true , true);
    ROTATE_INIT(Square90NoCropRecenter      , rotatelinear1,  2, 90 , false, true);
    ROTATE_INIT(Square90CropRecenter        , rotatelinear1,  3, 90 , true , true);
    ROTATE_INIT(Square45NoCropRecenter      , rotatelinear1,  4, 45 , false, true);
    ROTATE_INIT(Square45CropRecenter        , rotatelinear1,  5, 45 , true , true);
    ROTATE_INIT(Squarem45NoCropRecenter     , rotatelinear1,  6,-45 , false, true);
    ROTATE_INIT(Squarem45CropRecenter       , rotatelinear1,  7,-45 , true , true);
    ROTATE_INIT(Square60NoCropRecenter      , rotatelinear1,  8, 60 , false, true);
    ROTATE_INIT(Square60CropRecenter        , rotatelinear1,  9, 60 , true , true);
    ROTATE_INIT(Square30NoCropRecenter      , rotatelinear1, 10, 30 , false, true);
    ROTATE_INIT(Square30CropRecenter        , rotatelinear1, 11, 30 , true , true);
    ROTATE_INIT(Square15NoCropRecenter      , rotatelinear1, 12, 15 , false, true);
    ROTATE_INIT(Square15CropRecenter        , rotatelinear1, 13, 15 , true , true);
    ROTATE_INIT(Square10NoCropRecenter      , rotatelinear1, 14, 10 , false, true);
    ROTATE_INIT(Square10CropRecenter        , rotatelinear1, 15, 10 , true , true);
    ROTATE_INIT(Square01NoCropRecenter      , rotatelinear1, 16,  1 , false, true);
    ROTATE_INIT(Square01CropRecenter        , rotatelinear1, 17,  1 , true , true);
    ROTATE_INIT(Square360NoCropRecenter     , rotatelinear1, 18, 360, false, true);
    ROTATE_INIT(Square360CropRecenter       , rotatelinear1, 19, 360, true , true);
    ROTATE_INIT(Squarem180NoCropRecenter    , rotatelinear1, 20,-180, false, true);
    ROTATE_INIT(Squarem180CropRecenter      , rotatelinear1, 21,-180, false, true);
    ROTATE_INIT(Square00NoCropRecenter      , rotatelinear1, 22,  0 , false, true);
    ROTATE_INIT(Square00CropRecenter        , rotatelinear1, 23,  0 , true , true);
    ROTATE_INIT(Square45NoCropNoRecenter    , rotatelinear1, 24, 45 , false, false);
    ROTATE_INIT(Square45CropNoRecenter      , rotatelinear1, 25, 45 , true , false);

    ROTATE_INIT(Rectangle180NoCropRecenter     , rotatelinear2,  0, 180, false, true);
    ROTATE_INIT(Rectangle180CropRecenter       , rotatelinear2,  1, 180, true , true);
    ROTATE_INIT(Rectangle90NoCropRecenter      , rotatelinear2,  2, 90 , false, true);
    ROTATE_INIT(Rectangle90CropRecenter        , rotatelinear2,  3, 90 , true , true);
    ROTATE_INIT(Rectangle45NoCropRecenter      , rotatelinear2,  4, 45 , false, true);
    ROTATE_INIT(Rectangle45CropRecenter        , rotatelinear2,  5, 45 , true , true);
    ROTATE_INIT(Rectanglem45NoCropRecenter     , rotatelinear2,  6,-45 , false, true);
    ROTATE_INIT(Rectanglem45CropRecenter       , rotatelinear2,  7,-45 , true , true);
    ROTATE_INIT(Rectangle60NoCropRecenter      , rotatelinear2,  8, 60 , false, true);
    ROTATE_INIT(Rectangle60CropRecenter        , rotatelinear2,  9, 60 , true , true);
    ROTATE_INIT(Rectangle30NoCropRecenter      , rotatelinear2, 10, 30 , false, true);
    ROTATE_INIT(Rectangle30CropRecenter        , rotatelinear2, 11, 30 , true , true);
    ROTATE_INIT(Rectangle15NoCropRecenter      , rotatelinear2, 12, 15 , false, true);
    ROTATE_INIT(Rectangle15CropRecenter        , rotatelinear2, 13, 15 , true , true);
    ROTATE_INIT(Rectangle10NoCropRecenter      , rotatelinear2, 14, 10 , false, true);
    ROTATE_INIT(Rectangle10CropRecenter        , rotatelinear2, 15, 10 , true , true);
    ROTATE_INIT(Rectangle01NoCropRecenter      , rotatelinear2, 16,  1 , false, true);
    ROTATE_INIT(Rectangle01CropRecenter        , rotatelinear2, 17,  1 , true , true);
    ROTATE_INIT(Rectangle360NoCropRecenter     , rotatelinear2, 18, 360, false, true);
    ROTATE_INIT(Rectangle360CropRecenter       , rotatelinear2, 19, 360, true , true);
    ROTATE_INIT(Rectanglem180NoCropRecenter    , rotatelinear2, 20,-180, false, true);
    ROTATE_INIT(Rectanglem180CropRecenter      , rotatelinear2, 21,-180, false, true);
    ROTATE_INIT(Rectangle00NoCropRecenter      , rotatelinear2, 22,  0 , false, true);
    ROTATE_INIT(Rectangle00CropRecenter        , rotatelinear2, 23,  0 , true , true);
    ROTATE_INIT(Rectangle45NoCropNoRecenter    , rotatelinear2, 24, 45 , false, false);
    ROTATE_INIT(Rectangle45CropNoRecenter      , rotatelinear2, 25, 45 , true , false);

////////////////////////////////// CPP //////////////////////////////////////

TEST(Rotate, CPP)
{
    const unsigned resultIdx = 0;
    const float angle = 180;
    const bool crop = false;
    const bool recenter =true;

    vector<af::dim4> numDims;
    vector<vector<float>>   in;
    vector<vector<float>>   tests;
    readTests<float, float, float>(string(TEST_DIR"/rotate/rotatelinear1.test"),numDims,in,tests);

    af::dim4 dims = numDims[0];
    float theta = angle * PI / 180.0f;

    af::array input(dims, &(in[0].front()));
    af::array output = af::rotate(input, theta, AF_INTERP_BILINEAR, crop, recenter);

    // Get result
    float* outData = new float[tests[resultIdx].size()];
    output.host((void*)outData);

    // Compare result
    size_t nElems = tests[resultIdx].size();

    // This is a temporary solution. The reason we need this is because of
    // floating point error in the index computations on CPU/GPU, some
    // elements of GPU(CUDA/OpenCL) versions are different from the CPU version.
    // That is, the input index of CPU/GPU may differ by 1 (rounding error) on
    // x or y, hence a different value is copied.
    // We expect 99.99% values to be same between the CPU/GPU versions and
    // ASSERT_EQ (in comments below) to pass for CUDA & OpenCL backends
    size_t fail_count = 0;
    for(size_t i = 0; i < nElems; i++) {
        if(abs(tests[resultIdx][i] - outData[i]) > 0.0001)
            fail_count++;
    }
    ASSERT_EQ(true, ((fail_count / (float)nElems) < 0.01));

    // Delete
    delete[] outData;
}
<|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.                  *
**************************************************************************/

///////////////////////////////////////////////////////////////////////////
//                Dielectron DebugTree                                  //
//                                                                       //
//                                                                       //
/*
register variables from the variable manager. The output will be written
to a tree

NOTE: Please use with extream care! Only for debugging and test purposes!!!

*/
//                                                                       //
///////////////////////////////////////////////////////////////////////////

#include <TFile.h>
#include <TTree.h>
#include <TTreeStream.h>
#include <TObjString.h>
#include <TString.h>

#include <AliAnalysisManager.h>
#include <AliESDInputHandler.h>
#include <AliESDEvent.h>
#include <AliVTrack.h>

#include "AliDielectronPair.h"

#include "AliDielectronDebugTree.h"

ClassImp(AliDielectronDebugTree)

AliDielectronDebugTree::AliDielectronDebugTree() :
  TNamed(),
  fFileName("jpsi_debug.root"),
  fNVars(0),
  fNVarsLeg(0),
  fStreamer(0x0)
{
  //
  // Default Constructor
  //
  for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues;++i){
    fVariables[i]=0;
    fVariablesLeg[i]=0;
  }
}

//______________________________________________
AliDielectronDebugTree::AliDielectronDebugTree(const char* name, const char* title) :
  TNamed(name, title),
  fFileName("jpsi_debug.root"),
  fNVars(0),
  fNVarsLeg(0),
  fStreamer(0x0)
{
  //
  // Named Constructor
  //
  for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues;++i){
    fVariables[i]=0;
    fVariablesLeg[i]=0;
  }
}

//______________________________________________
AliDielectronDebugTree::~AliDielectronDebugTree()
{
  //
  // Default Destructor
  //
  if (fStreamer){
    fStreamer->GetFile()->Write();
    delete fStreamer;
  }
}

//______________________________________________
void AliDielectronDebugTree::Fill(AliDielectronPair *pair)
{
  //
  // Fill configured variables to the tree
  //

  //is there anything to fill
  if (fNVars==0&&fNVarsLeg==0) return;

  //only in local mode!!!
  AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
  if (man && man->GetAnalysisType()!=AliAnalysisManager::kLocalAnalysis) return;

  //Get File and event information
  TObjString fName;
  Int_t eventInFile=-1;

  TTree *t=man->GetTree();
  if (t) {
    TFile *file=t->GetCurrentFile();
    if (file) fName.SetString(file->GetName());
  }

  AliESDInputHandler *han=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler());
  if (han){
    AliESDEvent *ev=dynamic_cast<AliESDEvent*>(han->GetEvent());
    eventInFile=ev->GetEventNumberInFile();
  }

  if (!fStreamer) fStreamer=new TTreeSRedirector(fFileName.Data());
  Int_t id1=static_cast<AliVTrack*>(pair->GetFirstDaughter())->GetID();
  Int_t id2=static_cast<AliVTrack*>(pair->GetSecondDaughter())->GetID();
  //Fill Event information
  (*fStreamer) << "Pair"
    << "File.="       << &fName
    << "EventInFile=" << eventInFile
    << "Leg1_ID="     << id1
    << "Leg2_ID="     << id2;

  Int_t var=0;
  Double_t values[AliDielectronVarManager::kNMaxValues];
  Double_t valuesLeg1[AliDielectronVarManager::kNMaxValues];
  Double_t valuesLeg2[AliDielectronVarManager::kNMaxValues];
// fill pair values
  if (fNVars>0){
    AliDielectronVarManager::Fill(pair,values);

    for (Int_t i=0; i<fNVars; ++i){
      var=fVariables[i];
      (*fStreamer) << "Pair"
                   << Form("%s=",AliDielectronVarManager::GetValueName(var))
                   << values[var];
    }
  }

  if (fNVarsLeg>0){
    //leg1
    AliDielectronVarManager::Fill(pair->GetFirstDaughter(),valuesLeg1);
    //leg2
    AliDielectronVarManager::Fill(pair->GetSecondDaughter(),valuesLeg2);

    for (Int_t i=0; i<fNVarsLeg; ++i){
      var=fVariablesLeg[i];
      (*fStreamer) << "Pair"
                   << Form("Leg1_%s=",AliDielectronVarManager::GetValueName(var))
                   << valuesLeg1[var]
                   << Form("Leg2_%s=",AliDielectronVarManager::GetValueName(var))
                   << valuesLeg2[var];
    }

  }

  (*fStreamer) << "Pair" << "\n";

}

//______________________________________________
void AliDielectronDebugTree::DeleteStreamer()
{
  //
  // delete the streamer
  //
  if (!fStreamer) return;
  delete fStreamer;
  fStreamer=0x0;

}

//______________________________________________
void AliDielectronDebugTree::WriteTree()
{
  //
  // Write file
  //
  if (!fStreamer) return;
  fStreamer->GetFile()->Write();
}
<commit_msg>Fixed Warning (Jens)<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.                  *
**************************************************************************/

///////////////////////////////////////////////////////////////////////////
//                Dielectron DebugTree                                  //
//                                                                       //
//                                                                       //
/*
register variables from the variable manager. The output will be written
to a tree

NOTE: Please use with extream care! Only for debugging and test purposes!!!

*/
//                                                                       //
///////////////////////////////////////////////////////////////////////////

#include <TFile.h>
#include <TTree.h>
#include <TTreeStream.h>
#include <TObjString.h>
#include <TString.h>

#include <AliAnalysisManager.h>
#include <AliESDInputHandler.h>
#include <AliESDEvent.h>
#include <AliVTrack.h>

#include "AliDielectronPair.h"

#include "AliDielectronDebugTree.h"

ClassImp(AliDielectronDebugTree)

AliDielectronDebugTree::AliDielectronDebugTree() :
  TNamed(),
  fFileName("jpsi_debug.root"),
  fNVars(0),
  fNVarsLeg(0),
  fStreamer(0x0)
{
  //
  // Default Constructor
  //
  for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues;++i){
    fVariables[i]=0;
    fVariablesLeg[i]=0;
  }
}

//______________________________________________
AliDielectronDebugTree::AliDielectronDebugTree(const char* name, const char* title) :
  TNamed(name, title),
  fFileName("jpsi_debug.root"),
  fNVars(0),
  fNVarsLeg(0),
  fStreamer(0x0)
{
  //
  // Named Constructor
  //
  for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues;++i){
    fVariables[i]=0;
    fVariablesLeg[i]=0;
  }
}

//______________________________________________
AliDielectronDebugTree::~AliDielectronDebugTree()
{
  //
  // Default Destructor
  //
  if (fStreamer){
    fStreamer->GetFile()->Write();
    delete fStreamer;
  }
}

//______________________________________________
void AliDielectronDebugTree::Fill(AliDielectronPair *pair)
{
  //
  // Fill configured variables to the tree
  //

  //is there anything to fill
  if (fNVars==0&&fNVarsLeg==0) return;

  //only in local mode!!!
  AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
  if (man && man->GetAnalysisType()!=AliAnalysisManager::kLocalAnalysis) return;

  //Get File and event information
  TObjString fileName;
  Int_t eventInFile=-1;

  TTree *t=man->GetTree();
  if (t) {
    TFile *file=t->GetCurrentFile();
    if (file) fileName.SetString(file->GetName());
  }

  AliESDInputHandler *han=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler());
  if (han){
    AliESDEvent *ev=dynamic_cast<AliESDEvent*>(han->GetEvent());
    eventInFile=ev->GetEventNumberInFile();
  }

  if (!fStreamer) fStreamer=new TTreeSRedirector(fFileName.Data());
  Int_t id1=static_cast<AliVTrack*>(pair->GetFirstDaughter())->GetID();
  Int_t id2=static_cast<AliVTrack*>(pair->GetSecondDaughter())->GetID();
  //Fill Event information
  (*fStreamer) << "Pair"
    << "File.="       << &fileName
    << "EventInFile=" << eventInFile
    << "Leg1_ID="     << id1
    << "Leg2_ID="     << id2;

  Int_t var=0;
  Double_t values[AliDielectronVarManager::kNMaxValues];
  Double_t valuesLeg1[AliDielectronVarManager::kNMaxValues];
  Double_t valuesLeg2[AliDielectronVarManager::kNMaxValues];
// fill pair values
  if (fNVars>0){
    AliDielectronVarManager::Fill(pair,values);

    for (Int_t i=0; i<fNVars; ++i){
      var=fVariables[i];
      (*fStreamer) << "Pair"
                   << Form("%s=",AliDielectronVarManager::GetValueName(var))
                   << values[var];
    }
  }

  if (fNVarsLeg>0){
    //leg1
    AliDielectronVarManager::Fill(pair->GetFirstDaughter(),valuesLeg1);
    //leg2
    AliDielectronVarManager::Fill(pair->GetSecondDaughter(),valuesLeg2);

    for (Int_t i=0; i<fNVarsLeg; ++i){
      var=fVariablesLeg[i];
      (*fStreamer) << "Pair"
                   << Form("Leg1_%s=",AliDielectronVarManager::GetValueName(var))
                   << valuesLeg1[var]
                   << Form("Leg2_%s=",AliDielectronVarManager::GetValueName(var))
                   << valuesLeg2[var];
    }

  }

  (*fStreamer) << "Pair" << "\n";

}

//______________________________________________
void AliDielectronDebugTree::DeleteStreamer()
{
  //
  // delete the streamer
  //
  if (!fStreamer) return;
  delete fStreamer;
  fStreamer=0x0;

}

//______________________________________________
void AliDielectronDebugTree::WriteTree()
{
  //
  // Write file
  //
  if (!fStreamer) return;
  fStreamer->GetFile()->Write();
}
<|endoftext|>


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

#ifndef _SVMEMPOOL_HXX //autogen
#include <tools/mempool.hxx>
#endif

#include "layfrm.hxx"

class SwTableLine;
class SwBorderAttrs;

class SwRowFrm: public SwLayoutFrm
{
    virtual void Format( const SwBorderAttrs *pAttrs = 0 );
        //Aendern nur die Framesize, nicht die PrtArea-SSize
    virtual SwTwips ShrinkFrm( SwTwips, SZPTR
                               BOOL bTst = FALSE, BOOL bInfo = FALSE );
    virtual SwTwips GrowFrm  ( SwTwips, SZPTR
                               BOOL bTst = FALSE, BOOL bInfo = FALSE );

    const SwTableLine *pTabLine;

protected:
    virtual void MakeAll();

public:
    SwRowFrm( const SwTableLine & );
    ~SwRowFrm();

    virtual void Cut();
    virtual void  Modify( SfxPoolItem*, SfxPoolItem* );

    //Zum Anmelden der Flys nachdem eine Zeile erzeugt _und_ eingefuegt wurde.
    //Muss vom Erzeuger gerufen werden, denn erst nach dem Konstruieren wird
    //Das Teil gepastet; mithin ist auch erst dann die Seite zum Anmelden der
    //Flys erreichbar.
    void RegistFlys( SwPageFrm *pPage = 0 );

    const SwTableLine *GetTabLine() const { return pTabLine; }

    //Passt die Zellen auf die aktuelle Hoehe an, invalidiert die Zellen
    //wenn die Direction nicht der Hoehe entspricht.
    void AdjustCells( const SwTwips nHeight, const BOOL bHeight );
    DECL_FIXEDMEMPOOL_NEWDEL(SwRowFrm)
};

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

#ifndef _SVMEMPOOL_HXX //autogen
#include <tools/mempool.hxx>
#endif

#include "layfrm.hxx"

class SwTableLine;
class SwBorderAttrs;

class SwRowFrm: public SwLayoutFrm
{
    virtual void Format( const SwBorderAttrs *pAttrs = 0 );
        //Aendern nur die Framesize, nicht die PrtArea-SSize
    virtual SwTwips ShrinkFrm( SwTwips, SZPTR
                               BOOL bTst = FALSE, BOOL bInfo = FALSE );
    virtual SwTwips GrowFrm  ( SwTwips, SZPTR
                               BOOL bTst = FALSE, BOOL bInfo = FALSE );

    const SwTableLine *pTabLine;
    SwRowFrm* pFollowRow;
    bool bIsFollowFlowRow;

protected:
    virtual void MakeAll();

public:
    SwRowFrm( const SwTableLine &, bool bInsertContent = true );
    ~SwRowFrm();

    virtual void Cut();
    virtual void  Modify( SfxPoolItem*, SfxPoolItem* );

    //Zum Anmelden der Flys nachdem eine Zeile erzeugt _und_ eingefuegt wurde.
    //Muss vom Erzeuger gerufen werden, denn erst nach dem Konstruieren wird
    //Das Teil gepastet; mithin ist auch erst dann die Seite zum Anmelden der
    //Flys erreichbar.
    void RegistFlys( SwPageFrm *pPage = 0 );

    const SwTableLine *GetTabLine() const { return pTabLine; }

    //Passt die Zellen auf die aktuelle Hoehe an, invalidiert die Zellen
    //wenn die Direction nicht der Hoehe entspricht.
    void AdjustCells( const SwTwips nHeight, const BOOL bHeight );

    //
    //
    SwRowFrm* GetFollowRow() const { return pFollowRow; }
    void SetFollowRow( SwRowFrm* pNew ) { pFollowRow = pNew; }

    bool IsFollowFlowRow() const { return bIsFollowFlowRow; }
    void SetFollowFlowRow( bool bNew ) { bIsFollowFlowRow = bNew; }

    bool IsRowSplitAllowed() const;

    DECL_FIXEDMEMPOOL_NEWDEL(SwRowFrm)
};

#endif
<|endoftext|>


<commit_before>AliAnalysisTaskCombinHF *AddTaskCombinHF(Int_t meson = 0,
                                         Bool_t readMC = kTRUE,
                                         TString containerStr = "",
                                         TString cutObjFile = "",
                                         TString cutObjNam = "",
                                         Int_t filterMask = 1,
                                         Double_t ptcut = 0.3,
                                         Double_t etacut = 0.9,
                                         Int_t pidStrategy = 0,
                                         Int_t casePID = 2,
                                         Double_t bayesThresKaon = 0.4,
                                         Double_t bayesThresPion = 0.4,
                                         Double_t minMass = 1.6,
                                         Double_t maxMass = 2.15,
                                         Double_t maxPt = 20.,
                                         Double_t ptBinWidth = 0.5)
{

  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskCombinHF", "No analysis manager to connect to.");
  }

  //Analysis Task

  AliRDHFCuts* analysiscuts=0x0;
  AliAODPidHF* pid=0x0;
  if(!cutObjFile.IsNull()){
    TFile *f=TFile::Open(cutObjFile.Data(),"READ");
    if(f){
      analysiscuts=(AliRDHFCuts*)f->Get(cutObjNam.Data());
      AliESDtrackCuts *esdc=analysiscuts->GetTrackCuts();
      pid=analysiscuts->GetPidHF();
    }
  }
  else {
    if(meson==0) analysiscuts=new AliRDHFCutsD0toKpi();
    else analysiscuts=new AliRDHFCutsDplustoKpipi();
    analysiscuts->SetStandardCutsPP2010();
    pid=new AliAODPidHF();
    pid->SetMatch(5);
    pid->SetTPCnSigmaRangeForPions(-3.,3.);
    pid->SetTPCnSigmaRangeForKaons(-2.,3.);
    pid->SetTPCnSigmaRangeForProtons(-3.,3.);
    pid->SetTOFnSigmaRangeForPions(-3.,3.);
    pid->SetTOFnSigmaRangeForKaons(-2.,2.);
    pid->SetTOFnSigmaRangeForProtons(-3.,3.);

  }
  if(!analysiscuts){
    Printf("Wrong file or cut object name set");
    return 0x0;
  }

  AliAnalysisTaskCombinHF *dTask = new AliAnalysisTaskCombinHF(meson,analysiscuts);
  if(!cutObjFile.IsNull()){
    dTask->SetKaonTrackCuts(esdc);
    dTask->SetPionTrackCuts(esdc);
    dTask->SetTrackCuts(esdc);
  }
  dTask->SetReadMC(readMC);
  dTask->SetDebugLevel(0);

  dTask->SetFilterMask(filterMask);
  dTask->SetPtAccCut(ptcut);
  dTask->SetEtaAccCut(etacut);

  // mass and pt range for histograms
  dTask->SetMassWindow(minMass, maxMass);
  dTask->SetMaxPt(maxPt);
  dTask->SetPtBinWidth(ptBinWidth);

  // PID settings
  dTask->SetPIDHF(pid);
  dTask->SetPIDstrategy(pidStrategy);
  dTask->SetPIDselCaseZero(casePID);
  dTask->SetBayesThres(bayesThresKaon, bayesThresPion);

  mgr->AddTask(dTask);

  // Create containers for input/output

  TString mesname="Dzero";
  if(meson==1) mesname="Dplus";
  TString inname = Form("cinput%s%s",mesname.Data(),containerStr.Data());
  TString outname = Form("coutput%s%s",mesname.Data(),containerStr.Data());
  TString normname = Form("coutput%sNorm%s",mesname.Data(),containerStr.Data());

  AliAnalysisDataContainer *cinput = mgr->CreateContainer(inname,TChain::Class(),
                                                          AliAnalysisManager::kInputContainer);
  TString outputfile = AliAnalysisManager::GetCommonFileName();
  outputfile += Form(":PWG3_D2H_InvMass%sLowPt%s",mesname.Data(),containerStr.Data());

  AliAnalysisDataContainer *coutput = mgr->CreateContainer(outname,TList::Class(),
                                                           AliAnalysisManager::kOutputContainer,
                                                           outputfile.Data());
  AliAnalysisDataContainer *coutputNorm = mgr->CreateContainer(normname,AliNormalizationCounter::Class(),
                                                               AliAnalysisManager::kOutputContainer,
                                                               outputfile.Data());

  mgr->ConnectInput(dTask,0,mgr->GetCommonInputContainer());

  mgr->ConnectOutput(dTask,1,coutput);

  mgr->ConnectOutput(dTask,2,coutputNorm);

  return dTask;
}
<commit_msg>D_s case handled in the add task of the low-pt analysis<commit_after>AliAnalysisTaskCombinHF *AddTaskCombinHF(Int_t meson = 0,
                                         Bool_t readMC = kTRUE,
                                         TString containerStr = "",
                                         TString cutObjFile = "",
                                         TString cutObjNam = "",
                                         Int_t filterMask = 1,
                                         Double_t ptcut = 0.3,
                                         Double_t etacut = 0.9,
                                         Int_t pidStrategy = 0,
                                         Int_t casePID = 2,
                                         Double_t bayesThresKaon = 0.4,
                                         Double_t bayesThresPion = 0.4,
                                         Double_t minMass = 1.6,
                                         Double_t maxMass = 2.15,
                                         Double_t maxPt = 20.,
                                         Double_t ptBinWidth = 0.5)
{

  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskCombinHF", "No analysis manager to connect to.");
  }

  //Analysis Task

  AliRDHFCuts* analysiscuts=0x0;
  AliAODPidHF* pid=0x0;
  if(!cutObjFile.IsNull()){
    TFile *f=TFile::Open(cutObjFile.Data(),"READ");
    if(f){
      analysiscuts=(AliRDHFCuts*)f->Get(cutObjNam.Data());
      AliESDtrackCuts *esdc=analysiscuts->GetTrackCuts();
      pid=analysiscuts->GetPidHF();
    }
  }
  else {
    if(meson==0) analysiscuts=new AliRDHFCutsD0toKpi();
    else if(meson==1) analysiscuts=new AliRDHFCutsDplustoKpipi();
    else if(meson==3) analysiscuts=new AliRDHFCutsDstoKKpi();
    analysiscuts->SetStandardCutsPP2010();
    pid=new AliAODPidHF();
    pid->SetMatch(5);
    pid->SetTPCnSigmaRangeForPions(-3.,3.);
    pid->SetTPCnSigmaRangeForKaons(-2.,3.);
    pid->SetTPCnSigmaRangeForProtons(-3.,3.);
    pid->SetTOFnSigmaRangeForPions(-3.,3.);
    pid->SetTOFnSigmaRangeForKaons(-2.,2.);
    pid->SetTOFnSigmaRangeForProtons(-3.,3.);

  }
  if(!analysiscuts){
    Printf("Wrong file or cut object name set");
    return 0x0;
  }

  AliAnalysisTaskCombinHF *dTask = new AliAnalysisTaskCombinHF(meson,analysiscuts);
  if(!cutObjFile.IsNull()){
    dTask->SetKaonTrackCuts(esdc);
    dTask->SetPionTrackCuts(esdc);
    dTask->SetTrackCuts(esdc);
  }
  dTask->SetReadMC(readMC);
  dTask->SetDebugLevel(0);

  dTask->SetFilterMask(filterMask);
  dTask->SetPtAccCut(ptcut);
  dTask->SetEtaAccCut(etacut);

  // mass and pt range for histograms
  dTask->SetMassWindow(minMass, maxMass);
  dTask->SetMaxPt(maxPt);
  dTask->SetPtBinWidth(ptBinWidth);

  // PID settings
  dTask->SetPIDHF(pid);
  dTask->SetPIDstrategy(pidStrategy);
  dTask->SetPIDselCaseZero(casePID);
  dTask->SetBayesThres(bayesThresKaon, bayesThresPion);

  mgr->AddTask(dTask);

  // Create containers for input/output

  TString mesname="Dzero";
  if(meson==1) mesname="Dplus";
  else if(meson==3) mesname="Ds";
  TString inname = Form("cinput%s%s",mesname.Data(),containerStr.Data());
  TString outname = Form("coutput%s%s",mesname.Data(),containerStr.Data());
  TString normname = Form("coutput%sNorm%s",mesname.Data(),containerStr.Data());

  AliAnalysisDataContainer *cinput = mgr->CreateContainer(inname,TChain::Class(),
                                                          AliAnalysisManager::kInputContainer);
  TString outputfile = AliAnalysisManager::GetCommonFileName();
  outputfile += Form(":PWG3_D2H_InvMass%sLowPt%s",mesname.Data(),containerStr.Data());

  AliAnalysisDataContainer *coutput = mgr->CreateContainer(outname,TList::Class(),
                                                           AliAnalysisManager::kOutputContainer,
                                                           outputfile.Data());
  AliAnalysisDataContainer *coutputNorm = mgr->CreateContainer(normname,AliNormalizationCounter::Class(),
                                                               AliAnalysisManager::kOutputContainer,
                                                               outputfile.Data());

  mgr->ConnectInput(dTask,0,mgr->GetCommonInputContainer());

  mgr->ConnectOutput(dTask,1,coutput);

  mgr->ConnectOutput(dTask,2,coutputNorm);

  return dTask;
}
<|endoftext|>


<commit_before>///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Class for ZDC DCS data                                                    //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include "AliZDCDataDCS.h"

#include "AliCDBMetaData.h"
#include "AliDCSValue.h"
#include "AliLog.h"

#include <TCanvas.h>
#include <TDatime.h>
#include <TGraph.h>
#include <TH1.h>
#include <TObjString.h>
#include <TStyle.h>
#include <TTimeStamp.h>

ClassImp(AliZDCDataDCS)

//---------------------------------------------------------------
AliZDCDataDCS::AliZDCDataDCS():
   TObject(),
   fRun(0),
   fStartTime(0),
   fEndTime(0),
   fGraphs("TGraph",kNGraphs),
   fIsProcessed(kFALSE)
{
  // Default constructor
}

//---------------------------------------------------------------
AliZDCDataDCS::AliZDCDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime):
   TObject(),
   fRun(nRun),
   fStartTime(startTime),
   fEndTime(endTime),
   fGraphs("TGraph",kNGraphs),
   fIsProcessed(kFALSE)
{
   // Standard constructor

   AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", nRun,
   TTimeStamp(startTime).AsString(),
   TTimeStamp(endTime).AsString()));

   Init();

}

//---------------------------------------------------------------
AliZDCDataDCS::~AliZDCDataDCS()
{
  // Destructor
  fGraphs.Clear("C");
}

//---------------------------------------------------------------
void AliZDCDataDCS::ProcessData(TMap& aliasMap, Float_t *fCalibData)
{
   // Data processing

   TObjArray *aliasArr;
   AliDCSValue* aValue;
   for(int j=0; j<kNAliases; j++){
      aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[j].Data());
      if(!aliasArr){
   	AliError(Form("Alias %s not found!", fAliasNames[j].Data()));
   	continue;
      }
      Introduce(j, aliasArr);

      if(aliasArr->GetEntries()<2){
   	AliError(Form("Alias %s has just %d entries!",
   			fAliasNames[j].Data(),aliasArr->GetEntries()));
   	continue;
      }

      TIter iterarray(aliasArr);

      Double_t *time = new Double_t[aliasArr->GetEntries()];
      Double_t *val = new Double_t[aliasArr->GetEntries()];

      UInt_t ne=0;
      while((aValue = (AliDCSValue*) iterarray.Next())) {
   	val[ne] = aValue->GetFloat();
   	time[ne] = (Double_t) (aValue->GetTimeStamp());
   	fCalibData[ne] = val[ne];
   	ne++;
      }
      //

      //
      if(j>=4) CreateGraph(j, aliasArr->GetEntries(), time, val); // fill graphs
      //
      delete[] val;
      delete[] time;
   }
   //
   fIsProcessed=kTRUE;

}

//---------------------------------------------------------------
void AliZDCDataDCS::Init()
{
   // Initialization

   TH1::AddDirectory(kFALSE);

   fGraphs.SetOwner(1);

   for(int i=0;i<kNAliases;i++){
   	   if(i<4){
   	     fAliasNames[i] = "ZDC.Position";
   	     fAliasNames[i] += i;
   	   }
   	   else{
   	     fAliasNames[i] = "ZDC.HVValue";
   	     fAliasNames[i] += i-4;
   	   }
   }

}

//---------------------------------------------------------------
void AliZDCDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr)
{
   // Getting array of DCS aliases

   int entries=aliasArr->GetEntries();
   AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data()));
   AliInfo(Form("	   %d DP values collected",entries));

}

//---------------------------------------------------------------
void AliZDCDataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y)
{

   // Create graphics

   TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y);

   gr->GetXaxis()->SetTimeDisplay(1);
   gr->SetTitle(fAliasNames[i].Data());

   AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast()));

}

//---------------------------------------------------------------
void AliZDCDataDCS::Draw(const Option_t* /*option*/)
{
  // Draw graphics

  fIsProcessed=1;
  if(!fIsProcessed) return;

  if(fGraphs.GetEntries()==0)  return;

  TCanvas *cg1;
  TString canvas1Name="ZN1_HVs";
  cg1=new TCanvas(canvas1Name,canvas1Name,40,40,600,600);
  cg1->Divide(2,2);
  cg1->cd(1);
  ((TGraph*) fGraphs.UncheckedAt(0))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(0))->Draw("ALP");
  cg1->cd(2);
  ((TGraph*) fGraphs.UncheckedAt(1))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(1))->Draw("ALP");
  cg1->cd(3);
  ((TGraph*) fGraphs.UncheckedAt(2))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(2))->Draw("ALP");
  cg1->cd(4);
  ((TGraph*) fGraphs.UncheckedAt(3))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(3))->Draw("ALP");

  TCanvas *cg2;
  TString canvas2Name="ZP1_HVs";
  cg2=new TCanvas(canvas2Name,canvas2Name,80,80,600,600);
  cg2->Divide(2,2);
  cg2->cd(1);
  ((TGraph*) fGraphs.UncheckedAt(5))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(5))->Draw("ALP");
  cg2->cd(2);
  ((TGraph*) fGraphs.UncheckedAt(6))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(6))->Draw("ALP");
  cg2->cd(3);
  ((TGraph*) fGraphs.UncheckedAt(7))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(7))->Draw("ALP");
  cg2->cd(4);
  ((TGraph*) fGraphs.UncheckedAt(8))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(8))->Draw("ALP");

}

<commit_msg>Updated DCS DP aliases<commit_after>///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Class for ZDC DCS data                                                    //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include "AliZDCDataDCS.h"

#include "AliCDBMetaData.h"
#include "AliDCSValue.h"
#include "AliLog.h"

#include <TCanvas.h>
#include <TDatime.h>
#include <TGraph.h>
#include <TH1.h>
#include <TObjString.h>
#include <TStyle.h>
#include <TTimeStamp.h>

ClassImp(AliZDCDataDCS)

//---------------------------------------------------------------
AliZDCDataDCS::AliZDCDataDCS():
   TObject(),
   fRun(0),
   fStartTime(0),
   fEndTime(0),
   fGraphs("TGraph",kNGraphs),
   fIsProcessed(kFALSE)
{
  // Default constructor
}

//---------------------------------------------------------------
AliZDCDataDCS::AliZDCDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime):
   TObject(),
   fRun(nRun),
   fStartTime(startTime),
   fEndTime(endTime),
   fGraphs("TGraph",kNGraphs),
   fIsProcessed(kFALSE)
{
   // Standard constructor

   AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", nRun,
   TTimeStamp(startTime).AsString(),
   TTimeStamp(endTime).AsString()));

   Init();

}

//---------------------------------------------------------------
AliZDCDataDCS::~AliZDCDataDCS()
{
  // Destructor
  fGraphs.Clear("C");
}

//---------------------------------------------------------------
void AliZDCDataDCS::ProcessData(TMap& aliasMap, Float_t *fCalibData)
{
   // Data processing

   TObjArray *aliasArr;
   AliDCSValue* aValue;
   for(int j=0; j<kNAliases; j++){
      aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[j].Data());
      if(!aliasArr){
   	AliError(Form("Alias %s not found!", fAliasNames[j].Data()));
   	continue;
      }
      Introduce(j, aliasArr);

      if(aliasArr->GetEntries()<2){
   	AliError(Form("Alias %s has just %d entries!",
   			fAliasNames[j].Data(),aliasArr->GetEntries()));
   	continue;
      }

      TIter iterarray(aliasArr);

      Double_t *time = new Double_t[aliasArr->GetEntries()];
      Double_t *val = new Double_t[aliasArr->GetEntries()];

      UInt_t ne=0;
      while((aValue = (AliDCSValue*) iterarray.Next())) {
   	val[ne] = aValue->GetFloat();
   	time[ne] = (Double_t) (aValue->GetTimeStamp());
   	fCalibData[ne] = val[ne];
   	ne++;
      }
      //

      //
      if(j>=4) CreateGraph(j, aliasArr->GetEntries(), time, val); // fill graphs
      //
      delete[] val;
      delete[] time;
   }
   //
   fIsProcessed=kTRUE;

}

//---------------------------------------------------------------
void AliZDCDataDCS::Init()
{
   // Initialization

   TH1::AddDirectory(kFALSE);

   fGraphs.SetOwner(1);

   fAliasNames[0] = "ZNA_POS.actual.position";
   fAliasNames[1] = "ZPA_POS.actual.position";
   fAliasNames[2] = "ZNC_POS.actual.position";
   fAliasNames[3] = "ZPC_POS.actual.position";
   //
   fAliasNames[4]  = "ZNA_HV0.actual.vMon";
   fAliasNames[5]  = "ZNA_HV1.actual.vMon";
   fAliasNames[6]  = "ZNA_HV2.actual.vMon";
   fAliasNames[7]  = "ZNA_HV3.actual.vMon";
   fAliasNames[8]  = "ZNA_HV4.actual.vMon";
   //
   fAliasNames[9]   = "ZPA_HV0.actual.vMon";
   fAliasNames[10]  = "ZPA_HV1.actual.vMon";
   fAliasNames[11]  = "ZPA_HV2.actual.vMon";
   fAliasNames[12]  = "ZPA_HV3.actual.vMon";
   fAliasNames[13]  = "ZPA_HV4.actual.vMon";
   //
   fAliasNames[14]  = "ZNC_HV0.actual.vMon";
   fAliasNames[15]  = "ZNC_HV1.actual.vMon";
   fAliasNames[16]  = "ZNC_HV2.actual.vMon";
   fAliasNames[17]  = "ZNC_HV3.actual.vMon";
   fAliasNames[18]  = "ZNC_HV4.actual.vMon";
   //
   fAliasNames[19]  = "ZPC_HV0.actual.vMon";
   fAliasNames[20]  = "ZPC_HV1.actual.vMon";
   fAliasNames[21]  = "ZPC_HV2.actual.vMon";
   fAliasNames[22]  = "ZPC_HV3.actual.vMon";
   fAliasNames[23]  = "ZPC_HV4.actual.vMon";
   //
   fAliasNames[24]  = "ZEM_HV0.actual.vMon";
   fAliasNames[25]  = "ZEM_HV1.actual.vMon";

}

//---------------------------------------------------------------
void AliZDCDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr)
{
   // Getting array of DCS aliases

   int entries=aliasArr->GetEntries();
   AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data()));
   AliInfo(Form("	   %d DP values collected",entries));

}

//---------------------------------------------------------------
void AliZDCDataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y)
{

   // Create graphics

   TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y);

   gr->GetXaxis()->SetTimeDisplay(1);
   gr->SetTitle(fAliasNames[i].Data());

   AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast()));

}

//---------------------------------------------------------------
void AliZDCDataDCS::Draw(const Option_t* /*option*/)
{
  // Draw graphics

  fIsProcessed=1;
  if(!fIsProcessed) return;

  if(fGraphs.GetEntries()==0)  return;

  TCanvas *cg1;
  TString canvas1Name="ZN1_HVs";
  cg1=new TCanvas(canvas1Name,canvas1Name,40,40,600,600);
  cg1->Divide(2,2);
  cg1->cd(1);
  ((TGraph*) fGraphs.UncheckedAt(0))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(0))->Draw("ALP");
  cg1->cd(2);
  ((TGraph*) fGraphs.UncheckedAt(1))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(1))->Draw("ALP");
  cg1->cd(3);
  ((TGraph*) fGraphs.UncheckedAt(2))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(2))->Draw("ALP");
  cg1->cd(4);
  ((TGraph*) fGraphs.UncheckedAt(3))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(3))->Draw("ALP");

  TCanvas *cg2;
  TString canvas2Name="ZP1_HVs";
  cg2=new TCanvas(canvas2Name,canvas2Name,80,80,600,600);
  cg2->Divide(2,2);
  cg2->cd(1);
  ((TGraph*) fGraphs.UncheckedAt(5))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(5))->Draw("ALP");
  cg2->cd(2);
  ((TGraph*) fGraphs.UncheckedAt(6))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(6))->Draw("ALP");
  cg2->cd(3);
  ((TGraph*) fGraphs.UncheckedAt(7))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(7))->Draw("ALP");
  cg2->cd(4);
  ((TGraph*) fGraphs.UncheckedAt(8))->SetMarkerStyle(20);
  ((TGraph*) fGraphs.UncheckedAt(8))->Draw("ALP");

}

<|endoftext|>