//============================================================================ // StorableRun2SiStripSet.cc // ------------------------- // Implementation of the StorableRun2SiStripSet class: // // A collection derived from SiStripSet that is compliant with CDF EDM2. // The strip data is read and written to SIXD_StorableBank and // ISLD_StorableBank objects. This collection will also restore links to // MC truth information if that is present. // // Note that this collection does not yet deal with regional silicon tracking. // // R. Snider // Fermilab // 4-Oct-1999 //============================================================================ #ifdef USE_CDFEDM2 #include "TrackingObjects/Storable/StorableRun2SiStripSet.hh" #include "AbsEnv/AbsEnv.hh" #include "Edm/ConstHandle.hh" #include "Edm/EventRecord.hh" #include "Edm/GenericConstHandle.hh" #include "Edm/Handle.hh" #include "RawDataBanks/ISLD_StorableBank.hh" #include "RawDataBanks/SIXD_StorableBank.hh" #include "SimulationObjects/MISL_StorableBank.hh" #include "SimulationObjects/MSVX_StorableBank.hh" #include "Trybos/TRY_Bank_Number.hh" //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Standard find functions //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= StorableRun2SiStripSet::Error StorableRun2SiStripSet::find( StorableRun2SiStripSet_ch & setHandle ) { EventRecord::ConstIterator i( AbsEnv::instance()->theEvent(), "StorableRun2SiStripSet" ); if ( i.is_valid() ) { setHandle = i; return OK; } else { setHandle.set_null(); return ERROR; } } StorableRun2SiStripSet::Error StorableRun2SiStripSet::find( StorableRun2SiStripSet_ch & setHandle, const StorableObject::Selector & selector ) { EventRecord::ConstIterator i( AbsEnv::instance()->theEvent(), "StorableRun2SiStripSet" ); while ( i.is_valid() && !selector( *i ) ) { ++i; } if ( i.is_valid() ) { setHandle = i; return OK; } else { setHandle.set_null(); return ERROR; } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Constructors, desctructor //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // This one will create new banks on output // StorableRun2SiStripSet::StorableRun2SiStripSet() : TRYRun2SiStripSet(), _lSixd(), _lIsld(),_lMsvx(),_lMisl(), _lRegion(), _createBanksOnOutput(true) {} // This one cannot create new banks on output // // lhm 19feb02: added nndata and monitor capabilities // only valid if no MSVX and no regions and asked for StorableRun2SiStripSet:: StorableRun2SiStripSet( EventRecord * pEvent, const GeometricRegion & region) : TRYRun2SiStripSet( region ), _createBanksOnOutput(false) { loadFromBanks(pEvent, region); } // Note: this destructor is protected // StorableRun2SiStripSet::~StorableRun2SiStripSet() {} bool StorableRun2SiStripSet::loadFromBanks(EventRecord * pEvent, const GeometricRegion & region) { // Set the region : setRegion(region); std::vector hdiKeys; hdiKeys.reserve(360); _createBanksOnOutput = false; bool banksFound = false; if ( pEvent ) { //----------------------------------------------------------- // Unpack SVX data from global bank // At the moment, assume that the first SIXD bank found is // the one from the DAQ or simulation //----------------------------------------------------------- StorableObject::SelectByDescription desc(description() ); StorableObject::SelectByClassName cNameSVX( "SIXD_StorableBank" ); EventRecord::ConstIterator iSixd( pEvent, desc && cNameSVX ); if ( iSixd.is_valid() ) { banksFound = true; ConstHandle hSixd( iSixd ); _lSixd = hSixd; //----------------------------------------------- // Check for MC truth information //----------------------------------------------- StorableObject::SelectByClassName cNameMSVX( "MSVX_StorableBank" ); EventRecord::ConstIterator iMsvx( pEvent, desc && cNameMSVX ); //EventRecord::ConstIterator iMsvx( pEvent, "MSVX_StorableBank" ); if ( iMsvx.is_valid() ) { ConstHandle hMsvx( iMsvx ); if (®ion.myType() != &WorldRegion::_myType) { readSIXDBank_prepare( *hSixd, hdiKeys ); readSIXDBank_nndata ( *hSixd, hdiKeys ); } else { readSIXDBank_simple( *hSixd, hMsvx.operator->() ); } } else { readSIXDBank_prepare( *hSixd, hdiKeys ); readSIXDBank_nndata ( *hSixd, hdiKeys ); } } // else { // ERRLOG( ELinfo, "SIXD bank not found" ) // << "@SUB=StorableRun2SiStripSet::loadFromBanks" // << endmsg; // } //----------------------------------------------------------- // Unpack ISL data from global bank // At the moment, assume that the first ISLD bank found is // the one from the DAQ or simulation //----------------------------------------------------------- StorableObject::SelectByClassName cNameISL( "ISLD_StorableBank" ); EventRecord::ConstIterator iIsld( pEvent, desc && cNameISL ); if ( iIsld.is_valid() ) { banksFound = true; ConstHandle hIsld( iIsld ); _lIsld = hIsld; //----------------------------------------------- // Check for MC truth information //----------------------------------------------- //EventRecord::ConstIterator iMisl( pEvent, "MISL_StorableBank" ); StorableObject::SelectByClassName cNameMISL( "MISL_StorableBank" ); EventRecord::ConstIterator iMisl( pEvent, desc && cNameMISL ); if ( iMisl.is_valid() ) { ConstHandle hMisl( iMisl ); if (®ion.myType() != &WorldRegion::_myType) { readISLDBank_prepare( *hIsld, hdiKeys ); readISLDBank_nndata ( *hIsld, hdiKeys ); } else { readISLDBank_simple( *hIsld, hMisl.operator->() ); } } else { readISLDBank_prepare( *hIsld, hdiKeys ); readISLDBank_nndata ( *hIsld, hdiKeys ); } } } //------------------------------------------------------------- // Create link to input geometric region. // // There is a complication here. If the region is a WorldRegion, // then is does not really live in the event -- it is a global // symbol (TWorld) defined only at run-time. In this case, // we should *not* define the link, so that when the link is // stored in the event, it will have the value Link::undefined(). // When the strip set is read in, we will assume all links that // are undefined actually point to TWorld. //------------------------------------------------------------- if (®ion.myType() != &WorldRegion::_myType) { _lRegion = ®ion; } return banksFound; } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // EDM implementation //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void StorableRun2SiStripSet::destroy() { StorableRun2SiStripSet::deallocate(); delete this; } void StorableRun2SiStripSet::deallocate() { StorableObject::deallocate(); } std::string StorableRun2SiStripSet::class_name() const { return std::string( "StorableRun2SiStripSet" ); } Version_t StorableRun2SiStripSet::class_version() const { return StorableRun2SiStripSet::Class_Version(); // defined in ClassDef macro } bool StorableRun2SiStripSet::postread( EventRecord * pRecord ) { //------------------------------------------------------------- // This set can create SIXD and ISLD banks on output. If the // set is filled from links to existing banks, then new banks // should *not* be created on output. // // Do not create new banks on output //------------------------------------------------------------- _createBanksOnOutput = false; //------------------------------------------------------------- // Restore the links //------------------------------------------------------------- bool retVal = StorableObject::postread( pRecord ); retVal &= _lSixd.restore( pRecord ); retVal &= _lIsld.restore( pRecord ); retVal &= _lRegion.restore( pRecord ); return retVal; } void StorableRun2SiStripSet::Streamer( TBuffer & iobuffer ) { unsigned int start = 0; unsigned int byteCount = 0; if ( iobuffer.IsReading() ) { _originalVersion = iobuffer.ReadVersion( &start, &byteCount ); if ( _originalVersion == 1 ) { StorableObject::Streamer( iobuffer ); _lSixd.Streamer( iobuffer ); _lIsld.Streamer( iobuffer ); _lMsvx.Streamer( iobuffer ); _lMisl.Streamer( iobuffer ); _lRegion.Streamer( iobuffer ); } else { ERRLOG( ELerror, "Unsupported version" ) << "@SUB=StorableRun2SiStripSet::Streamer" << "Unsupported StorableRun2SiStripSet version cannot be read" << endmsg; } iobuffer.CheckByteCount( start, byteCount, StorableRun2SiStripSet::IsA() ); } else if ( iobuffer.IsWriting() ) { byteCount = iobuffer.WriteVersion( StorableRun2SiStripSet::IsA(), kTRUE ); Version_t currentVersion = class_version(); if ( currentVersion == 1 ) { StorableObject::Streamer( iobuffer ); _lSixd.Streamer( iobuffer ); _lIsld.Streamer( iobuffer ); _lMsvx.Streamer( iobuffer ); _lMisl.Streamer( iobuffer ); _lRegion.Streamer( iobuffer ); } else { ERRLOG( ELerror, "Unsupported version" ) << "@SUB=StorableRun2SiStripSet::Streamer" << "Unsupported StorableRun2SiStripSet version cannot be written" << endmsg; } iobuffer.SetByteCount( byteCount, kTRUE ); } else { //------------------------------------------------------------- // Dunno what's happening //------------------------------------------------------------- ERRLOG( ELerror, "StorableRun2SiStripSet:Streamer()" ) << "@SUB=StorableRun2SiStripSet::Streamer" << "Nothing done." << endmsg; } } bool StorableRun2SiStripSet::prewrite( EventRecord * pRecord ) { //------------------------------------------------------------------ // Check if new banks are needed. Don't bother if the strip // set is empty //------------------------------------------------------------------ bool appendBanks = _createBanksOnOutput; if ( appendBanks && nStrips() ) writeBanks( pRecord ); //------------------------------------------------------------------ // Call the link prewrites and return. //------------------------------------------------------------------ bool retVal = StorableObject::prewrite( pRecord ); _createBanksOnOutput = appendBanks; return retVal; } void StorableRun2SiStripSet::writeBanks(EventRecord * pRecord, const char* const theDescription) { //------------------------------------------------------ // First create and fill the banks //------------------------------------------------------ SIXD_StorableBank * pSixd; pSixd = new SIXD_StorableBank( TRY_Bank_Number( 1 ), estimateSIXDsize( nStrips() ) ); MSVX_StorableBank * pMsvx; pMsvx = new MSVX_StorableBank( TRY_Bank_Number( 1 ), estimateMSVXsize( nStrips() ) ); fillSIXDBank( *pSixd, *pMsvx ); ISLD_StorableBank * pIsld; pIsld = new ISLD_StorableBank( TRY_Bank_Number( 1 ), estimateISLDsize( nStrips() ) ); MISL_StorableBank * pMisl; pMisl = new MISL_StorableBank( TRY_Bank_Number( 1 ), estimateMISLsize( nStrips() ) ); fillISLDBank( *pIsld, *pMisl ); //------------------------------------------------------ // Add the banks to the event record //------------------------------------------------------ int nonDefDescript = strcmp(theDescription,""); if ( rcp_id().isValid() ) { pSixd->set_rcp_id( rcp_id() ); pIsld->set_rcp_id( rcp_id() ); } Handle hSixd( pSixd ); hSixd->set_description( theDescription ); GenericConstHandle chSixd = pRecord->append( hSixd ); if ( (!nonDefDescript)&&(pMsvx->data_size() > 0) ) { Handle hMsvx( pMsvx ); hMsvx->set_description(theDescription); GenericConstHandle chMsvx = pRecord->append( hMsvx ); _lMsvx = ConstHandle(chMsvx); } else { pMsvx->destroy(); } Handle hIsld( pIsld ); hIsld->set_description( theDescription ); GenericConstHandle chIsld = pRecord->append( hIsld ); if ( (!nonDefDescript)&&(pMisl->data_size() > 0) ) { Handle hMisl( pMisl ); hMisl->set_description(theDescription); GenericConstHandle chMisl = pRecord->append( hMisl ); _lMisl = ConstHandle(chMisl); } else { pMisl->destroy(); } //------------------------------------------------------ // Set the links to point to the new banks //------------------------------------------------------ _lSixd = ConstHandle(chSixd); _lIsld = ConstHandle(chIsld); _createBanksOnOutput = false; return; } bool StorableRun2SiStripSet::activate( EventRecord * pRecord ) { return StorableObject::activate( pRecord ); } bool StorableRun2SiStripSet::deactivate( EventRecord * pRecord ) { return StorableObject::deactivate( pRecord ); } void StorableRun2SiStripSet::print( std::ostream & os ) const { os << "========================================================================" << std::endl << "Contents of StorableRun2SiStripSet: OID: " << object_id() << " " << " Descr: " << description() << std::endl; this->TRYRun2SiStripSet::print( os ); } void StorableRun2SiStripSet::puff(EventRecord *event) { //------------------------------------------------------------- // Initialize region // If region is undefined or null, assume world region //------------------------------------------------------------- std::vector hdiKeys; hdiKeys.reserve(360); if ( _lRegion.is_stored() && _lRegion.is_nonnull() ) { setRegion( *_lRegion ); } else { setRegion( TWorld ); } //------------------------------------------------------------- // Read in the banks //------------------------------------------------------------- if ( _lSixd.is_stored() && _lSixd.is_nonnull() ) { //------------------------------------------------------ // Check for MC data //------------------------------------------------------ // EventRecord::ConstIterator iMsvx( event, "MSVX_StorableBank" ); // if ( iMsvx.is_valid() ) // { // ConstHandle hMsvx( iMsvx ); // readSIXDBank( *_lSixd, hMsvx.operator->() ); // } // else // { // readSIXDBank( *_lSixd, static_cast(0) ); // } EventRecord::ConstIterator iMsvx( event, "MSVX_StorableBank" ); if ( iMsvx.is_valid() ) { ConstHandle hMsvx( iMsvx ); if (&_lRegion->myType() != &WorldRegion::_myType) { readSIXDBank_prepare( *_lSixd, hdiKeys ); readSIXDBank_nndata ( *_lSixd, hdiKeys ); } else { readSIXDBank_simple( *_lSixd, hMsvx.operator->() ); } } else { readSIXDBank_prepare( *_lSixd, hdiKeys ); readSIXDBank_nndata ( *_lSixd, hdiKeys ); } } else { ERRLOG( ELinfo, "No SIXD link" ) << "@SUB=StorableRun2SiStripSet::postread" << "Link from event has is_defined = " << _lSixd.is_stored() << " and is_nonnull = " << _lSixd.is_nonnull() << ". No SVX data." << endmsg; } if ( _lIsld.is_stored() && _lIsld.is_nonnull() ) { //------------------------------------------------------ // Check for MC data //------------------------------------------------------ // EventRecord::ConstIterator iMisl( event, "MISL_StorableBank" ); // if ( iMisl.is_valid() ) // { // ConstHandle hMisl( iMisl ); // readISLDBank( *_lIsld, hMisl.operator->() ); // } // else // { // readISLDBank( *_lIsld, static_cast(0) ); // } EventRecord::ConstIterator iMisl( event, "MISL_StorableBank" ); if ( iMisl.is_valid() ) { ConstHandle hMisl( iMisl ); if (&_lRegion->myType() != &WorldRegion::_myType) { readISLDBank_prepare( *_lIsld, hdiKeys ); readISLDBank_nndata ( *_lIsld, hdiKeys ); } else { readISLDBank_simple( *_lIsld, hMisl.operator->() ); } } else { readISLDBank_prepare( *_lIsld, hdiKeys ); readISLDBank_nndata ( *_lIsld, hdiKeys ); } } else { ERRLOG( ELinfo, "No ISLD link" ) << "@SUB=StorableRun2SiStripSet::postread" << "Link from event has is_defined = " << _lIsld.is_stored() << " and is_nonnull = " << _lIsld.is_nonnull() << ". No ISL data." << endmsg; } } //---------------------------------------------------------------------------- // Root I/O hook implementation //---------------------------------------------------------------------------- CdfClassImp( StorableRun2SiStripSet ) #endif // USE_CDFEDM2