Skip to content
Snippets Groups Projects
Commit 01c54ec0 authored by Tatyana Kharlamova's avatar Tatyana Kharlamova Committed by Graeme Stewart
Browse files

data handles (IDC_OverlayBase-00-07-00)

parent 3dab5b74
No related merge requests found
################################################################################
# Package: IDC_OverlayBase
################################################################################
# Declare the package name:
atlas_subdir( IDC_OverlayBase )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Control/AthenaBaseComps
Control/DataModel
DetectorDescription/Identifier
Event/EventOverlay/OverlayAlgBase )
# Component(s) in the package:
atlas_add_library( IDC_OverlayBase
PUBLIC_HEADERS IDC_OverlayBase
LINK_LIBRARIES AthenaBaseComps DataModel Identifier OverlayAlgBase )
......@@ -49,7 +49,7 @@ namespace Overlay {
* specialization, see above.
*/
template<class Collection> void mergeCollectionsNew(Collection *data_coll, Collection *mc_coll, IDC_OverlayBase* parent);
template<class Collection> void mergeCollectionsNew(Collection *mc_coll, Collection *data_coll, Collection *out_coll, IDC_OverlayBase* parent);
}
......@@ -65,7 +65,7 @@ public:
* After this call the "data" container contains all information, and the "mc"
* container is empty.
*/
template<class IDC_Container> void overlayContainer(IDC_Container* data, IDC_Container* mc) {
template<class IDC_Container> void overlayContainer(IDC_Container* data, IDC_Container* mc ) {
Overlay::overlayContainer(data, mc, this);
}
......@@ -73,12 +73,12 @@ public:
this->overlayContainer(data.get(), mc.get());
}
template<class IDC_Container> void overlayContainerNew(IDC_Container* data, IDC_Container* mc) {
Overlay::overlayContainerNew(data, mc, this);
template<class IDC_Container> void overlayContainerNew(const IDC_Container* data, const IDC_Container* mc, IDC_Container* out ) {
Overlay::overlayContainerNew(data, mc, out, this);
}
template<class IDC_Container> void overlayContainerNew(const std::auto_ptr<IDC_Container>& data, const std::auto_ptr<IDC_Container>& mc) {
this->overlayContainerNew(data.get(), mc.get());
template<class IDC_Container> void overlayContainerNew(const std::auto_ptr<IDC_Container>& data, const std::auto_ptr<IDC_Container>& mc, std::auto_ptr<IDC_Container>& out) {
this->overlayContainerNew(data.get(), mc.get(), out.get());
}
template<class IDC_Container> std::string shortPrint(const IDC_Container *container, unsigned numprint = 25) {
......@@ -91,10 +91,10 @@ public:
/**
* Adds data from the second collection to the first merging where necessary.
* After this call the "data" collection contains all information, and the "mc"
* After this call the "mc" collection contains all information, and the "data"
* collection is empty.
*/
template<class Collection> void mergeCollections(Collection *data_coll, Collection *mc_coll);
template<class Collection> void mergeCollections(Collection *mc_coll, Collection *data_coll);
};
......
......@@ -30,23 +30,23 @@ namespace Overlay {
first_time = false;
parent->msg(MSG::WARNING)<<"Overlay::mergeChannelData(): Merging of hits on the same channel is not implemented for "
<<typeid(Datum).name()
<<endreq;
<<endmsg;
}
}
//================================================================
template<class Collection>
void mergeCollectionsNew(Collection *data_coll, Collection *mc_coll, IDC_OverlayBase *parent) {
void mergeCollectionsNew(Collection *mc_coll, Collection *data_coll, Collection *out_coll, IDC_OverlayBase *parent) {
if(data_coll->identify() != mc_coll->identify()) {
if(mc_coll->identify() != data_coll->identify()) {
std::ostringstream os;
os<<"mergeCollectionsNew<generic>(): collection Id mismatch";
parent->msg(MSG::FATAL)<<os.str()<<endreq;
parent->msg(MSG::FATAL)<<os.str()<<endmsg;
throw std::runtime_error(os.str());
}
const Identifier idColl = data_coll->identify();
const Identifier idColl = mc_coll->identify();
// ----------------------------------------------------------------
// debug
......@@ -55,8 +55,8 @@ namespace Overlay {
first_time = false;
parent->msg(MSG::INFO)<<"IDC_OverlayBase::mergeCollectionsNew(): "
<<"generic code is called for "
<<typeid(*data_coll).name()
<<endreq;
<<typeid(*mc_coll).name()
<<endmsg;
}
// ----------------------------------------------------------------
......@@ -71,11 +71,8 @@ namespace Overlay {
mc.setIdentifier(idColl);
mc_coll->swap(mc);
// Just an alias
Collection *output = data_coll;
//################################################################
// Merge by copying ptrs from data and mc to data_coll
// Merge by copying ptrs from data and mc to mc_coll
typename Collection::size_type idata = 0;
typename Collection::size_type imc = 0;
......@@ -85,34 +82,34 @@ namespace Overlay {
// The RDO that goes to the output at the end of this step.
typename Collection::base_value_type *p_rdo(0);
if(idata == data.size()) {
// just copy the remaining MC inputs
mc.swapElement(imc++, 0, p_rdo);
}
else if(imc == mc.size()) {
//just copy the remaining data digits
if(imc == mc.size()) {
// just copy the remaining data inputs
data.swapElement(idata++, 0, p_rdo);
}
else if(idata == data.size()) {
//just copy the remaining MC digits
mc.swapElement(imc++, 0, p_rdo);
}
else {
// Need to decide which one goes first.
// See comments in TRTDigitization.cxx about the assumption that id1<id2 <=> hash1<hash2
if( data[idata]->identify() < mc[imc]->identify() ) {
data.swapElement(idata++, 0, p_rdo);
}
else if(mc[imc]->identify() < data[idata]->identify()) {
if( mc[imc]->identify() < data[idata]->identify() ) {
mc.swapElement(imc++, 0, p_rdo);
}
else if(data[idata]->identify() < mc[imc]->identify()) {
data.swapElement(idata++, 0, p_rdo);
}
else {
// The hits are on the same channel.
typename Collection::base_value_type *p2(0);
mc.swapElement(imc++, 0, p2);
data.swapElement(idata++, 0, p_rdo);
data.swapElement(idata++, 0, p2);
mc.swapElement(imc++, 0, p_rdo);
Overlay::mergeChannelData(*p_rdo, *p2, parent);
delete p2;
}
}
output->push_back(p_rdo);
out_coll->push_back(p_rdo);
} // <= while
}
......@@ -121,8 +118,8 @@ namespace Overlay {
//================================================================
template<class Collection>
void IDC_OverlayBase::mergeCollections(Collection *data_coll,
Collection *mc_coll)
void IDC_OverlayBase::mergeCollections(Collection *mc_coll,
Collection *data_coll)
{
DataVector<typename Collection::base_value_type> data;
data_coll->swap(data);
......@@ -131,10 +128,10 @@ void IDC_OverlayBase::mergeCollections(Collection *data_coll,
mc_coll->swap(mc);
// Just an alias
Collection *output = data_coll;
Collection *output = mc_coll;
//################################################################
// Merge by copying ptrs from data and mc to data_coll
// Merge by copying ptrs from data and mc to mc_coll
typename Collection::size_type idata = 0;
typename Collection::size_type imc = 0;
......@@ -164,8 +161,8 @@ void IDC_OverlayBase::mergeCollections(Collection *data_coll,
else {
// The hits are on the same channel.
typename Collection::base_value_type *p2(0);
mc.swapElement(imc++, 0, p2);
data.swapElement(idata++, 0, p_rdo);
data.swapElement(idata++, 0, p2);
mc.swapElement(imc++, 0, p_rdo);
Overlay::mergeChannelData(*p_rdo, *p2, this);
delete p2;
}
......
......@@ -28,8 +28,10 @@ class IDC_OverlayBase;
namespace Overlay {
template<class Collection> void copyCollection(const Collection *input_coll, Collection *copy_coll);
//Forward decl for compiling ...
template<class Collection> void mergeCollectionsNew(Collection*, Collection*, IDC_OverlayBase*);
template<class Collection> void mergeCollectionsNew(Collection*, Collection*, Collection*, IDC_OverlayBase*);
/**
* Transfers all collection from the second argument the first merging where necessary.
......@@ -44,12 +46,13 @@ namespace Overlay {
overlayContainer(data.get(), mc.get(), parent);
}
template<class IDC_Container, class OvlAlg> void overlayContainerNew(IDC_Container* data, IDC_Container* mc, OvlAlg *parent);
template<class IDC_Container, class OvlAlg> void overlayContainerNew(const IDC_Container* dataContainer, const IDC_Container* mcContainer, IDC_Container* outputContainer, OvlAlg *parent);
template<class IDC_Container, class OvlAlg> void overlayContainerNew(const std::auto_ptr<IDC_Container>& data,
const std::auto_ptr<IDC_Container>& mc,
const std::auto_ptr<IDC_Container>& mc,
const std::auto_ptr<IDC_Container>& out,
OvlAlg *parent)
{
overlayContainerNew(data.get(), mc.get(), parent);
overlayContainerNew(data.get(), mc.get(), out.get(), parent);
}
/** Diagnostic output */
......
......@@ -40,86 +40,68 @@ namespace Overlay {
//================================================================
template<class IDC_Container, class OvlAlg>
void overlayContainerNew(IDC_Container *dataContainer,
IDC_Container *mcContainer,
void overlayContainerNew(const IDC_Container *dataContainer,
const IDC_Container *mcContainer,
IDC_Container *outputContainer,
OvlAlg *parent)
{
typedef typename IDC_Container::base_value_type Collection;
if(parent->msgLvl(MSG::DEBUG)) { parent->msg(MSG::DEBUG)<<"overlayContainerNew<>() begin"<<endreq; }
// The MC signal container should typically be smaller than
// dataContainer, because the latter contains all the noise,
// min bias and pile up. Thus we loop other MC inputs.
if(parent->msgLvl(MSG::DEBUG)) { parent->msg(MSG::DEBUG)<<"overlayContainerNew<>() begin"<<endmsg; }
// We are modifying both mcContainer and dataContainer in the loop.
// That invalidates iterators. Therefore we prepare a list of
// hashIds to work with and keep it in a separate container that is
// not modified during the loop.
/** Add data from the data container to the output one */
typename IDC_Container::const_iterator p_data = dataContainer->begin();
typename IDC_Container::const_iterator p_data_end = dataContainer->end();
std::vector<IdentifierHash> mc_hashIds;
mc_hashIds.reserve(mcContainer->numberOfCollections());
for(typename IDC_Container::const_iterator p = mcContainer->begin();
p != mcContainer->end();
++p)
{
mc_hashIds.push_back( p.hashId() );
for(; p_data != p_data_end; ++p_data) {
IdentifierHash hashId = p_data.hashId();
Collection *coll_data=new Collection(hashId);
copyCollection(p_data->cptr(),coll_data);
if ( outputContainer->addCollection(coll_data, p_data.hashId()).isFailure() ) {
parent->msg(MSG::WARNING) <<"add data Collection failed for output "<< p_data.hashId()<<endmsg; //" collectionNo "<<collectionNo<<endmsg;
}
}
/** Add data from the ovl container to the output one */
typename IDC_Container::const_iterator p_ovl = mcContainer->begin();
typename IDC_Container::const_iterator p_ovl_end = mcContainer->end();
for(; p_ovl != p_ovl_end; ++p_ovl) {
IdentifierHash coll_id = p_ovl.hashId();//(*p_ovl)->identify();
Collection *coll_ovl=new Collection(coll_id);
copyCollection(p_ovl->cptr(),coll_ovl);
/** The newly created stuff will go to the output EventStore SG */
Collection *out_coll = new Collection( coll_id );
out_coll->setIdentifier((*p_ovl)->identify());
/** Look for the same ID in the main StoreGate EventStore */
typename IDC_Container::const_iterator q = outputContainer->indexFind( coll_id );
if( q != outputContainer->end() ) {
/** Need to merge the collections
Retrieve q */
Collection *coll_data = (Collection *) q->cptr();
mergeCollectionsNew(coll_data,coll_ovl, out_coll,parent);
outputContainer->removeCollection(p_ovl.hashId());
if (outputContainer->addCollection(out_coll, p_ovl.hashId()).isFailure() ) {
parent->msg(MSG::WARNING) << "overlay addCollection failed " << endreq;
}
for(std::vector<IdentifierHash>::const_iterator ph = mc_hashIds.begin();
ph != mc_hashIds.end();
++ph)
{
IdentifierHash hashId = *ph;
// Take possession of the MC store collection
// If there is no matching collection in dataContainer we just transfer
// this whole collection to the "data" container.
Collection *c_mc = mcContainer->removeCollection(hashId);
// Look for the same ID in the dataContainer SG
// FIXME: removeCollection() should not need this protection.
// But without it, just using
//
// Collection *c_data = dataContainer->removeCollection(hashId);
//
// we get
//
// InDetOverlay DEBUG TRT MC = * 2 1 1 1 1 * 1 * * * * * 1 * * * 1 1 * 2 1 * 1 1
// InDetOverlay DEBUG overlayContainerNew<>() begin
// IDC_OverlayBase::overlayContainerNew() line= 163
// IDC_OverlayBase::overlayContainerNew() line= 169
// InDetOverlay.sysExecute() FATAL Standard std::exception is caught
// InDetOverlay.sysExecute() ERROR dereferencing invalid DataLink
//
// So use the following for now:
Collection *c_data =
(dataContainer->indexFind(hashId) != dataContainer->end()) ? dataContainer->removeCollection(hashId) : 0;
if(c_data) {
// Need to merge the collections
if(parent->msgLvl(MSG::VERBOSE)) { parent->msg(MSG::VERBOSE)<<"Merging collections"<<endreq; }
//parent->mergeCollections(c_mc, c_data);
mergeCollectionsNew(c_mc, c_data, parent);
}
else {
if(parent->msgLvl(MSG::VERBOSE)) {
parent->msg(MSG::VERBOSE)<<"Transferring to dataContainer complete ovl collection, no merging"<<endreq;
}
}
if(dataContainer->addCollection(c_mc, hashId).isFailure()) {
if(parent->msgLvl(MSG::WARNING)) {
parent->msg(MSG::WARNING)<<"overlayContainerNew(): Problem in dataContainer->addCollection(hash) for ovl collection="
<<c_mc<<endreq;
}
}
}
else {
/** Copy the complete collection from ovl to output,
hopefully preserving the "most derived" type of its raw data */
if ( outputContainer->addCollection(coll_ovl, coll_id).isFailure() ) {
parent->msg(MSG::WARNING) << "add mc Collection failed " << endreq;
}
}
}
}
......@@ -131,7 +113,7 @@ namespace Overlay {
{
typedef typename IDC_Container::base_value_type Collection;
if(parent->msgLvl(MSG::DEBUG)) { parent->msg(MSG::DEBUG)<<"overlayContainer<>() begin"<<endreq; }
if(parent->msgLvl(MSG::DEBUG)) { parent->msg(MSG::DEBUG)<<"overlayContainer<>() begin"<<endmsg; }
// The MC signal container should typically be smaller than
// dataContainer, because the latter contains all the noise,
......@@ -186,20 +168,20 @@ namespace Overlay {
if(c_data) {
// Need to merge the collections
if(parent->msgLvl(MSG::VERBOSE)) { parent->msg(MSG::VERBOSE)<<"Merging collections"<<endreq; }
if(parent->msgLvl(MSG::VERBOSE)) { parent->msg(MSG::VERBOSE)<<"Merging collections"<<endmsg; }
parent->mergeCollections(c_mc, c_data);
}
else {
if(parent->msgLvl(MSG::VERBOSE)) {
parent->msg(MSG::VERBOSE)<<"Transferring to dataContainer complete ovl collection, no merging"<<endreq;
parent->msg(MSG::VERBOSE)<<"Transferring to dataContainer complete ovl collection, no merging"<<endmsg;
}
}
if(dataContainer->addCollection(c_mc, hashId).isFailure()) {
if(parent->msgLvl(MSG::WARNING)) {
parent->msg(MSG::WARNING)<<"overlayContainer(): Problem in dataContainer->addCollection(hash) for ovl collection="
<<c_mc<<endreq;
<<c_mc<<endmsg;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment