Empty buffer while serializing my ROOT class

Hi everyone,

I implemented a class that wrap a TObject for my DQM system :

Header :


class DQMMonitorElement : public TObject
{
public:

	/** Default constructor (for root serialization)
	 */
	DQMMonitorElement();

	/** Returns the element quality
	 */
	DQMQuality getQuality() const;

	/** Set the element quality
	 */
	void setQuality(DQMQuality quality);

	/** Returns the reset policy of the element. See enumerator definition
	 */
	DQMResetPolicy getResetPolicy() const;

	/** Sets the reset policy of the element. See enumerator definition
	 */
	void setResetPolicy(DQMResetPolicy policy);

	/** Returns the element type
	 */
	DQMMonitorElementType getType() const;

	/** Returns the name of the element which is often the root object name
	 */
	virtual const std::string &getName();

	/** Returns the title of the object which is often the root object title
	 */
	virtual const std::string &getTitle();

	/** Sets the element title
		*/
	virtual void setTitle(const std::string &title);

	/** Returns the element description
	 */
	const std::string &getDescription() const;

	/** Sets the element description
		*/
	void setDescription(const std::string &description);

	/** Return the draw option
	 */
	const std::string &getDrawOption() const;

	/** Set the draw option
	 */
	void setDrawOption(const std::string &drawOption);

	/** Returns the current run for this monitor element
	 */
	unsigned int getRunNumber() const;

	/** Sets whether the element has to be published at the next end of cycle.
	 *  This flag is not reset by the framework. The user is
	 *  responsible for publishing or not the element.
	 */
	void setToPublish(bool publish);

	/** Whether the element has to be published at the next end of cycle.
	 */
	bool isToPublish() const;

	/** Return the associated TObject that is monitored
	 */
	TObject *const getObject();

	/** Reset the element
	 */
	virtual void reset();

protected:

 /** DQMMonitorElement with type, name and title
  */
 DQMMonitorElement(TObject *pObject, DQMMonitorElementType type,
 		const std::string &name, const std::string &title);

 /** Destructor
  */
 virtual ~DQMMonitorElement();

	/** Sets the current run number
	 */
	void setRunNumber(unsigned int runNumber);

 //members
	TObject                        *m_pObject;             ///< The monitored TObject

 std::string                     m_name;                ///< The element name
 std::string                     m_title;               ///< The element title
 std::string                     m_description;        ///< The element description
 std::string                     m_drawOption;         ///< The draw option to apply while drawing

 DQMMonitorElementType         m_type;                  ///< The element type
 DQMQuality                    m_quality;               ///< The element quality has defined by the user
 DQMResetPolicy                m_resetPolicy;          ///< The reset policy. See enumerator definition

 unsigned int                   m_runNumber;           ///< The run number when the element is published
 bool                            m_toPublish;           ///< Whether the element has to be published at end of cycle

	// friend classes
 friend class DQMModuleApi;

 // ROOT class definition. Needed for streamers
 ClassDef(DQMMonitorElement, 1);
};

Source file :


ClassImp(lcdqm::DQMMonitorElement)
templateClassImp(lcdqm::TScalarObject)

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------

DQMMonitorElement::DQMMonitorElement() :
		m_type(NO_ELEMENT_TYPE),
		m_name(""),
		m_title(""),
		m_description(""),
		m_drawOption(""),
		m_quality(NO_QUALITY),
		m_resetPolicy(END_OF_CYCLE_RESET_POLICY),
		m_runNumber(0),
		m_toPublish(true),
		m_pObject(NULL)
{
	/* nop */
}

//-------------------------------------------------------------------------------------------------

DQMMonitorElement::DQMMonitorElement(TObject *pObject, DQMMonitorElementType type,
		const std::string &name, const std::string &title) :
		m_type(type),
		m_name(name),
		m_title(title),
		m_description(""),
		m_drawOption(""),
		m_quality(NO_QUALITY),
		m_resetPolicy(END_OF_CYCLE_RESET_POLICY),
		m_runNumber(0),
		m_toPublish(true),
		m_pObject(pObject)
{
	if(NULL == m_pObject)
		throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
}

//-------------------------------------------------------------------------------------------------

DQMMonitorElement::~DQMMonitorElement()
{
	if(NULL != m_pObject)
		delete m_pObject;
}

//-------------------------------------------------------------------------------------------------

DQMQuality DQMMonitorElement::getQuality() const
{
	return m_quality;
}

//-------------------------------------------------------------------------------------------------

void DQMMonitorElement::setQuality(DQMQuality quality)
{
	m_quality = quality;
}

//-------------------------------------------------------------------------------------------------

DQMResetPolicy DQMMonitorElement::getResetPolicy() const
{
	return m_resetPolicy;
}

//-------------------------------------------------------------------------------------------------

void DQMMonitorElement::setResetPolicy(DQMResetPolicy policy)
{
	m_resetPolicy = policy;
}

//-------------------------------------------------------------------------------------------------

DQMMonitorElementType DQMMonitorElement::getType() const
{
	return m_type;
}

//-------------------------------------------------------------------------------------------------

const std::string &DQMMonitorElement::getName()
{
	return m_name;
}

//-------------------------------------------------------------------------------------------------

const std::string &DQMMonitorElement::getTitle()
{
	return m_title;
}

//-------------------------------------------------------------------------------------------------

void DQMMonitorElement::setTitle(const std::string &title)
{
	m_title = title;
}

//-------------------------------------------------------------------------------------------------

const std::string &DQMMonitorElement::getDescription() const
{
	return m_description;
}

//-------------------------------------------------------------------------------------------------

void DQMMonitorElement::setDescription(const std::string &description)
{
	m_description = description;
}

//-------------------------------------------------------------------------------------------------

const std::string &DQMMonitorElement::getDrawOption() const
{
	return m_drawOption;
}

//-------------------------------------------------------------------------------------------------

void DQMMonitorElement::setDrawOption(const std::string &drawOption)
{
	m_drawOption = drawOption;
}

//-------------------------------------------------------------------------------------------------

unsigned int DQMMonitorElement::getRunNumber() const
{
	return m_runNumber;
}

//-------------------------------------------------------------------------------------------------

void DQMMonitorElement::setToPublish(bool toPublish)
{
	m_toPublish = toPublish;
}

//-------------------------------------------------------------------------------------------------

bool DQMMonitorElement::isToPublish() const
{
	return m_toPublish;
}

//-------------------------------------------------------------------------------------------------

void DQMMonitorElement::setRunNumber(unsigned int runNumber)
{
	m_runNumber = runNumber;
}

//-------------------------------------------------------------------------------------------------

TObject *const DQMMonitorElement::getObject()
{
	return m_pObject;
}

//-------------------------------------------------------------------------------------------------

void DQMMonitorElement::reset()
{
	m_pObject->Clear();
}

//-------------------------------------------------------------------------------------------------

At some point, I wanted to serialze my class using a TBufferFile object and get the raw buffer and buffer size.
I’m doing this (in a loop) :

                // ...

		DQMMonitorElement *pMonitorElement = *iter;
 
                // ...

		TBufferFile message(TBuffer::kWrite);
		message.SetBit(TBuffer::kIsOwner, false);
		message.WriteObject(pMonitorElement);

		m_serializedData.m_pBuffer = message.Buffer();
		m_serializedData.m_bufferSize = message.BufferSize();

		std::cout << "m_serializedData.m_pBuffer : " << m_serializedData.m_pBuffer << std::endl;
		std::cout << "strlen(m_serializedData.m_pBuffer) : " << strlen(m_serializedData.m_pBuffer) << std::endl;
		std::cout << "m_serializedData.m_bufferSize : " << m_serializedData.m_bufferSize << std::endl;

                 // ...

which gives me :

m_serializedData.m_pBuffer : @
strlen(m_serializedData.m_pBuffer) : 1
m_serializedData.m_bufferSize : 5036

I have the same problem with a TMessage implementation.
Have got any idea why the buffer is empty (or at least containing only a “@”) ?
Do I have to add an instruction before serialzing my object or before getting the buffer ?

Thanks for help !

RE

std::cout << "m_serializedData.m_pBuffer : " << m_serializedData.m_pBuffer << std::endl; std::cout << "strlen(m_serializedData.m_pBuffer) : " << strlen(m_serializedData.m_pBuffer) << std::endl;The result of streaming an object into a TBufferFile or TMessage is an extremely compact binary representation of the object which is both efficient in time and space. You can not treat the result as a string (neither calling strlen nor trying to print it as a string will give a meaningful result).

If you need a string representation of the object (which would be inefficient in both time and space and thus should not be used a DAQ system), you might consider looking into TBufferXML which will produce an xml representation of the object.

Cheers,
Philippe.