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

In This Package:

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
RootIOCnvSvc Class Reference

Service to coordinate conversion with Root IO. More...

#include <RootIOCnvSvc.h>

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

List of all members.

Public Types

typedef std::map< std::string,
RootInputStream * > 
InputStreamMap
 Access the complete set of input streams.
typedef std::map< std::string,
std::string > 
FileMap
 Get copy of the output file map.

Public Member Functions

 RootIOCnvSvc (const std::string &name, ISvcLocator *svc)
virtual ~RootIOCnvSvc ()
virtual StatusCode initialize ()
virtual StatusCode reinitialize ()
virtual StatusCode finalize ()
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppint)
virtual StatusCode createAddress (long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&newAddr)
 Create a Generic address using explicit arguments to identify a single object.
virtual IDataProviderSvc * dataSvc ()
 Get the event data provider service.
virtual IDataManagerSvc * dataMgrSvc ()
 Get the event data manager service.
virtual StatusCode createAddress (DataObject *obj, RootOutputAddress *&newAddr)
 Extend ConversionSvc interface to create address based on existing DataObject.
RootOutputStreamoutputStream (const RootOutputAddress &roa)
 Return a root output stream for the given address (needs clid and tespath filled in).
const std::string & outputFilename (const std::string &tespath)
 Get the output filename coresonding to the path.
void associateOutput (const char *filename, const char *streamname)
 Associate an output file name with a stream name.
FileMap fileMap ()
RootInputStreaminputStream (const RootInputAddress &ria)
 Return a root input stream for the given address (needs clid and tespath to be filled in).
InputStreamMapinputStreams ()
 Access the complete set of input streams.
std::vector< std::string > inputFilenames (const std::string &tespath)
 Get the input filename coresponding to the path.

Static Public Member Functions

static const InterfaceID & interfaceID ()

Protected Member Functions

StatusCode doInitialize ()
void initializeInputStream (const std::string &path, const std::string &filename)
void initializeInputStream (const std::string &path, const std::vector< std::string > &filename_list)

Protected Attributes

std::map< std::string,
std::string > 
m_outputFileMap
 Property: "OutputFileMap": maping of TES path to output filename.
std::map< std::string,
RootOutputStream * > 
m_outputStreamMap
std::string m_defaultOutputFilename
 Property: "DefaultOutput": name of file to use if TES path not found in path.
std::map< std::string,
std::vector< std::string > > 
m_inputFileMap
 Property: "InputFileMap": maping of TES path to a list of input filenames.
InputStreamMap m_inputStreamMap
std::vector< std::string > m_defaultInputFilenames
 Property: "DefaultInput": list of names of files to use if TES path not found in the InputFileMap.
std::string m_dataSvcName
 Property: "EventDataService": name of event data service.
IDataProviderSvc * m_dataSvc
IDataManagerSvc * m_dataMgr
std::string m_majorIndex
 Property: "MajorIndexExpression": expression passed as first argument to TTree::BuildIndex().
std::string m_minorIndex
 Property: "MinorIndexExpression": expression passed as second argument to TTree::BuildIndex().

Detailed Description

Service to coordinate conversion with Root IO.

TES objects are mapped to TTrees in TFiles. An object's location in the TES is reflected by its TTree location in the TFile. The mapping to files is a user configurable property.

This class is inspired by RootCnvSvc.

bv@bnl.gov Wed Jun 25 12:08:44 2008

Definition at line 34 of file RootIOCnvSvc.h.


Member Typedef Documentation

typedef std::map<std::string,RootInputStream*> IRootIOSvc::InputStreamMap [inherited]

Access the complete set of input streams.

Definition at line 36 of file IRootIOSvc.h.

typedef std::map<std::string,std::string> IRootIOSvc::FileMap [inherited]

Get copy of the output file map.

Definition at line 43 of file IRootIOSvc.h.


Constructor & Destructor Documentation

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

Definition at line 19 of file RootIOCnvSvc.cc.

    : ConversionSvc(name,svc,ROOT_StorageType)
    , m_dataSvc(0)
{
    declareProperty("OutputStreams",m_outputFileMap,
                    "Map of TES location to output filename");
    declareProperty("DefaultOutput",m_defaultOutputFilename="",
                    "Name of output file to store unregistered paths.");

    declareProperty("InputStreams",m_inputFileMap,
                    "Map of TES location to input filename");
    declareProperty("DefaultInput",m_defaultInputFilenames,
                    "Name of input file to store unregistered paths.");

    declareProperty("EventDataService",m_dataSvcName="EventDataSvc",
                    "Name of event data service.");

    declareProperty("MajorIndexExpression",m_majorIndex="execNumber",
                    "Expression to use for building the tree's index.");
    declareProperty("MinorIndexExpression",m_minorIndex="0",
                    "Expression to use for building the tree's index.");
}
RootIOCnvSvc::~RootIOCnvSvc ( ) [virtual]

Definition at line 41 of file RootIOCnvSvc.cc.

{
}

Member Function Documentation

StatusCode RootIOCnvSvc::initialize ( ) [virtual]

Definition at line 58 of file RootIOCnvSvc.cc.

{
    MsgStream log(msgSvc(), "RootIOCnvSvc");
    log << MSG::DEBUG << "initializing @" << (void*)this << endreq;
    StatusCode sc = ConversionSvc::initialize();
    if (sc.isFailure()) {
        log << MSG::ERROR << "parent class failed to initialize" << endreq;
        return sc;
    }
    sc= this->doInitialize();
    log << MSG::DEBUG << "initialized @" << (void*)this << endreq;
    return sc;
}
StatusCode RootIOCnvSvc::reinitialize ( ) [virtual]

Definition at line 45 of file RootIOCnvSvc.cc.

{
    MsgStream log(msgSvc(), "RootIOCnvSvc");
    log << MSG::DEBUG << "reinitializing @" << (void*)this << endreq;
    StatusCode sc = ConversionSvc::initialize();
    if (sc.isFailure()) {
        log << MSG::ERROR << "parent class failed to initialize" << endreq;
        return sc;
    }
    sc= this->doInitialize();
    log << MSG::DEBUG << "reinitialized @" << (void*)this << endreq;
    return sc;
}
StatusCode RootIOCnvSvc::finalize ( ) [virtual]

Definition at line 487 of file RootIOCnvSvc.cc.

{
    map<string,RootOutputStream*>::iterator it, done = m_outputStreamMap.end();
    for (it = m_outputStreamMap.begin(); it != done; ++it) {
        bool okay = it->second->close();
        if (!okay) {
            MsgStream log(msgSvc(), "RootIOCnvSvc");
            log << MSG::WARNING
                << "error in closing file for " << it->first
                << endreq;
        }            
    }
    if (m_outputStreamMap.size()) {
        RootOutputFileManager::get().setIncidentSvc(0); // trigger a release
    }
    return ConversionSvc::finalize();
}
StatusCode RootIOCnvSvc::queryInterface ( const InterfaceID &  riid,
void **  ppint 
) [virtual]

Definition at line 505 of file RootIOCnvSvc.cc.

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

    if (IID_IRootIOSvc.versionMatch(riid)) {
        log << MSG::DEBUG << "queryInterface("<<riid<<") --> (IRootIOSvc*)" 
            << (void*)this
            << endreq;
        *ppint = (IRootIOSvc*)this;
    }
    else if (IID_IConversionSvc.versionMatch(riid)) {
        log << MSG::DEBUG << "queryInterface("<<riid<<") --> (IConversionSvc*)"
            << (void*)this
            << endreq;        
        *ppint = (IConversionSvc*)this;
    }
    else {
        return this->ConversionSvc::queryInterface(riid,ppint);
    }
    addRef();
    return StatusCode::SUCCESS;
}
virtual StatusCode RootIOCnvSvc::createAddress ( long  svc_type,
const CLID &  clid,
const std::string *  par,
const unsigned long *  ip,
IOpaqueAddress *&  newAddr 
) [virtual]

Create a Generic address using explicit arguments to identify a single object.

virtual IDataProviderSvc* RootIOCnvSvc::dataSvc ( ) [inline, virtual]

Get the event data provider service.

Implements IRootIOSvc.

Definition at line 63 of file RootIOCnvSvc.h.

{ return m_dataSvc; }
virtual IDataManagerSvc* RootIOCnvSvc::dataMgrSvc ( ) [inline, virtual]

Get the event data manager service.

Implements IRootIOSvc.

Definition at line 66 of file RootIOCnvSvc.h.

{ return m_dataMgr; }
StatusCode RootIOCnvSvc::createAddress ( DataObject *  obj,
RootOutputAddress *&  newAddr 
) [virtual]

Extend ConversionSvc interface to create address based on existing DataObject.

Called by RootIOBaseCnv.

Implements IRootIOSvc.

Definition at line 452 of file RootIOCnvSvc.cc.

{
    // wangzhe: There is no ObjectReg created for RegistrationSequence
    // So there is no ganrantee there is Registry alive for each RegistrationSequence
    string tespath;
    if(obj->clID()==DayaBay::RegistrationSequence::classID()) {
      tespath=DayaBay::RegistrationSequence::defaultLocation();
    } else {
      tespath = obj->registry()->identifier();
    }
    // wz

    string filename = m_defaultOutputFilename;
    map<string,string>::iterator it = m_outputFileMap.find(tespath);
    if (it != m_outputFileMap.end()) 
        filename = it->second;

    if ("" == filename) {
        MsgStream log(msgSvc(), "RootIOCnvSvc");
        static map<string,int> errorMap;
        if (!errorMap[tespath]) {
            log << MSG::WARNING
                << "Can not create address for " << tespath
                << " no output file specified, I won't tell you again." 
                << endreq;
            errorMap[tespath] = 1;
        }
        return StatusCode::FAILURE;
    }

    newAddr = new RootOutputAddress(obj->clID(),tespath);
    return StatusCode::SUCCESS;
}
RootOutputStream * RootIOCnvSvc::outputStream ( const RootOutputAddress roa) [virtual]

Return a root output stream for the given address (needs clid and tespath filled in).

The current associated output file is set on the stream.

Implements IRootIOSvc.

Definition at line 290 of file RootIOCnvSvc.cc.

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

    const string& filename = this->outputFilename(roa.tespath());
    if ("" == filename) {
        log << MSG::ERROR << "Bad (empty) output filename, no ouput stream for " 
            << roa.tespath() << endreq;
        return 0;
    }

    RootOutputStream* os = m_outputStreamMap[roa.tespath()];
    if (os) {
        os->newFile(filename); // noop unless filename differs from old one
        log << MSG::DEBUG << "outputStream for " << roa.tespath() 
            << " cached, file = " << filename << endreq;
        return os;
    }

    IConverter*  cnv  = converter(roa.clID());
    if (!cnv) {
        log << MSG::WARNING
            << "Failed to get converter for class ID = " << roa.clID()
            << " tespath = " << roa.tespath() << endreq;
        return 0;
    }

    RootIOBaseCnv* riocnv = dynamic_cast<RootIOBaseCnv*>(cnv);
    if (!riocnv) {
        log << MSG::WARNING 
            << "Converter not a RootIOBaseCnv for class ID = " << roa.clID()
            << " tespath = " << roa.tespath() << endreq;
        return 0;
    }

    os = riocnv->makeOutputStream(roa);
    if (!os) {
        log << MSG::WARNING
            << "Converter failed to make new output stream for class ID = " 
            << roa.clID()
            << " tespath = " << roa.tespath() << endreq;
        return 0;
    }

    if (roa.clID() != DayaBay::RegistrationSequence::classID()) {
        log << MSG::DEBUG
            << "outputStream for " << roa.tespath() 
            << " gets major=\"" << m_majorIndex << "\", "
            << "minor=\"" << m_minorIndex << "\"" << endreq;
        os->setIndexExpression(m_majorIndex,m_minorIndex);
    }

    m_outputStreamMap[roa.tespath()] = os;
    os->newFile(filename);
    log << MSG::DEBUG << "outputStream for " << roa.tespath() 
        << " new, file = " << filename << endreq;
    return os;
}
const string & RootIOCnvSvc::outputFilename ( const std::string &  tespath)

Get the output filename coresonding to the path.

Definition at line 418 of file RootIOCnvSvc.cc.

{
    map<string,string>::iterator it = m_outputFileMap.find(tespath);
    if (it == m_outputFileMap.end()) return m_defaultOutputFilename;
    return it->second;
}
void RootIOCnvSvc::associateOutput ( const char *  filename,
const char *  streamname 
) [virtual]

Associate an output file name with a stream name.

Implements IRootIOSvc.

Definition at line 278 of file RootIOCnvSvc.cc.

{
    m_outputFileMap[streamname] = filename;
    if (string("default") == streamname) {
        m_defaultOutputFilename = filename;
    }
}
IRootIOSvc::FileMap RootIOCnvSvc::fileMap ( ) [virtual]

Implements IRootIOSvc.

Definition at line 285 of file RootIOCnvSvc.cc.

{
    return m_outputFileMap;
}
RootInputStream * RootIOCnvSvc::inputStream ( const RootInputAddress ria) [virtual]

Return a root input stream for the given address (needs clid and tespath to be filled in).

If newly created the set of associated input files will be set.

Implements IRootIOSvc.

Definition at line 349 of file RootIOCnvSvc.cc.

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

    vector<string> filenames = this->inputFilenames(ria.tespath());
    if (0 == filenames.size()) {
        log << MSG::DEBUG << "Bad (empty) input filename, no input stream for " 
            << ria.tespath() << endreq;
        return 0;
    }

    RootInputStream* ris = m_inputStreamMap[ria.tespath()];
    if (ris) {
        log << MSG::DEBUG << "inputStream for " << ria.tespath()
            << " cached, files = [";
        for (size_t ind=0; ind<filenames.size(); ++ind) {
            log << " " << filenames[ind];
        }
        log << "]" << endreq;
        return ris;
    }

    IConverter*  cnv  = converter(ria.clID());
    if (!cnv) {
        log << MSG::WARNING
            << "Failed to get converter for class ID = " << ria.clID()
            << " tespath = " << ria.tespath() << endreq;
        return 0;
    }

    RootIOBaseCnv* riocnv = dynamic_cast<RootIOBaseCnv*>(cnv);
    if (!riocnv) {
        log << MSG::WARNING 
            << "Converter not a RootIOBaseCnv for class ID = " << ria.clID()
            << " tespath = " << ria.tespath() << endreq;
        return 0;
    }

    ris = riocnv->makeInputStream(ria);
    if (!ris) {
        log << MSG::WARNING
            << "Converter failed to make new input stream for class ID = " 
            << ria.clID()
            << " tespath = " << ria.tespath() << endreq;
        return 0;
    }

    for (size_t ind = 0; ind < filenames.size(); ++ind) {
        bool okay = ris->append(filenames[ind], true);
        if (!okay) {
            log << MSG::ERROR
                << "failed to append file " << filenames[ind] << " to input stream for " 
                << ria.tespath() << endreq;
            return 0;
        }
    }

    m_inputStreamMap[ria.tespath()] = ris;

    log << MSG::DEBUG << "inputStream for " << ria.tespath() 
        << " new, files = [";
    for (size_t ind=0; ind<filenames.size(); ++ind) {
        log << " " << filenames[ind];
    }
    log << "]" << endreq;

    return ris;    
}
InputStreamMap& RootIOCnvSvc::inputStreams ( ) [inline, virtual]

Access the complete set of input streams.

Implements IRootIOSvc.

Definition at line 94 of file RootIOCnvSvc.h.

{ return m_inputStreamMap; }
vector< string > RootIOCnvSvc::inputFilenames ( const std::string &  tespath)

Get the input filename coresponding to the path.

If not explicitly in the map then the map's default entry is used, unless a default was explicitly set then that is returned.

Definition at line 425 of file RootIOCnvSvc.cc.

{
    map<string,vector<string> >::iterator it = m_inputFileMap.find(tespath);
    if (it == m_inputFileMap.end()) {
        return m_defaultInputFilenames;
    }
    return it->second;
}
StatusCode RootIOCnvSvc::doInitialize ( ) [protected]

Definition at line 72 of file RootIOCnvSvc.cc.

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

    if (0 == m_defaultInputFilenames.size()  && 0 == m_inputFileMap.size() &&
        "" == m_defaultOutputFilename && 0 == m_outputFileMap.size())
    {
        log << MSG::WARNING 
            << "No input nor output files specified.  Why am I here?"
            << endreq;
        return StatusCode::FAILURE;
    }
        

    // --- ouput --- //
    {                           
        map<string,string>::iterator it, done = m_outputFileMap.end();
        log << MSG::INFO 
            << " default output = \"" << m_defaultOutputFilename << "\""
            << " output file map (" << m_outputFileMap.size() << " entries):";
        for (it = m_outputFileMap.begin(); it != done; ++it) {
            log << "\n\t\"" << it->first << "\" ==> \"" << it->second << "\"";
        }
        log << endreq;
    }
    if (m_defaultOutputFilename.size()) { // if set, it should override "default" in map
        m_outputFileMap["default"] = m_defaultOutputFilename;
    }
    else { 
        map<string,string>::iterator it = m_outputFileMap.find("default");
        if (it == m_outputFileMap.end()) {
            log << MSG::WARNING 
                << " no \"default\" output file name specified, "
                "unregistered TES paths will not be saved." << endreq;
        }
        else {
            m_defaultOutputFilename = it->second;
        }
    }
    
    // If we have output, configure the output file manager
    if (m_outputFileMap.size()) {
        IIncidentSvc *incsvc = 0;
        StatusCode sc = service("IncidentSvc", incsvc, true);
        if(sc.isFailure()){
            log << MSG::ERROR << "Unable start IncidentSvc service" 
                << endreq;
            return sc;
        }
        RootOutputFileManager::get().setIncidentSvc(incsvc);

        // make sure we get finalized before IncidentSvc does.
        // SmartIF<ISvcManager> mgr(IID_ISvcManager, serviceLocator());
        // int pri_inc = mgr->getPriority("IncidentSvc");
        // log << MSG::INFO << "Setting my priority to one more than IncidentSvc (" << pri_inc << ")" << endreq;
        // mgr->setPriority("RootIOCnvSvc",pri_inc + 1);
    }


    // --- input --- //
    {
        map<string,vector<string> >::iterator it, done = m_inputFileMap.end();
        string defin =  "";
        if (m_defaultInputFilenames.size()) defin = m_defaultInputFilenames[0];
        log << MSG::INFO
            << " default input = \"" << defin << "\""
            << " input file map (" << m_inputFileMap.size() << " entries):";
        for (it = m_inputFileMap.begin(); it != done; ++it) {
            log << "\t" << it->first << " : [";
            vector<string>& vec = it->second;
            for (size_t ind = 0; ind < vec.size(); ++ind) {
                log << " " << vec[ind];
            }
            log << "]\n";
        }
        log << endreq;
    }

    if (0 == m_defaultInputFilenames.size()) {
        map<string,vector<string> >::iterator it = m_inputFileMap.find("default");
        if (it == m_inputFileMap.end()) {
            log << MSG::WARNING
                << " no \"default\" input file name specified, "
                "unregistered TES paths will not be saved." << endreq;
        }
        else {
            m_defaultInputFilenames = it->second;
        }
    }
    {
        map<string,vector<string> >::iterator it, done = m_inputFileMap.end();
        for (it = m_inputFileMap.begin(); it != done; ++it) {
            if (it->first == "default") continue;
            if (!it->second.size()) {
                log << MSG::WARNING
                    << "Skipping input stream with no files: "
                    << it->first << endreq;
                continue;
            }
            initializeInputStream(it->first,it->second);
        }
        if (m_defaultInputFilenames.size())
            initializeInputStream("default",m_defaultInputFilenames);
    }
    
    log << MSG::DEBUG << "Initialized input and output streams." << endreq;

    // Get DataSvc
    log << MSG::DEBUG << "Getting " << m_dataSvcName << " as IService" << endreq;
    IService* isvc = 0;
    StatusCode sc = service(m_dataSvcName, isvc, true);
    if(sc.isFailure()){
        log << MSG::ERROR << "Unable start EventData service" 
            << m_dataSvcName << endreq;
        return sc;
    }
    isvc->addRef();

    log << MSG::DEBUG << "Querying " << m_dataSvcName << " for IID_IDataProviderSvc" << endreq;
    sc = isvc->queryInterface(IID_IDataProviderSvc, (void**)&m_dataSvc);
    if(sc.isFailure()){
        log << MSG::ERROR << "EventData service " << m_dataSvcName 
            << "not an IDataProviderSvc" << endreq;
        return sc;
    }

    log << MSG::DEBUG << "Querying " << m_dataSvcName << " for IID_IDataManagerSvc" << endreq;
    sc = isvc->queryInterface(IDataManagerSvc::interfaceID(),
                              (void**)(&m_dataMgr));
    if (sc.isFailure()) {
        log << MSG::ERROR << "EventData service " << m_dataSvcName 
            << "not an IDataManagerSvc" << endreq;
        return sc;
    }

    return StatusCode::SUCCESS;
}
void RootIOCnvSvc::initializeInputStream ( const std::string &  path,
const std::string &  filename 
) [protected]
void RootIOCnvSvc::initializeInputStream ( const std::string &  path,
const std::vector< std::string > &  filename_list 
) [protected]
static const InterfaceID& IRootIOSvc::interfaceID ( ) [inline, static, inherited]

Definition at line 23 of file IRootIOSvc.h.

{ return IID_IRootIOSvc; }

Member Data Documentation

std::map<std::string,std::string> RootIOCnvSvc::m_outputFileMap [protected]

Property: "OutputFileMap": maping of TES path to output filename.

A "path" of "default" can be used to set a file name to use for unregistered paths. The property below will override this.

Definition at line 109 of file RootIOCnvSvc.h.

std::map<std::string,RootOutputStream*> RootIOCnvSvc::m_outputStreamMap [protected]

Definition at line 110 of file RootIOCnvSvc.h.

std::string RootIOCnvSvc::m_defaultOutputFilename [protected]

Property: "DefaultOutput": name of file to use if TES path not found in path.

Definition at line 114 of file RootIOCnvSvc.h.

std::map<std::string,std::vector<std::string> > RootIOCnvSvc::m_inputFileMap [protected]

Property: "InputFileMap": maping of TES path to a list of input filenames.

A "path" of "default" can be used to set a file name to use for unregistered paths. The property below will override this. All trees in default files will be candidates for loading unless their path is explicitly associated with a file.

Definition at line 122 of file RootIOCnvSvc.h.

Definition at line 123 of file RootIOCnvSvc.h.

std::vector<std::string> RootIOCnvSvc::m_defaultInputFilenames [protected]

Property: "DefaultInput": list of names of files to use if TES path not found in the InputFileMap.

Definition at line 131 of file RootIOCnvSvc.h.

std::string RootIOCnvSvc::m_dataSvcName [protected]

Property: "EventDataService": name of event data service.

Definition at line 134 of file RootIOCnvSvc.h.

IDataProviderSvc* RootIOCnvSvc::m_dataSvc [protected]

Definition at line 135 of file RootIOCnvSvc.h.

IDataManagerSvc* RootIOCnvSvc::m_dataMgr [protected]

Definition at line 136 of file RootIOCnvSvc.h.

std::string RootIOCnvSvc::m_majorIndex [protected]

Property: "MajorIndexExpression": expression passed as first argument to TTree::BuildIndex().

Definition at line 140 of file RootIOCnvSvc.h.

std::string RootIOCnvSvc::m_minorIndex [protected]

Property: "MinorIndexExpression": expression passed as second argument to TTree::BuildIndex().

Definition at line 144 of file RootIOCnvSvc.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 09:58:18 for RootIOSvc by doxygen 1.7.4