/* PESQ_Coll This class holds all of the corrected, integerized strips for an event. Benn Tannenbaum benn@physics.ucla.edu */ #include "CalorObjects/PESQ_Coll.hh" //------------------------------- // Collaborating Class Headers -- //------------------------------- #include "Experiment/Experiment.hh" #include "AbsEnv/AbsEnv.hh" #include "ErrorLogger_i/gERRLOG.hh" #include // ROOT Headers : #include "TBuffer.h" #include "EdmUtilities/CdfClassImp.hh" PESQ_Coll::PESQ_Coll() : StorableObject() {} PESQ_Coll::PESQ_Coll( const PESQ_Coll& rhs) : StorableObject(rhs) , _maxEnergy(rhs._maxEnergy), _threshold(rhs._threshold), _container(rhs._container) {} //----------------------------------------------------------------------------- // Destruction //----------------------------------------------------------------------------- void PESQ_Coll::destroy() { PESQ_Coll::deallocate(); delete this; } void PESQ_Coll::deallocate() { StorableObject::deallocate(); } //----------------------------------------------------------------------------- // EDM: functions required by StorableObject //----------------------------------------------------------------------------- PESQ_List& PESQ_Coll::contents() { return _container.contents(); } const PESQ_List& PESQ_Coll::contents() const { return _container.contents(); } std::string PESQ_Coll::class_name() const { return PESQ_Coll::Class_Name();} Version_t PESQ_Coll::class_version() const { return PESQ_Coll::Class_Version(); } void PESQ_Coll::print(std::ostream& os) const { StorableObject::print(os); os << "Maximum energy: " << _maxEnergy << std::endl << "Strip threshold: " << _threshold << std::endl; _container.print(os); } bool PESQ_Coll::postread(EventRecord* record) { bool status = StorableObject::postread(record); status &= _container.postread(record); return status; } bool PESQ_Coll::prewrite(EventRecord* record) { bool status = StorableObject::prewrite(record); status &= _container.prewrite(record); return status; } bool PESQ_Coll::activate(EventRecord* record) { bool status = StorableObject::activate(record); return status; } bool PESQ_Coll::deactivate(EventRecord* record) { bool status = StorableObject::deactivate(record); return status; } void PESQ_Coll::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 == 1) { // Version 1 of PESQ_Coll contains version 1 PESQs PESQ::set_read_version(1); StorableObject::Streamer(iobuffer); readFromBuffer(iobuffer); _maxEnergy = float((unsigned short)(-1)); _threshold = -1; _container.Streamer(iobuffer); } else if (original_version == 2) { // Version 2 of PESQ_Coll contains version 2 PESQs PESQ::set_read_version(2); StorableObject::Streamer(iobuffer); readFromBuffer(iobuffer); iobuffer >> _maxEnergy; iobuffer >> _threshold; _container.Streamer(iobuffer); } else { ERRLOG( ELerror, "Unsupported PESQ_Coll version" ) << "@SUB=PESQ_Coll::Streamer()" << "PESQ_Coll cannot be read." << endmsg; } iobuffer.CheckByteCount(start, byte_count, PESQ_Coll::IsA()) ; } //--------------------------------------------------------------------------- // Write object to buffer //--------------------------------------------------------------------------- else if (iobuffer.IsWriting()) { byte_count = iobuffer.WriteVersion(PESQ_Coll::IsA(), kTRUE) ; Version_t current_version = PESQ_Coll::class_version() ; // No need to check version # since it will always be the current one. StorableObject::Streamer(iobuffer); writeToBuffer(iobuffer); iobuffer << _maxEnergy; iobuffer << _threshold; _container.Streamer(iobuffer); iobuffer.SetByteCount(byte_count, kTRUE) ; } //--------------------------------------------------------------------------- // Unanticipated action //--------------------------------------------------------------------------- else { ERRLOG( ELerror, "PESQ_Coll::Streamer()" ) << "@SUB=PESQ_Coll::Streamer" << "NOTHING DONE." << endmsg; } } //----------------------------------------------------------------------------- // Functions to retrieve the collection from the event //----------------------------------------------------------------------------- PESQ_Coll::Error PESQ_Coll::find(PESQ_Coll_ch& cHandle) { AbsEvent* theEvent = AbsEnv::theEvent(); EventRecord::ConstIterator ciEvent(AbsEnv::theEvent(),"PESQ_Coll"); if (ciEvent.is_valid()) { cHandle = PESQ_Coll_ch(ciEvent); return OK; } else { cHandle.set_null(); return ERROR; } } PESQ_Coll::Error PESQ_Coll::find(PESQ_Coll_ch& cHandle, const std::string& description) { AbsEvent* theEvent = AbsEnv::theEvent(); StorableObject::SelectByDescription selector( description ); EventRecord::ConstIterator iter( theEvent, selector ); if(iter.is_invalid()) return ERROR; cHandle = PESQ_Coll_ch(iter); return OK ; } // these next two are incase we ever need to do any special stuff when // reading/writing. void PESQ_Coll::readFromBuffer(TBuffer& iobuffer) {} void PESQ_Coll::writeToBuffer(TBuffer& iobuffer) {} //============================================================================= // ROOT I/O Hook //============================================================================= CdfClassImp(PESQ_Coll)