<commit_before>#pragma once
#include <map>
namespace Doremi
{
    namespace Core
    {
        /**
        The audio component contains the handle to the soundchannel and a handle to the sound
        */
        // If you add someone,
        enum class AudioCompEnum : int32_t
        {
            Jump,
            Death,
            DebugSound,

            Num_Sounds,
        };
        struct AudioComponent
        {
            // std::map<AudioCompEnum, int> m_enumToSoundID;

            int32_t m_enumToSoundID[(int32_t)(AudioCompEnum::Num_Sounds)]; // +1]; //Todo maybe bugs out
            // int mySoundID = sounds[(int)AudioCompEnum::Jump];
            AudioComponent()
            {
                for(int32_t i = 0; i < (int32_t)AudioCompEnum::Num_Sounds; i++)
                {
                    m_enumToSoundID[i] = (int32_t)AudioCompEnum::DebugSound;
                }
            }
        };
    }
}<commit_msg>Added damage taken sound to audio enum<commit_after>#pragma once
#include <map>
namespace Doremi
{
    namespace Core
    {
        /**
        The audio component contains the handle to the soundchannel and a handle to the sound
        */
        // If you add someone,
        enum class AudioCompEnum : int32_t
        {
            Jump,
            Death,
            DamageTaken,
            DebugSound,

            Num_Sounds,
        };
        struct AudioComponent
        {
            // std::map<AudioCompEnum, int> m_enumToSoundID;

            int32_t m_enumToSoundID[(int32_t)(AudioCompEnum::Num_Sounds)]; // +1]; //Todo maybe bugs out
            // int mySoundID = sounds[(int)AudioCompEnum::Jump];
            AudioComponent()
            {
                for(int32_t i = 0; i < (int32_t)AudioCompEnum::Num_Sounds; i++)
                {
                    m_enumToSoundID[i] = (int32_t)AudioCompEnum::DebugSound;
                }
            }
        };
    }
}<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    GaussianMinimumErrorClassifier.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "OptionList.h"
#include "itkImage.h"
#include "itkReadMetaImage.h"
#include "itkWriteMetaImage.h"
#include "itkImageRegionIterator.h"

#include "vnl/vnl_matrix.h"

#include "itkImageToListAdaptor.h"
#include "itkSubsample.h"
#include "itkMembershipSample.h"
#include "itkMembershipSampleGenerator.h"
#include "itkGaussianDensityFunction.h"
#include "itkMeanCalculator.h"
#include "itkCovarianceCalculator.h"
#include "itkTableLookupSampleClassifier.h"
#include "MaximumLikelihoodRatioDecisionRule.h"
#include "itkStatisticsAlgorithm.h"

void print_usage()
{
  std::cout << "GaussianMinimumErrorClassifier 1.0 (17. Dec. 2001)" << std::endl ;

  std::cout << "usage: GaussianMinimumErrorClassifier --training file"  << std::endl ;
  std::cout << "       --class-mask file" << std::endl ;
  std::cout << "       --target file"  << std::endl ;
  std::cout << "       --output file"  << std::endl ;

  std::cout << "" << std::endl ;

  std::cout << "--training file" << std::endl ;
  std::cout << "        image file name with intesnity values [meta image format]"
    << std::endl ;
  std::cout << "--class-mask file" << std::endl ;
  std::cout << "        image file name with class labels [meta image format]"
    << std::endl ;
  std::cout << "--target file" << std::endl ;
  std::cout << "        target image file name with intensity values [meta image format]"
    << std::endl ;
  std::cout << "--output file" << std::endl ;
  std::cout << "        output image file name that will have the class labels for pixels"
    << std::endl ;
  std::cout << "        in the target image file [meta image format]"  << std::endl ;

  std::cout << "" << std::endl ;

  std::cout << "example: GaussianMinimumErrorClassifier --training train.mhd" << std::endl ;
  std::cout << "         --class-mask class_mask.mhd" << std::endl ;
  std::cout << "         --target target.mhd" << std::endl ;
  std::cout << "         --output output.mhd" << std::endl ;
}

int main(int argc, char* argv[])
{

  namespace stat = itk::Statistics ;

  if (argc <= 1)
    {
      print_usage() ;
      exit(0) ;
    }

  OptionList options(argc, argv) ;

  std::string trainingFileName ;
  std::string classMaskFileName ;
  std::string targetFileName ;
  std::string outputFileName ;

  try
    {
      // get image file options
      options.GetStringOption("training", &trainingFileName, true) ;
      // get image file options
      options.GetStringOption("class-mask", &classMaskFileName, true) ;
      // get image file options
      options.GetStringOption("target", &targetFileName, true) ;
      // get image file options
      options.GetStringOption("output", &outputFileName, true) ;
    }
  catch(OptionList::RequiredOptionMissing e)
    {
      std::cout << "Error: The '" << e.OptionTag
                << "' option is required but missing."
                << std::endl ;
      return 1 ;
    }

  typedef itk::Image< short, 3 > ImageType ;
  typedef ImageType::Pointer ImagePointer ;

  ImagePointer training ;
  ImagePointer classMask ;
  ImagePointer target ;

  std::cout << "Loading image(s)..." << std::endl ;
  //      readMetaImageHeader(trainingFileName, trainingDimension, trainingSize) ;
  typedef itk::ReadMetaImage<ImageType> Reader ;
  Reader::Pointer reader = Reader::New() ;

  reader->SetFileName(trainingFileName.c_str()) ;
  reader->Update() ;
  training = reader->GetOutput() ;
  std::cout << "Training image loaded." << std::endl ;

  Reader::Pointer reader2 = Reader::New() ;
  reader2->SetFileName(classMaskFileName.c_str()) ;
  reader2->Update() ;
  classMask = reader2->GetOutput() ;
  std::cout << "Class mask loaded." << std::endl ;

  Reader::Pointer reader3 = Reader::New() ;
  reader3->SetFileName(targetFileName.c_str()) ;
  reader3->Update() ;
  target = reader3->GetOutput() ;
  std::cout << "Target image loaded." << std::endl ;

  /* ================================================== */
  std::cout << "Importing the images to samples..."
            << std::endl ;
  typedef stat::ImageToListAdaptor< ImageType, stat::ScalarImageAccessor< ImageType > >
    ImageListSampleType;

  ImageListSampleType::Pointer sample =
    ImageListSampleType::New() ;

  ImageListSampleType::Pointer mask =
    ImageListSampleType::New() ;

  ImageListSampleType::Pointer targetSample =
    ImageListSampleType::New() ;

  sample->SetImage(training);
  mask->SetImage(classMask) ;
  targetSample->SetImage(target) ;
  /* ==================================================== */
  std::cout << "Creating the membership sample for training.." << std::endl ;
  typedef stat::MembershipSampleGenerator< ImageListSampleType,
    ImageListSampleType > MembershipSampleGeneratorType ;
  MembershipSampleGeneratorType::Pointer generator =
    MembershipSampleGeneratorType::New() ;

  generator->SetInput(sample) ;
  generator->SetClassMask(mask) ;
  generator->SetNumberOfClasses(10) ;
  generator->GenerateData() ;
  MembershipSampleGeneratorType::OutputPointer membershipSample =
    generator->GetOutput() ;
  unsigned int numberOfClasses = membershipSample->GetNumberOfClasses() ;

  /* =================================================== */
  std::cout << "Inducing the gaussian density function parameters and apriori probabilities..."
            << std::endl ;
  typedef ImageListSampleType::MeasurementVectorType
    MeasurementVectorType ;
  typedef stat::GaussianDensityFunction< MeasurementVectorType >
    DensityFunctionType ;
  typedef DensityFunctionType::Pointer DensityFunctionPointer ;
  std::vector< DensityFunctionPointer > densityFunctions ;
  densityFunctions.resize(numberOfClasses) ;

  typedef MembershipSampleGeneratorType::OutputType::ClassSampleType
    ClassSampleType ;
  typedef stat::MeanCalculator< ClassSampleType >
    MeanCalculatorType ;
  typedef stat::CovarianceCalculator< ClassSampleType >
    CovarianceCalculatorType ;
  MeanCalculatorType::Pointer meanCalculator = MeanCalculatorType::New() ;
  CovarianceCalculatorType::Pointer covarianceCalculator =
    CovarianceCalculatorType::New() ;
  vnl_vector< double > mean ;
  vnl_matrix< double > covariance ;

  typedef MaximumLikelihoodRatioDecisionRule DecisionRuleType ;
  DecisionRuleType::Pointer rule = DecisionRuleType::New() ;

  unsigned int sampleSize = 0 ;
  std::cout << "Inducing the gaussian density function parameters and apriori probabilities..." << std::endl ;
  std::cout << "number of classes = " << numberOfClasses << std::endl ;
  for (unsigned int i = 0 ; i < numberOfClasses ; i++)
    {
      std::cout << "gaussian [" << i << "]" << std::endl ;
      // add the class sample size to the decision rule
      // for the a priori probability calculation
      std::cout << "  Sample size = " ;
      sampleSize = membershipSample->GetClassSampleSize(i) ;
      std::cout << sampleSize << std::endl ;
      rule->AddClassSampleSize(sampleSize) ;

      ClassSampleType::Pointer subSample =
        membershipSample->GetClassSample(i) ;
      meanCalculator->SetSample(subSample) ;
      meanCalculator->GenerateData() ;
      mean = meanCalculator->GetOutput() ;

      covarianceCalculator->SetSample(subSample) ;
      covarianceCalculator->SetMean(mean) ;
      covarianceCalculator->GenerateData() ;
      covariance = covarianceCalculator->GetOutput() ;

      densityFunctions[i] = DensityFunctionType::New() ;
      (densityFunctions[i])->SetMean(mean) ;
      (densityFunctions[i])->SetCovariance(covariance) ;
      std::cout << "  mean = " << (densityFunctions[i])->GetMean()
                << std::endl ;
      std::cout << "  covariance = " << std::endl ;
      (densityFunctions[i])->GetCovariance().print(std::cout) ;

    }

  /* =================================================== */
  std::cout << "Classifying..." << std::endl ;

  typedef stat::TableLookupSampleClassifier< ImageListSampleType, DensityFunctionType, DecisionRuleType > ClassifierType ;

  ClassifierType::Pointer classifier = ClassifierType::New() ;
  classifier->SetSample(targetSample) ;
  for (unsigned int i = 0 ; i < numberOfClasses ; i++)
    {
      classifier->AddMembershipCalculator(densityFunctions[i]) ;
    }

  classifier->SetDecisionRule(rule) ;
  ImageListSampleType::MeasurementVectorType upper ;
  ImageListSampleType::MeasurementVectorType lower ;

  stat::FindSampleBound< ImageListSampleType >(targetSample, targetSample->Begin(),
                                               targetSample->End(), lower, upper) ;
  std::cout << "min = " << lower[0] << " max = " << upper[0] << std::endl ;

  classifier->SetLookupTableLowerBound(lower) ;
  classifier->SetLookupTableUpperBound(upper) ;
  classifier->GenerateData() ;

  ClassifierType::OutputPointer result = classifier->GetOutput() ;

  /* ===================================================== */
  std::cout << "Creating a image with result class labels..." << std::endl ;
  typedef itk::ImageRegionIterator< ImageType > ImageIteratorType ;
  typedef itk::WriteMetaImage< ImageType > Writer ;
  Writer::Pointer writer = Writer::New() ;

  ImagePointer output = ImageType::New() ;
  output->SetBufferedRegion(target->GetLargestPossibleRegion()) ;
  output->SetLargestPossibleRegion(target->GetLargestPossibleRegion()) ;
  output->Allocate() ;
  ImageIteratorType i_iter(output, output->GetLargestPossibleRegion()) ;
  i_iter.GoToBegin() ;
  ClassifierType::OutputType::Iterator m_iter = result->Begin() ;
  while (!i_iter.IsAtEnd())
    {
      i_iter.Set((ImageType::PixelType)m_iter.GetClassLabel()) ;
      ++i_iter ;
      ++m_iter ;
    }

  writer->SetInput(output) ;
  writer->SetFileName(outputFileName.c_str()) ;
  writer->GenerateData() ;

  return 0 ;
}

<commit_msg>ENH: As the TableLookupSampleClassifier's template arguments is reduced to one and the decision rule is derived from the DecisionRuleBase class, changes are made to reflect such changes.<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    GaussianMinimumErrorClassifier.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "OptionList.h"
#include "itkImage.h"
#include "itkReadMetaImage.h"
#include "itkWriteMetaImage.h"
#include "itkImageRegionIterator.h"

#include "vnl/vnl_matrix.h"

#include "itkImageToListAdaptor.h"
#include "itkSubsample.h"
#include "itkMembershipSample.h"
#include "itkMembershipSampleGenerator.h"
#include "itkGaussianDensityFunction.h"
#include "itkMeanCalculator.h"
#include "itkCovarianceCalculator.h"
#include "itkTableLookupSampleClassifier.h"
#include "itkDecisionRuleBase.h"
#include "MaximumLikelihoodRatioDecisionRule.h"
#include "itkStatisticsAlgorithm.h"

void print_usage()
{
  std::cout << "GaussianMinimumErrorClassifier 1.0 (17. Dec. 2001)" << std::endl ;

  std::cout << "usage: GaussianMinimumErrorClassifier --training file"  << std::endl ;
  std::cout << "       --class-mask file" << std::endl ;
  std::cout << "       --number-of-classes int" << std::endl ;
  std::cout << "       --target file"  << std::endl ;
  std::cout << "       --output file"  << std::endl ;

  std::cout << "" << std::endl ;

  std::cout << "--training file" << std::endl ;
  std::cout << "        image file name with intesnity values [meta image format]"
    << std::endl ;
  std::cout << "--class-mask file" << std::endl ;
  std::cout << "        image file name with class labels [meta image format]"
    << std::endl ;
  std::cout << "--number-of-classes int" << std::endl ;
  std::cout << "        the number of classes in the training image."
    << std::endl ;
  std::cout << "--target file" << std::endl ;
  std::cout << "        target image file name with intensity values [meta image format]"
    << std::endl ;
  std::cout << "--output file" << std::endl ;
  std::cout << "        output image file name that will have the class labels for pixels"
    << std::endl ;
  std::cout << "        in the target image file [meta image format]"  << std::endl ;

  std::cout << "" << std::endl ;

  std::cout << "example: GaussianMinimumErrorClassifier --training train.mhd" << std::endl ;
  std::cout << "         --class-mask class_mask.mhd" << std::endl ;
  std::cout << "         --number-of-classes 10" << std::endl ;
  std::cout << "         --target target.mhd" << std::endl ;
  std::cout << "         --output output.mhd" << std::endl ;
}

int main(int argc, char* argv[])
{

  namespace stat = itk::Statistics ;

  if (argc <= 1)
    {
      print_usage() ;
      exit(0) ;
    }

  OptionList options(argc, argv) ;

  std::string trainingFileName ;
  std::string classMaskFileName ;
  std::string targetFileName ;
  std::string outputFileName ;
  int numberOfClasses ;
  try
    {
      // get image file options
      options.GetStringOption("training", &trainingFileName, true) ;
      // get image file options
      options.GetStringOption("class-mask", &classMaskFileName, true) ;
      // get image file options
      options.GetStringOption("target", &targetFileName, true) ;
      // get image file options
      options.GetStringOption("output", &outputFileName, true) ;
      // get the number of classes
      numberOfClasses = options.GetIntOption("number-of-classes", 10, true) ;
    }
  catch(OptionList::RequiredOptionMissing e)
    {
      std::cout << "Error: The '" << e.OptionTag
                << "' option is required but missing."
                << std::endl ;
      return 1 ;
    }

  typedef itk::Image< short, 3 > ImageType ;
  typedef ImageType::Pointer ImagePointer ;

  ImagePointer training ;
  ImagePointer classMask ;
  ImagePointer target ;

  std::cout << "Loading image(s)..." << std::endl ;
  //      readMetaImageHeader(trainingFileName, trainingDimension, trainingSize) ;
  typedef itk::ReadMetaImage<ImageType> Reader ;
  Reader::Pointer reader = Reader::New() ;

  reader->SetFileName(trainingFileName.c_str()) ;
  reader->Update() ;
  training = reader->GetOutput() ;
  std::cout << "Training image loaded." << std::endl ;

  Reader::Pointer reader2 = Reader::New() ;
  reader2->SetFileName(classMaskFileName.c_str()) ;
  reader2->Update() ;
  classMask = reader2->GetOutput() ;
  std::cout << "Class mask loaded." << std::endl ;

  Reader::Pointer reader3 = Reader::New() ;
  reader3->SetFileName(targetFileName.c_str()) ;
  reader3->Update() ;
  target = reader3->GetOutput() ;
  std::cout << "Target image loaded." << std::endl ;

  /* ================================================== */
  std::cout << "Importing the images to samples..."
            << std::endl ;
  typedef stat::ImageToListAdaptor< ImageType, stat::ScalarImageAccessor< ImageType > >
    ImageListSampleType;

  ImageListSampleType::Pointer sample =
    ImageListSampleType::New() ;

  ImageListSampleType::Pointer mask =
    ImageListSampleType::New() ;

  ImageListSampleType::Pointer targetSample =
    ImageListSampleType::New() ;

  sample->SetImage(training);
  mask->SetImage(classMask) ;
  targetSample->SetImage(target) ;
  /* ==================================================== */
  std::cout << "Creating the membership sample for training.." << std::endl ;
  typedef stat::MembershipSampleGenerator< ImageListSampleType,
    ImageListSampleType > MembershipSampleGeneratorType ;
  MembershipSampleGeneratorType::Pointer generator =
    MembershipSampleGeneratorType::New() ;

  generator->SetInput(sample) ;
  generator->SetClassMask(mask) ;
  generator->SetNumberOfClasses(numberOfClasses) ;
  generator->GenerateData() ;
  MembershipSampleGeneratorType::OutputPointer membershipSample =
    generator->GetOutput() ;

  /* =================================================== */
  std::cout << "Inducing the gaussian density function parameters and apriori probabilities..."
            << std::endl ;
  typedef ImageListSampleType::MeasurementVectorType
    MeasurementVectorType ;
  typedef stat::GaussianDensityFunction< MeasurementVectorType >
    DensityFunctionType ;
  typedef DensityFunctionType::Pointer DensityFunctionPointer ;
  std::vector< DensityFunctionPointer > densityFunctions ;
  densityFunctions.resize(numberOfClasses) ;

  typedef MembershipSampleGeneratorType::OutputType::ClassSampleType
    ClassSampleType ;
  typedef stat::MeanCalculator< ClassSampleType >
    MeanCalculatorType ;
  typedef stat::CovarianceCalculator< ClassSampleType >
    CovarianceCalculatorType ;
  MeanCalculatorType::Pointer meanCalculator = MeanCalculatorType::New() ;
  CovarianceCalculatorType::Pointer covarianceCalculator =
    CovarianceCalculatorType::New() ;
  vnl_vector< double > mean ;
  vnl_matrix< double > covariance ;

  typedef MaximumLikelihoodRatioDecisionRule DecisionRuleType ;
  DecisionRuleType::Pointer rule = DecisionRuleType::New() ;

  unsigned int sampleSize = 0 ;
  std::cout << "Inducing the gaussian density function parameters and apriori probabilities..." << std::endl ;
  for (unsigned int i = 0 ; i < numberOfClasses ; i++)
    {
      std::cout << "gaussian [" << i << "]" << std::endl ;
      // add the class sample size to the decision rule
      // for the a priori probability calculation
      std::cout << "  Sample size = " ;
      sampleSize = membershipSample->GetClassSampleSize(i) ;
      std::cout << sampleSize << std::endl ;
      rule->AddClassSampleSize(sampleSize) ;

      ClassSampleType::Pointer subSample =
        membershipSample->GetClassSample(i) ;
      meanCalculator->SetSample(subSample) ;
      meanCalculator->GenerateData() ;
      mean = meanCalculator->GetOutput() ;

      covarianceCalculator->SetSample(subSample) ;
      covarianceCalculator->SetMean(mean) ;
      covarianceCalculator->GenerateData() ;
      covariance = covarianceCalculator->GetOutput() ;

      densityFunctions[i] = DensityFunctionType::New() ;
      (densityFunctions[i])->SetMean(mean) ;
      (densityFunctions[i])->SetCovariance(covariance) ;
      std::cout << "  mean = " << (densityFunctions[i])->GetMean()
                << std::endl ;
      std::cout << "  covariance = " << std::endl ;
      (densityFunctions[i])->GetCovariance().print(std::cout) ;

    }

  /* =================================================== */
  std::cout << "Classifying..." << std::endl ;

  typedef stat::TableLookupSampleClassifier< ImageListSampleType >
    ClassifierType ;

  ClassifierType::Pointer classifier = ClassifierType::New() ;
  classifier->SetNumberOfClasses(numberOfClasses) ;
  classifier->SetSample(targetSample) ;
  for (unsigned int i = 0 ; i < numberOfClasses ; i++)
    {
      classifier->AddMembershipFunction(densityFunctions[i]) ;
    }

  classifier->SetDecisionRule((itk::DecisionRuleBase::Pointer)rule) ;
  ImageListSampleType::MeasurementVectorType upper ;
  ImageListSampleType::MeasurementVectorType lower ;

  stat::FindSampleBound< ImageListSampleType >(targetSample, targetSample->Begin(),
                                               targetSample->End(), lower, upper) ;
  std::cout << "min = " << lower[0] << " max = " << upper[0] << std::endl ;

  classifier->SetLookupTableLowerBound(lower) ;
  classifier->SetLookupTableUpperBound(upper) ;
  classifier->Update() ;

  ClassifierType::OutputPointer result = classifier->GetOutput() ;

  /* ===================================================== */
  std::cout << "Creating a image with result class labels..." << std::endl ;
  typedef itk::ImageRegionIterator< ImageType > ImageIteratorType ;
  typedef itk::WriteMetaImage< ImageType > Writer ;
  Writer::Pointer writer = Writer::New() ;

  ImagePointer output = ImageType::New() ;
  output->SetBufferedRegion(target->GetLargestPossibleRegion()) ;
  output->SetLargestPossibleRegion(target->GetLargestPossibleRegion()) ;
  output->Allocate() ;
  ImageIteratorType i_iter(output, output->GetLargestPossibleRegion()) ;
  i_iter.GoToBegin() ;
  ClassifierType::OutputType::Iterator m_iter = result->Begin() ;
  while (!i_iter.IsAtEnd())
    {
      i_iter.Set((ImageType::PixelType)m_iter.GetClassLabel()) ;
      ++i_iter ;
      ++m_iter ;
    }

  writer->SetInput(output) ;
  writer->SetFileName(outputFileName.c_str()) ;
  writer->GenerateData() ;

  return 0 ;
}

<|endoftext|>


<commit_before>#include "Model.h"
#include "Effect.h"
#include "main.h"

Model::Model()
    : m_context(renderContext) {
}

Model::~Model() {
}

QSharedPointer<VideoNode> Model::addVideoNode(QString type) {
    // TODO
    QSharedPointer<VideoNode> videoNode(new Effect(m_context));

    m_vertices.append(videoNode);
    emit videoNodeAdded(videoNode);

    return videoNode;
}

void Model::removeVideoNode(QSharedPointer<VideoNode> videoNode) {
    for (auto edge = m_edges.begin(); edge != m_edges.end(); edge++) {
        if (edge->fromVertex == videoNode || edge->toVertex == videoNode) {
            Edge edgeCopy = *edge;
            m_edges.erase(edge);
            emit edgeRemoved(edgeCopy);
        }
    }

    int count = m_vertices.removeAll(videoNode);
    if (count > 0) {
        emit videoNodeRemoved(videoNode);
    }
}

void Model::addEdge(QSharedPointer<VideoNode> fromVertex, QSharedPointer<VideoNode> toVertex, int toInput) {
    Q_ASSERT(fromVertex != nullptr);
    Q_ASSERT(toVertex != nullptr);
    Q_ASSERT(toInput >= 0);
    Q_ASSERT(m_vertices.contains(fromVertex));
    Q_ASSERT(m_vertices.contains(toVertex));

    for (auto edge = m_edges.begin(); edge != m_edges.end(); edge++) {
        if (edge->toVertex == toVertex && edge->toInput == toInput) {
            if (edge->fromVertex == fromVertex)
                return;
            Edge edgeCopy = *edge;
            m_edges.erase(edge);
            emit edgeRemoved(edgeCopy);
        }
    }

    Edge newEdge = {
        .fromVertex = fromVertex,
        .toVertex = toVertex,
        .toInput = toInput,
    };
    m_edges.append(newEdge);
    emit edgeAdded(newEdge);
}

void Model::removeEdge(QSharedPointer<VideoNode> fromVertex, QSharedPointer<VideoNode> toVertex, int toInput) {
    Q_ASSERT(fromVertex != nullptr);
    Q_ASSERT(toVertex != nullptr);
    Q_ASSERT(toInput >= 0);
    Q_ASSERT(m_vertices.contains(fromVertex));
    Q_ASSERT(m_vertices.contains(toVertex));

    for (auto edge = m_edges.begin(); edge != m_edges.end(); edge++) {
        if (edge->fromVertex == fromVertex &&
            edge->toVertex == toVertex &&
            edge->toInput == toInput) {

            Edge edgeCopy = *edge;
            m_edges.erase(edge);
            emit edgeRemoved(edgeCopy);
        }
    }

RenderContext *Model::context() {
    return m_context;
}
<commit_msg>fix a small merge bug<commit_after>#include "Model.h"
#include "Effect.h"
#include "main.h"

Model::Model()
    : m_context(renderContext) {
}

Model::~Model() {
}

QSharedPointer<VideoNode> Model::addVideoNode(QString type) {
    // TODO
    QSharedPointer<VideoNode> videoNode(new Effect(m_context));

    m_vertices.append(videoNode);
    emit videoNodeAdded(videoNode);

    return videoNode;
}

void Model::removeVideoNode(QSharedPointer<VideoNode> videoNode) {
    for (auto edge = m_edges.begin(); edge != m_edges.end(); edge++) {
        if (edge->fromVertex == videoNode || edge->toVertex == videoNode) {
            Edge edgeCopy = *edge;
            m_edges.erase(edge);
            emit edgeRemoved(edgeCopy);
        }
    }

    int count = m_vertices.removeAll(videoNode);
    if (count > 0) {
        emit videoNodeRemoved(videoNode);
    }
}

void Model::addEdge(QSharedPointer<VideoNode> fromVertex, QSharedPointer<VideoNode> toVertex, int toInput) {
    Q_ASSERT(fromVertex != nullptr);
    Q_ASSERT(toVertex != nullptr);
    Q_ASSERT(toInput >= 0);
    Q_ASSERT(m_vertices.contains(fromVertex));
    Q_ASSERT(m_vertices.contains(toVertex));

    for (auto edge = m_edges.begin(); edge != m_edges.end(); edge++) {
        if (edge->toVertex == toVertex && edge->toInput == toInput) {
            if (edge->fromVertex == fromVertex)
                return;
            Edge edgeCopy = *edge;
            m_edges.erase(edge);
            emit edgeRemoved(edgeCopy);
        }
    }

    Edge newEdge = {
        .fromVertex = fromVertex,
        .toVertex = toVertex,
        .toInput = toInput,
    };
    m_edges.append(newEdge);
    emit edgeAdded(newEdge);
}

void Model::removeEdge(QSharedPointer<VideoNode> fromVertex, QSharedPointer<VideoNode> toVertex, int toInput) {
    Q_ASSERT(fromVertex != nullptr);
    Q_ASSERT(toVertex != nullptr);
    Q_ASSERT(toInput >= 0);
    Q_ASSERT(m_vertices.contains(fromVertex));
    Q_ASSERT(m_vertices.contains(toVertex));

    for (auto edge = m_edges.begin(); edge != m_edges.end(); edge++) {
        if (edge->fromVertex == fromVertex &&
            edge->toVertex == toVertex &&
            edge->toInput == toInput) {

            Edge edgeCopy = *edge;
            m_edges.erase(edge);
            emit edgeRemoved(edgeCopy);
        }
    }
}

RenderContext *Model::context() {
    return m_context;
}
<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    GaussianMinimumErrorClassifier.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "OptionList.h"
#include "itkImage.h"
#include "itkReadMetaImage.h"
#include "itkWriteMetaImage.h"
#include "itkImageRegionIterator.h"

#include "vnl/vnl_matrix.h"

#include "itkImageToListAdaptor.h"
#include "itkSubsample.h"
#include "itkMembershipSample.h"
#include "itkMembershipSampleGenerator.h"
#include "itkGaussianDensityFunction.h"
#include "itkMeanCalculator.h"
#include "itkCovarianceCalculator.h"
#include "itkTableLookupSampleClassifier.h"
#include "itkDecisionRuleBase.h"
#include "MaximumLikelihoodRatioDecisionRule.h"
#include "itkStatisticsAlgorithm.h"

void print_usage()
{
  std::cout << "GaussianMinimumErrorClassifier 1.0 (17. Dec. 2001)" << std::endl ;

  std::cout << "usage: GaussianMinimumErrorClassifier --training file"  << std::endl ;
  std::cout << "       --class-mask file" << std::endl ;
  std::cout << "       --number-of-classes int" << std::endl ;
  std::cout << "       --target file"  << std::endl ;
  std::cout << "       --output file"  << std::endl ;

  std::cout << "" << std::endl ;

  std::cout << "--training file" << std::endl ;
  std::cout << "        image file name with intesnity values [meta image format]"
    << std::endl ;
  std::cout << "--class-mask file" << std::endl ;
  std::cout << "        image file name with class labels [meta image format]"
    << std::endl ;
  std::cout << "--number-of-classes int" << std::endl ;
  std::cout << "        the number of classes in the training image."
    << std::endl ;
  std::cout << "--target file" << std::endl ;
  std::cout << "        target image file name with intensity values [meta image format]"
    << std::endl ;
  std::cout << "--output file" << std::endl ;
  std::cout << "        output image file name that will have the class labels for pixels"
    << std::endl ;
  std::cout << "        in the target image file [meta image format]"  << std::endl ;

  std::cout << "" << std::endl ;

  std::cout << "example: GaussianMinimumErrorClassifier --training train.mhd" << std::endl ;
  std::cout << "         --class-mask class_mask.mhd" << std::endl ;
  std::cout << "         --number-of-classes 10" << std::endl ;
  std::cout << "         --target target.mhd" << std::endl ;
  std::cout << "         --output output.mhd" << std::endl ;
}

int main(int argc, char* argv[])
{

  namespace stat = itk::Statistics ;

  if (argc <= 1)
    {
      print_usage() ;
      exit(0) ;
    }

  OptionList options(argc, argv) ;

  std::string trainingFileName ;
  std::string classMaskFileName ;
  std::string targetFileName ;
  std::string outputFileName ;
  unsigned int numberOfClasses ;
  try
    {
      // get image file options
      options.GetStringOption("training", &trainingFileName, true) ;
      // get image file options
      options.GetStringOption("class-mask", &classMaskFileName, true) ;
      // get image file options
      options.GetStringOption("target", &targetFileName, true) ;
      // get image file options
      options.GetStringOption("output", &outputFileName, true) ;
      // get the number of classes
      numberOfClasses = options.GetIntOption("number-of-classes", 10, true) ;
    }
  catch(OptionList::RequiredOptionMissing e)
    {
      std::cout << "Error: The '" << e.OptionTag
                << "' option is required but missing."
                << std::endl ;
      return 1 ;
    }

  typedef itk::Image< short, 3 > ImageType ;
  typedef ImageType::Pointer ImagePointer ;

  ImagePointer training ;
  ImagePointer classMask ;
  ImagePointer target ;

  std::cout << "Loading image(s)..." << std::endl ;
  //      readMetaImageHeader(trainingFileName, trainingDimension, trainingSize) ;
  typedef itk::ReadMetaImage<ImageType> Reader ;
  Reader::Pointer reader = Reader::New() ;

  reader->SetFileName(trainingFileName.c_str()) ;
  reader->Update() ;
  training = reader->GetOutput() ;
  std::cout << "Training image loaded." << std::endl ;

  Reader::Pointer reader2 = Reader::New() ;
  reader2->SetFileName(classMaskFileName.c_str()) ;
  reader2->Update() ;
  classMask = reader2->GetOutput() ;
  std::cout << "Class mask loaded." << std::endl ;

  Reader::Pointer reader3 = Reader::New() ;
  reader3->SetFileName(targetFileName.c_str()) ;
  reader3->Update() ;
  target = reader3->GetOutput() ;
  std::cout << "Target image loaded." << std::endl ;

  /* ================================================== */
  std::cout << "Importing the images to samples..."
            << std::endl ;
  typedef stat::ImageToListAdaptor< ImageType, stat::ScalarImageAccessor< ImageType > >
    ImageListSampleType;

  ImageListSampleType::Pointer sample =
    ImageListSampleType::New() ;

  ImageListSampleType::Pointer mask =
    ImageListSampleType::New() ;

  ImageListSampleType::Pointer targetSample =
    ImageListSampleType::New() ;

  sample->SetImage(training);
  mask->SetImage(classMask) ;
  targetSample->SetImage(target) ;
  /* ==================================================== */
  std::cout << "Creating the membership sample for training.." << std::endl ;
  typedef stat::MembershipSampleGenerator< ImageListSampleType,
    ImageListSampleType > MembershipSampleGeneratorType ;
  MembershipSampleGeneratorType::Pointer generator =
    MembershipSampleGeneratorType::New() ;

  generator->SetInput(sample) ;
  generator->SetClassMask(mask) ;
  generator->SetNumberOfClasses(numberOfClasses) ;
  generator->GenerateData() ;
  MembershipSampleGeneratorType::OutputPointer membershipSample =
    generator->GetOutput() ;

  /* =================================================== */
  std::cout << "Inducing the gaussian density function parameters and apriori probabilities..."
            << std::endl ;
  typedef ImageListSampleType::MeasurementVectorType
    MeasurementVectorType ;
  typedef stat::GaussianDensityFunction< MeasurementVectorType >
    DensityFunctionType ;
  typedef DensityFunctionType::Pointer DensityFunctionPointer ;
  std::vector< DensityFunctionPointer > densityFunctions ;
  densityFunctions.resize(numberOfClasses) ;

  typedef MembershipSampleGeneratorType::OutputType::ClassSampleType
    ClassSampleType ;
  typedef stat::MeanCalculator< ClassSampleType >
    MeanCalculatorType ;
  typedef stat::CovarianceCalculator< ClassSampleType >
    CovarianceCalculatorType ;
  MeanCalculatorType::Pointer meanCalculator = MeanCalculatorType::New() ;
  CovarianceCalculatorType::Pointer covarianceCalculator =
    CovarianceCalculatorType::New() ;
  vnl_vector< double > mean ;
  vnl_matrix< double > covariance ;

  typedef MaximumLikelihoodRatioDecisionRule DecisionRuleType ;
  DecisionRuleType::Pointer rule = DecisionRuleType::New() ;

  unsigned int sampleSize = 0 ;
  std::cout << "Inducing the gaussian density function parameters and apriori probabilities..." << std::endl ;
  for (unsigned int i = 0 ; i < numberOfClasses ; i++)
    {
      std::cout << "gaussian [" << i << "]" << std::endl ;
      // add the class sample size to the decision rule
      // for the a priori probability calculation
      std::cout << "  Sample size = " ;
      sampleSize = membershipSample->GetClassSampleSize(i) ;
      std::cout << sampleSize << std::endl ;
      rule->AddClassSampleSize(sampleSize) ;

      ClassSampleType::Pointer subSample =
        membershipSample->GetClassSample(i) ;
      meanCalculator->SetSample(subSample) ;
      meanCalculator->GenerateData() ;
      mean = meanCalculator->GetOutput() ;

      covarianceCalculator->SetSample(subSample) ;
      covarianceCalculator->SetMean(mean) ;
      covarianceCalculator->GenerateData() ;
      covariance = covarianceCalculator->GetOutput() ;

      densityFunctions[i] = DensityFunctionType::New() ;
      (densityFunctions[i])->SetMean(mean) ;
      (densityFunctions[i])->SetCovariance(covariance) ;
      std::cout << "  mean = " << (densityFunctions[i])->GetMean()
                << std::endl ;
      std::cout << "  covariance = " << std::endl ;
      (densityFunctions[i])->GetCovariance().print(std::cout) ;

    }

  /* =================================================== */
  std::cout << "Classifying..." << std::endl ;

  typedef stat::TableLookupSampleClassifier< ImageListSampleType >
    ClassifierType ;

  ClassifierType::Pointer classifier = ClassifierType::New() ;
  classifier->SetNumberOfClasses(numberOfClasses) ;
  classifier->SetSample(targetSample) ;
  for (unsigned int i = 0 ; i < numberOfClasses ; i++)
    {
      classifier->AddMembershipFunction(densityFunctions[i]) ;
    }

  classifier->SetDecisionRule((itk::DecisionRuleBase::Pointer)rule) ;
  ImageListSampleType::MeasurementVectorType upper ;
  ImageListSampleType::MeasurementVectorType lower ;

  stat::FindSampleBound< ImageListSampleType >(targetSample, targetSample->Begin(),
                                               targetSample->End(), lower, upper) ;
  std::cout << "min = " << lower[0] << " max = " << upper[0] << std::endl ;

  classifier->SetLookupTableLowerBound(lower) ;
  classifier->SetLookupTableUpperBound(upper) ;
  classifier->Update() ;

  ClassifierType::OutputPointer result = classifier->GetOutput() ;

  /* ===================================================== */
  std::cout << "Creating a image with result class labels..." << std::endl ;
  typedef itk::ImageRegionIterator< ImageType > ImageIteratorType ;
  typedef itk::WriteMetaImage< ImageType > Writer ;
  Writer::Pointer writer = Writer::New() ;

  ImagePointer output = ImageType::New() ;
  output->SetBufferedRegion(target->GetLargestPossibleRegion()) ;
  output->SetLargestPossibleRegion(target->GetLargestPossibleRegion()) ;
  output->Allocate() ;
  ImageIteratorType i_iter(output, output->GetLargestPossibleRegion()) ;
  i_iter.GoToBegin() ;
  ClassifierType::OutputType::Iterator m_iter = result->Begin() ;
  while (!i_iter.IsAtEnd())
    {
      i_iter.Set((ImageType::PixelType)m_iter.GetClassLabel()) ;
      ++i_iter ;
      ++m_iter ;
    }

  writer->SetInput(output) ;
  writer->SetFileName(outputFileName.c_str()) ;
  writer->GenerateData() ;

  return 0 ;
}

<commit_msg>ENH: MeanCalculator and CovarianceCalculator need Update() call instead of GenerateData() call to generate data.<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    GaussianMinimumErrorClassifier.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "OptionList.h"
#include "itkImage.h"
#include "itkReadMetaImage.h"
#include "itkWriteMetaImage.h"
#include "itkImageRegionIterator.h"

#include "vnl/vnl_matrix.h"

#include "itkImageToListAdaptor.h"
#include "itkSubsample.h"
#include "itkMembershipSample.h"
#include "itkMembershipSampleGenerator.h"
#include "itkGaussianDensityFunction.h"
#include "itkMeanCalculator.h"
#include "itkCovarianceCalculator.h"
#include "itkTableLookupSampleClassifier.h"
#include "itkDecisionRuleBase.h"
#include "MaximumLikelihoodRatioDecisionRule.h"
#include "itkStatisticsAlgorithm.h"

void print_usage()
{
  std::cout << "GaussianMinimumErrorClassifier 1.0 (17. Dec. 2001)" << std::endl ;

  std::cout << "usage: GaussianMinimumErrorClassifier --training file"  << std::endl ;
  std::cout << "       --class-mask file" << std::endl ;
  std::cout << "       --number-of-classes int" << std::endl ;
  std::cout << "       --target file"  << std::endl ;
  std::cout << "       --output file"  << std::endl ;

  std::cout << "" << std::endl ;

  std::cout << "--training file" << std::endl ;
  std::cout << "        image file name with intesnity values [meta image format]"
    << std::endl ;
  std::cout << "--class-mask file" << std::endl ;
  std::cout << "        image file name with class labels [meta image format]"
    << std::endl ;
  std::cout << "--number-of-classes int" << std::endl ;
  std::cout << "        the number of classes in the training image."
    << std::endl ;
  std::cout << "--target file" << std::endl ;
  std::cout << "        target image file name with intensity values [meta image format]"
    << std::endl ;
  std::cout << "--output file" << std::endl ;
  std::cout << "        output image file name that will have the class labels for pixels"
    << std::endl ;
  std::cout << "        in the target image file [meta image format]"  << std::endl ;

  std::cout << "" << std::endl ;

  std::cout << "example: GaussianMinimumErrorClassifier --training train.mhd" << std::endl ;
  std::cout << "         --class-mask class_mask.mhd" << std::endl ;
  std::cout << "         --number-of-classes 10" << std::endl ;
  std::cout << "         --target target.mhd" << std::endl ;
  std::cout << "         --output output.mhd" << std::endl ;
}

int main(int argc, char* argv[])
{

  namespace stat = itk::Statistics ;

  if (argc <= 1)
    {
      print_usage() ;
      exit(0) ;
    }

  OptionList options(argc, argv) ;

  std::string trainingFileName ;
  std::string classMaskFileName ;
  std::string targetFileName ;
  std::string outputFileName ;
  unsigned int numberOfClasses ;
  try
    {
      // get image file options
      options.GetStringOption("training", &trainingFileName, true) ;
      // get image file options
      options.GetStringOption("class-mask", &classMaskFileName, true) ;
      // get image file options
      options.GetStringOption("target", &targetFileName, true) ;
      // get image file options
      options.GetStringOption("output", &outputFileName, true) ;
      // get the number of classes
      numberOfClasses = options.GetIntOption("number-of-classes", 10, true) ;
    }
  catch(OptionList::RequiredOptionMissing e)
    {
      std::cout << "Error: The '" << e.OptionTag
                << "' option is required but missing."
                << std::endl ;
      return 1 ;
    }

  typedef itk::Image< short, 3 > ImageType ;
  typedef ImageType::Pointer ImagePointer ;

  ImagePointer training ;
  ImagePointer classMask ;
  ImagePointer target ;

  std::cout << "Loading image(s)..." << std::endl ;
  //      readMetaImageHeader(trainingFileName, trainingDimension, trainingSize) ;
  typedef itk::ReadMetaImage<ImageType> Reader ;
  Reader::Pointer reader = Reader::New() ;

  reader->SetFileName(trainingFileName.c_str()) ;
  reader->Update() ;
  training = reader->GetOutput() ;
  std::cout << "Training image loaded." << std::endl ;

  Reader::Pointer reader2 = Reader::New() ;
  reader2->SetFileName(classMaskFileName.c_str()) ;
  reader2->Update() ;
  classMask = reader2->GetOutput() ;
  std::cout << "Class mask loaded." << std::endl ;

  Reader::Pointer reader3 = Reader::New() ;
  reader3->SetFileName(targetFileName.c_str()) ;
  reader3->Update() ;
  target = reader3->GetOutput() ;
  std::cout << "Target image loaded." << std::endl ;

  /* ================================================== */
  std::cout << "Importing the images to samples..."
            << std::endl ;
  typedef stat::ImageToListAdaptor< ImageType, stat::ScalarImageAccessor< ImageType > >
    ImageListSampleType;

  ImageListSampleType::Pointer sample =
    ImageListSampleType::New() ;

  ImageListSampleType::Pointer mask =
    ImageListSampleType::New() ;

  ImageListSampleType::Pointer targetSample =
    ImageListSampleType::New() ;

  sample->SetImage(training);
  mask->SetImage(classMask) ;
  targetSample->SetImage(target) ;
  /* ==================================================== */
  std::cout << "Creating the membership sample for training.." << std::endl ;
  typedef stat::MembershipSampleGenerator< ImageListSampleType,
    ImageListSampleType > MembershipSampleGeneratorType ;
  MembershipSampleGeneratorType::Pointer generator =
    MembershipSampleGeneratorType::New() ;

  generator->SetInput(sample) ;
  generator->SetClassMask(mask) ;
  generator->SetNumberOfClasses(numberOfClasses) ;
  generator->GenerateData() ;
  MembershipSampleGeneratorType::OutputPointer membershipSample =
    generator->GetOutput() ;

  /* =================================================== */
  std::cout << "Inducing the gaussian density function parameters and apriori probabilities..."
            << std::endl ;
  typedef ImageListSampleType::MeasurementVectorType
    MeasurementVectorType ;
  typedef stat::GaussianDensityFunction< MeasurementVectorType >
    DensityFunctionType ;
  typedef DensityFunctionType::Pointer DensityFunctionPointer ;
  std::vector< DensityFunctionPointer > densityFunctions ;
  densityFunctions.resize(numberOfClasses) ;

  typedef MembershipSampleGeneratorType::OutputType::ClassSampleType
    ClassSampleType ;
  typedef stat::MeanCalculator< ClassSampleType >
    MeanCalculatorType ;
  typedef stat::CovarianceCalculator< ClassSampleType >
    CovarianceCalculatorType ;
  MeanCalculatorType::Pointer meanCalculator = MeanCalculatorType::New() ;
  CovarianceCalculatorType::Pointer covarianceCalculator =
    CovarianceCalculatorType::New() ;
  vnl_vector< double > mean ;
  vnl_matrix< double > covariance ;

  typedef MaximumLikelihoodRatioDecisionRule DecisionRuleType ;
  DecisionRuleType::Pointer rule = DecisionRuleType::New() ;

  unsigned int sampleSize = 0 ;
  std::cout << "Inducing the gaussian density function parameters and apriori probabilities..." << std::endl ;
  for (unsigned int i = 0 ; i < numberOfClasses ; i++)
    {
      std::cout << "gaussian [" << i << "]" << std::endl ;
      // add the class sample size to the decision rule
      // for the a priori probability calculation
      std::cout << "  Sample size = " ;
      sampleSize = membershipSample->GetClassSampleSize(i) ;
      std::cout << sampleSize << std::endl ;
      rule->AddClassSampleSize(sampleSize) ;

      ClassSampleType::Pointer subSample =
        membershipSample->GetClassSample(i) ;
      meanCalculator->SetSample(subSample) ;
      meanCalculator->Update() ;
      mean = meanCalculator->GetOutput() ;

      covarianceCalculator->SetSample(subSample) ;
      covarianceCalculator->SetMean(mean) ;
      covarianceCalculator->Update() ;
      covariance = covarianceCalculator->GetOutput() ;

      densityFunctions[i] = DensityFunctionType::New() ;
      (densityFunctions[i])->SetMean(mean) ;
      (densityFunctions[i])->SetCovariance(covariance) ;
      std::cout << "  mean = " << (densityFunctions[i])->GetMean()
                << std::endl ;
      std::cout << "  covariance = " << std::endl ;
      (densityFunctions[i])->GetCovariance().print(std::cout) ;

    }

  /* =================================================== */
  std::cout << "Classifying..." << std::endl ;

  typedef stat::TableLookupSampleClassifier< ImageListSampleType >
    ClassifierType ;

  ClassifierType::Pointer classifier = ClassifierType::New() ;
  classifier->SetNumberOfClasses(numberOfClasses) ;
  classifier->SetSample(targetSample) ;
  for (unsigned int i = 0 ; i < numberOfClasses ; i++)
    {
      classifier->AddMembershipFunction(densityFunctions[i]) ;
    }

  classifier->SetDecisionRule((itk::DecisionRuleBase::Pointer)rule) ;
  ImageListSampleType::MeasurementVectorType upper ;
  ImageListSampleType::MeasurementVectorType lower ;

  stat::FindSampleBound< ImageListSampleType >(targetSample, targetSample->Begin(),
                                               targetSample->End(), lower, upper) ;
  std::cout << "min = " << lower[0] << " max = " << upper[0] << std::endl ;

  classifier->SetLookupTableLowerBound(lower) ;
  classifier->SetLookupTableUpperBound(upper) ;
  classifier->Update() ;

  ClassifierType::OutputPointer result = classifier->GetOutput() ;

  /* ===================================================== */
  std::cout << "Creating a image with result class labels..." << std::endl ;
  typedef itk::ImageRegionIterator< ImageType > ImageIteratorType ;
  typedef itk::WriteMetaImage< ImageType > Writer ;
  Writer::Pointer writer = Writer::New() ;

  ImagePointer output = ImageType::New() ;
  output->SetBufferedRegion(target->GetLargestPossibleRegion()) ;
  output->SetLargestPossibleRegion(target->GetLargestPossibleRegion()) ;
  output->Allocate() ;
  ImageIteratorType i_iter(output, output->GetLargestPossibleRegion()) ;
  i_iter.GoToBegin() ;
  ClassifierType::OutputType::Iterator m_iter = result->Begin() ;
  while (!i_iter.IsAtEnd())
    {
      i_iter.Set((ImageType::PixelType)m_iter.GetClassLabel()) ;
      ++i_iter ;
      ++m_iter ;
    }

  writer->SetInput(output) ;
  writer->SetFileName(outputFileName.c_str()) ;
  writer->GenerateData() ;

  return 0 ;
}

<|endoftext|>


<commit_before>//________________________________________________________________________
void demoInteractive() {
  //____________________________________________//
  AliTagAnalysis *TagAna = new AliTagAnalysis();

  AliRunTagCuts *RunCuts = new AliRunTagCuts();
  AliEventTagCuts *EvCuts = new AliEventTagCuts();
  EvCuts->SetMultiplicityRange(11,12);
  //grid tags
  TAlienCollection* coll = TAlienCollection::Open("tag.xml");
  TGridResult* TagResult = coll->GetGridResult("");
  TagAna->ChainGridTags(TagResult);
  TChain* chain = 0x0;
  chain = TagAna->QueryTags(RunCuts,EvCuts);

  //____________________________________________//
  // Make the analysis manager
  AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
  //____________________________________________//
  // 1st Pt task
  AliAnalysisTaskPt *task1 = new AliAnalysisTaskPt("TaskPt");
  mgr->AddTask(task1);
  // Create containers for input/output
  AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("chist1", TH1::Class(),AliAnalysisManager::kOutputContainer,"Pt.ESD.root");

  //____________________________________________//
  mgr->ConnectInput(task1,0,cinput1);
  mgr->ConnectOutput(task1,0,coutput1);
  cinput1->SetData(chain);

  if (mgr->InitAnalysis()) {
    mgr->PrintStatus();
    mgr->StartAnalysis("local",chain);
  }
}

<commit_msg>Adding the 0,0 option in the TGridResult<commit_after>//________________________________________________________________________
void demoInteractive() {
  //____________________________________________//
  AliTagAnalysis *TagAna = new AliTagAnalysis();

  AliRunTagCuts *RunCuts = new AliRunTagCuts();
  AliEventTagCuts *EvCuts = new AliEventTagCuts();
  EvCuts->SetMultiplicityRange(11,12);
  //grid tags
  TAlienCollection* coll = TAlienCollection::Open("tag.xml");
  TGridResult* TagResult = coll->GetGridResult("",0,0);
  TagAna->ChainGridTags(TagResult);
  TChain* chain = 0x0;
  chain = TagAna->QueryTags(RunCuts,EvCuts);

  //____________________________________________//
  // Make the analysis manager
  AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
  //____________________________________________//
  // 1st Pt task
  AliAnalysisTaskPt *task1 = new AliAnalysisTaskPt("TaskPt");
  mgr->AddTask(task1);
  // Create containers for input/output
  AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("chist1", TH1::Class(),AliAnalysisManager::kOutputContainer,"Pt.ESD.root");

  //____________________________________________//
  mgr->ConnectInput(task1,0,cinput1);
  mgr->ConnectOutput(task1,0,coutput1);
  cinput1->SetData(chain);

  if (mgr->InitAnalysis()) {
    mgr->PrintStatus();
    mgr->StartAnalysis("local",chain);
  }
}

<|endoftext|>


<commit_before>// RUN: %clangxx -fsanitize=integer -g0 %s -o %t

// Fails without any suppression.
// RUN: %env_ubsan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck %s

// RUN: echo "signed-integer-overflow:%t" > %t.wrong-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.wrong-supp"' not %run %t 2>&1 | FileCheck %s

// RUN: echo "unsigned-integer-overflow:do_overflow" > %t.func-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.func-supp"' %run %t
// RUN: echo "unsigned-integer-overflow:%t" > %t.module-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.module-supp"' %run %t

// Note: file-level suppressions should work even without debug info.
// RUN: echo "unsigned-integer-overflow:%s" > %t.file-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.file-supp"' %run %t

// Suppressions don't work for unrecoverable kinds.
// RUN: %clangxx -fsanitize=integer -fno-sanitize-recover=integer %s -o %t-norecover
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.module-supp"' not %run %t-norecover 2>&1 | FileCheck %s

#include <stdint.h>

extern "C" void do_overflow() {
  (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull));
  // CHECK: runtime error: unsigned integer overflow
}

int main() {
  do_overflow();
  return 0;
}

<commit_msg>Re-disable suppressions.cpp on Windows.<commit_after>// XFAIL: win32
// This test fails on Windows if the environment was set up by SetEnv.cmd from
// the Windows SDK.  If it's set up via vcvarsall.bat, it passes.
// FIXME: Figure out how to make this reliably pass on Windows.
// test/asan/TestCases/suppressions-interceptor.cc will need the same fix.

// RUN: %clangxx -fsanitize=integer -g0 %s -o %t

// Fails without any suppression.
// RUN: %env_ubsan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck %s

// RUN: echo "signed-integer-overflow:%t" > %t.wrong-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.wrong-supp"' not %run %t 2>&1 | FileCheck %s

// RUN: echo "unsigned-integer-overflow:do_overflow" > %t.func-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.func-supp"' %run %t
// RUN: echo "unsigned-integer-overflow:%t" > %t.module-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.module-supp"' %run %t

// Note: file-level suppressions should work even without debug info.
// RUN: echo "unsigned-integer-overflow:%s" > %t.file-supp
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.file-supp"' %run %t

// Suppressions don't work for unrecoverable kinds.
// RUN: %clangxx -fsanitize=integer -fno-sanitize-recover=integer %s -o %t-norecover
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.module-supp"' not %run %t-norecover 2>&1 | FileCheck %s

#include <stdint.h>

extern "C" void do_overflow() {
  (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull));
  // CHECK: runtime error: unsigned integer overflow
}

int main() {
  do_overflow();
  return 0;
}

<|endoftext|>


<commit_before>AliAnalysisTaskSECharmFraction* AddTaskSECharmFraction(TString fileout="d0D0.root",Int_t *switchMC=0x0,Int_t readmc=0,Bool_t usepid=kTRUE,Bool_t likesign=kFALSE,TString cutfile="D0toKpiCharmFractCuts.root",TString containerprefix="c",Int_t ppPbPb=0,Int_t analysLevel=2, Float_t minC=0., Float_t maxC=7.5,Float_t minCloose=20., Float_t maxCloose=50.,Bool_t useWeight=kFALSE,Bool_t fillTree=kFALSE,Bool_t checkBitD0=kTRUE)
{
  //
  // Configuration macro for the task to analyze the fraction of prompt charm
  // using the D0 impact parameter
  // andrea.rossi@ts.infn.it
  //
  //==========================================================================

  //######## !!! THE SWITCH FOR MC ANALYSIS IS NOT IMPLEMENTED YET!!! ##########
  if(switchMC!=0x0){
    switchMC[0]=1;
    switchMC[1]=1;
    switchMC[2]=1;
    switchMC[3]=1;
    switchMC[4]=1;
  }
  Int_t last=0;

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

  TString str,containername;
  if(fileout.Contains("standard"))if(fileout.Contains("standard")){
      TString  fileouttmp = fileout;
      fileout=AliAnalysisManager::GetCommonFileName();
      fileout+=":PWG3_D2H_";
      fileout+="d0D0";
      fileout+=fileouttmp;
      if(containerprefix!="c")fileout+=containerprefix;
      str="d0D0";
    }
    else if(fileout=="standardUp"){
      fileout=AliAnalysisManager::GetCommonFileName();
      fileout+=":PWG3_D2H_Up_";
      fileout+="d0D0";
      if(containerprefix!="c")fileout+=containerprefix;
      str="d0D0";
    }
    else {
      str=fileout;
      str.ReplaceAll(".root","");
    }
  str.Prepend("_");

  AliAnalysisTaskSECharmFraction *hfTask;
  if(!gSystem->AccessPathName(cutfile.Data(),kFileExists)){
    TFile *f=TFile::Open(cutfile.Data());
    AliRDHFCutsD0toKpi *cutTight= (AliRDHFCutsD0toKpi*)f->Get("D0toKpiCutsStandard");
    cutTight->PrintAll();
    AliRDHFCutsD0toKpi *cutLoose= (AliRDHFCutsD0toKpi*)f->Get("D0toKpiCutsLoose");
    cutLoose->PrintAll();
    hfTask = new AliAnalysisTaskSECharmFraction("AliAnalysisTaskSECharmFraction",cutTight,cutLoose);
  }
  else {
    //hfTask = new AliAnalysisTaskSECharmFraction("AliAnalysisTaskSECharmFraction");
    AliRDHFCutsD0toKpi *cutTight=new AliRDHFCutsD0toKpi("D0toKpiCutsStandard");
    AliRDHFCutsD0toKpi *cutLoose=new AliRDHFCutsD0toKpi("D0toKpiCutsLoose");
    if(ppPbPb==1){
      printf("USING STANDARD CUTS 2011 \n");
      cutTight->SetStandardCutsPbPb2011();
      cutTight->SetMinCentrality(minC);
      cutTight->SetMaxCentrality(maxC);
      cutTight->SetMinPtCandidate(0.);
      cutLoose->SetStandardCutsPbPb2011();
      cutLoose->SetMinCentrality(minCloose);
      cutLoose->SetMaxCentrality(maxCloose);
      cutLoose->SetMinPtCandidate(0.);
    }
    else {
      cutTight->SetStandardCutsPP2010();
      cutLoose->SetStandardCutsPP2010();
    }
    hfTask = new AliAnalysisTaskSECharmFraction("AliAnalysisTaskSECharmFraction",cutTight,cutLoose);
    cutLoose->PrintAll();
  }

  if(ppPbPb==1){// Switch Off recalctulation of primary vertex w/o candidate's daughters
    // a protection that must be kept here to be sure
    //that this is done also if the cut objects are provided by outside
    Printf("AddTaskSECharmFraction: Switch Off recalculation of primary vertex w/o candidate's daughters (PbPb analysis) \n");
    AliRDHFCutsD0toKpi *cloose=hfTask->GetLooseCut();
    AliRDHFCutsD0toKpi *ctight=hfTask->GetTightCut();
    cloose->SetRemoveDaughtersFromPrim(kFALSE);
    ctight->SetRemoveDaughtersFromPrim(kFALSE);
    if(analysLevel<2){
      printf("Cannot activate the filling of all the histograms for PbPb analysis \n changing analysis level to 2 \n");
      analysLevel=2;
    }
    // Activate Default PID for proton rejection (TEMPORARY)
    // cloose->SetUseDefaultPID(kTRUE);
    // ctight->SetUseDefaultPID(kTRUE);
  }

  if(readmc>0)hfTask->SetReadMC(kTRUE);
  if(readmc==2){
    hfTask->SetRejecCandidateMCUpgrade(kTRUE);
    hfTask->SetSkipEventSelection(kTRUE);
    hfTask->SetMaxZvtxForSkipEventSelection(10.);
  }

  hfTask->SetNMaxTrForVtx(2);
  hfTask->SetAnalyzeLikeSign(likesign);
  hfTask->SetUsePID(usepid);
  hfTask->SetStandardMassSelection();
  hfTask->SetAnalysisLevel(analysLevel);
  hfTask->SetFillImpParTree(fillTree);

  hfTask->SetCheckBitD0flag(checkBitD0);
  if(readmc&&useWeight)hfTask->SetPtWeightsFromDataPbPb276overLHC12a17a();
  // hfTask->SignalInvMassCut(0.27);

  /*  ############### HERE THE POSSIBILITY TO SWITCH ON/OFF THE TLISTS AND MC SELECTION WILL BE SET #########à

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

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

  //Now container for general properties histograms
  containername="outputNentries";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputNentries = mgr->CreateContainer(containername.Data(),TH1F::Class(),
								   AliAnalysisManager::kOutputContainer,
								   fileout.Data());

  mgr->ConnectOutput(hfTask,1,coutputNentries);

  containername="outputSignalType";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSignalType = mgr->CreateContainer(containername.Data(),TH1F::Class(),
								     AliAnalysisManager::kOutputContainer,
								     fileout.Data());

  mgr->ConnectOutput(hfTask,2,coutputSignalType);

  containername="outputSignalType_LsCuts";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSignalType_LsCuts = mgr->CreateContainer(containername.Data(),TH1F::Class(),
									    AliAnalysisManager::kOutputContainer,
									    fileout.Data());

  mgr->ConnectOutput(hfTask,3,coutputSignalType_LsCuts);

  containername="outputSignalType_TghCuts";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSignalType_TghCuts = mgr->CreateContainer(containername.Data(),TH1F::Class(),
									     AliAnalysisManager::kOutputContainer,
									     fileout.Data());

  mgr->ConnectOutput(hfTask,4,coutputSignalType_TghCuts);

  containername="outputNormalizationCounter";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputNormCounter = mgr ->CreateContainer(containername.Data(), AliNormalizationCounter::Class(),
								       AliAnalysisManager::kOutputContainer,
								       fileout.Data());
  mgr->ConnectOutput(hfTask, 5, coutputNormCounter);

  //Now Container for MC TList
  containername="listMCproperties";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistMCprop = mgr->CreateContainer(containername.Data(),TList::Class(),
							       AliAnalysisManager::kOutputContainer,
							       fileout.Data());
  mgr->ConnectOutput(hfTask,6,clistMCprop);

  // Now container for TLists
  last=7;
  //##########  NO CUTS TLISTS CONTAINER ##############à
  containername="listNCsign";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCsign = mgr->CreateContainer(containername.Data(),TList::Class(),
							       AliAnalysisManager::kOutputContainer,
							       fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCsign);
  last++;

  containername="listNCback";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCback = mgr->CreateContainer(containername.Data(),TList::Class(),
							       AliAnalysisManager::kOutputContainer,
							       fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCback);
  last++;

  containername="listNCfromB";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCfromB = mgr->CreateContainer(containername.Data(),TList::Class(),
								AliAnalysisManager::kOutputContainer,
								fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCfromB);
  last++;

  containername="listNCfromDstar";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCfromDstar = mgr->CreateContainer(containername.Data(),TList::Class(),
								    AliAnalysisManager::kOutputContainer,
								    fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCfromDstar);
  last++;

  containername="listNCother";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCother = mgr->CreateContainer(containername.Data(),TList::Class(),
								AliAnalysisManager::kOutputContainer,
								fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCother);
  last++;

  //######### LOOSE CUTS TLISTS CONTAINER #############
  containername="listLSCsign";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCsign = mgr->CreateContainer(containername.Data(),TList::Class(),
								AliAnalysisManager::kOutputContainer,
								fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCsign);
  last++;

  containername="listLSCback";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCback = mgr->CreateContainer(containername.Data(),TList::Class(),
								AliAnalysisManager::kOutputContainer,
								fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCback);
  last++;

  containername="listLSCfromB";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCfromB = mgr->CreateContainer(containername.Data(),TList::Class(),
								 AliAnalysisManager::kOutputContainer,
								 fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCfromB);
  last++;

  containername="listLSCfromDstar";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCfromDstar = mgr->CreateContainer(containername.Data(),TList::Class(),
								     AliAnalysisManager::kOutputContainer,
								     fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCfromDstar);
  last++;

  containername="listLSCother";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCother = mgr->CreateContainer(containername.Data(),TList::Class(),
								 AliAnalysisManager::kOutputContainer,
								 fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCother);
  last++;

  //######### TIGHT CUTS TLISTS CONTAINER #############
  containername="listTGHCsign";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCsign = mgr->CreateContainer(containername.Data(),TList::Class(),
								 AliAnalysisManager::kOutputContainer,
								 fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCsign);
  last++;

  containername="listTGHCback";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCback = mgr->CreateContainer(containername.Data(),TList::Class(),
								 AliAnalysisManager::kOutputContainer,
								 fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCback);
  last++;

  containername="listTGHCfromB";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCfromB = mgr->CreateContainer(containername.Data(),TList::Class(),
								  AliAnalysisManager::kOutputContainer,
								  fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCfromB);
  last++;

  containername="listTGHCfromDstar";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCfromDstar = mgr->CreateContainer(containername.Data(),TList::Class(),
								      AliAnalysisManager::kOutputContainer,
								      fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCfromDstar);
  last++;

  containername="listTGHCother";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCother = mgr->CreateContainer(containername.Data(),TList::Class(),
								  AliAnalysisManager::kOutputContainer,
								  fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCother);
  last++;

  // Container for Cuts Objects
  containername="cutsObjectTight";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *cCutsObjectTight = mgr->CreateContainer(containername,AliRDHFCutsD0toKpi::Class(),AliAnalysisManager::kOutputContainer,fileout.Data()); //cuts
  mgr->ConnectOutput(hfTask,last,cCutsObjectTight);
  last++;

  containername="cutsObjectLoose";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *cCutsObjectLoose = mgr->CreateContainer(containername,AliRDHFCutsD0toKpi::Class(),AliAnalysisManager::kOutputContainer,fileout.Data()); //cuts
  mgr->ConnectOutput(hfTask,last,cCutsObjectLoose);

  return hfTask;
}
<commit_msg>fix typo in AddTaskSECharmFraction.C (Cristina)<commit_after>AliAnalysisTaskSECharmFraction* AddTaskSECharmFraction(TString fileout="d0D0.root",Int_t *switchMC=0x0,Int_t readmc=0,Bool_t usepid=kTRUE,Bool_t likesign=kFALSE,TString cutfile="D0toKpiCharmFractCuts.root",TString containerprefix="c",Int_t ppPbPb=0,Int_t analysLevel=2, Float_t minC=0., Float_t maxC=7.5,Float_t minCloose=20., Float_t maxCloose=50.,Bool_t useWeight=kFALSE,Bool_t fillTree=kFALSE,Bool_t checkBitD0=kTRUE)
{
  //
  // Configuration macro for the task to analyze the fraction of prompt charm
  // using the D0 impact parameter
  // andrea.rossi@ts.infn.it
  //
  //==========================================================================

  //######## !!! THE SWITCH FOR MC ANALYSIS IS NOT IMPLEMENTED YET!!! ##########
  if(switchMC!=0x0){
    switchMC[0]=1;
    switchMC[1]=1;
    switchMC[2]=1;
    switchMC[3]=1;
    switchMC[4]=1;
  }
  Int_t last=0;

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

  TString str,containername;
  if(fileout.Contains("standard")){
      TString  fileouttmp = fileout;
      fileout=AliAnalysisManager::GetCommonFileName();
      fileout+=":PWG3_D2H_";
      fileout+="d0D0";
      fileout+=fileouttmp;
      if(containerprefix!="c")fileout+=containerprefix;
      str="d0D0";
    }
    else if(fileout=="standardUp"){
      fileout=AliAnalysisManager::GetCommonFileName();
      fileout+=":PWG3_D2H_Up_";
      fileout+="d0D0";
      if(containerprefix!="c")fileout+=containerprefix;
      str="d0D0";
    }
    else {
      str=fileout;
      str.ReplaceAll(".root","");
    }
  str.Prepend("_");

  AliAnalysisTaskSECharmFraction *hfTask;
  if(!gSystem->AccessPathName(cutfile.Data(),kFileExists)){
    TFile *f=TFile::Open(cutfile.Data());
    AliRDHFCutsD0toKpi *cutTight= (AliRDHFCutsD0toKpi*)f->Get("D0toKpiCutsStandard");
    cutTight->PrintAll();
    AliRDHFCutsD0toKpi *cutLoose= (AliRDHFCutsD0toKpi*)f->Get("D0toKpiCutsLoose");
    cutLoose->PrintAll();
    hfTask = new AliAnalysisTaskSECharmFraction("AliAnalysisTaskSECharmFraction",cutTight,cutLoose);
  }
  else {
    //hfTask = new AliAnalysisTaskSECharmFraction("AliAnalysisTaskSECharmFraction");
    AliRDHFCutsD0toKpi *cutTight=new AliRDHFCutsD0toKpi("D0toKpiCutsStandard");
    AliRDHFCutsD0toKpi *cutLoose=new AliRDHFCutsD0toKpi("D0toKpiCutsLoose");
    if(ppPbPb==1){
      printf("USING STANDARD CUTS 2011 \n");
      cutTight->SetStandardCutsPbPb2011();
      cutTight->SetMinCentrality(minC);
      cutTight->SetMaxCentrality(maxC);
      cutTight->SetMinPtCandidate(0.);
      cutLoose->SetStandardCutsPbPb2011();
      cutLoose->SetMinCentrality(minCloose);
      cutLoose->SetMaxCentrality(maxCloose);
      cutLoose->SetMinPtCandidate(0.);
    }
    else {
      cutTight->SetStandardCutsPP2010();
      cutLoose->SetStandardCutsPP2010();
    }
    hfTask = new AliAnalysisTaskSECharmFraction("AliAnalysisTaskSECharmFraction",cutTight,cutLoose);
    cutLoose->PrintAll();
  }

  if(ppPbPb==1){// Switch Off recalctulation of primary vertex w/o candidate's daughters
    // a protection that must be kept here to be sure
    //that this is done also if the cut objects are provided by outside
    Printf("AddTaskSECharmFraction: Switch Off recalculation of primary vertex w/o candidate's daughters (PbPb analysis) \n");
    AliRDHFCutsD0toKpi *cloose=hfTask->GetLooseCut();
    AliRDHFCutsD0toKpi *ctight=hfTask->GetTightCut();
    cloose->SetRemoveDaughtersFromPrim(kFALSE);
    ctight->SetRemoveDaughtersFromPrim(kFALSE);
    if(analysLevel<2){
      printf("Cannot activate the filling of all the histograms for PbPb analysis \n changing analysis level to 2 \n");
      analysLevel=2;
    }
    // Activate Default PID for proton rejection (TEMPORARY)
    // cloose->SetUseDefaultPID(kTRUE);
    // ctight->SetUseDefaultPID(kTRUE);
  }

  if(readmc>0)hfTask->SetReadMC(kTRUE);
  if(readmc==2){
    hfTask->SetRejecCandidateMCUpgrade(kTRUE);
    hfTask->SetSkipEventSelection(kTRUE);
    hfTask->SetMaxZvtxForSkipEventSelection(10.);
  }

  hfTask->SetNMaxTrForVtx(2);
  hfTask->SetAnalyzeLikeSign(likesign);
  hfTask->SetUsePID(usepid);
  hfTask->SetStandardMassSelection();
  hfTask->SetAnalysisLevel(analysLevel);
  hfTask->SetFillImpParTree(fillTree);

  hfTask->SetCheckBitD0flag(checkBitD0);
  if(readmc&&useWeight)hfTask->SetPtWeightsFromDataPbPb276overLHC12a17a();
  // hfTask->SignalInvMassCut(0.27);

  /*  ############### HERE THE POSSIBILITY TO SWITCH ON/OFF THE TLISTS AND MC SELECTION WILL BE SET #########à

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

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

  //Now container for general properties histograms
  containername="outputNentries";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputNentries = mgr->CreateContainer(containername.Data(),TH1F::Class(),
								   AliAnalysisManager::kOutputContainer,
								   fileout.Data());

  mgr->ConnectOutput(hfTask,1,coutputNentries);

  containername="outputSignalType";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSignalType = mgr->CreateContainer(containername.Data(),TH1F::Class(),
								     AliAnalysisManager::kOutputContainer,
								     fileout.Data());

  mgr->ConnectOutput(hfTask,2,coutputSignalType);

  containername="outputSignalType_LsCuts";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSignalType_LsCuts = mgr->CreateContainer(containername.Data(),TH1F::Class(),
									    AliAnalysisManager::kOutputContainer,
									    fileout.Data());

  mgr->ConnectOutput(hfTask,3,coutputSignalType_LsCuts);

  containername="outputSignalType_TghCuts";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputSignalType_TghCuts = mgr->CreateContainer(containername.Data(),TH1F::Class(),
									     AliAnalysisManager::kOutputContainer,
									     fileout.Data());

  mgr->ConnectOutput(hfTask,4,coutputSignalType_TghCuts);

  containername="outputNormalizationCounter";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *coutputNormCounter = mgr ->CreateContainer(containername.Data(), AliNormalizationCounter::Class(),
								       AliAnalysisManager::kOutputContainer,
								       fileout.Data());
  mgr->ConnectOutput(hfTask, 5, coutputNormCounter);

  //Now Container for MC TList
  containername="listMCproperties";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistMCprop = mgr->CreateContainer(containername.Data(),TList::Class(),
							       AliAnalysisManager::kOutputContainer,
							       fileout.Data());
  mgr->ConnectOutput(hfTask,6,clistMCprop);

  // Now container for TLists
  last=7;
  //##########  NO CUTS TLISTS CONTAINER ##############à
  containername="listNCsign";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCsign = mgr->CreateContainer(containername.Data(),TList::Class(),
							       AliAnalysisManager::kOutputContainer,
							       fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCsign);
  last++;

  containername="listNCback";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCback = mgr->CreateContainer(containername.Data(),TList::Class(),
							       AliAnalysisManager::kOutputContainer,
							       fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCback);
  last++;

  containername="listNCfromB";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCfromB = mgr->CreateContainer(containername.Data(),TList::Class(),
								AliAnalysisManager::kOutputContainer,
								fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCfromB);
  last++;

  containername="listNCfromDstar";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCfromDstar = mgr->CreateContainer(containername.Data(),TList::Class(),
								    AliAnalysisManager::kOutputContainer,
								    fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCfromDstar);
  last++;

  containername="listNCother";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistNCother = mgr->CreateContainer(containername.Data(),TList::Class(),
								AliAnalysisManager::kOutputContainer,
								fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistNCother);
  last++;

  //######### LOOSE CUTS TLISTS CONTAINER #############
  containername="listLSCsign";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCsign = mgr->CreateContainer(containername.Data(),TList::Class(),
								AliAnalysisManager::kOutputContainer,
								fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCsign);
  last++;

  containername="listLSCback";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCback = mgr->CreateContainer(containername.Data(),TList::Class(),
								AliAnalysisManager::kOutputContainer,
								fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCback);
  last++;

  containername="listLSCfromB";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCfromB = mgr->CreateContainer(containername.Data(),TList::Class(),
								 AliAnalysisManager::kOutputContainer,
								 fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCfromB);
  last++;

  containername="listLSCfromDstar";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCfromDstar = mgr->CreateContainer(containername.Data(),TList::Class(),
								     AliAnalysisManager::kOutputContainer,
								     fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCfromDstar);
  last++;

  containername="listLSCother";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistLSCother = mgr->CreateContainer(containername.Data(),TList::Class(),
								 AliAnalysisManager::kOutputContainer,
								 fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistLSCother);
  last++;

  //######### TIGHT CUTS TLISTS CONTAINER #############
  containername="listTGHCsign";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCsign = mgr->CreateContainer(containername.Data(),TList::Class(),
								 AliAnalysisManager::kOutputContainer,
								 fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCsign);
  last++;

  containername="listTGHCback";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCback = mgr->CreateContainer(containername.Data(),TList::Class(),
								 AliAnalysisManager::kOutputContainer,
								 fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCback);
  last++;

  containername="listTGHCfromB";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCfromB = mgr->CreateContainer(containername.Data(),TList::Class(),
								  AliAnalysisManager::kOutputContainer,
								  fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCfromB);
  last++;

  containername="listTGHCfromDstar";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCfromDstar = mgr->CreateContainer(containername.Data(),TList::Class(),
								      AliAnalysisManager::kOutputContainer,
								      fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCfromDstar);
  last++;

  containername="listTGHCother";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *clistTGHCother = mgr->CreateContainer(containername.Data(),TList::Class(),
								  AliAnalysisManager::kOutputContainer,
								  fileout.Data());
  mgr->ConnectOutput(hfTask,last,clistTGHCother);
  last++;

  // Container for Cuts Objects
  containername="cutsObjectTight";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *cCutsObjectTight = mgr->CreateContainer(containername,AliRDHFCutsD0toKpi::Class(),AliAnalysisManager::kOutputContainer,fileout.Data()); //cuts
  mgr->ConnectOutput(hfTask,last,cCutsObjectTight);
  last++;

  containername="cutsObjectLoose";
  containername.Prepend(containerprefix.Data());
  containername.Append(str.Data());
  AliAnalysisDataContainer *cCutsObjectLoose = mgr->CreateContainer(containername,AliRDHFCutsD0toKpi::Class(),AliAnalysisManager::kOutputContainer,fileout.Data()); //cuts
  mgr->ConnectOutput(hfTask,last,cCutsObjectLoose);

  return hfTask;
}
<|endoftext|>


<commit_before>/*

Copyright (c) 2014-2015, Arvid Norberg
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/

#include "libtorrent/config.hpp"
#include <cstring>

#include "libtorrent/aux_/cpuid.hpp"

#if defined _MSC_VER && TORRENT_HAS_SSE
#include <intrin.h>
#include <nmmintrin.h>
#endif

namespace libtorrent { namespace aux
{
	namespace {

	// internal
	void cpuid(unsigned int info[4], int type)
	{
#if TORRENT_HAS_SSE && defined _MSC_VER
		__cpuid((int*)info, type);

#elif TORRENT_HAS_SSE && defined __GNUC__
		asm volatile
			("cpuid" : "=a" (info[0]), "=b" (info[1]), "=c" (info[2]), "=d" (info[3])
			 : "a" (type), "c" (0));
#else
		// for non-x86 and non-amd64, just return zeroes
		std::memset(&info[0], 0, sizeof(unsigned int) * 4);
#endif
	}

	bool supports_sse42()
	{
#if TORRENT_HAS_SSE
		unsigned int cpui[4];
		cpuid(cpui, 1);
		return cpui[2] & (1 << 20);
#else
		return false;
#endif
	}

	bool supports_mmx()
	{
#if TORRENT_HAS_SSE
		unsigned int cpui[4];
		cpuid(cpui, 1);
		return cpui[2] & (1 << 23);
#else
		return false;
#endif
	}

	} // anonymous namespace

	bool sse42_support = supports_sse42();
	bool mmx_support = supports_mmx();
} }

<commit_msg>attempted fix for cpu_id issues on ubuntu<commit_after>/*

Copyright (c) 2014-2015, Arvid Norberg
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/

#include "libtorrent/config.hpp"
#include <cstring>

#include "libtorrent/aux_/cpuid.hpp"

#if defined _MSC_VER && TORRENT_HAS_SSE
#include <intrin.h>
#include <nmmintrin.h>
#endif

#if TORRENT_HAS_SSE && defined __GNUC__
#include <cpuid.h>
#endif

namespace libtorrent { namespace aux
{
	namespace {

	// internal
	void cpuid(unsigned int info[4], int type)
	{
#if TORRENT_HAS_SSE && defined _MSC_VER
		__cpuid((int*)info, type);

#elif TORRENT_HAS_SSE && defined __GNUC__
		__get_cpuid(type, &info[0], &info[1], &info[2], &info[3]);
#else
		// for non-x86 and non-amd64, just return zeroes
		std::memset(&info[0], 0, sizeof(unsigned int) * 4);
#endif
	}

	bool supports_sse42()
	{
#if TORRENT_HAS_SSE
		unsigned int cpui[4];
		cpuid(cpui, 1);
		return cpui[2] & (1 << 20);
#else
		return false;
#endif
	}

	bool supports_mmx()
	{
#if TORRENT_HAS_SSE
		unsigned int cpui[4];
		cpuid(cpui, 1);
		return cpui[2] & (1 << 23);
#else
		return false;
#endif
	}

	} // anonymous namespace

	bool sse42_support = supports_sse42();
	bool mmx_support = supports_mmx();
} }

<|endoftext|>