/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Static Public Member Functions | Private Attributes
DybStorageSvc Class Reference

Implementation of IDybStorageSvc. More...

#include <DybStorageSvc.h>

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

List of all members.

Public Member Functions

 DybStorageSvc (const std::string &name, ISvcLocator *svc)
virtual ~DybStorageSvc ()
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode store (const IRegistrationSequence &regSeq)
virtual StatusCode store (DataObject *object, const std::string &path)
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)

Static Public Member Functions

static const InterfaceID & interfaceID ()

Private Attributes

IConversionSvc * m_cnv
ToolHandleArray< IRegSeqVisitorm_rsVisitors

Detailed Description

Implementation of IDybStorageSvc.

bv@bnl.gov Mon Jul 14 02:38:04 2008

Definition at line 22 of file DybStorageSvc.h.


Constructor & Destructor Documentation

DybStorageSvc::DybStorageSvc ( const std::string &  name,
ISvcLocator *  svc 
)

Definition at line 20 of file DybStorageSvc.cc.

    : Service(name,svc)
    , m_cnv(0)
{
    declareProperty("RegSeqVisitors",  m_rsVisitors,
                    "List IRegSeqVisitors" );
}
DybStorageSvc::~DybStorageSvc ( ) [virtual]

Definition at line 28 of file DybStorageSvc.cc.

{
}

Member Function Documentation

StatusCode DybStorageSvc::initialize ( ) [virtual]

Definition at line 32 of file DybStorageSvc.cc.

{
    StatusCode sc = Service::initialize();
    if (sc.isFailure()) return sc;

    MsgStream log(msgSvc(), "DybStorageSvc");

    sc = serviceLocator()->getService("RootIOCnvSvc",
                                      IID_IConversionSvc,
                                      *pp_cast<IInterface>(&m_cnv));
    if (sc.isFailure()) {
        log << MSG::ERROR
            << "Failed to get IConversionSvc RootIOCnvSvc" << endreq;
        return sc;
    }

    sc = m_rsVisitors.retrieve();
    if (sc.isFailure()) {
        log << MSG::ERROR
            << "Failed to retrieve IRegSeqVisitors" << endreq;
        return sc;
    }

    // info
    ToolHandleArray<IRegSeqVisitor>::iterator it, done = m_rsVisitors.end();
    for (it = m_rsVisitors.begin(); it != done; ++it) {
        AlgTool* tool = dynamic_cast<AlgTool*>(&**it);
        if (tool) {
            log << MSG::INFO << "Got RegSeqVisitor: " << tool->name() << endreq;
        }
    }

    return StatusCode::SUCCESS;
}
StatusCode DybStorageSvc::finalize ( ) [virtual]

Definition at line 67 of file DybStorageSvc.cc.

{
    return StatusCode::SUCCESS;
}
StatusCode DybStorageSvc::store ( const IRegistrationSequence regSeq) [virtual]

Implements IDybStorageSvc.

Definition at line 72 of file DybStorageSvc.cc.

{
    MsgStream log(msgSvc(), "DybStorageSvc");

    RegistrationSequence* regSeq = 
        const_cast<RegistrationSequence*>(
            dynamic_cast<const RegistrationSequence*>(&iregSeq));

    if (!regSeq) {
        log << MSG::ERROR
            << "given an IRegistrationSequence that " 
            << "is not a RegistrationSequence"
            << endreq;
        return StatusCode::FAILURE;
    }
    
    // give a chance for any visitors to visit the RS
    {                           
        ToolHandleArray<IRegSeqVisitor>::iterator it, done = m_rsVisitors.end();
        for (it = m_rsVisitors.begin(); it != done; ++it) {
            { // debug
                AlgTool* tool = dynamic_cast<AlgTool*>(&**it);
                if (tool) {
                    log << MSG::DEBUG << "Calling RegSeqVisitor: " << tool->name() << endreq;
                }
            }
            StatusCode sc = (*it)->visit(*regSeq);
            if (sc.isFailure()) {
                log << MSG::ERROR 
                    << "RegistartionSequence visitor failed" << endreq;
                return sc;
            }
        }
    }

    // wangzhe
    // use a common regSeq_addr to avoid the using of Registry
    IOpaqueAddress* regSeq_addr = 0;
    // wz
    {   // first convert the RS itself
        StatusCode sc = m_cnv->createRep(regSeq,regSeq_addr);
        if (sc.isFailure()) {
            log << MSG::ERROR 
                << "failed to create persistent representation "
                << "for the RegistrationSequence"
                << endreq;
            return sc;
        }
    }

    // Next spin over registrations and do it for them.

    IRegistrationSequence::Registrations& regs = 
        const_cast<IRegistrationSequence::Registrations&>(regSeq->registrations());
    IRegistrationSequence::Registrations::iterator it, done = regs.end();

    // First, createRep() on each
    for (it = regs.begin(); it != done; ++it) {
      {
        ObjectReg& objreg = *it;
        if (!objreg.store()) {
          log << MSG::DEBUG << "Not storing " << objreg.path() << endreq;
          continue;
        }

        DataObject* child = const_cast<DataObject*>(objreg.object());

        IOpaqueAddress* addr = 0;
        StatusCode sc = m_cnv->createRep(child,addr);
        
        if (sc.isFailure()) {
          log << MSG::WARNING
              << "Failed to createRep for " 
              << objreg.path() << ", skipping" << endreq;
          continue;
        }
        IRegistry* reg = child->registry();
        reg->setAddress(addr);
      }
      {
        const ObjectReg& objreg = *it;
        if (!objreg.store()) { continue; }

        DataObject* child = const_cast<DataObject*>(objreg.object());

        IRegistry* reg = child->registry();
        StatusCode sc = m_cnv->fillRepRefs(reg->address(), child);
        if (sc.isFailure()) {
          log << MSG::WARNING
              << "Failed to fillRepRefs with " 
              << objreg.path() << ", skipping" << endreq;
          continue;
        }
        IOpaqueAddress* iaddr = reg->address();
        if (!iaddr) {
            static map<string,int> errorMap;
            string tespath = objreg.path();
            if (!errorMap[tespath]) {
                log << (child->clID() == 1 ? MSG::DEBUG : MSG::WARNING)
                    << "No address for object id #"<<child->clID()<<" registered at " 
                    << tespath << ", skipping and won't tell you about it again."
                    << endreq;
                errorMap[tespath] = 1;
            }
            continue;
        }
        RootOutputAddress* roa = dynamic_cast<RootOutputAddress*>(iaddr);
        if (!roa) {
          log << MSG::ERROR
              << "Address for" << objreg.path() 
              << " not a RootOutputAddress, skipping" << endreq;
          continue;
        }
        RootIOBaseCnv* rbcnv =
          dynamic_cast<RootIOBaseCnv*>(m_cnv->converter(child->clID()));
        if (!rbcnv) {
          log << MSG::ERROR
              << "No converter for type " << roa->clID() 
              << " from " << objreg.path() << ", skipping" << endreq;
          continue;
        }

        int entry = rbcnv->commit(*roa);
        roa->setEntry(entry);

        // set output address
        TemporalDataObject* tdo = dynamic_cast<TemporalDataObject*>(child);
        tdo->setOutputAddress(roa);

        HeaderObject* ho = dynamic_cast<HeaderObject*>(child);
        log << MSG::DEBUG
            << "Setting entry [" << entry << "], execNum=" << ho->execNumber() << " to " << objreg.path()
            << " earliest:" << tdo->earliest()
            << endreq;
        //log << MSG::DEBUG
        //    << "Setting entry [" << entry << "] to " << objreg.path() << endreq;
        const_cast<ObjectReg&>(objreg).setEntry(entry);
      }
    } // loop over children
    
    { // Finalize the regSeq
        StatusCode sc = m_cnv->fillRepRefs(regSeq_addr,regSeq);
        if (sc.isFailure()) {
            log << MSG::ERROR
                << "failed to fillRepRefs with RegistrationSequence"
                << endreq;
            return sc;
        }
        RootOutputAddress* roa = 
            dynamic_cast<RootOutputAddress*>(regSeq_addr);
        if (!roa) {
            log << MSG::ERROR
                << "Failed to find a RootOutputAddress for RegistrationSequence!\n"
                << "\tDid you fail to tell me a file in which to save it?"
                << endreq;
            return StatusCode::FAILURE;
        }
        RootIOBaseCnv* rbcnv =
            dynamic_cast<RootIOBaseCnv*>(m_cnv->converter(roa->clID()));
        int entry = rbcnv->commit(*roa);
        roa->setEntry(entry);

        // set output address
        regSeq->setOutputAddress(roa);
    }

    return StatusCode::SUCCESS;
}
StatusCode DybStorageSvc::store ( DataObject *  object,
const std::string &  path 
) [virtual]

Implements IDybStorageSvc.

Definition at line 241 of file DybStorageSvc.cc.

{
  // Store a single (non-TES) object
  MsgStream log(msgSvc(), "DybStorageSvc");

  IOpaqueAddress* addr = 0;
  log << MSG::VERBOSE << "Calling createRep for path " << path 
      << " with object " << object << endreq;
  StatusCode sc = m_cnv->createRep(object,addr);
  log << MSG::VERBOSE << "Called createRep for path " << path 
      << "and got addr " << addr << endreq;
  if (sc.isFailure()) {
    log << MSG::WARNING
        << "Failed to createRep for " 
        << path << ", skipping" << endreq;
    return sc;
  }
  IRegistry* reg = object->registry();
  reg->setAddress(addr);

  sc = m_cnv->fillRepRefs(reg->address(), object);
  if (sc.isFailure()) {
    log << MSG::WARNING
        << "Failed to fillRepRefs with " 
        << path << ", skipping" << endreq;
    return sc;
  }

  if (!addr) {
    log << (object->clID() == 1 ? MSG::VERBOSE : MSG::WARNING)
        << "No address for object id #"<<object->clID()<<" registered at " 
        << path << ", skipping"
        << endreq;
    return sc;
  }
  RootOutputAddress* roa = dynamic_cast<RootOutputAddress*>(addr);
  if (!roa) {
    log << MSG::ERROR
        << "Address for" << path 
        << " not a RootOutputAddress, skipping" << endreq;
    return sc;
  }
  RootIOBaseCnv* rbcnv =
    dynamic_cast<RootIOBaseCnv*>(m_cnv->converter(object->clID()));
  if (!rbcnv) {
    log << MSG::ERROR
        << "No converter for type " << roa->clID() 
        << " from " << path << ", skipping" << endreq;
    return sc;
  }

  int entry = rbcnv->commit(*roa);
  roa->setEntry(entry);

  HeaderObject* ho = dynamic_cast<HeaderObject*>(object);
  log << MSG::DEBUG
      << "Setting entry [" << entry << "], execNum=" << ho->execNumber() << " to " << path << endreq;

  return StatusCode::SUCCESS;
}
StatusCode DybStorageSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvInterface 
) [virtual]

Definition at line 304 of file DybStorageSvc.cc.

{
    MsgStream log(msgSvc(), "DybStorageSvc::queryInterface");
    log << MSG::DEBUG << "queryInterface(" << riid << ")" << endreq;

    StatusCode sc = StatusCode::FAILURE;
    if (ppvInterface) {
        *ppvInterface = 0;
    
        if (IDybStorageSvc::interfaceID().versionMatch(riid)) {
            *ppvInterface = static_cast<IDybStorageSvc*>(this);
            sc = StatusCode::SUCCESS;
            addRef();
        }
        else sc = Service::queryInterface( riid, ppvInterface );    
    }
    return sc;
}

Member Data Documentation

IConversionSvc* DybStorageSvc::m_cnv [private]

Definition at line 40 of file DybStorageSvc.h.

ToolHandleArray<IRegSeqVisitor> DybStorageSvc::m_rsVisitors [private]

Definition at line 42 of file DybStorageSvc.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:15:57 for DybIO by doxygen 1.7.4