//----------------------- // This Class's Header -- //----------------------- #include "CalorObjects/CPRQColl.hh" //------------------------------- // Collaborating Class Headers -- //------------------------------- #include "Experiment/Experiment.hh" #include "AbsEnv/AbsEnv.hh" #include "ErrorLogger_i/gERRLOG.hh" // ROOT Headers : #include "TBuffer.h" #include "EdmUtilities/CdfClassImp.hh" //----------------------------------------------------------------------------- // Creation //----------------------------------------------------------------------------- CPRQColl::CPRQColl() : StorableObject() {} CPRQColl::CPRQColl(const CPRQColl& rhs) : StorableObject(rhs), _container(rhs._container) {} //----------------------------------------------------------------------------- // Destruction //----------------------------------------------------------------------------- CPRQColl::~CPRQColl() {} void CPRQColl::destroy() { CPRQColl::deallocate(); delete this; } void CPRQColl::deallocate() { StorableObject::deallocate(); } //----------------------------------------------------------------------------- // EDM: functions required by StorableObject //----------------------------------------------------------------------------- std::string CPRQColl::class_name() const { return CPRQColl::Class_Name() ; } Version_t CPRQColl::class_version() const { return CPRQColl::Class_Version(); } void CPRQColl::print(std::ostream& os) const { StorableObject::print(os); _container.print(os); } bool CPRQColl::postread(EventRecord* record) { // Note : ValueVector does not currently call postread on its elements, // so do so here : bool status = StorableObject::postread(record); status = _container.postread(record) && status; for (CPRQColl::iterator i = _container.contents().begin(); i != _container.contents().end(); ++i) { status = (*i).postread(record) && status; } return status; } bool CPRQColl::prewrite(EventRecord* record) { // Note : ValueVector does not currently call prewrite on its elements, // so do so here : bool status = StorableObject::prewrite(record); status = _container.prewrite(record) && status; for (CPRQColl::iterator i = _container.contents().begin(); i != _container.contents().end(); ++i) { status = (*i).prewrite(record) && status; } return status; } bool CPRQColl::activate(EventRecord* record) { bool status = StorableObject::activate(record); return status; } bool CPRQColl::deactivate(EventRecord* record) { bool status = StorableObject::deactivate(record); return status; } void CPRQColl::Streamer(TBuffer& iobuffer) { unsigned int start = 0 ; unsigned int byte_count = 0 ; //----------------------------------------------------------------------------- // Read object from buffer //----------------------------------------------------------------------------- if (iobuffer.IsReading()) { Version_t original_version = iobuffer.ReadVersion(&start, &byte_count) ; if (original_version == 2) { StorableObject::Streamer(iobuffer) ; _container.Streamer(iobuffer); } else { ERRLOG( ELerror, "Unsupported CPRQColl version" ) << "@SUB=CPRQColl::Streamer()" << "CPRQColl cannot be read." << endmsg; } iobuffer.CheckByteCount(start, byte_count, CPRQColl::IsA()) ; } //----------------------------------------------------------------------------- // Write object to buffer //----------------------------------------------------------------------------- else if (iobuffer.IsWriting()) { byte_count = iobuffer.WriteVersion(CPRQColl::IsA(), kTRUE) ; Version_t current_version = CPRQColl::class_version() ; if (current_version == 2) { StorableObject::Streamer(iobuffer) ; _container.Streamer(iobuffer); } else { ERRLOG( ELerror, "Unsupported CPRQColl version" ) << "@SUB=CPRQColl::Streamer()" << "CPRQColl cannot be written." << endmsg; } iobuffer.SetByteCount(byte_count, kTRUE) ; } //----------------------------------------------------------------------------- // Unanticipated action //----------------------------------------------------------------------------- else { ERRLOG( ELerror, "CPRQColl::Streamer()" ) << "@SUB=CPRQColl::Streamer" << "NOTHING DONE." << endmsg; } } //----------------------------------------------------------------------------- // Functions to retrieve the collection from the event //----------------------------------------------------------------------------- CPRQColl::Error CPRQColl::find(CPRQColl_ch& cHandle) { EventRecord::ConstIterator ciEvent(AbsEnv::theEvent(),"CPRQColl"); if (ciEvent.is_valid()) { cHandle = ciEvent; return OK; } else { cHandle.set_null(); return ERROR; } } CPRQColl::Error CPRQColl::find(CPRQColl_ch& cHandle, const StorableObject::Selector & selector) { EventRecord::ConstIterator ciEvent(AbsEnv::theEvent(),"CPRQColl"); while (ciEvent.is_valid() && !selector(*ciEvent)) { ++ciEvent; } if (ciEvent.is_valid()) { cHandle = ciEvent; return OK; } else { cHandle.set_null(); return ERROR; } } //============================================================================= // ROOT I/O Hook //============================================================================= CdfClassImp(CPRQColl)