| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Public Member Functions | Protected Member Functions | Protected Attributes

# TagCollectionStream Class Reference

Specialized output stream class for event tag collections, where the basic Event entry point should be placed as well into the collection itself. More...

`#include <PersistencySvc/TagCollectionStream.h>`

Inheritance diagram for TagCollectionStream:
[legend]
Collaboration diagram for TagCollectionStream:
[legend]

List of all members.

## Public Member Functions
| TagCollectionStream (const std::string &name, ISvcLocator *pSvcLocator)
| Standard algorithm Constructor.
virtual | ~TagCollectionStream ()
| Standard Destructor.
virtual StatusCode | initialize ()
| Initialize TagCollectionStream.
virtual StatusCode | finalize ()
| Terminate TagCollectionStream.
## Protected Member Functions
virtual StatusCode | writeObjects ()
| OutputStream override: Select the different objects and write them to file.
virtual StatusCode | connectAddress ()
| Connect address column, if not already connected.
StatusCode | writeData ()
| Write data objects.
StatusCode | writeTuple ()
| Write tuple data.
StatusCode | writeRecord ()
| Write full event record.
## Protected Attributes
std::string | m_addrLeaf
| Property: Name of the address leaf in the transient event store.
std::string | m_addrColName
| Property: Name of the address column of the tag collection.
std::string | m_tagName
| Property: Name of the tag collection in the transient store.
std::string | m_collSvcName
| Property: Name of the collection service.
bool | m_objectsFirst
| Property: Flag to indicate that the objects should be written first.
INTupleItem * | m_addrColumn
| NTuple column to hold the opaque address of the address leaf.
std::string | m_topLeafName
| Name of the top leaf (performance cache)
bool | m_isTopLeaf
| Short cut flag to indicate if the address leaf is the top leaf (performace cache)
INTupleSvc * | m_collectionSvc
| Keep reference to the tuple service.
GenericAddress * | m_addr
| Address buffer.
NTuple::Item< IOpaqueAddress * > | m_item
| Address item buffer.

## Detailed Description

Specialized output stream class for event tag collections, where the basic Event entry point should be placed as well into the collection itself.

The TagCollectionStream is a rather specialized object combining features of NTuple I/O and object I/O. The main working points are:

1) Write a "normal" tag collection. The address column [property AddressColumn, default:"Address"] is added to the Ntuple identified by its name [mandatory property Collection]. The address column is set to the opaque address of the specified leaf [property "AddressLeaf", default:"/Event"]. The NTuple must be registered to the TES of the service [property: TagCollectionSvc, default:"NTupleSvc"]. This is the normal mode event tag collections work.

2) Write a tag collection with "REDIRECTED INPUT". Example: The collection is created from an intermediate file (MINI DST), but the Address column of the NTuple should point to the file e.g. containing the raw data.

- Set the property "AddressLeaf" to something different from "/Event" e.g. "/Event/DAQ/RawEvent"

Note: The actual address of "/Event" get changed. No other output should be created after writing such a tag collection.

3) Write an "EMBEDDED COLLECTION". In this mode the OutputStream and the NTuple stream are combined. depending on the property TagCollectionStream.ObjectsFirst the objects are written first and the the tags. The tag file and the file containing the objects may be identical.

Note:

- Also if the OutputStream features are NOT used, the options must still be properly set.

- Tags or objects are only written to the output stream if the event is accepted according to the output stream criteria (veto algorithms, etc.)

- If the address column is not present in the N-tuple (ie. it was not added by the N-tuple creator), it is automatically added at the first write attempt.

- If the logical N-tuple output file is not yet connected to the tuple service, it is automatically connected to the the same as the OutputStream device.

Author: M.Frank Version: 1.0

Definition at line 63 of file TagCollectionStream.h.

## Constructor & Destructor Documentation

TagCollectionStream::TagCollectionStream | ( | const std::string & | name,
|  | ISvcLocator * | pSvcLocator
| ) |  |

Standard algorithm Constructor.

Definition at line 22 of file TagCollectionStream.cpp.

      : OutputStream(nam, pSvc), m_addrColumn(0),
        m_isTopLeaf(false), m_collectionSvc(0)
    {
      declareProperty("AddressLeaf",      m_addrLeaf     = "/Event" );
      declareProperty("AddressColumn",    m_addrColName  = "Address");
      declareProperty("TagCollectionSvc", m_collSvcName  = "NTupleSvc");
      declareProperty("ObjectsFirst",     m_objectsFirst = true);
      declareProperty("Collection",       m_tagName );
      m_addr = new GenericAddress();
    }

TagCollectionStream::~TagCollectionStream | ( | ) | `[virtual]`

Standard Destructor.

Definition at line 35 of file TagCollectionStream.cpp.

                                                {
      delete m_addr;
    }

## Member Function Documentation

StatusCode TagCollectionStream::connectAddress | ( | ) | `[protected, virtual]`

Connect address column, if not already connected.

Definition at line 40 of file TagCollectionStream.cpp.

                                                    {
            MsgStream log(msgSvc(), name());
      NTuplePtr nt(m_collectionSvc, m_tagName);
      if ( nt )    {
        m_addrColumn = nt->find(m_addrColName);
        if ( 0 == m_addrColumn )  {
          StatusCode sc = nt->addItem (m_addrColName,m_item);
          if ( sc.isSuccess() )  {
            m_addrColumn = m_item.operator->();
            return sc;
          }
          log << MSG::ERROR << "Failed to add the address column:"
              << m_addrColName << " to the tag collection " << m_tagName
              << endmsg;
          return sc;
        }
        return StatusCode::SUCCESS;
      }
      log << MSG::ERROR << "Failed to connect to the tag collection "
          << m_tagName << endmsg;
      return StatusCode::FAILURE;
    }

StatusCode TagCollectionStream::finalize | ( | void | ) | `[virtual]`

Terminate TagCollectionStream.

Reimplemented from OutputStream.

Definition at line 118 of file TagCollectionStream.cpp.

                                             {
      MsgStream log(msgSvc(), name());
      StatusCode status = OutputStream::finalize();
      if ( m_collectionSvc ) m_collectionSvc->release();
      m_collectionSvc = 0;
      m_addrColumn = 0;
      return status;
    }

StatusCode TagCollectionStream::initialize | ( | void | ) | `[virtual]`

Initialize TagCollectionStream.

Reimplemented from OutputStream.

Definition at line 64 of file TagCollectionStream.cpp.

                                               {
      std::string log_node, log_file, logical_name;
      StatusCode sc = service(m_collSvcName, m_collectionSvc, true);
      if ( sc.isSuccess() )  {
        Tokenizer tok(true);
        tok.analyse(m_output, " ", "", "", "=", "'", "'");
        m_output = "";
        for(Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); ++i)   {
          const std::string& tag = (*i).tag();
          const std::string& val = (*i).value();
          switch( ::toupper(tag[0]) )    {
          case 'C':
            m_tagName = val;
            break;
          case 'A':
            m_addrLeaf = val;
            break;
          default:
            m_output += tag + "='" + val + "' ";
            break;
          }
        }
        std::string::size_type idx = m_tagName[0]==SEPARATOR ? m_tagName.find(SEPARATOR,1) : 0;
        log_node = m_tagName.substr(idx,m_tagName.find(SEPARATOR,idx+1));
        log_file = log_node + " " + m_output + " SHARED='YES'";
      }
      m_addrColumn = 0;                           // reset pointer to item column
      sc = OutputStream::initialize();            // Now initialize the base class
      if ( sc.isSuccess() )  {
        SmartIF<IDataSourceMgr> src_mgr(m_collectionSvc);
        if ( src_mgr.isValid() )  {
          SmartIF<IDataManagerSvc> data_mgr(m_collectionSvc);
          if ( data_mgr.isValid() )  {
            logical_name = data_mgr->rootName();
            logical_name += SEPARATOR;
            logical_name += log_node;
            m_topLeafName = m_addrLeaf.substr(0,m_addrLeaf.find(SEPARATOR,m_addrLeaf[0]=='/' ? 1 : 0));
            m_isTopLeaf   = m_topLeafName == m_addrLeaf;
            if ( src_mgr->isConnected(logical_name) )  {
              return sc;
            }
            sc = src_mgr->connect(log_file);
            if ( sc.isSuccess() )  {
              return sc;
            }
          }
        }
      }
            MsgStream log(msgSvc(), name());
      log << MSG::ERROR << "Failed to initialize TagCollection Stream." << endmsg;
      return StatusCode::FAILURE;
    }

StatusCode TagCollectionStream::writeData | ( | ) | `[protected]`

Write data objects.

Definition at line 139 of file TagCollectionStream.cpp.

                                              {
      StatusCode sc = OutputStream::writeObjects();
      if ( !sc.isSuccess() )  {
        MsgStream log(msgSvc(), name());
        log << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
            << "[Object write error]" << endmsg;
      }
      return sc;
    }

StatusCode TagCollectionStream::writeObjects | ( | ) | `[protected, virtual]`

OutputStream override: Select the different objects and write them to file.

Reimplemented from OutputStream.

Definition at line 158 of file TagCollectionStream.cpp.

                                                 {
      StatusCode status = m_addrColumn == 0 ? connectAddress() : StatusCode::SUCCESS;
      if ( status.isSuccess() )  {
        status = m_objectsFirst ? writeData() : StatusCode::SUCCESS;
        if ( status.isSuccess() )  {
          if ( !m_addrColName.empty() )  {
            SmartDataPtr<DataObject> top(eventSvc(), m_topLeafName);
            if ( top != 0 )  {
              IOpaqueAddress* pA = top->registry()->address();
              if ( pA != 0 )  {
                std::string*    par = (std::string*)m_addr->par();
                unsigned long* ipar = (unsigned long*)m_addr->ipar();
                m_addr->setClID(pA->clID());
                m_addr->setSvcType(pA->svcType());
                par[0]  = pA->par()[0];
                par[1]  = pA->par()[1];
                ipar[0] = pA->ipar()[0];
                ipar[1] = pA->ipar()[1];
                *(IOpaqueAddress**)(m_addrColumn->buffer()) = m_addr;
                if ( m_isTopLeaf )  {
                  return writeRecord();
                }
                // Handle redirection mode. Normal tag collection mode
                // is the same like leaving this out....
                SmartDataPtr<DataObject> leaf(eventSvc(), m_addrLeaf);
                if ( 0 != leaf )  {
                  IOpaqueAddress* redir = leaf->registry()->address();
                  if ( redir )  {
                    par[0]  = redir->par()[0];
                    ipar[0] = ~0x0;
                    ipar[1] = redir->ipar()[1];
                    return writeRecord();
                  }
                  MsgStream log3(msgSvc(), name());
                  log3 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
                      << m_addrLeaf << "'s address not found." << endmsg;
                  return StatusCode::FAILURE;
                }
                MsgStream log2(msgSvc(), name());
                log2 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
                    << m_addrLeaf << " not found." << endmsg;
                return StatusCode::FAILURE;
              }
              MsgStream log1(msgSvc(), name());
              log1 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
                  << m_topLeafName << "'s address not found." << endmsg;
              return StatusCode::FAILURE;
            }
            MsgStream log0(msgSvc(), name());
            log0 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
                << m_topLeafName << " not found." << endmsg;
            return StatusCode::FAILURE;
          }
        }
      }
      return status;
    }

StatusCode TagCollectionStream::writeRecord | ( | ) | `[protected]`

Write full event record.

Definition at line 150 of file TagCollectionStream.cpp.

                                                {
      if ( writeTuple().isSuccess() )  {
        return m_objectsFirst ? StatusCode::SUCCESS : writeData();
      }
      return StatusCode::FAILURE;
    }

StatusCode TagCollectionStream::writeTuple | ( | ) | `[protected]`

Write tuple data.

Definition at line 128 of file TagCollectionStream.cpp.

                                               {
      StatusCode sc = m_collectionSvc->writeRecord(m_tagName);
      if ( !sc.isSuccess() )  {
        MsgStream log(msgSvc(), name());
        log << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
            << "[Tuple write error]" << endmsg;
      }
      return sc;
    }

## Member Data Documentation

GenericAddress* TagCollectionStream::m_addr`[protected]`

Address buffer.

Definition at line 85 of file TagCollectionStream.h.

std::string TagCollectionStream::m_addrColName`[protected]`

Property: Name of the address column of the tag collection.

Definition at line 69 of file TagCollectionStream.h.

INTupleItem* TagCollectionStream::m_addrColumn`[protected]`

NTuple column to hold the opaque address of the address leaf.

Definition at line 77 of file TagCollectionStream.h.

std::string TagCollectionStream::m_addrLeaf`[protected]`

Property: Name of the address leaf in the transient event store.

Definition at line 67 of file TagCollectionStream.h.

INTupleSvc* TagCollectionStream::m_collectionSvc`[protected]`

Keep reference to the tuple service.

Definition at line 83 of file TagCollectionStream.h.

std::string TagCollectionStream::m_collSvcName`[protected]`

Property: Name of the collection service.

Definition at line 73 of file TagCollectionStream.h.

bool TagCollectionStream::m_isTopLeaf`[protected]`

Short cut flag to indicate if the address leaf is the top leaf (performace cache)

Definition at line 81 of file TagCollectionStream.h.

NTuple::Item<IOpaqueAddress*> TagCollectionStream::m_item`[protected]`

Address item buffer.

Definition at line 87 of file TagCollectionStream.h.

bool TagCollectionStream::m_objectsFirst`[protected]`

Property: Flag to indicate that the objects should be written first.

Definition at line 75 of file TagCollectionStream.h.

std::string TagCollectionStream::m_tagName`[protected]`

Property: Name of the tag collection in the transient store.

Definition at line 71 of file TagCollectionStream.h.

std::string TagCollectionStream::m_topLeafName`[protected]`

Name of the top leaf (performance cache)

Definition at line 79 of file TagCollectionStream.h.

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/GaudiSvc/src/PersistencySvc/TagCollectionStream.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/GaudiSvc/src/PersistencySvc/TagCollectionStream.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines