Gaudi Framework, version v22r4

Home   Generated: Fri Sep 2 2011
Public Member Functions | Private Attributes

CollectionCloneAlg Class Reference

Small algorithm, which allows to merge N-tuples in a generic way. More...

Inheritance diagram for CollectionCloneAlg:
Inheritance graph
[legend]
Collaboration diagram for CollectionCloneAlg:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CollectionCloneAlg (const std::string &name, ISvcLocator *pSvcLocator)
 Standard algorithm constructor.
virtual ~CollectionCloneAlg ()
 Standard Destructor.
virtual StatusCode initialize ()
 Initialize.
virtual StatusCode finalize ()
 Finalize.
virtual StatusCode execute ()
 Execute procedure.
virtual StatusCode book (const NTuple::Tuple *nt)
 Book the N-tuple according to the specification.
virtual StatusCode checkInput (const NTuple::Tuple *clone, const NTuple::Tuple *src)
StatusCode mergeEntries (const std::string &input)
 Merge the entries of a single input tuple into the output.
StatusCode connect ()
 Connect input and output N-tuples.
StatusCode mergeInputTuples ()
 Merge all N-tuple entries.

Private Attributes

INTupleSvcm_dataSvc
 Reference to data provider service.
std::string m_tupleSvc
 Name of the data provider service.
std::string m_output
 Output specification.
std::vector< std::stringm_inputs
 input specifications
std::string m_rootName
 Name of the root leaf (obtained at initialize)
std::string m_outName
 Output tuple name.
std::string m_criteria
 Selection criteria (if any)
std::string m_selectorName
 Selector factory.

Detailed Description

Small algorithm, which allows to merge N-tuples in a generic way.

In the options directory an python interface is presented, which shows how to steer this algorithm in a standaqlone program.

Author:
: M.Frank
Version:
: 1.0

Definition at line 127 of file CollectionCloneAlg.cpp.


Constructor & Destructor Documentation

CollectionCloneAlg::CollectionCloneAlg ( const std::string name,
ISvcLocator pSvcLocator 
) [inline]

Standard algorithm constructor.

Definition at line 147 of file CollectionCloneAlg.cpp.

  :     Algorithm(name, pSvcLocator),  m_dataSvc(0)
  {
    declareProperty("EvtTupleSvc", m_tupleSvc="EvtTupleSvc");
    declareProperty("Input",       m_inputs);
    declareProperty("Output",      m_output);
  }
virtual CollectionCloneAlg::~CollectionCloneAlg (  ) [inline, virtual]

Standard Destructor.

Definition at line 155 of file CollectionCloneAlg.cpp.

                                    {
  }

Member Function Documentation

virtual StatusCode CollectionCloneAlg::book ( const NTuple::Tuple nt ) [inline, virtual]

Book the N-tuple according to the specification.

Definition at line 220 of file CollectionCloneAlg.cpp.

                                                  {
    MsgStream log(msgSvc(), name());
    const INTuple::ItemContainer& items = nt->items();
    StatusCode status = StatusCode::SUCCESS;
    INTuple::ItemContainer::const_iterator i;
    NTuple::Tuple* tuple = m_dataSvc->book(m_outName, nt->clID(), nt->title());
    for (i = items.begin(); i != items.end(); ++i)  {
      long type = (*i)->type();
      switch(type)  {
      case DataTypeInfo::UCHAR:
        status = createItem(log, tuple, *i, (unsigned char)0);
        break;
      case DataTypeInfo::USHORT:
        status = createItem(log, tuple, *i, (unsigned short)0);
        break;
      case DataTypeInfo::UINT:
        status = createItem(log, tuple, *i, (unsigned int)0);
        break;
      case DataTypeInfo::ULONG:
        status = createItem(log, tuple, *i, (unsigned long)0);
        break;
      case DataTypeInfo::CHAR:
        status = createItem(log, tuple, *i, char(0));
        break;
      case DataTypeInfo::SHORT:
        status = createItem(log, tuple, *i, short(0));
        break;
      case DataTypeInfo::INT:
        status = createItem(log, tuple, *i, int(0));
        break;
      case DataTypeInfo::LONG:
        status = createItem(log, tuple, *i, long(0));
        break;
      case DataTypeInfo::BOOL:
        status = createItem(log, tuple, *i, false);
        break;
      case DataTypeInfo::FLOAT:
        status = createItem(log, tuple, *i, float(0.0));
        break;
      case DataTypeInfo::DOUBLE:
        status = createItem(log, tuple, *i, double(0.0));
        break;
      case DataTypeInfo::OBJECT_ADDR:
        status = createItem(log, tuple, *i, (IOpaqueAddress*)0);
        break;
      case DataTypeInfo::POINTER:
        status = createItem(log, tuple, *i, (void*)0);
        break;
      case DataTypeInfo::STRING:
//        status = createItem(log, tuple, *i, (std::string*)0);
//        break;
      case DataTypeInfo::NTCHAR:
//        status = createItem(log, tuple, *i, (char*)0);
//        break;
      case DataTypeInfo::UNKNOWN:
      default:
        status = StatusCode::FAILURE;
        break;
      }
    }
    return status;
  }
virtual StatusCode CollectionCloneAlg::checkInput ( const NTuple::Tuple clone,
const NTuple::Tuple src 
) [inline, virtual]

Definition at line 284 of file CollectionCloneAlg.cpp.

                                                                                   {
    MsgStream log(msgSvc(), name());
    if ( 0 != clone && 0 != src )   {
      const INTuple::ItemContainer& clone_items  = clone->items();
      const std::string clone_id = clone->registry()->identifier();
      const std::string src_id = src->registry()->identifier();

      INTuple::ItemContainer::const_iterator i;
      log << MSG::ERROR;
      for (i = clone_items.begin(); i != clone_items.end(); ++i)  {
        const INTupleItem* itm = *i;
        const std::string& nam = itm->name();
        const INTupleItem* src_itm = src->find(nam);
        if ( !src_itm )  {
          log << "Tuple item " << nam << " not present in " << src_id << endmsg;
          return StatusCode::FAILURE;
        }
        if ( itm->type() != src_itm->type() )  {
          log << "Tuple item " << nam << " are of different types in "
            << src_id   << ":" << src_itm->typeName() << " <-> "
            << clone_id << ":" << itm->typeName() << endmsg;
          return StatusCode::FAILURE;
        }
        if ( itm->ndim() != src_itm->ndim() )  {
          log << "Tuple item " << nam << " have different dimensions in "
            << src_id   << ":" << src_itm->ndim() << " <-> "
            << clone_id << ":" << itm->ndim() << endmsg;
          return StatusCode::FAILURE;
        }
        for (int j=0; j<itm->ndim(); ++j)  {
          if ( src_itm->dim(j) != itm->dim(j) )  {
            log << "Tuple item " << nam << " have different dimensions in "
              << src_id   << "[" << j << "]:" << src_itm->dim(j) << " <-> "
              << clone_id << "[" << j << "]:" << itm->dim(j) << endmsg;
            return StatusCode::FAILURE;
          }
        }
        if ( itm->hasIndex() != src_itm->hasIndex() )  {
          log << "Tuple item " << nam << " has different index colums "
            << src_id   << ":" << src_itm->hasIndex() << " <-> "
            << clone_id << ":" << itm->hasIndex() << endmsg;
          return StatusCode::FAILURE;
        }
        if ( itm->hasIndex() )  {
          if ( itm->index() != src_itm->index() )  {
            log << "Tuple item " << nam << " has different index colums "
              << src_id   << ":" << src_itm->index() << " <-> "
              << clone_id << ":" << itm->index() << endmsg;
            return StatusCode::FAILURE;
          }
        }
      }
      return StatusCode::SUCCESS;
    }
    return StatusCode::FAILURE;
  }
StatusCode CollectionCloneAlg::connect (  ) [inline]

Connect input and output N-tuples.

Definition at line 452 of file CollectionCloneAlg.cpp.

                         {
    StatusCode status = StatusCode::SUCCESS;
    for (size_t i=0; i < m_inputs.size(); ++i)  {
      NTuplePtr nt(m_dataSvc, m_inputs[i]);
      if ( !(0 == nt) )    {
        NTuplePtr out(m_dataSvc, m_outName);
        if ( 0 == out )  {
          status = book(nt);
        }
        else  {
          status = checkInput(out, nt);
        }
        if ( !status.isSuccess() )  {
          return status;
        }
        else if ( m_selectorName != "" )   {
          SmartIF<ISelectStatement> stmt(ROOT::Reflex::PluginService::Create<IInterface*>(m_selectorName,serviceLocator()));
          if ( stmt.isValid( ) )    {
            if ( m_criteria.length() > 0 ) stmt->setCriteria(m_criteria);
            nt->attachSelector(stmt);
          }
          else  {
            MsgStream log(msgSvc(), name());
            log << MSG::ERROR << "Failed to attach tuple selector to " << m_inputs[i] << endmsg;
            return StatusCode::FAILURE;
          }
        }
      }
      else  {
        MsgStream log(msgSvc(), name());
        log << MSG::ERROR << "Failed to access tuple: " << m_inputs[i] << endmsg;
        return StatusCode::FAILURE;
      }
    }
    return StatusCode::SUCCESS;
  }
virtual StatusCode CollectionCloneAlg::execute ( void   ) [inline, virtual]

Execute procedure.

Definition at line 211 of file CollectionCloneAlg.cpp.

                                  {
    StatusCode status = connect();
    if ( status.isSuccess() )  {
      status = mergeInputTuples();
    }
    return status;
  }
virtual StatusCode CollectionCloneAlg::finalize ( void   ) [inline, virtual]

Finalize.

Reimplemented from Algorithm.

Definition at line 204 of file CollectionCloneAlg.cpp.

virtual StatusCode CollectionCloneAlg::initialize ( void   ) [inline, virtual]

Initialize.

Reimplemented from Algorithm.

Definition at line 159 of file CollectionCloneAlg.cpp.

                                    {
    MsgStream log(msgSvc(), name());
    m_rootName = "";
    m_outName = "";
    m_criteria = "";
    m_selectorName = "";
    StatusCode sc = service(m_tupleSvc, m_dataSvc, true);
    if ( sc.isSuccess() )  {
      std::string fun;
      Tokenizer tok(true);
      tok.analyse(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 'D':
          m_outName = val;
          break;
        case 'S':
          m_criteria = val;
          break;
        case 'F':
          fun = val;
          break ;
        default:
          break;
        }
      }
      if ( m_outName.empty() )  {
        log << MSG::ERROR << "Failed to analyze output specs:" << m_output << endmsg;
        return StatusCode::FAILURE;
      }
      if ( fun.length() > 0 || m_criteria.length() > 0 )   {
        if ( m_criteria.length() > 0 && fun.length() == 0 ) fun = "NTuple::Selector";
        m_selectorName = fun;
        return StatusCode::SUCCESS;
      }
      return sc;
    }
    log << MSG::ERROR << "Failed to access service \""
        << m_tupleSvc << "\"." << endmsg;
    return sc;
  }
StatusCode CollectionCloneAlg::mergeEntries ( const std::string input ) [inline]

Merge the entries of a single input tuple into the output.

Definition at line 342 of file CollectionCloneAlg.cpp.

                                                   {
    MsgStream log(msgSvc(), name());
    NTuplePtr out(m_dataSvc, m_outName);
    if ( 0 != out )  {
      const INTuple::ItemContainer& clone_items  = out->items();
      std::vector<GenericAddress> addrVector(clone_items.size());
      StatusCode status = StatusCode::SUCCESS;
      NTuplePtr nt(m_dataSvc, input);
      size_t k = 0, nentry = 0;
      if ( 0 != nt ) {
        const INTuple::ItemContainer& source_items = nt->items();
        for (k=0; k < source_items.size(); ++k )  {
          if ( source_items[k]->type() == DataTypeInfo::OBJECT_ADDR )  {
            *(IOpaqueAddress**)source_items[k]->buffer() = &addrVector[k];
          }
        }
        while ( status.isSuccess() ) {
          status = m_dataSvc->readRecord(nt.ptr());
          if ( status.isSuccess() )   {
            INTuple::ItemContainer::const_iterator i;
            nentry++;
            for (k=0,i = source_items.begin(); i != source_items.end(); ++i,++k)  {
              const INTupleItem* src_itm = *i;
              const INTupleItem* out_itm = out->find(src_itm->name());
              size_t size = 0;
              switch((*i)->type())  {
              case DataTypeInfo::UCHAR:
                size = sizeof(unsigned char);
                break;
              case DataTypeInfo::USHORT:
                size = sizeof(unsigned short);
                break;
              case DataTypeInfo::UINT:
                size = sizeof(unsigned int);
                break;
              case DataTypeInfo::ULONG:
                size = sizeof(unsigned long);
                break;
              case DataTypeInfo::CHAR:
                size = sizeof(char);
                break;
              case DataTypeInfo::SHORT:
                size = sizeof(short);
                break;
              case DataTypeInfo::INT:
                size = sizeof(int);
                break;
              case DataTypeInfo::LONG:
                size = sizeof(long);
                break;
              case DataTypeInfo::BOOL:
                size = sizeof(bool);
                break;
              case DataTypeInfo::FLOAT:
                size = sizeof(float);
                break;
              case DataTypeInfo::DOUBLE:
                size = sizeof(double);
                break;
              case DataTypeInfo::STRING:
                *(std::string*)out_itm->buffer() = *(std::string*)src_itm->buffer();
                size = 0;
                break;
              case DataTypeInfo::NTCHAR:
                size = ::strlen((const char*)src_itm->buffer())+1;
                break;
              case DataTypeInfo::POINTER:
                {
                  *(void**)out_itm->buffer() = *(void**)src_itm->buffer();
                  size = 0;
                }
                break;
              case DataTypeInfo::OBJECT_ADDR:
                {
                IOpaqueAddress* ppA1  = &addrVector[k];
                IOpaqueAddress** ppA2 = (IOpaqueAddress**)out_itm->buffer();
                *ppA2 = ppA1;
                size = 0;
                }
                break;
              case DataTypeInfo::UNKNOWN:
              default:
                size = 0;
                break;
              }
              if ( size > 0 )  {
                ::memcpy((void*)out_itm->buffer(), src_itm->buffer(), size*src_itm->length());
              }
            }
            status = m_dataSvc->writeRecord(out.ptr());
            if ( !status.isSuccess() )  {
              log << MSG::ERROR << "Failed to write record " << nentry
                  << " from " << input << " to " << m_outName << endmsg;
            }
          }
        }
        log << MSG::INFO << "End of reading tuple " << input
            << " after " << nentry << " entries." << endmsg;

        if ( nentry > 0 || m_selectorName != "" )  {
          return StatusCode::SUCCESS;
        }
        return StatusCode::FAILURE;
      }
      log << MSG::ERROR << "Failed to access input: " << input << endmsg;
    }
    return StatusCode::FAILURE;
  }
StatusCode CollectionCloneAlg::mergeInputTuples (  ) [inline]

Merge all N-tuple entries.

Definition at line 490 of file CollectionCloneAlg.cpp.

                                 {
    MsgStream log(msgSvc(), name());
    for (size_t inp=0; inp < m_inputs.size(); ++inp)  {
      StatusCode sc = mergeEntries(m_inputs[inp]);
      if ( !sc.isSuccess() )  {
        log << MSG::ERROR << "Failed to merge tuple:" << m_inputs[inp] << endmsg;
        return sc;
      }
    }
    return StatusCode::SUCCESS;
  }

Member Data Documentation

Selection criteria (if any)

Definition at line 141 of file CollectionCloneAlg.cpp.

Reference to data provider service.

Definition at line 129 of file CollectionCloneAlg.cpp.

input specifications

Definition at line 135 of file CollectionCloneAlg.cpp.

Output tuple name.

Definition at line 139 of file CollectionCloneAlg.cpp.

Output specification.

Definition at line 133 of file CollectionCloneAlg.cpp.

Name of the root leaf (obtained at initialize)

Definition at line 137 of file CollectionCloneAlg.cpp.

Selector factory.

Definition at line 143 of file CollectionCloneAlg.cpp.

Name of the data provider service.

Definition at line 131 of file CollectionCloneAlg.cpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Fri Sep 2 2011 16:25:15 for Gaudi Framework, version v22r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004