| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# 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.

    00023   : OutputStream(nam, pSvc), m_addrColumn(0),
    00024     m_isTopLeaf(false), m_collectionSvc(0)
    00025 {
    00026   declareProperty("AddressLeaf",      m_addrLeaf     = "/Event" );
    00027   declareProperty("AddressColumn",    m_addrColName  = "Address");
    00028   declareProperty("TagCollectionSvc", m_collSvcName  = "NTupleSvc");
    00029   declareProperty("ObjectsFirst",     m_objectsFirst = true);
    00030   declareProperty("Collection",       m_tagName );
    00031   m_addr = new GenericAddress();
    00032 }

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

Standard Destructor.

Definition at line 35 of file TagCollectionStream.cpp.

    00035                                             {
    00036   delete m_addr;
    00037 }

## Member Function Documentation

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.

    00158                                              {
    00159   StatusCode status = m_addrColumn == 0 ? connectAddress() : StatusCode::SUCCESS;
    00160   if ( status.isSuccess() )  {
    00161     status = m_objectsFirst ? writeData() : StatusCode::SUCCESS;
    00162     if ( status.isSuccess() )  {
    00163       if ( !m_addrColName.empty() )  {
    00164         SmartDataPtr<DataObject> top(eventSvc(), m_topLeafName);
    00165         if ( top != 0 )  {
    00166           IOpaqueAddress* pA = top->registry()->address();
    00167           if ( pA != 0 )  {
    00168             std::string*    par = (std::string*)m_addr->par();
    00169             unsigned long* ipar = (unsigned long*)m_addr->ipar();
    00170             m_addr->setClID(pA->clID());
    00171             m_addr->setSvcType(pA->svcType());
    00172             par[0]  = pA->par()[0];
    00173             par[1]  = pA->par()[1];
    00174             ipar[0] = pA->ipar()[0];
    00175             ipar[1] = pA->ipar()[1];
    00176             *(IOpaqueAddress**)(m_addrColumn->buffer()) = m_addr;
    00177             if ( m_isTopLeaf )  {
    00178               return writeRecord();
    00179             }
    00180             // Handle redirection mode. Normal tag collection mode
    00181             // is the same like leaving this out....
    00182             SmartDataPtr<DataObject> leaf(eventSvc(), m_addrLeaf);
    00183             if ( 0 != leaf )  {
    00184               IOpaqueAddress* redir = leaf->registry()->address();
    00185               if ( redir )  {
    00186                 par[0]  = redir->par()[0];
    00187                 ipar[0] = ~0x0;
    00188                 ipar[1] = redir->ipar()[1];
    00189                 return writeRecord();
    00190               }
    00191               MsgStream log3(msgSvc(), name());
    00192               log3 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
    00193                   << m_addrLeaf << "'s address not found." << endmsg;
    00194               return StatusCode::FAILURE;
    00195             }
    00196             MsgStream log2(msgSvc(), name());
    00197             log2 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
    00198                 << m_addrLeaf << " not found." << endmsg;
    00199             return StatusCode::FAILURE;
    00200           }
    00201           MsgStream log1(msgSvc(), name());
    00202           log1 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
    00203               << m_topLeafName << "'s address not found." << endmsg;
    00204           return StatusCode::FAILURE;
    00205         }
    00206         MsgStream log0(msgSvc(), name());
    00207         log0 << MSG::ERROR << "Failed to write tag collection " << m_tagName << ". "
    00208             << m_topLeafName << " not found." << endmsg;
    00209         return StatusCode::FAILURE;
    00210       }
    00211     }
    00212   }
    00213   return status;
    00214 }

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

Connect address column, if not already connected.

Definition at line 40 of file TagCollectionStream.cpp.

    00040                                                 {
    00041         MsgStream log(msgSvc(), name());
    00042   NTuplePtr nt(m_collectionSvc, m_tagName);
    00043   if ( nt )    {
    00044     m_addrColumn = nt->find(m_addrColName);
    00045     if ( 0 == m_addrColumn )  {
    00046       StatusCode sc = nt->addItem (m_addrColName,m_item);
    00047       if ( sc.isSuccess() )  {
    00048         m_addrColumn = m_item.operator->();
    00049         return sc;
    00050       }
    00051       log << MSG::ERROR << "Failed to add the address column:"
    00052           << m_addrColName << " to the tag collection " << m_tagName
    00053           << endmsg;
    00054       return sc;
    00055     }
    00056     return StatusCode::SUCCESS;
    00057   }
    00058   log << MSG::ERROR << "Failed to connect to the tag collection "
    00059       << m_tagName << endmsg;
    00060   return StatusCode::FAILURE;
    00061 }

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

Write data objects.

Definition at line 139 of file TagCollectionStream.cpp.

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

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

Write tuple data.

Definition at line 128 of file TagCollectionStream.cpp.

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

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

Write full event record.

Definition at line 150 of file TagCollectionStream.cpp.

    00150                                             {
    00151   if ( writeTuple().isSuccess() )  {
    00152     return m_objectsFirst ? StatusCode::SUCCESS : writeData();
    00153   }
    00154   return StatusCode::FAILURE;
    00155 }

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

Initialize TagCollectionStream.

Reimplemented from OutputStream.

Definition at line 64 of file TagCollectionStream.cpp.

    00064                                            {
    00065   std::string log_node, log_file, logical_name;
    00066   StatusCode sc = service(m_collSvcName, m_collectionSvc, true);
    00067   if ( sc.isSuccess() )  {
    00068     Tokenizer tok(true);
    00069     tok.analyse(m_output, " ", "", "", "=", "'", "'");
    00070     m_output = "";
    00071     for(Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); ++i)   {
    00072       const std::string& tag = (*i).tag();
    00073       const std::string& val = (*i).value();
    00074       switch( ::toupper(tag[0]) )    {
    00075       case 'C':
    00076         m_tagName = val;
    00077         break;
    00078       case 'A':
    00079         m_addrLeaf = val;
    00080         break;
    00081       default:
    00082         m_output += tag + "='" + val + "' ";
    00083         break;
    00084       }
    00085     }
    00086     std::string::size_type idx = m_tagName[0]==SEPARATOR ? m_tagName.find(SEPARATOR,1) : 0;
    00087     log_node = m_tagName.substr(idx,m_tagName.find(SEPARATOR,idx+1));
    00088     log_file = log_node + " " + m_output + " SHARED='YES'";
    00089   }
    00090   m_addrColumn = 0;                           // reset pointer to item column
    00091   sc = OutputStream::initialize();            // Now initialize the base class
    00092   if ( sc.isSuccess() )  {
    00093     SmartIF<IDataSourceMgr> src_mgr(m_collectionSvc);
    00094     if ( src_mgr.isValid() )  {
    00095       SmartIF<IDataManagerSvc> data_mgr(m_collectionSvc);
    00096       if ( data_mgr.isValid() )  {
    00097         logical_name = data_mgr->rootName();
    00098         logical_name += SEPARATOR;
    00099         logical_name += log_node;
    00100         m_topLeafName = m_addrLeaf.substr(0,m_addrLeaf.find(SEPARATOR,m_addrLeaf[0]=='/' ? 1 : 0));
    00101         m_isTopLeaf   = m_topLeafName == m_addrLeaf;
    00102         if ( src_mgr->isConnected(logical_name) )  {
    00103           return sc;
    00104         }
    00105         sc = src_mgr->connect(log_file);
    00106         if ( sc.isSuccess() )  {
    00107           return sc;
    00108         }
    00109       }
    00110     }
    00111   }
    00112         MsgStream log(msgSvc(), name());
    00113   log << MSG::ERROR << "Failed to initialize TagCollection Stream." << endmsg;
    00114   return StatusCode::FAILURE;
    00115 }

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

Terminate TagCollectionStream.

Reimplemented from OutputStream.

Definition at line 118 of file TagCollectionStream.cpp.

    00118                                          {
    00119   MsgStream log(msgSvc(), name());
    00120   StatusCode status = OutputStream::finalize();
    00121   if ( m_collectionSvc ) m_collectionSvc->release();
    00122   m_collectionSvc = 0;
    00123   m_addrColumn = 0;
    00124   return status;
    00125 }

## Member Data Documentation

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.

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

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

Definition at line 69 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_collSvcName`[protected]`

Property: Name of the collection service.

Definition at line 73 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.

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_topLeafName`[protected]`

Name of the top leaf (performance cache).

Definition at line 79 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.

INTupleSvc* TagCollectionStream::m_collectionSvc`[protected]`

Keep reference to the tuple service.

Definition at line 83 of file TagCollectionStream.h.

GenericAddress* TagCollectionStream::m_addr`[protected]`

Address buffer.

Definition at line 85 of file TagCollectionStream.h.

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

Address item buffer.

Definition at line 87 of file TagCollectionStream.h.

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

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