//--------------- // C++ Headers -- //--------------- #include "CalorObjects/CprCluster.hh" #include #include "TBuffer.h" /****************************************************************************** Description: CprCluster class header file Author List: 04/30/2000 Tania Moulik : created Revision History : 08/30/2000 Tania Moulik Remove ifndef _CINT_ around constructor 10/05/2000 Bob Wagner Fix syntax error in virtual destructor definition 02/03/2001 Tania Moulik Writing out TrackId & CprWire info to buffer 02/05/2001 Tania Moulik changing version to 2..due to change in streamer. 09/09/2002 Bob Wagner Move reading of track id value from Streamer to postread(). In Streamer, the track collection is not guaranteed to have been read in yet, so links to it may not be restored causing crashes. *******************************************************************************/ const Version_t CprCluster::_VERSION = 3; void CprCluster::print(std::ostream& os) const { int trackid=0; if (class_version()==3 || version ==3) { if (_theTrack.is_nonnull()) trackid = _theTrack->id().value(); } if (version == 2) trackid = _track_id; os << "**************************************************" << "\n"; os << "CPR Cluster " << "\n"; os << "************" << "\n"; os << "Module " << _module << "\n"; os << "Side " << _barrel << "\n"; os << "Position " << _wirePosition << "\n" ; os << "Position Error " << _errorWirePosition << "\n" ; os << "Charge " << _wireEnergy << "\n" ; os << "Matching Track Id " << trackid << "\n"; if (_copyWires.size()) { os << "Associated Wires :" << "\n"; for (vector ::const_iterator iw=_copyWires.begin(); iw!=_copyWires.end(); iw++){ std::cout.setf(std::ios::left); os << "wire number " << std::setw(3) << iw->getWireNo() << " wire energy " << iw->getPulseHeight() << "\n"; } std::cout.unsetf(std::ios::left); } os << "*************************************************" << "\n"; } /*===========================================================================*\ * CprCluster accessors * \*===========================================================================*/ float CprCluster::clusterWidth( void ) const { return _errorWirePosition; } /************************************************************************** * CprCluster::region * * Return the detector identification number which should be 0 * * for the CPR * **************************************************************************/ Detector CprCluster::region( void ) const { return CEM; } /************************************************************************** * CprCluster::energy * * Return energy of CPR Cluster * **************************************************************************/ float CprCluster::energy( void ) const { return _wireEnergy; } /************************************************************************** * CprCluster::localCoord * * Return double giving value of shower centroid * * in local coordinate system * **************************************************************************/ float CprCluster::localCoord( void ) const { return _wirePosition; } /************************************************************************** * CprCluster::globalCoord * * Return double giving value of shower centroid * * in local coordinate system * **************************************************************************/ float CprCluster::globalCoord( void ) const { return 0.; } /************************************************************************** * CprCluster::module * * Return wedge number containing CPR Cluster * **************************************************************************/ int CprCluster::module( void ) const { return _module; } /***************************************************************************** * CprCluster::side * * Return integer indicating East or West detector contains CPR Cluster * *****************************************************************************/ int CprCluster::side( void ) const { return _barrel; } int CprCluster::view( void ) const { return 0; } //=========================================================================== // Required by StorableObject //=========================================================================== void CprCluster::Streamer(TBuffer& iobuffer) { //--------------------------------------------------------------------------- // Read object from buffer //--------------------------------------------------------------------------- int size; float charge; int wire; if (iobuffer.IsReading()) { iobuffer >> version; iobuffer >> _barrel >> _module >> _wirePosition >> _errorWirePosition >> _wireEnergy; if (version > 1 ) { if (version == 2) { iobuffer >> _track_id; } else if (version == 3) { _theTrack.readStreamer(iobuffer); // Zero track id. We set it in postread if we have valid track link. _track_id = 0; } iobuffer >> size; CprWire cprwire; if (size !=0) { for (int iw=0; iw < size; iw++) { iobuffer >> wire >> charge; unsigned int newwire = wire; double newcharge = charge; cprwire.setWireNo(newwire); cprwire.setPulseHeight(newcharge); cprwire.setModule(_module); cprwire.setSide(_barrel); _copyWires.push_back(cprwire); } } } } //--------------------------------------------------------------------------- // Write object to buffer //--------------------------------------------------------------------------- else if (iobuffer.IsWriting()) { version = class_version(); iobuffer << version; iobuffer << _barrel << _module << _wirePosition << _errorWirePosition << _wireEnergy; _theTrack.writeStreamer(iobuffer); size = _copyWires.size(); iobuffer << size; if (_copyWires.size()!=0) { for (vector ::const_iterator iw=_copyWires.begin(); iw!=_copyWires.end(); iw++){ wire = iw->getWireNo(); charge = iw->getPulseHeight(); iobuffer << wire << charge; } } } //--------------------------------------------------------------------------- // Unanticipated action //--------------------------------------------------------------------------- else { std::cerr << "CprCluster::Streamer(): " "NOTHING DONE.\n"; } } bool CprCluster::postread(EventRecord* p) { // Fill in the track id is we have a valid link. if (_theTrack.is_nonnull()) _track_id = _theTrack->id().value(); else _track_id = 0; return ShowerMaxCluster::postread(p); } bool CprCluster::prewrite(EventRecord* p) {return ShowerMaxCluster::prewrite(p);}