RootTreeSink

Name

RootTreeSink -- Event sink that writes root trees.

Synopsis


class RootTreeSink : public CEventSink
{

public:
    RootTreeSink(
        std::string name, const std::vector<std::string>& patterns,
        CGateContainer* m_pGate
    );
    void OnOpen(TFile* pNewFile);
    void OnAboutToClose();
    virtual void operator()(CEventList& rEvents);
    const std::vector<std::string>& getParameterPatterns() const;
    CGateContainer& getGate();
    
};
        

DESCRIPTION

This class is an event sink that writes root trees. It works in close cooperation with the RootEventProcessor. In normal SpecTcl operation you won't need to interact programmatically with these classes.

Since event sinks know nothing of run boundaries, the paring of RootTreeSink with a managing event processor, RootEventProcessor, allows that information to be communicated between the event processing pipeline and the event sink.

METHODS

RootTreeSink(std::string name, const std::vector<std::string>& patterns, CGateContainer* pGate);

Constructs a sink. Note that the constructing code must still add the sink to the event sink pipeline. Construction generates sufficient information to automatically construct a TTree object when the root file is opened and automatically fill it as event are seen.

name is used as the name of the TTree object when it is constructed.

patterns is a vector of glob patterns. These describe the parameters that will be written to the tree. To write all parameters, for example,just have a single element vector contaning *.

pGate is a pointer to the gate container used to conditionalize filling events into the tree. Note that if you want to write all events to the tree, supply a pointer to a gate container that contains a true gate.

void OnOpen(TFile* pNewFile);

RootTreeSink objects rely on their RootEventProcessor to manage their connections to files. This event processor will open the output root file at the beginning of a run and invok OnOpen for each RootTreeSink it knows about.

The sink then creates its TTree objects and associated branches into the file pNewFile.

void OnAboutToClose();

Called by the associated event processor when the TFile* handed to this object on the previous call to OnOpen is about to be closed. This method allows the sink to flush any unwritten data to file.

On return the file the sink's tree was created into will be closed. After that it's not safe to write any data until another call to OnOpen.

virtual void operator()(CEventList& rEvents);

Called when the event sink has data to process. Each event in the rEvents that satisfies the gate, should be filled into the tree.

It is important that there be an open file (call to OnOpen that is not paired with a OnAboutToClose).

const const std::vector<std::string>& getParameterPatterns();

Returns the set of patterns that describe the parameters written to trees. Note that this is not the set of parameters but the set of glob patterns on which this object was constructed,

CGateContainer& getGate();

Returns a reference to the gate container that contains the gate which is used to determine which events are written to file. Note that the reference is not const so it is possible to change the gate contained by the container.