<commit_before>/*
    Copyright 2005-2007 Adobe Systems Incorporated
    Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
    or a copy at http://stlab.adobe.com/licenses.html)
*/

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

#include <GG/adobe/future/widgets/headers/platform_label.hpp>

#include <GG/adobe/future/widgets/headers/display.hpp>
#include <GG/adobe/future/widgets/headers/widget_utils.hpp>
#include <GG/adobe/future/widgets/headers/platform_metrics.hpp>
#include <GG/adobe/placeable_concept.hpp>

#include <string>
#include <cassert>

#include <GG/GUI.h>
#include <GG/StyleFactory.h>
#include <GG/TextControl.h>

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

namespace adobe {

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

label_t::label_t(const std::string& name,
                 const std::string& alt_text,
                 std::size_t        characters,
                 theme_t            theme) :
    window_m(0),
    theme_m(theme),
    name_m(name),
    alt_text_m(alt_text),
    characters_m(characters)
{ }

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

void place(label_t& value, const place_data_t& place_data)
{
    implementation::set_control_bounds(value.window_m, place_data);
    if (!value.alt_text_m.empty())
        implementation::set_control_alt_text(value.window_m, value.alt_text_m);
}

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

void measure(label_t& value, extents_t& result)
{
    assert(value.window_m);
    boost::shared_ptr<GG::StyleFactory> style = GG::GUI::GetGUI()->GetStyleFactory();
    GG::Pt size =
        style->DefaultFont()->TextExtent(value.name_m, value.window_m->GetTextFormat());
    result.horizontal().length_m = Value(size.x);
    assert(result.horizontal().length_m);
}

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

void measure_vertical(label_t& value, extents_t& calculated_horizontal,
                      const place_data_t& placed_horizontal)
{
    assert(value.window_m);
    boost::shared_ptr<GG::StyleFactory> style = GG::GUI::GetGUI()->GetStyleFactory();
    GG::Pt size =
        style->DefaultFont()->TextExtent(value.name_m, value.window_m->GetTextFormat(),
                                         GG::X(width(placed_horizontal)));
    calculated_horizontal.vertical().length_m = Value(size.y);
    calculated_horizontal.vertical().guide_set_m.push_back(
        Value(style->DefaultFont()->Ascent()));
}

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

void enable(label_t& value, bool make_enabled)
{ value.window_m->Disable(make_enabled); }

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

extents_t measure_text(const std::string& text, const boost::shared_ptr<GG::Font>& font)
{
    extents_t result;
    boost::shared_ptr<GG::StyleFactory> style = GG::GUI::GetGUI()->GetStyleFactory();
    GG::Pt size = font->TextExtent(text);
    result.horizontal().length_m = Value(size.x);
    result.vertical().length_m = Value(size.y);
    return result;
}

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

std::string get_control_string(const label_t& widget)
{ return widget.window_m->Text(); }

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

// REVISIT: MM--we need to replace the display_t mechanism with concepts/any_*/
//              container idiom for event and drawing system.

template <>
platform_display_type insert<label_t>(display_t& display,
                                      platform_display_type& parent,
                                      label_t& element)
{
    boost::shared_ptr<GG::StyleFactory> style = GG::GUI::GetGUI()->GetStyleFactory();
    element.window_m = style->NewTextControl(GG::X0, GG::Y0, GG::X(100), GG::Y(100),
                                             element.name_m, style->DefaultFont());

    if (!element.alt_text_m.empty())
        implementation::set_control_alt_text(element.window_m, element.alt_text_m);

    return display.insert(parent, get_display(element));
}

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

} // namespace adobe

/****************************************************************************************************/
<commit_msg>Corrected the size and default format (added FORMAT_WORDBREAK) of labels/static_texts the experimental Eve bindings.<commit_after>/*
    Copyright 2005-2007 Adobe Systems Incorporated
    Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
    or a copy at http://stlab.adobe.com/licenses.html)
*/

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

#include <GG/adobe/future/widgets/headers/platform_label.hpp>

#include <GG/adobe/future/widgets/headers/display.hpp>
#include <GG/adobe/future/widgets/headers/widget_utils.hpp>
#include <GG/adobe/future/widgets/headers/platform_metrics.hpp>
#include <GG/adobe/placeable_concept.hpp>

#include <string>
#include <cassert>

#include <GG/GUI.h>
#include <GG/StyleFactory.h>
#include <GG/TextControl.h>

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

namespace adobe {

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

label_t::label_t(const std::string& name,
                 const std::string& alt_text,
                 std::size_t        characters,
                 theme_t            theme) :
    window_m(0),
    theme_m(theme),
    name_m(name),
    alt_text_m(alt_text),
    characters_m(characters)
{ }

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

void place(label_t& value, const place_data_t& place_data)
{
    implementation::set_control_bounds(value.window_m, place_data);
    if (!value.alt_text_m.empty())
        implementation::set_control_alt_text(value.window_m, value.alt_text_m);
}

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

void measure(label_t& value, extents_t& result)
{
    assert(value.window_m);
    boost::shared_ptr<GG::StyleFactory> style = GG::GUI::GetGUI()->GetStyleFactory();
    GG::Pt size =
        style->DefaultFont()->TextExtent(value.characters_m ?
                                         std::string(value.characters_m, '0') :
                                         value.name_m,
                                         value.window_m->GetTextFormat());
    result.horizontal().length_m = Value(size.x);
    assert(result.horizontal().length_m);
}

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

void measure_vertical(label_t& value, extents_t& calculated_horizontal,
                      const place_data_t& placed_horizontal)
{
    assert(value.window_m);
    boost::shared_ptr<GG::StyleFactory> style = GG::GUI::GetGUI()->GetStyleFactory();
    GG::Pt size =
        style->DefaultFont()->TextExtent(value.name_m, value.window_m->GetTextFormat(),
                                         GG::X(width(placed_horizontal)));
    calculated_horizontal.vertical().length_m = Value(size.y);
    calculated_horizontal.vertical().guide_set_m.push_back(
        Value(style->DefaultFont()->Ascent()));
}

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

void enable(label_t& value, bool make_enabled)
{ value.window_m->Disable(make_enabled); }

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

extents_t measure_text(const std::string& text, const boost::shared_ptr<GG::Font>& font)
{
    extents_t result;
    boost::shared_ptr<GG::StyleFactory> style = GG::GUI::GetGUI()->GetStyleFactory();
    GG::Pt size = font->TextExtent(text);
    result.horizontal().length_m = Value(size.x);
    result.vertical().length_m = Value(size.y);
    return result;
}

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

std::string get_control_string(const label_t& widget)
{ return widget.window_m->Text(); }

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

// REVISIT: MM--we need to replace the display_t mechanism with concepts/any_*/
//              container idiom for event and drawing system.

template <>
platform_display_type insert<label_t>(display_t& display,
                                      platform_display_type& parent,
                                      label_t& element)
{
    boost::shared_ptr<GG::StyleFactory> style = GG::GUI::GetGUI()->GetStyleFactory();
    element.window_m = style->NewTextControl(GG::X0, GG::Y0, GG::X(100), GG::Y(100),
                                             element.name_m, style->DefaultFont(),
                                             GG::CLR_BLACK, GG::FORMAT_WORDBREAK);

    if (!element.alt_text_m.empty())
        implementation::set_control_alt_text(element.window_m, element.alt_text_m);

    return display.insert(parent, get_display(element));
}

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

} // namespace adobe

/****************************************************************************************************/
<|endoftext|>


<commit_before>#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#include <SDL_messagebox.h>

#include "Debug.h"

#include "String.h"

namespace
{
	const std::map<Debug::MessageType, std::string> DebugMessageTypeNames =
	{
		{ Debug::MessageType::Info, "" },
		{ Debug::MessageType::Warning, "Warning: " },
		{ Debug::MessageType::Error, "Error: " },
	};
}

const std::string Debug::LOG_FILENAME = "log.txt";

std::string Debug::getShorterPath(const char *__file__)
{
	// Replace back-slashes with forward slashes, then split.
	const std::string path = String::replace(std::string(__file__), '\\', '/');
	const std::vector<std::string> tokens = String::split(path, '/');

	std::string shortPath;

	if (tokens.size() >= 2)
	{
		shortPath = tokens.at(tokens.size() - 2) + '/' + tokens.back();
	}
	else if (tokens.size() == 1)
	{
		shortPath = tokens.front();
	}

	return shortPath;
}

void Debug::write(Debug::MessageType type, const std::string &filePath,
	int lineNumber, const std::string &message)
{
	const std::string &messageType = DebugMessageTypeNames.at(type);
	std::cerr << "[" << filePath << "(" << std::to_string(lineNumber) << ")] " <<
		messageType << message << "\n";
}

void Debug::mention(const char *__file__, int lineNumber, const std::string &message)
{
	Debug::write(Debug::MessageType::Info, Debug::getShorterPath(__file__),
		lineNumber, message);
}

void Debug::warning(const char *__file__, int lineNumber, const std::string &message)
{
	Debug::write(Debug::MessageType::Warning, Debug::getShorterPath(__file__),
		lineNumber, message);
}

void Debug::crash(const char *__file__, int lineNumber, const std::string &message)
{
	Debug::write(Debug::MessageType::Error, Debug::getShorterPath(__file__),
		lineNumber, message);
    const std::string platformName(SDL_GetPlatform());
    if (platformName == "Mac OS X") {
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", message.c_str(), NULL);
    } else {
        std::getchar();
    }
	exit(EXIT_FAILURE);
}

void Debug::check(bool condition, const char *__file__, int lineNumber,
	const std::string &message)
{
	if (!condition)
	{
		Debug::crash(__file__, lineNumber, message);
	}
}
<commit_msg>Changing NULL to nullptr<commit_after>#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#include <SDL_messagebox.h>

#include "Debug.h"

#include "String.h"

namespace
{
	const std::map<Debug::MessageType, std::string> DebugMessageTypeNames =
	{
		{ Debug::MessageType::Info, "" },
		{ Debug::MessageType::Warning, "Warning: " },
		{ Debug::MessageType::Error, "Error: " },
	};
}

const std::string Debug::LOG_FILENAME = "log.txt";

std::string Debug::getShorterPath(const char *__file__)
{
	// Replace back-slashes with forward slashes, then split.
	const std::string path = String::replace(std::string(__file__), '\\', '/');
	const std::vector<std::string> tokens = String::split(path, '/');

	std::string shortPath;

	if (tokens.size() >= 2)
	{
		shortPath = tokens.at(tokens.size() - 2) + '/' + tokens.back();
	}
	else if (tokens.size() == 1)
	{
		shortPath = tokens.front();
	}

	return shortPath;
}

void Debug::write(Debug::MessageType type, const std::string &filePath,
	int lineNumber, const std::string &message)
{
	const std::string &messageType = DebugMessageTypeNames.at(type);
	std::cerr << "[" << filePath << "(" << std::to_string(lineNumber) << ")] " <<
		messageType << message << "\n";
}

void Debug::mention(const char *__file__, int lineNumber, const std::string &message)
{
	Debug::write(Debug::MessageType::Info, Debug::getShorterPath(__file__),
		lineNumber, message);
}

void Debug::warning(const char *__file__, int lineNumber, const std::string &message)
{
	Debug::write(Debug::MessageType::Warning, Debug::getShorterPath(__file__),
		lineNumber, message);
}

void Debug::crash(const char *__file__, int lineNumber, const std::string &message)
{
	Debug::write(Debug::MessageType::Error, Debug::getShorterPath(__file__),
		lineNumber, message);
    const std::string platformName(SDL_GetPlatform());
    if (platformName == "Mac OS X") {
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", message.c_str(), nullptr);
    } else {
        std::getchar();
    }
	exit(EXIT_FAILURE);
}

void Debug::check(bool condition, const char *__file__, int lineNumber,
	const std::string &message)
{
	if (!condition)
	{
		Debug::crash(__file__, lineNumber, message);
	}
}
<|endoftext|>


<commit_before>/*
   Source File : PrimitiveObjectsWriter.cpp

   Copyright 2011 Gal Kahana PDFWriter

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

*/
#include "PrimitiveObjectsWriter.h"
#include "SafeBufferMacrosDefs.h"
#include "IByteWriter.h"

using namespace IOBasicTypes;

PrimitiveObjectsWriter::PrimitiveObjectsWriter(IByteWriter* inStreamForWriting)
{
	mStreamForWriting = inStreamForWriting;
}

PrimitiveObjectsWriter::~PrimitiveObjectsWriter(void)
{
}

static const IOBasicTypes::Byte scSpace[] = {' '};
void PrimitiveObjectsWriter::WriteTokenSeparator(ETokenSeparator inSeparate)
{
	if(eTokenSeparatorSpace == inSeparate)
		mStreamForWriting->Write(scSpace,1);
	else if(eTokenSeparatorEndLine == inSeparate)
		EndLine();
}

static const IOBasicTypes::Byte scNewLine[2] = {'\r','\n'};
void PrimitiveObjectsWriter::EndLine()
{
	mStreamForWriting->Write(scNewLine,2);
}

void PrimitiveObjectsWriter::WriteKeyword(const std::string& inKeyword)
{
	mStreamForWriting->Write((const IOBasicTypes::Byte *)inKeyword.c_str(),inKeyword.size());
	EndLine();
}

static const IOBasicTypes::Byte scSlash[1] = {'/'};
void PrimitiveObjectsWriter::WriteName(const std::string& inName,ETokenSeparator inSeparate)
{
/*
from the pdf reference:
This syntax is required to represent any of the delimiter or white-space characters or the number sign character itself;
it is recommended but not required for characters whose codes are outside the range 33 (!) to 126 (~).
*/

	mStreamForWriting->Write(scSlash,1);

	IOBasicTypes::Byte buffer[5];
	std::string::const_iterator it = inName.begin();
	for(;it != inName.end();++it)
	{
		Byte aValue = *it;

		if(aValue < 33 || aValue > 126)
		{
			SAFE_SPRINTF_1((char*)buffer,5,"#%02x",aValue);
			mStreamForWriting->Write(buffer,strlen((char*)buffer));
		}
		else
		{
			buffer[0] = aValue;
			mStreamForWriting->Write(buffer,1);
		}
	}

	WriteTokenSeparator(inSeparate);
}

void PrimitiveObjectsWriter::WriteInteger(long long inIntegerToken,ETokenSeparator inSeparate)
{
	char buffer[512];

	SAFE_SPRINTF_1(buffer,512,"%lld",inIntegerToken);
	mStreamForWriting->Write((const IOBasicTypes::Byte *)buffer,strlen(buffer));
	WriteTokenSeparator(inSeparate);
}

static const IOBasicTypes::Byte scLeftParanthesis[1] = {'('};
static const IOBasicTypes::Byte scRightParanthesis[1] = {')'};

void PrimitiveObjectsWriter::WriteUnsafeLiteralString(const std::string& inString,ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scLeftParanthesis,1);
	mStreamForWriting->Write((const IOBasicTypes::Byte *)inString.c_str(),inString.size());
	mStreamForWriting->Write(scRightParanthesis,1);
	WriteTokenSeparator(inSeparate);
}

void PrimitiveObjectsWriter::WriteLiteralString(const std::string& inString,ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scLeftParanthesis,1);
	// doing some string conversion, so that charachters are written as safe ones.
	IOBasicTypes::Byte buffer[5];
	std::string::const_iterator it = inString.begin();
	for(;it != inString.end();++it)
	{
		Byte aValue = *it;
		if(aValue == '(' || aValue == ')' || aValue == '\\')
		{
			buffer[0] = '\\';
			buffer[1] = aValue;
			mStreamForWriting->Write(buffer,2);
		}
		else if (aValue < 32 || aValue > 126) // grabbing all nonprintable chars
		{
			SAFE_SPRINTF_1((char*)buffer,5,"\\%03o",aValue);
			mStreamForWriting->Write(buffer,4);
		}
		else
		{
			buffer[0] = aValue;
			mStreamForWriting->Write(buffer,1);
		}

	}
	mStreamForWriting->Write(scRightParanthesis,1);
	WriteTokenSeparator(inSeparate);
}

void PrimitiveObjectsWriter::WriteDouble(double inDoubleToken,ETokenSeparator inSeparate)
{
	char buffer[512];

	SAFE_SPRINTF_1(buffer,512,"%lf",inDoubleToken);

	LongBufferSizeType sizeToWrite = DetermineDoubleTrimmedLength(buffer);

	mStreamForWriting->Write((const IOBasicTypes::Byte *)buffer,sizeToWrite);
	WriteTokenSeparator(inSeparate);
}

size_t PrimitiveObjectsWriter::DetermineDoubleTrimmedLength(const char* inBufferWithDouble)
{
	size_t result = strlen(inBufferWithDouble);

	// remove all ending 0's
	while(result > 0 && inBufferWithDouble[result-1] == '0')
		--result;

	// if it's actually an integer, remove also decimal point
	if(result > 0 && inBufferWithDouble[result-1] == '.')
		--result;
	return result;
}

static const IOBasicTypes::Byte scTrue[4] = {'t','r','u','e'};
static const IOBasicTypes::Byte scFalse[5] = {'f','a','l','s','e'};

void PrimitiveObjectsWriter::WriteBoolean(bool inBoolean,ETokenSeparator inSeparate)
{
	if(inBoolean)
		mStreamForWriting->Write(scTrue,4);
	else
		mStreamForWriting->Write(scFalse,5);
	WriteTokenSeparator(inSeparate);
}

static const IOBasicTypes::Byte scNull[4] = {'n','u','l','l'};
void PrimitiveObjectsWriter::WriteNull(ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scNull,4);
	WriteTokenSeparator(inSeparate);
}

void PrimitiveObjectsWriter::SetStreamForWriting(IByteWriter* inStreamForWriting)
{
	mStreamForWriting = inStreamForWriting;
}

static const IOBasicTypes::Byte scOpenBracketSpace[2] = {'[',' '};
void PrimitiveObjectsWriter::StartArray()
{
	mStreamForWriting->Write(scOpenBracketSpace,2);
}

static const IOBasicTypes::Byte scCloseBracket[1] = {']'};
void PrimitiveObjectsWriter::EndArray(ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scCloseBracket,1);
	WriteTokenSeparator(inSeparate);
}

static const IOBasicTypes::Byte scLeftAngle[1] = {'<'};
static const IOBasicTypes::Byte scRightAngle[1] = {'>'};
void PrimitiveObjectsWriter::WriteHexString(const std::string& inString,ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scLeftAngle,1);
	mStreamForWriting->Write((const IOBasicTypes::Byte *)inString.c_str(),inString.size());
	mStreamForWriting->Write(scRightAngle,1);
	WriteTokenSeparator(inSeparate);
}

IByteWriter* PrimitiveObjectsWriter::GetWritingStream()
{
    return mStreamForWriting;
}<commit_msg>Update PrimitiveObjectsWriter.cpp<commit_after>/*
   Source File : PrimitiveObjectsWriter.cpp

   Copyright 2011 Gal Kahana PDFWriter

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

*/
#include "PrimitiveObjectsWriter.h"
#include "SafeBufferMacrosDefs.h"
#include "IByteWriter.h"

using namespace IOBasicTypes;

PrimitiveObjectsWriter::PrimitiveObjectsWriter(IByteWriter* inStreamForWriting)
{
	mStreamForWriting = inStreamForWriting;
}

PrimitiveObjectsWriter::~PrimitiveObjectsWriter(void)
{
}

static const IOBasicTypes::Byte scSpace[] = {' '};
void PrimitiveObjectsWriter::WriteTokenSeparator(ETokenSeparator inSeparate)
{
	if(eTokenSeparatorSpace == inSeparate)
		mStreamForWriting->Write(scSpace,1);
	else if(eTokenSeparatorEndLine == inSeparate)
		EndLine();
}

static const IOBasicTypes::Byte scNewLine[2] = {'\r','\n'};
void PrimitiveObjectsWriter::EndLine()
{
	mStreamForWriting->Write(scNewLine,2);
}

void PrimitiveObjectsWriter::WriteKeyword(const std::string& inKeyword)
{
	mStreamForWriting->Write((const IOBasicTypes::Byte *)inKeyword.c_str(),inKeyword.size());
	EndLine();
}

static const IOBasicTypes::Byte scSlash[1] = {'/'};
static const std::string scSpecialChars("()<>[]{}/%#");
void PrimitiveObjectsWriter::WriteName(const std::string& inName,ETokenSeparator inSeparate)
{
/*
from the pdf reference:
This syntax is required to represent any of the delimiter or white-space characters or the number sign character itself;
it is recommended but not required for characters whose codes are outside the range 33 (!) to 126 (~).
*/

	mStreamForWriting->Write(scSlash,1);

	IOBasicTypes::Byte buffer[5];
	std::string::const_iterator it = inName.begin();
	for(;it != inName.end();++it)
	{
		Byte aValue = *it;

		if(aValue < 33 || aValue > 126 || scSpecialChars.find(aValue) != scSpecialChars.npos)
		{
			SAFE_SPRINTF_1((char*)buffer,5,"#%02x",aValue);
			mStreamForWriting->Write(buffer,strlen((char*)buffer));
		}
		else
		{
			buffer[0] = aValue;
			mStreamForWriting->Write(buffer,1);
		}
	}

	WriteTokenSeparator(inSeparate);
}

void PrimitiveObjectsWriter::WriteInteger(long long inIntegerToken,ETokenSeparator inSeparate)
{
	char buffer[512];

	SAFE_SPRINTF_1(buffer,512,"%lld",inIntegerToken);
	mStreamForWriting->Write((const IOBasicTypes::Byte *)buffer,strlen(buffer));
	WriteTokenSeparator(inSeparate);
}

static const IOBasicTypes::Byte scLeftParanthesis[1] = {'('};
static const IOBasicTypes::Byte scRightParanthesis[1] = {')'};

void PrimitiveObjectsWriter::WriteUnsafeLiteralString(const std::string& inString,ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scLeftParanthesis,1);
	mStreamForWriting->Write((const IOBasicTypes::Byte *)inString.c_str(),inString.size());
	mStreamForWriting->Write(scRightParanthesis,1);
	WriteTokenSeparator(inSeparate);
}

void PrimitiveObjectsWriter::WriteLiteralString(const std::string& inString,ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scLeftParanthesis,1);
	// doing some string conversion, so that charachters are written as safe ones.
	IOBasicTypes::Byte buffer[5];
	std::string::const_iterator it = inString.begin();
	for(;it != inString.end();++it)
	{
		Byte aValue = *it;
		if(aValue == '(' || aValue == ')' || aValue == '\\')
		{
			buffer[0] = '\\';
			buffer[1] = aValue;
			mStreamForWriting->Write(buffer,2);
		}
		else if (aValue < 32 || aValue > 126) // grabbing all nonprintable chars
		{
			SAFE_SPRINTF_1((char*)buffer,5,"\\%03o",aValue);
			mStreamForWriting->Write(buffer,4);
		}
		else
		{
			buffer[0] = aValue;
			mStreamForWriting->Write(buffer,1);
		}

	}
	mStreamForWriting->Write(scRightParanthesis,1);
	WriteTokenSeparator(inSeparate);
}

void PrimitiveObjectsWriter::WriteDouble(double inDoubleToken,ETokenSeparator inSeparate)
{
	char buffer[512];

	SAFE_SPRINTF_1(buffer,512,"%lf",inDoubleToken);

	LongBufferSizeType sizeToWrite = DetermineDoubleTrimmedLength(buffer);

	mStreamForWriting->Write((const IOBasicTypes::Byte *)buffer,sizeToWrite);
	WriteTokenSeparator(inSeparate);
}

size_t PrimitiveObjectsWriter::DetermineDoubleTrimmedLength(const char* inBufferWithDouble)
{
	size_t result = strlen(inBufferWithDouble);

	// remove all ending 0's
	while(result > 0 && inBufferWithDouble[result-1] == '0')
		--result;

	// if it's actually an integer, remove also decimal point
	if(result > 0 && inBufferWithDouble[result-1] == '.')
		--result;
	return result;
}

static const IOBasicTypes::Byte scTrue[4] = {'t','r','u','e'};
static const IOBasicTypes::Byte scFalse[5] = {'f','a','l','s','e'};

void PrimitiveObjectsWriter::WriteBoolean(bool inBoolean,ETokenSeparator inSeparate)
{
	if(inBoolean)
		mStreamForWriting->Write(scTrue,4);
	else
		mStreamForWriting->Write(scFalse,5);
	WriteTokenSeparator(inSeparate);
}

static const IOBasicTypes::Byte scNull[4] = {'n','u','l','l'};
void PrimitiveObjectsWriter::WriteNull(ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scNull,4);
	WriteTokenSeparator(inSeparate);
}

void PrimitiveObjectsWriter::SetStreamForWriting(IByteWriter* inStreamForWriting)
{
	mStreamForWriting = inStreamForWriting;
}

static const IOBasicTypes::Byte scOpenBracketSpace[2] = {'[',' '};
void PrimitiveObjectsWriter::StartArray()
{
	mStreamForWriting->Write(scOpenBracketSpace,2);
}

static const IOBasicTypes::Byte scCloseBracket[1] = {']'};
void PrimitiveObjectsWriter::EndArray(ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scCloseBracket,1);
	WriteTokenSeparator(inSeparate);
}

static const IOBasicTypes::Byte scLeftAngle[1] = {'<'};
static const IOBasicTypes::Byte scRightAngle[1] = {'>'};
void PrimitiveObjectsWriter::WriteHexString(const std::string& inString,ETokenSeparator inSeparate)
{
	mStreamForWriting->Write(scLeftAngle,1);
	mStreamForWriting->Write((const IOBasicTypes::Byte *)inString.c_str(),inString.size());
	mStreamForWriting->Write(scRightAngle,1);
	WriteTokenSeparator(inSeparate);
}

IByteWriter* PrimitiveObjectsWriter::GetWritingStream()
{
    return mStreamForWriting;
}
<|endoftext|>


<commit_before>AliAnalysisVertexingHF* ConfigVertexingHF() {

  printf("Call to AliAnalysisVertexingHF parameters setting :\n");
  vHF = new AliAnalysisVertexingHF();

  //--- switch-off candidates finding (default: all on)
  //vHF->SetD0toKpiOff();
  //vHF->SetJPSItoEleOff();
  //vHF->Set3ProngOff();
  vHF->SetLikeSignOn(); // like-sign pairs and triplets
  //vHF->Set4ProngOff();
  //vHF->SetDstarOff();
  vHF->SetFindVertexForDstar(kFALSE);
  //--- secondary vertex with KF?
  //vHF->SetSecVtxWithKF();

  //--- set cuts for single-track selection
  AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts","default");
  esdTrackCuts->SetRequireITSRefit(kTRUE);
  esdTrackCuts->SetMinNClustersITS(5);
  esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,
					 AliESDtrackCuts::kBoth);
  esdTrackCuts->SetMinDCAToVertexXY(0.);
  esdTrackCuts->SetPtRange(0.3,1.e10);
  AliAnalysisFilter *trkFilter = new AliAnalysisFilter("trackFilter");
  trkFilter->AddCuts(esdTrackCuts);
  vHF->SetTrackFilter(trkFilter);
  AliESDtrackCuts *esdTrackCutsSoftPi = new AliESDtrackCuts("AliESDtrackCuts","default");
  esdTrackCutsSoftPi->SetRequireITSRefit(kTRUE);
  AliAnalysisFilter *trkFilterSoftPi = new AliAnalysisFilter("trackFilterSoftPi");
  trkFilterSoftPi->AddCuts(esdTrackCutsSoftPi);
  vHF->SetTrackFilterSoftPi(trkFilterSoftPi);
  //--- set cuts for candidates selection
  vHF->SetD0toKpiCuts(0.3,999999.,1.1,0.,0.,999999.,999999.,999999.,0.);
  vHF->SetBtoJPSICuts(0.350);
  vHF->SetDplusCuts(0.2,0.4,0.4,0.,0.,0.01,0.06,0.02,0.,0.85);
  vHF->SetDsCuts(0.2,0.4,0.4,0.,0.,0.005,0.06,0.,0.,0.85,0.,0.1,0.1);
  vHF->SetLcCuts(0.2,0.4,0.4,0.,0.,0.01,0.06,0.,0.,0.85);
  vHF->SetD0to4ProngsCuts(0.2,0.04,0.00,0.01,0.02,0.8,0.,0.1,0.);
  vHF->SetDstarCuts(0.3, 0.1, 0.05, 100000000000.0, 0.5);
  vHF->SetD0fromDstarCuts(0.3,999999.,1.1,0.,0.,999999.,999999.,999999.,0.);
  //--- set this if you want to reconstruct primary vertex candidate by
  //    candidate using other tracks in the event (for pp, broad
  //    interaction region)
  //vHF->SetRecoPrimVtxSkippingTrks();
  //--- OR set this if you want to remove the candidate daughters from
  //    the primary vertex, without recostructing it from scratch
  //vHF->SetRmTrksFromPrimVtx();

  //--- check the settings
  vHF->PrintStatus();
  //--- verbose
  //AliLog::SetClassDebugLevel("AliAnalysisVertexingHF",2);

  return vHF;
}

<commit_msg>Added kTPCrefit and nTPCcls>50 requirements for displaced tracks; remove kITSrefit for soft-pi (just nITScls>=4)<commit_after>AliAnalysisVertexingHF* ConfigVertexingHF() {

  printf("Call to AliAnalysisVertexingHF parameters setting :\n");
  vHF = new AliAnalysisVertexingHF();

  //--- switch-off candidates finding (default: all on)
  //vHF->SetD0toKpiOff();
  //vHF->SetJPSItoEleOff();
  //vHF->Set3ProngOff();
  vHF->SetLikeSignOn(); // like-sign pairs and triplets
  //vHF->Set4ProngOff();
  //vHF->SetDstarOff();
  vHF->SetFindVertexForDstar(kFALSE);
  //--- secondary vertex with KF?
  //vHF->SetSecVtxWithKF();

  //--- set cuts for single-track selection
  //     displaced tracks
  AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts","default");
  esdTrackCuts->SetRequireTPCRefit(kTRUE);
  esdTrackCuts->SetMinNClustersTPC(50);
  esdTrackCuts->SetRequireITSRefit(kTRUE);
  esdTrackCuts->SetMinNClustersITS(5);
  esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,
					 AliESDtrackCuts::kBoth);
  esdTrackCuts->SetMinDCAToVertexXY(0.);
  esdTrackCuts->SetPtRange(0.3,1.e10);
  AliAnalysisFilter *trkFilter = new AliAnalysisFilter("trackFilter");
  trkFilter->AddCuts(esdTrackCuts);
  vHF->SetTrackFilter(trkFilter);
  //     D* soft pion tracks
  AliESDtrackCuts *esdTrackCutsSoftPi = new AliESDtrackCuts("AliESDtrackCuts","default");
  esdTrackCutsSoftPi->SetMinNClustersITS(4);
  AliAnalysisFilter *trkFilterSoftPi = new AliAnalysisFilter("trackFilterSoftPi");
  trkFilterSoftPi->AddCuts(esdTrackCutsSoftPi);
  vHF->SetTrackFilterSoftPi(trkFilterSoftPi);
  //--- set cuts for candidates selection
  vHF->SetD0toKpiCuts(0.3,999999.,1.1,0.,0.,999999.,999999.,999999.,0.);
  vHF->SetBtoJPSICuts(0.350);
  vHF->SetDplusCuts(0.2,0.4,0.4,0.,0.,0.01,0.06,0.02,0.,0.85);
  vHF->SetDsCuts(0.2,0.4,0.4,0.,0.,0.005,0.06,0.,0.,0.85,0.,0.1,0.1);
  vHF->SetLcCuts(0.2,0.4,0.4,0.,0.,0.01,0.06,0.,0.,0.85);
  vHF->SetD0to4ProngsCuts(0.2,0.04,0.00,0.01,0.02,0.8,0.,0.1,0.);
  vHF->SetDstarCuts(0.3, 0.1, 0.05, 100000000000.0, 0.5);
  vHF->SetD0fromDstarCuts(0.3,999999.,1.1,0.,0.,999999.,999999.,999999.,0.);
  //--- set this if you want to reconstruct primary vertex candidate by
  //    candidate using other tracks in the event (for pp, broad
  //    interaction region)
  //vHF->SetRecoPrimVtxSkippingTrks();
  //--- OR set this if you want to remove the candidate daughters from
  //    the primary vertex, without recostructing it from scratch
  //vHF->SetRmTrksFromPrimVtx();

  //--- check the settings
  vHF->PrintStatus();
  //--- verbose
  //AliLog::SetClassDebugLevel("AliAnalysisVertexingHF",2);

  return vHF;
}

<|endoftext|>


<commit_before>TChain *MakeAODInputChain(const char* collectionfileAOD,
			  const char* collectionfileAODfriend,Int_t nfiles=-1) {
  //
  // Check one-to-one correspondence of the two collections
  // Create AOD chain with friend AODVertexingHF chain
  // Origin: A.Rossi, andrea.rossi@ts.infn.it
  //

  TAlienCollection *collectionAOD       = TAlienCollection::Open(collectionfileAOD);
  TGridResult *tagResultAOD = collectionAOD->GetGridResult("",0,0);
  TChain *chainAOD = new TChain("aodTree");
  TChain *chainAODfriend = new TChain("aodTree");
  Int_t nmaxentr;
  if(collectionfileAODfriend!="none"){
    TAlienCollection *collectionAODfriend = TAlienCollection::Open(collectionfileAODfriend);
    TGridResult *tagResultAODFriend = collectionAODfriend->GetGridResult("",0,0);
    //  tagResultAOD->Print();
    TMap *mappa;
    TObjString *filename;
    Int_t event,dir,pos;
    string str;
    Int_t lastAOD[1000],lastAODFriend[1000];
    TArrayI ***arrAOD=new TArrayI**[1000];
    TArrayI ***arrAODFriend=new TArrayI**[1000];

    for(Int_t j=0;j<1000;j++) {
      arrAOD[j]=new TArrayI*[2];
      arrAOD[j][0]=new TArrayI(100);
      arrAOD[j][0]->Reset(0);
      arrAOD[j][1]=new TArrayI(100);
      arrAOD[j][1]->Reset(-1);

      arrAODFriend[j]=new TArrayI*[2];
      arrAODFriend[j][0]=new TArrayI(100);
      arrAODFriend[j][0]->Reset(0);
      arrAODFriend[j][1]=new TArrayI(100);
      arrAODFriend[j][1]->Reset(-1);

      lastAOD[j]=0;
      lastAODFriend[j]=0;
    }

    nmaxentr=tagResultAOD->GetEntries();
    if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;

    for(Int_t j=0;j<tagResultAOD->GetEntries();j++) {
      mappa=(TMap*)tagResultAOD->At(j);
      filename=(TObjString*)mappa->GetValue("turl");
      str=filename->GetString();
      pos=str.find_last_of("/");
      str.string::replace(pos,50,"");
      pos=str.find_last_of("/");
      str.string::replace(pos,1," ");
      sscanf(str.data(),"%*s %d",&event);
      pos=str.find_last_of("/");
      str.string::replace(pos,1," ");
      sscanf(str.data(),"%*s %d",&dir);
      arrAOD[event][0]->AddAt(dir,lastAOD[event]);
      arrAOD[event][1]->AddAt(j,lastAOD[event]);
      // printf("Adding AOD, event:%d,dir:%d,position:%d\n",event,dir,j);
      lastAOD[event]++;
    }

    for(Int_t j=0;j<tagResultAODFriend->GetEntries();j++) {
      mappa=(TMap*)tagResultAODFriend->At(j);
      filename=(TObjString*)mappa->GetValue("turl");
      str=filename->GetString();
      pos=str.find_last_of("/");
      str.string::replace(pos,50,"");
      pos=str.find_last_of("/");
      str.string::replace(pos,1," ");
      sscanf(str.data(),"%*s %d",&event);
      pos=str.find_last_of("/");
      str.string::replace(pos,1," ");
      sscanf(str.data(),"%*s %d",&dir);
      arrAODFriend[event][0]->AddAt(dir,lastAODFriend[event]);
      arrAODFriend[event][1]->AddAt(j,lastAODFriend[event]);
      //printf("Adding AODFriend, event:%d,dir:%d,position:%d\n",event,dir,j);
      lastAODFriend[event]++;
    }

    for(Int_t ev=0;ev<1000;ev++) {
      for(Int_t j=0;j<lastAOD[ev];j++) {
	dir= arrAOD[ev][0]->At(j);
	for(Int_t k=0;k<lastAODFriend[ev];k++) {
	  if(arrAODFriend[ev][0]->At(k)==dir){
	    chainAOD->Add((((TObjString*)((TMap*)tagResultAOD->At(arrAOD[ev][1]->At(j)))->GetValue("turl"))->GetString()).Data());
	    chainAODfriend->Add((((TObjString*)((TMap*)tagResultAODFriend->At(arrAODFriend[ev][1]->At(k)))->GetValue("turl"))->GetString()).Data());
	    printf("Events: %d, adding AOD at position %d,dir:%d posarray:%d \n and Friend at %d, dir:%d , posarray: %d \n \n",ev,arrAOD[ev][1]->At(j),arrAOD[ev][0]->At(j),j,arrAODFriend[ev][1]->At(k),arrAODFriend[ev][0]->At(k),k);
	    break;
	  }
	}
      }
    }
  }
  else {
    nmaxentr=tagResultAOD->GetEntries();
    if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;
    TString aodlfn,vertexlfn;
    for(Int_t ifile=0; ifile<nmaxentr; ifile++) {
      aodlfn=tagResultAOD->GetKey(ifile,"lfn");
      vertexlfn=aodlfn;
      vertexlfn.ReplaceAll("AliAOD.root","");
      TGridResult *r=gGrid->Query(vertexlfn.Data(),"AliAOD.VertexingHF.root");
      if(r->GetEntries()!=1)continue;
      printf("Adding file : %s \n",tagResultAOD->GetKey(ifile,"turl"));
      chainAOD->Add(tagResultAOD->GetKey(ifile,"turl"));
      printf("Adding friend file : %s \n \n",r->GetKey(0,"turl"));
      chainAODfriend->Add(r->GetKey(0,"turl"));
    }
  }

  chainAOD->AddFriend(chainAODfriend);

  return chainAOD;
}
  //----------------------------------------------------------------------------
TChain *MakeAODInputChain(const char* pathname="",
			  Int_t firstdir=1,Int_t lastdir=-1) {
  //
  // Create AOD chain with friend AODVertexingHF chain
  // Example path: "alien:///alice/cern.ch/user/r/rbala/analysis/out_lhcw/290001/"
  // Origin: A.Rossi, andrea.rossi@ts.infn.it
  //

  TChain *chainAOD = new TChain("aodTree");
  TChain *chainAODfriend = new TChain("aodTree");

  if(firstdir==-1) {
    // require the path is an alien path (!!!but without alien::// or /alien/ ), use lastdir as the requested number of files
    TGridResult* resultAOD=gGrid->Query(pathname,"AliAOD.root","","");
    Int_t nfiles=resultAOD->GetEntries();
    TString aodlfn,vertexlfn;
    if(lastdir>nfiles)lastdir=nfiles;
    for(Int_t ifile=0; ifile<nfiles; ifile++) {
      aodlfn=resultAOD->GetKey(ifile,"lfn");
      vertexlfn=aodlfn;
      vertexlfn.ReplaceAll("AliAOD.root","");
      TGridResult *r=gGrid->Query(vertexlfn.Data(),"AliAOD.VertexingHF.root");
      if(r->GetEntries()!=1)continue;
      chainAOD->Add(resultAOD->GetKey(ifile,"turl"));
      chainAODfriend->Add(r->GetKey(0,"turl"));
    }
  }
  else{
    if(lastdir==-1) { // only one pair of files
      chainAOD->Add("AliAOD.root");
      chainAODfriend->Add("AliAOD.VertexingHF.root");
    } else {

      // set the path to the files (can be local or on alien)
      for(Int_t idir=firstdir; idir<=lastdir; idir++) {
	TString aodname=pathname;
	TString aodHFname=pathname;
	aodname+=idir;
	aodHFname+=idir;
	aodname.Append("/AliAOD.root");
	aodHFname.Append("/AliAOD.VertexingHF.root");
	chainAOD->Add(aodname.Data());
	chainAODfriend->Add(aodHFname.Data());
      }
    }
  }

  chainAOD->AddFriend(chainAODfriend);

  return chainAOD;
}
<commit_msg>Added methods to stage a dataset on CAF (Andrea R, Andrea D)<commit_after>TChain *MakeAODInputChain(const char* collectionfileAOD,
			  const char* collectionfileAODfriend,Int_t nfiles=-1) {
  //
  // Check one-to-one correspondence of the two collections
  // Create AOD chain with friend AODVertexingHF chain
  // Origin: A.Rossi, andrea.rossi@ts.infn.it
  //

  TAlienCollection *collectionAOD       = TAlienCollection::Open(collectionfileAOD);
  TGridResult *tagResultAOD = collectionAOD->GetGridResult("",0,0);
  TChain *chainAOD = new TChain("aodTree");
  TChain *chainAODfriend = new TChain("aodTree");
  Int_t nmaxentr;
  if(collectionfileAODfriend!="none"){
    TAlienCollection *collectionAODfriend = TAlienCollection::Open(collectionfileAODfriend);
    TGridResult *tagResultAODFriend = collectionAODfriend->GetGridResult("",0,0);
    //  tagResultAOD->Print();
    TMap *mappa;
    TObjString *filename;
    Int_t event,dir,pos;
    string str;
    Int_t lastAOD[1000],lastAODFriend[1000];
    TArrayI ***arrAOD=new TArrayI**[1000];
    TArrayI ***arrAODFriend=new TArrayI**[1000];

    for(Int_t j=0;j<1000;j++) {
      arrAOD[j]=new TArrayI*[2];
      arrAOD[j][0]=new TArrayI(100);
      arrAOD[j][0]->Reset(0);
      arrAOD[j][1]=new TArrayI(100);
      arrAOD[j][1]->Reset(-1);

      arrAODFriend[j]=new TArrayI*[2];
      arrAODFriend[j][0]=new TArrayI(100);
      arrAODFriend[j][0]->Reset(0);
      arrAODFriend[j][1]=new TArrayI(100);
      arrAODFriend[j][1]->Reset(-1);

      lastAOD[j]=0;
      lastAODFriend[j]=0;
    }

    nmaxentr=tagResultAOD->GetEntries();
    if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;

    for(Int_t j=0;j<tagResultAOD->GetEntries();j++) {
      mappa=(TMap*)tagResultAOD->At(j);
      filename=(TObjString*)mappa->GetValue("turl");
      str=filename->GetString();
      pos=str.find_last_of("/");
      str.string::replace(pos,50,"");
      pos=str.find_last_of("/");
      str.string::replace(pos,1," ");
      sscanf(str.data(),"%*s %d",&event);
      pos=str.find_last_of("/");
      str.string::replace(pos,1," ");
      sscanf(str.data(),"%*s %d",&dir);
      arrAOD[event][0]->AddAt(dir,lastAOD[event]);
      arrAOD[event][1]->AddAt(j,lastAOD[event]);
      // printf("Adding AOD, event:%d,dir:%d,position:%d\n",event,dir,j);
      lastAOD[event]++;
    }

    for(Int_t j=0;j<tagResultAODFriend->GetEntries();j++) {
      mappa=(TMap*)tagResultAODFriend->At(j);
      filename=(TObjString*)mappa->GetValue("turl");
      str=filename->GetString();
      pos=str.find_last_of("/");
      str.string::replace(pos,50,"");
      pos=str.find_last_of("/");
      str.string::replace(pos,1," ");
      sscanf(str.data(),"%*s %d",&event);
      pos=str.find_last_of("/");
      str.string::replace(pos,1," ");
      sscanf(str.data(),"%*s %d",&dir);
      arrAODFriend[event][0]->AddAt(dir,lastAODFriend[event]);
      arrAODFriend[event][1]->AddAt(j,lastAODFriend[event]);
      //printf("Adding AODFriend, event:%d,dir:%d,position:%d\n",event,dir,j);
      lastAODFriend[event]++;
    }

    for(Int_t ev=0;ev<1000;ev++) {
      for(Int_t j=0;j<lastAOD[ev];j++) {
	dir= arrAOD[ev][0]->At(j);
	for(Int_t k=0;k<lastAODFriend[ev];k++) {
	  if(arrAODFriend[ev][0]->At(k)==dir){
	    chainAOD->Add((((TObjString*)((TMap*)tagResultAOD->At(arrAOD[ev][1]->At(j)))->GetValue("turl"))->GetString()).Data());
	    chainAODfriend->Add((((TObjString*)((TMap*)tagResultAODFriend->At(arrAODFriend[ev][1]->At(k)))->GetValue("turl"))->GetString()).Data());
	    printf("Events: %d, adding AOD at position %d,dir:%d posarray:%d \n and Friend at %d, dir:%d , posarray: %d \n \n",ev,arrAOD[ev][1]->At(j),arrAOD[ev][0]->At(j),j,arrAODFriend[ev][1]->At(k),arrAODFriend[ev][0]->At(k),k);
	    break;
	  }
	}
      }
    }
  }
  else {
    nmaxentr=tagResultAOD->GetEntries();
    if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;
    TString aodlfn,vertexlfn;
    for(Int_t ifile=0; ifile<nmaxentr; ifile++) {
      aodlfn=tagResultAOD->GetKey(ifile,"lfn");
      vertexlfn=aodlfn;
      vertexlfn.ReplaceAll("AliAOD.root","");
      TGridResult *r=gGrid->Query(vertexlfn.Data(),"AliAOD.VertexingHF.root");
      if(r->GetEntries()!=1)continue;
      printf("Adding file : %s \n",tagResultAOD->GetKey(ifile,"turl"));
      chainAOD->Add(tagResultAOD->GetKey(ifile,"turl"));
      printf("Adding friend file : %s \n \n",r->GetKey(0,"turl"));
      chainAODfriend->Add(r->GetKey(0,"turl"));
    }
  }

  chainAOD->AddFriend(chainAODfriend);

  return chainAOD;
}
  //----------------------------------------------------------------------------
TChain *MakeAODInputChain(const char* pathname="",
			  Int_t firstdir=1,Int_t lastdir=-1) {
  //
  // Create AOD chain with friend AODVertexingHF chain
  // Example path: "alien:///alice/cern.ch/user/r/rbala/analysis/out_lhcw/290001/"
  // Origin: A.Rossi, andrea.rossi@ts.infn.it
  //

  TChain *chainAOD = new TChain("aodTree");
  TChain *chainAODfriend = new TChain("aodTree");

  if(firstdir==-1) {
    // require the path is an alien path (!!!but without alien::// or /alien/ ), use lastdir as the requested number of files
    TGridResult* resultAOD=gGrid->Query(pathname,"AliAOD.root","","");
    Int_t nfiles=resultAOD->GetEntries();
    TString aodlfn,vertexlfn;
    if(lastdir>nfiles)lastdir=nfiles;
    for(Int_t ifile=0; ifile<nfiles; ifile++) {
      aodlfn=resultAOD->GetKey(ifile,"lfn");
      vertexlfn=aodlfn;
      vertexlfn.ReplaceAll("AliAOD.root","");
      TGridResult *r=gGrid->Query(vertexlfn.Data(),"AliAOD.VertexingHF.root");
      if(r->GetEntries()!=1)continue;
      chainAOD->Add(resultAOD->GetKey(ifile,"turl"));
      chainAODfriend->Add(r->GetKey(0,"turl"));
    }
  }
  else{
    if(lastdir==-1) { // only one pair of files
      chainAOD->Add("AliAOD.root");
      chainAODfriend->Add("AliAOD.VertexingHF.root");
    } else {

      // set the path to the files (can be local or on alien)
      for(Int_t idir=firstdir; idir<=lastdir; idir++) {
	TString aodname=pathname;
	TString aodHFname=pathname;
	aodname+=idir;
	aodHFname+=idir;
	aodname.Append("/AliAOD.root");
	aodHFname.Append("/AliAOD.VertexingHF.root");
	chainAOD->Add(aodname.Data());
	chainAODfriend->Add(aodHFname.Data());
      }
    }
  }

  chainAOD->AddFriend(chainAODfriend);

  return chainAOD;
}
//----------------------------------------------------------------------------
TFileCollection* MakeRootArchFileCollection(const char* collectionfileAOD,
					    Int_t nfiles=-1){

  // METHOD USEFUL FOR ANALYSIS ON THE CAF
  // Check the presence of both AliAOD.root and AODVertexingHF.root files
  // in the same path
  // returns a TFileCollection suitable for storing datasets in CAF
  // Origin: A.Rossi, andrea.rossi@ts.infn.it
  //

  TAlienCollection *collectionAOD       = TAlienCollection::Open(collectionfileAOD);
  TGridResult *tagResultAOD = collectionAOD->GetGridResult("",0,0);

  Int_t nmaxentr;
  TFileCollection *proofColl=new TFileCollection("proofColl","proofColl");

  nmaxentr=tagResultAOD->GetEntries();
    if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;
    TString aodlfn;
    for(Int_t ifile=0; ifile<nmaxentr; ifile++) {
      aodlfn=tagResultAOD->GetKey(ifile,"lfn");
      aodlfn.ReplaceAll("AliAOD.root","");
      aodlfn.ReplaceAll("AliAODs.root","");
      TGridResult *r=gGrid->Query(aodlfn.Data(),"AliAOD.VertexingHF.root");
        if(r->GetEntries()!=1)continue;
      r=gGrid->Query(aodlfn.Data(),"root_archive.zip");
      if(r->GetEntries()!=1)continue;
      aodlfn.Append("root_archive.zip");
      printf("Adding file %s\n",aodlfn.Data());
      proofColl->Add(r->GetKey(0,"turl"));
    }
    return proofColl;
}
//----------------------------------------------------------------------------
void StageToCAF(TString xmlcoll="collAODLHC08x.xml",
		TString datasetname="AODVertexingHF_LHC08x_10files",
		Int_t nfiles=-1) {
  //
  // Staging a dataset to CAF
  // andrea.dainese@pd.infn.it
  //

  //gROOT->LoadMacro("MakeAODInputChain.C");

  TGrid::Connect("alien://");

  // find -x collAODLHC08x -z /alice/cern.ch/user/r/rbala/newtrain/out_lhc08x/* AliAOD.root > collAODLHC08x.xml

  TFileCollection *proofColl = MakeRootArchFileCollection(xmlcoll.Data(),nfiles);
  proofColl->SetAnchor("AliAOD.root");

  gEnv->SetValue("XSec.GSI.DelegProxy","2");
  TProof::Open("dainesea:PWG3@alicecaf");
  gProof->RegisterDataSet(datasetname.Data(),proofColl);
  gProof->ShowDataSets();

  return;
}
<|endoftext|>


<commit_before>//https://code.google.com/p/nya-engine/

#include "nms.h"
#include "memory/memory_reader.h"
#include "memory/memory_writer.h"
#include <stdio.h>
#include <stdint.h>

namespace { const char nms_sign[]={'n','y','a',' ','m','e','s','h'}; }

namespace nya_formats
{

static std::string read_string(nya_memory::memory_reader &reader)
{
    unsigned short size=reader.read<unsigned short>();
    const char *str=(const char *)reader.get_data();
    if(!size || !str || !reader.check_remained(size))
    {
        reader.skip(size);
        return "";
    }

    reader.skip(size);

    return std::string(str,size);
}

bool nms::read_chunks_info(const void *data,size_t size)
{
    *this=nms();

    if(!data || !size)
        return false;

    const char *cdata=(const char *)data;
    const char *const data_end=cdata+size;
    header h;
    cdata+=read_header(h,data,size);
    if(cdata==data)
        return false;

    version=h.version;
    chunks.resize(h.chunks_count);
    for(size_t i=0;i<chunks.size();++i)
    {
        cdata+=read_chunk_info(chunks[i],cdata,data_end-cdata);
        cdata+=chunks[i].size;
        if(cdata>data_end)
        {
            *this=nms();
            return false;
        }
    }

    return true;
}

size_t nms::read_header(header &out_header,const void *data,size_t size)
{
    out_header.version=out_header.chunks_count=0;
    if(size<nms_header_size)
        return 0;

    nya_memory::memory_reader reader(data,size);
    if(!reader.test(nms_sign,sizeof(nms_sign)))
        return 0;

    out_header.version=reader.read<uint32_t>();
    if(!out_header.version)
        return 0;

    out_header.chunks_count=reader.read<uint32_t>();

    return reader.get_offset();
}

size_t nms::read_chunk_info(chunk_info &out_chunk_info,const void *data,size_t size)
{
    if(size<sizeof(uint32_t)*2)
        return 0;

    out_chunk_info.type=out_chunk_info.size=0;
    nya_memory::memory_reader reader(data,size);
    out_chunk_info.type=reader.read<uint32_t>();
    out_chunk_info.size=reader.read<uint32_t>();
    out_chunk_info.data=reader.get_data();

    return reader.get_offset();
}

size_t nms::get_nms_size()
{
    size_t size=nms_header_size;
    for(size_t i=0;i<chunks.size();++i)
        size+=get_chunk_write_size(chunks[i].size);

    return size;
}

size_t nms::write_to_buf(void *data,size_t size)
{
    if(!data)
        return 0;

    char *cdata=(char *)data;
    const char *const data_end=cdata+size;

    header h;
    h.version=version;
    h.chunks_count=(unsigned int)chunks.size();
    cdata+=write_header_to_buf(h,data,size);
    if(data==cdata)
        return 0;

    for(size_t i=0;i<chunks.size();++i)
        cdata+=write_chunk_to_buf(chunks[i],cdata,data_end-cdata);

    return cdata-(char *)data;
}

size_t nms::write_header_to_buf(const header &h,void *to_data,size_t to_size)
{
    if(!to_data || to_size<nms_header_size)
        return 0;

    nya_memory::memory_writer writer(to_data,to_size);
    writer.write(nms_sign,sizeof(nms_sign));
    writer.write_uint(h.version);
    writer.write_uint(h.chunks_count);

    return writer.get_offset();
}

size_t nms::get_chunk_write_size(size_t chunk_data_size) { return chunk_data_size+sizeof(uint32_t)*2; }

size_t nms::write_chunk_to_buf(const chunk_info &chunk,void *to_data,size_t to_size)
{
    if(!to_data || to_size<get_chunk_write_size(chunk.size))
        return 0;

    nya_memory::memory_writer writer(to_data,to_size);
    writer.write_uint(chunk.type);
    writer.write_uint(chunk.size);
    if(!chunk.size)
        return writer.get_offset();

    if(!chunk.data)
        return 0;

    writer.write(chunk.data,chunk.size);
    return writer.get_offset();
}

size_t nms_mesh_chunk::read_header(const void *data, size_t size, int version)
{
    *this=nms_mesh_chunk();

    if(!data || !size)
        return false;

    typedef uint32_t uint;
    typedef uint16_t ushort;
    typedef uint8_t uchar;

    nya_memory::memory_reader reader(data,size);

    aabb_min=reader.read<nya_math::vec3>();
    aabb_max=reader.read<nya_math::vec3>();

    elements.resize(reader.read<uchar>());
    for(size_t i=0;i<elements.size();++i)
    {
        element &e=elements[i];

        e.type=reader.read<uchar>();
        e.dimension=reader.read<uchar>();
        uchar data_type=float32;
        if(version>1)
        {
            data_type=reader.read<uchar>();
            if(data_type!=float16 && data_type!=float32)
            {
                *this=nms_mesh_chunk();
                return 0;
            }
        }

        e.data_type=(vertex_atrib_type)data_type;
        read_string(reader); //semantics

        vertex_stride+=e.dimension*sizeof(float);
    }

    if(!vertex_stride)
    {
        *this=nms_mesh_chunk();
        return false;
    }

    verts_count=reader.read<uint>();
    if(!reader.check_remained(verts_count*vertex_stride))
    {
        *this=nms_mesh_chunk();
        return false;
    }

    vertices_data=reader.get_data();

    if(!reader.skip(verts_count*vertex_stride))
    {
        *this=nms_mesh_chunk();
        return false;
    }

    index_size=reader.read<uchar>();
    if(index_size)
    {
        indices_count=reader.read<uint>();
        if(!reader.check_remained(indices_count*index_size))
            return false;

        indices_data=reader.get_data();

        if(!reader.skip(index_size*indices_count))
            return false;
    }

    lods.resize(reader.read<ushort>());
    for(size_t i=0;i<lods.size();++i)
    {
        lod &l=lods[i];
        l.groups.resize(reader.read<ushort>());
        for(size_t j=0;j<l.groups.size();++j)
        {
            group &g=l.groups[j];
            g.name=read_string(reader);

            g.aabb_min=reader.read<nya_math::vec3>();
            g.aabb_max=reader.read<nya_math::vec3>();

            g.material_idx=reader.read<ushort>();
            g.offset=reader.read<uint>();
            g.count=reader.read<uint>();
            g.element_type=version>1?draw_element_type(reader.read<uchar>()):triangles;
        }
    }

    return 0;
}

bool nms_material_chunk::read(const void *data,size_t size,int version)
{
    *this=nms_material_chunk();

    if(!data || !size)
        return false;

    nya_memory::memory_reader reader(data,size);

    materials.resize(reader.read<uint16_t>());
    for(size_t i=0;i<materials.size();++i)
    {
        material_info &m=materials[i];
        m.name=read_string(reader);

        m.textures.resize(reader.read<uint16_t>());
        for(size_t j=0;j<m.textures.size();++j)
        {
            m.textures[j].semantics=read_string(reader);
            m.textures[j].filename=read_string(reader);
        }

        m.strings.resize(reader.read<uint16_t>());
        for(size_t j=0;j<m.strings.size();++j)
        {
            m.strings[j].name=read_string(reader);
            m.strings[j].value=read_string(reader);
        }

        m.vectors.resize(reader.read<uint16_t>());
        for(size_t j=0;j<m.vectors.size();++j)
        {
            m.vectors[j].name=read_string(reader);
            m.vectors[j].value.x=reader.read<float>();
            m.vectors[j].value.y=reader.read<float>();
            m.vectors[j].value.z=reader.read<float>();
            m.vectors[j].value.w=reader.read<float>();
        }

        m.ints.resize(reader.read<uint16_t>());
        for(size_t j=0;j<m.ints.size();++j)
        {
            m.ints[j].name=read_string(reader);
            m.ints[j].value=reader.read<int32_t>();
        }
    }

    return true;
}

size_t nms_material_chunk::write_to_buf(void *to_data,size_t to_size)
{
    nya_memory::memory_writer writer(to_data,to_size);
    writer.write_ushort((unsigned short)materials.size());
    for(size_t i=0;i<materials.size();++i)
    {
        material_info &m=materials[i];
        writer.write_string(m.name);

        writer.write_ushort((unsigned short)m.textures.size());
        for(size_t j=0;j<m.textures.size();++j)
        {
            writer.write_string(m.textures[j].semantics);
            writer.write_string(m.textures[j].filename);
        }

        writer.write_ushort((unsigned short)m.strings.size());
        for(size_t j=0;j<m.strings.size();++j)
        {
            writer.write_string(m.strings[j].name);
            writer.write_string(m.strings[j].value);
        }

        writer.write_ushort((unsigned short)m.vectors.size());
        for(size_t j=0;j<m.vectors.size();++j)
        {
            writer.write_string(m.vectors[j].name);
            writer.write_float(m.vectors[j].value.x);
            writer.write_float(m.vectors[j].value.y);
            writer.write_float(m.vectors[j].value.z);
            writer.write_float(m.vectors[j].value.w);
        }

        writer.write_ushort((unsigned short)m.ints.size());
        for(size_t j=0;j<m.ints.size();++j)
        {
            writer.write_string(m.ints[j].name);
            writer.write_int(m.ints[j].value);
        }
    }

    return writer.get_offset();
}

bool nms_skeleton_chunk::read(const void *data,size_t size,int version)
{
    *this=nms_skeleton_chunk();

    if(!data || !size)
        return false;

    nya_memory::memory_reader reader(data,size);

    bones.resize(reader.read<int32_t>());
    for(size_t i=0;i<bones.size();++i)
    {
        bone &b=bones[i];
        b.name=read_string(reader);
        b.rot=reader.read<nya_math::quat>();
        b.pos=reader.read<nya_math::vec3>();
        b.parent=reader.read<int32_t>();
    }

    return true;
}

}
<commit_msg>formats: nms<commit_after>//https://code.google.com/p/nya-engine/

#include "nms.h"
#include "memory/memory_reader.h"
#include "memory/memory_writer.h"
#include <stdio.h>
#include <stdint.h>

namespace { const char nms_sign[]={'n','y','a',' ','m','e','s','h'}; }

namespace nya_formats
{

static std::string read_string(nya_memory::memory_reader &reader)
{
    unsigned short size=reader.read<unsigned short>();
    const char *str=(const char *)reader.get_data();
    if(!size || !str || !reader.check_remained(size))
    {
        reader.skip(size);
        return "";
    }

    reader.skip(size);

    return std::string(str,size);
}

bool nms::read_chunks_info(const void *data,size_t size)
{
    *this=nms();

    if(!data || !size)
        return false;

    const char *cdata=(const char *)data;
    const char *const data_end=cdata+size;
    header h;
    cdata+=read_header(h,data,size);
    if(cdata==data)
        return false;

    version=h.version;
    chunks.resize(h.chunks_count);
    for(size_t i=0;i<chunks.size();++i)
    {
        cdata+=read_chunk_info(chunks[i],cdata,data_end-cdata);
        cdata+=chunks[i].size;
        if(cdata>data_end)
        {
            *this=nms();
            return false;
        }
    }

    return true;
}

size_t nms::read_header(header &out_header,const void *data,size_t size)
{
    out_header.version=out_header.chunks_count=0;
    if(size<nms_header_size)
        return 0;

    nya_memory::memory_reader reader(data,size);
    if(!reader.test(nms_sign,sizeof(nms_sign)))
        return 0;

    out_header.version=reader.read<uint32_t>();
    if(!out_header.version)
        return 0;

    out_header.chunks_count=reader.read<uint32_t>();

    return reader.get_offset();
}

size_t nms::read_chunk_info(chunk_info &out_chunk_info,const void *data,size_t size)
{
    if(size<sizeof(uint32_t)*2)
        return 0;

    out_chunk_info.type=out_chunk_info.size=0;
    nya_memory::memory_reader reader(data,size);
    out_chunk_info.type=reader.read<uint32_t>();
    out_chunk_info.size=reader.read<uint32_t>();
    out_chunk_info.data=reader.get_data();

    return reader.get_offset();
}

size_t nms::get_nms_size()
{
    size_t size=nms_header_size;
    for(size_t i=0;i<chunks.size();++i)
        size+=get_chunk_write_size(chunks[i].size);

    return size;
}

size_t nms::write_to_buf(void *data,size_t size)
{
    if(!data)
        return 0;

    char *cdata=(char *)data;
    const char *const data_end=cdata+size;

    header h;
    h.version=version;
    h.chunks_count=(unsigned int)chunks.size();
    cdata+=write_header_to_buf(h,data,size);
    if(data==cdata)
        return 0;

    for(size_t i=0;i<chunks.size();++i)
        cdata+=write_chunk_to_buf(chunks[i],cdata,data_end-cdata);

    return cdata-(char *)data;
}

size_t nms::write_header_to_buf(const header &h,void *to_data,size_t to_size)
{
    if(!to_data || to_size<nms_header_size)
        return 0;

    nya_memory::memory_writer writer(to_data,to_size);
    writer.write(nms_sign,sizeof(nms_sign));
    writer.write_uint(h.version);
    writer.write_uint(h.chunks_count);

    return writer.get_offset();
}

size_t nms::get_chunk_write_size(size_t chunk_data_size) { return chunk_data_size+sizeof(uint32_t)*2; }

size_t nms::write_chunk_to_buf(const chunk_info &chunk,void *to_data,size_t to_size)
{
    if(!to_data || to_size<get_chunk_write_size(chunk.size))
        return 0;

    nya_memory::memory_writer writer(to_data,to_size);
    writer.write_uint(chunk.type);
    writer.write_uint(chunk.size);
    if(!chunk.size)
        return writer.get_offset();

    if(!chunk.data)
        return 0;

    writer.write(chunk.data,chunk.size);
    return writer.get_offset();
}

size_t nms_mesh_chunk::read_header(const void *data, size_t size, int version)
{
    *this=nms_mesh_chunk();

    if(!data || !size)
        return 0;

    typedef uint32_t uint;
    typedef uint16_t ushort;
    typedef uint8_t uchar;

    nya_memory::memory_reader reader(data,size);

    aabb_min=reader.read<nya_math::vec3>();
    aabb_max=reader.read<nya_math::vec3>();

    elements.resize(reader.read<uchar>());
    for(size_t i=0;i<elements.size();++i)
    {
        element &e=elements[i];

        e.type=reader.read<uchar>();
        e.dimension=reader.read<uchar>();
        uchar data_type=float32;
        if(version>1)
        {
            data_type=reader.read<uchar>();
            if(data_type!=float16 && data_type!=float32)
            {
                *this=nms_mesh_chunk();
                return 0;
            }
        }

        e.data_type=(vertex_atrib_type)data_type;
        read_string(reader); //semantics

        vertex_stride+=e.dimension*sizeof(float);
    }

    if(!vertex_stride)
    {
        *this=nms_mesh_chunk();
        return 0;
    }

    verts_count=reader.read<uint>();
    if(!reader.check_remained(verts_count*vertex_stride))
    {
        *this=nms_mesh_chunk();
        return 0;
    }

    vertices_data=reader.get_data();

    if(!reader.skip(verts_count*vertex_stride))
    {
        *this=nms_mesh_chunk();
        return 0;
    }

    index_size=reader.read<uchar>();
    if(index_size)
    {
        indices_count=reader.read<uint>();
        if(!reader.check_remained(indices_count*index_size))
            return 0;

        indices_data=reader.get_data();

        if(!reader.skip(index_size*indices_count))
            return 0;
    }

    lods.resize(reader.read<ushort>());
    for(size_t i=0;i<lods.size();++i)
    {
        lod &l=lods[i];
        l.groups.resize(reader.read<ushort>());
        for(size_t j=0;j<l.groups.size();++j)
        {
            group &g=l.groups[j];
            g.name=read_string(reader);

            g.aabb_min=reader.read<nya_math::vec3>();
            g.aabb_max=reader.read<nya_math::vec3>();

            g.material_idx=reader.read<ushort>();
            g.offset=reader.read<uint>();
            g.count=reader.read<uint>();
            g.element_type=version>1?draw_element_type(reader.read<uchar>()):triangles;
        }
    }

    return reader.get_offset();
}

bool nms_material_chunk::read(const void *data,size_t size,int version)
{
    *this=nms_material_chunk();

    if(!data || !size)
        return false;

    nya_memory::memory_reader reader(data,size);

    materials.resize(reader.read<uint16_t>());
    for(size_t i=0;i<materials.size();++i)
    {
        material_info &m=materials[i];
        m.name=read_string(reader);

        m.textures.resize(reader.read<uint16_t>());
        for(size_t j=0;j<m.textures.size();++j)
        {
            m.textures[j].semantics=read_string(reader);
            m.textures[j].filename=read_string(reader);
        }

        m.strings.resize(reader.read<uint16_t>());
        for(size_t j=0;j<m.strings.size();++j)
        {
            m.strings[j].name=read_string(reader);
            m.strings[j].value=read_string(reader);
        }

        m.vectors.resize(reader.read<uint16_t>());
        for(size_t j=0;j<m.vectors.size();++j)
        {
            m.vectors[j].name=read_string(reader);
            m.vectors[j].value.x=reader.read<float>();
            m.vectors[j].value.y=reader.read<float>();
            m.vectors[j].value.z=reader.read<float>();
            m.vectors[j].value.w=reader.read<float>();
        }

        m.ints.resize(reader.read<uint16_t>());
        for(size_t j=0;j<m.ints.size();++j)
        {
            m.ints[j].name=read_string(reader);
            m.ints[j].value=reader.read<int32_t>();
        }
    }

    return true;
}

size_t nms_material_chunk::write_to_buf(void *to_data,size_t to_size)
{
    nya_memory::memory_writer writer(to_data,to_size);
    writer.write_ushort((unsigned short)materials.size());
    for(size_t i=0;i<materials.size();++i)
    {
        material_info &m=materials[i];
        writer.write_string(m.name);

        writer.write_ushort((unsigned short)m.textures.size());
        for(size_t j=0;j<m.textures.size();++j)
        {
            writer.write_string(m.textures[j].semantics);
            writer.write_string(m.textures[j].filename);
        }

        writer.write_ushort((unsigned short)m.strings.size());
        for(size_t j=0;j<m.strings.size();++j)
        {
            writer.write_string(m.strings[j].name);
            writer.write_string(m.strings[j].value);
        }

        writer.write_ushort((unsigned short)m.vectors.size());
        for(size_t j=0;j<m.vectors.size();++j)
        {
            writer.write_string(m.vectors[j].name);
            writer.write_float(m.vectors[j].value.x);
            writer.write_float(m.vectors[j].value.y);
            writer.write_float(m.vectors[j].value.z);
            writer.write_float(m.vectors[j].value.w);
        }

        writer.write_ushort((unsigned short)m.ints.size());
        for(size_t j=0;j<m.ints.size();++j)
        {
            writer.write_string(m.ints[j].name);
            writer.write_int(m.ints[j].value);
        }
    }

    return writer.get_offset();
}

bool nms_skeleton_chunk::read(const void *data,size_t size,int version)
{
    *this=nms_skeleton_chunk();

    if(!data || !size)
        return false;

    nya_memory::memory_reader reader(data,size);

    bones.resize(reader.read<int32_t>());
    for(size_t i=0;i<bones.size();++i)
    {
        bone &b=bones[i];
        b.name=read_string(reader);
        b.rot=reader.read<nya_math::quat>();
        b.pos=reader.read<nya_math::vec3>();
        b.parent=reader.read<int32_t>();
    }

    return true;
}

}
<|endoftext|>


<commit_before>#include "openhevcfilter.h"

#include "common.h"

#include <QDebug>
#include <QSettings>

enum OHThreadType {OH_THREAD_FRAME  = 1, OH_THREAD_SLICE  = 2, OH_THREAD_FRAMESLICE  = 3};

OpenHEVCFilter::OpenHEVCFilter(QString id, StatisticsInterface *stats):
  Filter(id, "OpenHEVC", stats, HEVCVIDEO, YUV420VIDEO),
  handle_(),
  parameterSets_(false),
  waitFrames_(0),
  slices_(true)
{}

bool OpenHEVCFilter::init()
{
  qDebug() << getName() << "iniating";
  QSettings settings("kvazzup.ini", QSettings::IniFormat);

  handle_ = libOpenHevcInit(settings.value("video/OPENHEVC_threads").toInt(), OH_THREAD_FRAME);

  libOpenHevcSetDebugMode(handle_, 0);
  if(libOpenHevcStartDecoder(handle_) == -1)
  {
    printDebug(DEBUG_PROGRAM_ERROR, this, "Failed to start decoder.");
    return false;
  }
  libOpenHevcSetTemporalLayer_id(handle_, 0);
  libOpenHevcSetActiveDecoders(handle_, 0);
  libOpenHevcSetViewLayers(handle_, 0);
  qDebug() << getName() << "initiation success. Version: " << libOpenHevcVersion(handle_);

  // This is because we don't know anything about the incoming stream
  maxBufferSize_ = -1; // no buffer limit

  return true;
}

void OpenHEVCFilter::uninit()
{
  qDebug() << getName() << "uniniating.";
  libOpenHevcFlush(handle_);
  libOpenHevcClose(handle_);
}

void OpenHEVCFilter::run()
{
  // TODO: if not iniated, init

  // TODO: call uninit when stopping?

  setPriority(QThread::HighPriority);
  Filter::run();
}

void OpenHEVCFilter::combineFrame(std::unique_ptr<Data>& combinedFrame)
{
  if(sliceBuffer_.size() == 0)
  {
    qDebug() << "No previous slices";
    return;
  }

  combinedFrame = std::unique_ptr<Data>(shallowDataCopy(sliceBuffer_.at(0).get()));
  combinedFrame->data_size = 0;

  for(unsigned int i = 0; i < sliceBuffer_.size(); ++i)
  {
    combinedFrame->data_size += sliceBuffer_.at(i)->data_size;
  }

  combinedFrame->data = std::unique_ptr<uchar[]>(new uchar[combinedFrame->data_size]);

  uint32_t dataWritten = 0;
  for(unsigned int i = 0; i < sliceBuffer_.size(); ++i)
  {
    memcpy(combinedFrame->data.get() + dataWritten,
           sliceBuffer_.at(i)->data.get(), sliceBuffer_.at(i)->data_size );
    dataWritten += sliceBuffer_.at(i)->data_size;
  }

  if(slices_ && sliceBuffer_.size() == 1)
  {
    slices_ = false;
    qDebug() << getName() << "Detected no slices in incoming stream.";
    uninit();
    init();
  }

  sliceBuffer_.clear();

  return;
}

void OpenHEVCFilter::process()
{
  std::unique_ptr<Data> input = getInput();
  while(input)
  {
    const unsigned char *buff = input->data.get();

    bool nextSlice = buff[0] == 0
        && buff[1] == 0
        && buff[2] == 0;

    if(!slices_ && buff[0] == 0
       && buff[1] == 0
       && buff[2] == 1)
    {
      slices_ = true;
      qDebug() << "Detected slices in incoming stream";
      uninit();
      init();
    }

    if(!parameterSets_ && (buff[4] >> 1) == 32)
    {
      parameterSets_ = true;
      qDebug() << getName() << ": Parameter set found after" << waitFrames_ << "frames";
    }

    if(parameterSets_)
    {
      if(nextSlice && sliceBuffer_.size() != 0)
      {
        std::unique_ptr<Data> frame;
        combineFrame(frame);

        if (frame == nullptr)
        {
          break;
        }

        int64_t pts = frame->presentationTime.tv_sec*90000 + frame->presentationTime.tv_usec*90000/1000000;
        int gotPicture = libOpenHevcDecode(handle_, frame->data.get(), frame->data_size, pts);

        OpenHevc_Frame openHevcFrame;
        if( gotPicture == -1)
        {
          printDebug(DEBUG_ERROR, this,  "Error while decoding.");
        }
        else if(!gotPicture && frame->data_size >= 2)
        {
          const unsigned char *buff2 = frame->data.get();
          printDebug(DEBUG_WARNING, getName(),  "Could not decode video frame.",
                     {"NAL type"}, {QString() + QString::number(buff2[0]) + QString::number(buff2[1])
                     + QString::number(buff2[2]) + QString::number(buff2[3]) + QString::number(buff2[4] >> 1) });
        }
        else if( libOpenHevcGetOutput(handle_, gotPicture, &openHevcFrame) == -1 )
        {
          printDebug(DEBUG_ERROR, this,  "Failed to get output.");
        }
        else
        {
          frame->width = openHevcFrame.frameInfo.nWidth;
          frame->height = openHevcFrame.frameInfo.nHeight;
          uint32_t finalDataSize = frame->width*frame->height + frame->width*frame->height/2;
          std::unique_ptr<uchar[]> yuv_frame(new uchar[finalDataSize]);

          uint8_t* pY = (uint8_t*)yuv_frame.get();
          uint8_t* pU = (uint8_t*)&(yuv_frame.get()[frame->width*frame->height]);
          uint8_t* pV = (uint8_t*)&(yuv_frame.get()[frame->width*frame->height + frame->width*frame->height/4]);

          uint32_t s_stride = openHevcFrame.frameInfo.nYPitch;
          uint32_t qs_stride = openHevcFrame.frameInfo.nUPitch/2;

          uint32_t d_stride = frame->width/2;
          uint32_t dd_stride = frame->width;

          for (int i=0; i<frame->height; i++) {
            memcpy(pY,  (uint8_t *) openHevcFrame.pvY + i*s_stride, dd_stride);
            pY += dd_stride;

            if (! (i%2) ) {
              memcpy(pU,  (uint8_t *) openHevcFrame.pvU + i*qs_stride, d_stride);
              pU += d_stride;

              memcpy(pV,  (uint8_t *) openHevcFrame.pvV + i*qs_stride, d_stride);
              pV += d_stride;
            }
          }

          // TODO: put delay into deque, and set timestamp accordingly to get more accurate latency.

          frame->type = YUV420VIDEO;
          frame->framerate = openHevcFrame.frameInfo.frameRate.num/openHevcFrame.frameInfo.frameRate.den;
          frame->data_size = finalDataSize;
          frame->data = std::move(yuv_frame);

          sendOutput(std::move(frame));
        }
      }
      sliceBuffer_.push_back(std::move(input));
    }
    else
    {
      ++waitFrames_;
    }

    input = getInput();
  }
}
<commit_msg>fix(Processing): Fixed missing new presentationTime type usage.<commit_after>#include "openhevcfilter.h"

#include "common.h"

#include <QDebug>
#include <QSettings>

enum OHThreadType {OH_THREAD_FRAME  = 1, OH_THREAD_SLICE  = 2, OH_THREAD_FRAMESLICE  = 3};

OpenHEVCFilter::OpenHEVCFilter(QString id, StatisticsInterface *stats):
  Filter(id, "OpenHEVC", stats, HEVCVIDEO, YUV420VIDEO),
  handle_(),
  parameterSets_(false),
  waitFrames_(0),
  slices_(true)
{}

bool OpenHEVCFilter::init()
{
  qDebug() << getName() << "iniating";
  QSettings settings("kvazzup.ini", QSettings::IniFormat);

  handle_ = libOpenHevcInit(settings.value("video/OPENHEVC_threads").toInt(), OH_THREAD_FRAME);

  libOpenHevcSetDebugMode(handle_, 0);
  if(libOpenHevcStartDecoder(handle_) == -1)
  {
    printDebug(DEBUG_PROGRAM_ERROR, this, "Failed to start decoder.");
    return false;
  }
  libOpenHevcSetTemporalLayer_id(handle_, 0);
  libOpenHevcSetActiveDecoders(handle_, 0);
  libOpenHevcSetViewLayers(handle_, 0);
  qDebug() << getName() << "initiation success. Version: " << libOpenHevcVersion(handle_);

  // This is because we don't know anything about the incoming stream
  maxBufferSize_ = -1; // no buffer limit

  return true;
}

void OpenHEVCFilter::uninit()
{
  qDebug() << getName() << "uniniating.";
  libOpenHevcFlush(handle_);
  libOpenHevcClose(handle_);
}

void OpenHEVCFilter::run()
{
  // TODO: if not iniated, init

  // TODO: call uninit when stopping?

  setPriority(QThread::HighPriority);
  Filter::run();
}

void OpenHEVCFilter::combineFrame(std::unique_ptr<Data>& combinedFrame)
{
  if(sliceBuffer_.size() == 0)
  {
    qDebug() << "No previous slices";
    return;
  }

  combinedFrame = std::unique_ptr<Data>(shallowDataCopy(sliceBuffer_.at(0).get()));
  combinedFrame->data_size = 0;

  for(unsigned int i = 0; i < sliceBuffer_.size(); ++i)
  {
    combinedFrame->data_size += sliceBuffer_.at(i)->data_size;
  }

  combinedFrame->data = std::unique_ptr<uchar[]>(new uchar[combinedFrame->data_size]);

  uint32_t dataWritten = 0;
  for(unsigned int i = 0; i < sliceBuffer_.size(); ++i)
  {
    memcpy(combinedFrame->data.get() + dataWritten,
           sliceBuffer_.at(i)->data.get(), sliceBuffer_.at(i)->data_size );
    dataWritten += sliceBuffer_.at(i)->data_size;
  }

  if(slices_ && sliceBuffer_.size() == 1)
  {
    slices_ = false;
    qDebug() << getName() << "Detected no slices in incoming stream.";
    uninit();
    init();
  }

  sliceBuffer_.clear();

  return;
}

void OpenHEVCFilter::process()
{
  std::unique_ptr<Data> input = getInput();
  while(input)
  {
    const unsigned char *buff = input->data.get();

    bool nextSlice = buff[0] == 0
        && buff[1] == 0
        && buff[2] == 0;

    if(!slices_ && buff[0] == 0
       && buff[1] == 0
       && buff[2] == 1)
    {
      slices_ = true;
      qDebug() << "Detected slices in incoming stream";
      uninit();
      init();
    }

    if(!parameterSets_ && (buff[4] >> 1) == 32)
    {
      parameterSets_ = true;
      qDebug() << getName() << ": Parameter set found after" << waitFrames_ << "frames";
    }

    if(parameterSets_)
    {
      if(nextSlice && sliceBuffer_.size() != 0)
      {
        std::unique_ptr<Data> frame;
        combineFrame(frame);

        if (frame == nullptr)
        {
          break;
        }

        int64_t pts = frame->presentationTime;
        int gotPicture = libOpenHevcDecode(handle_, frame->data.get(), frame->data_size, pts);

        OpenHevc_Frame openHevcFrame;
        if( gotPicture == -1)
        {
          printDebug(DEBUG_ERROR, this,  "Error while decoding.");
        }
        else if(!gotPicture && frame->data_size >= 2)
        {
          const unsigned char *buff2 = frame->data.get();
          printDebug(DEBUG_WARNING, getName(),  "Could not decode video frame.",
                     {"NAL type"}, {QString() + QString::number(buff2[0]) + QString::number(buff2[1])
                     + QString::number(buff2[2]) + QString::number(buff2[3]) + QString::number(buff2[4] >> 1) });
        }
        else if( libOpenHevcGetOutput(handle_, gotPicture, &openHevcFrame) == -1 )
        {
          printDebug(DEBUG_ERROR, this,  "Failed to get output.");
        }
        else
        {
          frame->width = openHevcFrame.frameInfo.nWidth;
          frame->height = openHevcFrame.frameInfo.nHeight;
          uint32_t finalDataSize = frame->width*frame->height + frame->width*frame->height/2;
          std::unique_ptr<uchar[]> yuv_frame(new uchar[finalDataSize]);

          uint8_t* pY = (uint8_t*)yuv_frame.get();
          uint8_t* pU = (uint8_t*)&(yuv_frame.get()[frame->width*frame->height]);
          uint8_t* pV = (uint8_t*)&(yuv_frame.get()[frame->width*frame->height + frame->width*frame->height/4]);

          uint32_t s_stride = openHevcFrame.frameInfo.nYPitch;
          uint32_t qs_stride = openHevcFrame.frameInfo.nUPitch/2;

          uint32_t d_stride = frame->width/2;
          uint32_t dd_stride = frame->width;

          for (int i=0; i<frame->height; i++) {
            memcpy(pY,  (uint8_t *) openHevcFrame.pvY + i*s_stride, dd_stride);
            pY += dd_stride;

            if (! (i%2) ) {
              memcpy(pU,  (uint8_t *) openHevcFrame.pvU + i*qs_stride, d_stride);
              pU += d_stride;

              memcpy(pV,  (uint8_t *) openHevcFrame.pvV + i*qs_stride, d_stride);
              pV += d_stride;
            }
          }

          // TODO: put delay into deque, and set timestamp accordingly to get more accurate latency.

          frame->type = YUV420VIDEO;
          frame->framerate = openHevcFrame.frameInfo.frameRate.num/openHevcFrame.frameInfo.frameRate.den;
          frame->data_size = finalDataSize;
          frame->data = std::move(yuv_frame);

          sendOutput(std::move(frame));
        }
      }
      sliceBuffer_.push_back(std::move(input));
    }
    else
    {
      ++waitFrames_;
    }

    input = getInput();
  }
}
<|endoftext|>


<commit_before>#pragma once

#include "../tags/Logics.hpp"

#include <boost/mpl/map/map50.hpp>
#include <boost/mpl/string.hpp>
#include <boost/utility/enable_if.hpp>

namespace metaSMT {

  namespace predtags = ::metaSMT::logic::tag;
  namespace bvtags = ::metaSMT::logic::QF_BV::tag;
  namespace arraytags = ::metaSMT::logic::Array::tag;
  namespace mpl = boost::mpl;

  /** \cond **/
  typedef mpl::map42<
      mpl::pair<predtags::true_tag,    mpl::string<'t', 'r', 'u', 'e'> >
    , mpl::pair<predtags::false_tag,   mpl::string<'f', 'a', 'l', 's', 'e'> >
    , mpl::pair<bvtags::bvult_tag,     mpl::string<'b', 'v', 'u', 'l', 't'> >
    , mpl::pair<bvtags::bvneg_tag,     mpl::string<'b', 'v', 'n', 'e', 'g'> >
    , mpl::pair<bvtags::bvnot_tag,     mpl::string<'b', 'v', 'n', 'o', 't'> >

    , mpl::pair<bvtags::bvand_tag,     mpl::string<'b', 'v', 'a', 'n', 'd'> >
    , mpl::pair<bvtags::bvor_tag,      mpl::string<'b', 'v', 'o', 'r'> >
    , mpl::pair<bvtags::bvnand_tag,    mpl::string<'b', 'v', 'n', 'a', 'n', 'd'> >
    , mpl::pair<bvtags::bvnor_tag,     mpl::string<'b', 'v', 'n', 'o', 'r'> >
    , mpl::pair<bvtags::bvxor_tag,     mpl::string<'b', 'v', 'x', 'o', 'r'> >

    , mpl::pair<bvtags::bvxnor_tag,    mpl::string<'b', 'v', 'x', 'n', 'o', 'r'> >
    , mpl::pair<bvtags::bvadd_tag,     mpl::string<'b', 'v', 'a', 'd', 'd'> >
    , mpl::pair<bvtags::bvsub_tag,     mpl::string<'b', 'v', 's', 'u', 'b'> >
    , mpl::pair<bvtags::bvmul_tag,     mpl::string<'b', 'v', 'm', 'u', 'l'> >
    , mpl::pair<bvtags::bvudiv_tag,    mpl::string<'b', 'v', 'u', 'd', 'i', 'v'> >
    , mpl::pair<bvtags::bvsrem_tag,    mpl::string<'b', 'v', 's', 'r', 'e', 'm'> >
    , mpl::pair<bvtags::bvsdiv_tag,    mpl::string<'b', 'v', 's', 'd', 'i', 'v'> >
    , mpl::pair<bvtags::bvurem_tag,    mpl::string<'b', 'v', 'u', 'r', 'e', 'm'> >
    , mpl::pair<bvtags::bvsle_tag,     mpl::string<'b', 'v', 's', 'l', 'e'> >

    , mpl::pair<bvtags::bvslt_tag,     mpl::string<'b', 'v', 's', 'l', 't'> >
    , mpl::pair<bvtags::bvsge_tag,     mpl::string<'b', 'v', 's', 'g', 'e'> >
    , mpl::pair<bvtags::bvsgt_tag,     mpl::string<'b', 'v', 's', 'g', 't'> >
    , mpl::pair<bvtags::bvule_tag,     mpl::string<'b', 'v', 'u', 'l', 'e'> >
    , mpl::pair<bvtags::bvult_tag,     mpl::string<'b', 'v', 'u', 'l', 't'> >

    , mpl::pair<bvtags::bvuge_tag,     mpl::string<'b', 'v', 'u', 'g', 'e'> >
    , mpl::pair<bvtags::bvugt_tag,     mpl::string<'b', 'v', 'u', 'g', 't'> >
    , mpl::pair<predtags::implies_tag, mpl::string<'=', '>'> >
    , mpl::pair<predtags::equal_tag,   mpl::string<'='> >
    , mpl::pair<predtags::xor_tag,     mpl::string<'x', 'o', 'r'> >

    , mpl::pair<predtags::and_tag,     mpl::string<'a', 'n', 'd'> >
    , mpl::pair<predtags::or_tag,      mpl::string<'o', 'r'> >
    , mpl::pair<bvtags::bit0_tag,      mpl::string<'b', 'i', 't', '0'> >
    , mpl::pair<bvtags::bit1_tag,      mpl::string<'b', 'i', 't', '1'> >
    , mpl::pair<predtags::ite_tag,     mpl::string<'i', 't', 'e'> >

    , mpl::pair<predtags::not_tag,     mpl::string<'n', 'o', 't'> >
    , mpl::pair<bvtags::bvcomp_tag,    mpl::string<'b', 'v', 'c', 'o', 'm', 'p'> >
    , mpl::pair<bvtags::concat_tag,    mpl::string<'c', 'o', 'n', 'c', 'a', 't'> >
    , mpl::pair<arraytags::select_tag, mpl::string<'s', 'e', 'l', 'e', 'c', 't'> >
    , mpl::pair<arraytags::store_tag,  mpl::string<'s', 't', 'o', 'r', 'e'> >
    , mpl::pair<bvtags::bvshl_tag,     mpl::string<'b', 'v', 's', 'h', 'l'> >
    , mpl::pair<bvtags::bvshr_tag,     mpl::string<'b', 'v', 'l', 's', 'h', 'r'> >
    , mpl::pair<bvtags::bvashr_tag,     mpl::string<'b', 'v', 'a', 's', 'h', 'r'> >
  > SMT_NameMap;
  /** \endcond **/

  template<typename Tag>
  inline typename boost::enable_if<
      typename mpl::has_key< SMT_NameMap, Tag>::type
    , std::string
    >::type
  get_tag_name(Tag const &t) {
    typedef typename mpl::at< SMT_NameMap, Tag >::type name;
    return mpl::c_str<name>::value;
  }

  template<typename Tag>
  inline typename boost::disable_if<
      typename mpl::has_key< SMT_NameMap, Tag>::type
    , std::string
    >::type
  get_tag_name(Tag const &t) {
    return "unknown_name";
  }

  typedef mpl::map<
      mpl::pair<predtags::nequal_tag, mpl::pair<predtags::not_tag, predtags::equal_tag > >
    , mpl::pair<predtags::nand_tag, mpl::pair<predtags::not_tag, predtags::and_tag > >
    , mpl::pair<predtags::nor_tag, mpl::pair<predtags::not_tag, predtags::or_tag > >
    , mpl::pair<predtags::xnor_tag, mpl::pair<predtags::not_tag, predtags::xor_tag > >
    , mpl::pair<bvtags::bvnand_tag, mpl::pair<bvtags::bvnot_tag, bvtags::bvand_tag > >
    , mpl::pair<bvtags::bvnor_tag, mpl::pair<bvtags::bvnot_tag, bvtags::bvor_tag > >
    , mpl::pair<bvtags::bvxnor_tag, mpl::pair<bvtags::bvnot_tag, bvtags::bvxor_tag > >
  > SMT_Negated_Map;

} // metaSMT
<commit_msg>fix map name in SMT_Tag_Mapping<commit_after>#pragma once

#include "../tags/Logics.hpp"

#include <boost/mpl/map/map50.hpp>
#include <boost/mpl/string.hpp>
#include <boost/utility/enable_if.hpp>

namespace metaSMT {

  namespace predtags = ::metaSMT::logic::tag;
  namespace bvtags = ::metaSMT::logic::QF_BV::tag;
  namespace arraytags = ::metaSMT::logic::Array::tag;
  namespace mpl = boost::mpl;

  /** \cond **/
  typedef mpl::map42<
      mpl::pair<predtags::true_tag,    mpl::string<'t', 'r', 'u', 'e'> >
    , mpl::pair<predtags::false_tag,   mpl::string<'f', 'a', 'l', 's', 'e'> >
    , mpl::pair<bvtags::bvult_tag,     mpl::string<'b', 'v', 'u', 'l', 't'> >
    , mpl::pair<bvtags::bvneg_tag,     mpl::string<'b', 'v', 'n', 'e', 'g'> >
    , mpl::pair<bvtags::bvnot_tag,     mpl::string<'b', 'v', 'n', 'o', 't'> >

    , mpl::pair<bvtags::bvand_tag,     mpl::string<'b', 'v', 'a', 'n', 'd'> >
    , mpl::pair<bvtags::bvor_tag,      mpl::string<'b', 'v', 'o', 'r'> >
    , mpl::pair<bvtags::bvnand_tag,    mpl::string<'b', 'v', 'n', 'a', 'n', 'd'> >
    , mpl::pair<bvtags::bvnor_tag,     mpl::string<'b', 'v', 'n', 'o', 'r'> >
    , mpl::pair<bvtags::bvxor_tag,     mpl::string<'b', 'v', 'x', 'o', 'r'> >

    , mpl::pair<bvtags::bvxnor_tag,    mpl::string<'b', 'v', 'x', 'n', 'o', 'r'> >
    , mpl::pair<bvtags::bvadd_tag,     mpl::string<'b', 'v', 'a', 'd', 'd'> >
    , mpl::pair<bvtags::bvsub_tag,     mpl::string<'b', 'v', 's', 'u', 'b'> >
    , mpl::pair<bvtags::bvmul_tag,     mpl::string<'b', 'v', 'm', 'u', 'l'> >
    , mpl::pair<bvtags::bvudiv_tag,    mpl::string<'b', 'v', 'u', 'd', 'i', 'v'> >
    , mpl::pair<bvtags::bvsrem_tag,    mpl::string<'b', 'v', 's', 'r', 'e', 'm'> >
    , mpl::pair<bvtags::bvsdiv_tag,    mpl::string<'b', 'v', 's', 'd', 'i', 'v'> >
    , mpl::pair<bvtags::bvurem_tag,    mpl::string<'b', 'v', 'u', 'r', 'e', 'm'> >
    , mpl::pair<bvtags::bvsle_tag,     mpl::string<'b', 'v', 's', 'l', 'e'> >

    , mpl::pair<bvtags::bvslt_tag,     mpl::string<'b', 'v', 's', 'l', 't'> >
    , mpl::pair<bvtags::bvsge_tag,     mpl::string<'b', 'v', 's', 'g', 'e'> >
    , mpl::pair<bvtags::bvsgt_tag,     mpl::string<'b', 'v', 's', 'g', 't'> >
    , mpl::pair<bvtags::bvule_tag,     mpl::string<'b', 'v', 'u', 'l', 'e'> >
    , mpl::pair<bvtags::bvult_tag,     mpl::string<'b', 'v', 'u', 'l', 't'> >

    , mpl::pair<bvtags::bvuge_tag,     mpl::string<'b', 'v', 'u', 'g', 'e'> >
    , mpl::pair<bvtags::bvugt_tag,     mpl::string<'b', 'v', 'u', 'g', 't'> >
    , mpl::pair<predtags::implies_tag, mpl::string<'=', '>'> >
    , mpl::pair<predtags::equal_tag,   mpl::string<'='> >
    , mpl::pair<predtags::xor_tag,     mpl::string<'x', 'o', 'r'> >

    , mpl::pair<predtags::and_tag,     mpl::string<'a', 'n', 'd'> >
    , mpl::pair<predtags::or_tag,      mpl::string<'o', 'r'> >
    , mpl::pair<bvtags::bit0_tag,      mpl::string<'b', 'i', 't', '0'> >
    , mpl::pair<bvtags::bit1_tag,      mpl::string<'b', 'i', 't', '1'> >
    , mpl::pair<predtags::ite_tag,     mpl::string<'i', 't', 'e'> >

    , mpl::pair<predtags::not_tag,     mpl::string<'n', 'o', 't'> >
    , mpl::pair<bvtags::bvcomp_tag,    mpl::string<'b', 'v', 'c', 'o', 'm', 'p'> >
    , mpl::pair<bvtags::concat_tag,    mpl::string<'c', 'o', 'n', 'c', 'a', 't'> >
    , mpl::pair<arraytags::select_tag, mpl::string<'s', 'e', 'l', 'e', 'c', 't'> >
    , mpl::pair<arraytags::store_tag,  mpl::string<'s', 't', 'o', 'r', 'e'> >
    , mpl::pair<bvtags::bvshl_tag,     mpl::string<'b', 'v', 's', 'h', 'l'> >
    , mpl::pair<bvtags::bvshr_tag,     mpl::string<'b', 'v', 'l', 's', 'h', 'r'> >
    , mpl::pair<bvtags::bvashr_tag,     mpl::string<'b', 'v', 'a', 's', 'h', 'r'> >
  > SMT_NameMap;
  /** \endcond **/

  template<typename Tag>
  inline typename boost::enable_if<
      typename mpl::has_key< SMT_NameMap, Tag>::type
    , std::string
    >::type
  get_tag_name(Tag const &t) {
    typedef typename mpl::at< SMT_NameMap, Tag >::type name;
    return mpl::c_str<name>::value;
  }

  template<typename Tag>
  inline typename boost::disable_if<
      typename mpl::has_key< SMT_NameMap, Tag>::type
    , std::string
    >::type
  get_tag_name(Tag const &t) {
    return "unknown_name";
  }

  typedef mpl::map7<
      mpl::pair<predtags::nequal_tag, mpl::pair<predtags::not_tag, predtags::equal_tag > >
    , mpl::pair<predtags::nand_tag, mpl::pair<predtags::not_tag, predtags::and_tag > >
    , mpl::pair<predtags::nor_tag, mpl::pair<predtags::not_tag, predtags::or_tag > >
    , mpl::pair<predtags::xnor_tag, mpl::pair<predtags::not_tag, predtags::xor_tag > >
    , mpl::pair<bvtags::bvnand_tag, mpl::pair<bvtags::bvnot_tag, bvtags::bvand_tag > >
    , mpl::pair<bvtags::bvnor_tag, mpl::pair<bvtags::bvnot_tag, bvtags::bvor_tag > >
    , mpl::pair<bvtags::bvxnor_tag, mpl::pair<bvtags::bvnot_tag, bvtags::bvxor_tag > >
  > SMT_Negated_Map;

} // metaSMT
<|endoftext|>