Commit 493dceb5 authored by Rachid Mazini's avatar Rachid Mazini
Browse files

Merge branch 'dataheader-mc16a' into '21.0-mc16a'

DataHeader_p6 for MC16a

See merge request !37527
parents 34faff46 70c40036
......@@ -426,7 +426,7 @@ void EventSelectorAthenaPool::fireEndFileIncidents(bool isLastFile, bool fireEnd
// Assume that the end of collection file indicates the end of payload file.
if (m_guid != Guid::null()) {
// Fire EndInputFile incident
FileIncident endInputFileIncident(name(), "EndInputFile", "FID:" + m_guid.toString());
FileIncident endInputFileIncident(name(), "EndInputFile", "FID:" + m_guid.toString(), m_guid.toString());
m_incidentSvc->fireIncident(endInputFileIncident);
}
// Fire EndTagFile incident if not out of files (maybe we should make it fire then as well?)
......@@ -1080,7 +1080,7 @@ PoolCollectionConverter* EventSelectorAthenaPool::getCollectionCnv(bool throwInc
if (throwIncidents && m_processMetadata.value()) {
FileIncident beginInputFileIncident(name(), "BeginInputFile", *m_inputCollectionsIterator);
m_incidentSvc->fireIncident(beginInputFileIncident);
FileIncident endInputFileIncident(name(), "EndInputFile", "eventless " + *m_inputCollectionsIterator);
FileIncident endInputFileIncident(name(), "EndInputFile", "eventless " + *m_inputCollectionsIterator, m_guid.toString() );
m_incidentSvc->fireIncident(endInputFileIncident);
}
m_athenaPoolCnvSvc->getPoolSvc()->disconnectDb(*m_inputCollectionsIterator, IPoolSvc::kInputStream).ignore();
......
......@@ -75,11 +75,13 @@ public: // Non-static members
/// Add new entry to hash map
void addHash(IStringPool* pool);
void dump(std::ostream& ostr) const;
private:
friend class DataHeaderElementCnv_p3;
friend class DataHeaderElementCnv_p4;
friend class DataHeaderElementCnv_p5;
friend class DataHeaderElementCnv_p6;
friend class DataHeaderCnv_p6;
/// primary ClassID.
CLID m_pClid;
......@@ -165,6 +167,8 @@ public: // Non-static members
void setEvtRefTokenStr(const std::string& tokenStr);
const std::string& getEvtRefTokenStr();
void dump(std::ostream& ostr) const;
private:
friend class DataHeaderCnv_p3;
friend class DataHeaderCnv_p4;
......
......@@ -149,6 +149,34 @@ SG::TransientAddress* DataHeaderElement::getAddress(const std::string& key,
sgAddress->setAlias(m_alias);
return(sgAddress);
}
//______________________________________________________________________________
void DataHeaderElement::dump(std::ostream& ostr) const
{
using namespace std;
ostr << "SGKey: " << getKey() << endl;
ostr << "CLID: " << getPrimaryClassID();
if( getClassIDs().size() > 1 ) {
ostr << " ||";
for( auto& c : getClassIDs() ) ostr << " " << c;
}
ostr << std::endl;
if( getAlias().size() > 0 ) {
ostr << "Alias: ";
for( auto& a : getAlias() ) ostr << " " << a;
ostr << endl;
}
if( m_token ) {
ostr << "Token: " << m_token->toString();
if( m_ownToken ) ostr << " owned";
ostr << endl;
}
if( m_hashes.size() ) {
ostr << "Hashes:";
for( auto h : m_hashes ) ostr << " " << h;
ostr << endl;
}
}
//______________________________________________________________________________
//______________________________________________________________________________
DataHeader::DataHeader() : m_dataHeader(),
......@@ -270,3 +298,24 @@ void DataHeader::setEvtRefTokenStr(const std::string& tokenStr) {
const std::string& DataHeader::getEvtRefTokenStr() {
return(m_evtRefTokenStr);
}
//______________________________________________________________________________
#include "CoralBase/AttributeList.h"
#include "CoralBase/Attribute.h"
void DataHeader::dump(std::ostream& ostr) const
{
using namespace std;
ostr << "--- DataHeader Dump ---" << endl;
for( auto& el : m_dataHeader ) {
el.dump(ostr);
}
for( auto& el : m_inputDataHeader ) {
el.dump(ostr);
}
ostr << "Status: " << m_status << endl;
ostr << "Proc tag: " << m_processTag << endl;
ostr << "evtRef: " << m_evtRefTokenStr << endl;
ostr << "attrListPtr: " << m_attrList << endl;
if( m_attrList ) ostr << "attrListSize: " << m_attrList->size() << endl;
ostr << "--- DataHeader End ---" << endl;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
/** @file DataHeaderCnv.cxx
* @brief This file contains the implementation for the DataHeaderCnv class.
* @author Peter van Gemmeren <gemmeren@anl.gov>
* $Id: DataHeaderCnv.cxx,v 1.15 2009-04-21 22:04:51 gemmeren Exp $
**/
#include "DataHeaderCnv.h"
......@@ -14,10 +13,15 @@
#include "PersistentDataModel/Token.h"
#include "PersistentDataModelTPCnv/DataHeaderCnv_p3.h"
#include "PersistentDataModelTPCnv/DataHeaderCnv_p4.h"
#include "PersistentDataModelTPCnv/DataHeader_p6.h"
#include "CoralBase/AttributeList.h"
#include "CoralBase/Attribute.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "GaudiKernel/FileIncident.h"
#include "AthenaBaseComps/AthCheckMacros.h"
#include <memory>
#include <stdexcept>
......@@ -27,8 +31,47 @@ DataHeaderCnv::DataHeaderCnv(ISvcLocator* svcloc) :
m_dhFormMdx(),
m_dhForm(0) {
}
DataHeaderCnv::~DataHeaderCnv() {
delete m_dhForm ; m_dhForm = 0;
//______________________________________________________________________________
DataHeaderCnv::~DataHeaderCnv()
{
// Remove itself from the IncidentSvc - if it is still around
ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", "DataHeaderCnv");
if( incSvc.retrieve().isSuccess() ) {
incSvc->removeListener(this, IncidentType::EndInputFile);
}
delete m_dhForm ; m_dhForm = nullptr;
for( auto& item : m_persFormMap ) {
delete item.second;
}
}
//______________________________________________________________________________
StatusCode DataHeaderCnv::initialize()
{
// listen to EndFile incidents to clear old DataHeaderForms from the cache
//Get IncidentSvc
ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", "DataHeaderCnv");
ATH_CHECK( incSvc.retrieve() );
incSvc->addListener(this, IncidentType::EndInputFile, 0);
return DataHeaderCnvBase::initialize();
}
//______________________________________________________________________________
void DataHeaderCnv::handle(const Incident& incident)
{
if( incident.type() == IncidentType::EndInputFile ) {
// remove cached DHForms that came from the file that is now being closed
const std::string& guid = static_cast<const FileIncident&>(incident).fileGuid();
auto iter = m_persFormMap.begin();
while( iter != m_persFormMap.end() ) {
size_t dbpos = iter->first.find("[DB=");
if( dbpos != std::string::npos && iter->first.substr(dbpos+4, dbpos+36) == guid ) {
delete iter->second;
iter = m_persFormMap.erase( iter );
} else {
iter++;
}
}
}
}
//______________________________________________________________________________
......@@ -142,6 +185,8 @@ StatusCode DataHeaderCnv::DataObjectToPool(DataObject* pObj, const std::string&
this->m_o_poolToken = dh_token; // return to converter
return(StatusCode::SUCCESS);
}
#include <sstream>
using namespace std;
//______________________________________________________________________________
DataHeader_p5* DataHeaderCnv::poolReadObject_p5() {
DataHeader_p5* pObj = 0;
......@@ -188,6 +233,37 @@ DataHeader_p5* DataHeaderCnv::poolReadObject_p5() {
}
return(pObj);
}
//______________________________________________________________________________
// Read the persistent rep of DataHeader_p6 and also DataHeaderForm_p6 if necessary
// Set dh_form pointer to the correct DataHeaderForm, either from file or cache
DataHeader_p6* DataHeaderCnv::poolReadObject_p6( DataHeaderForm_p6* &dh_form )
{
void* voidPtr1 = nullptr;
m_athenaPoolCnvSvc->setObjPtr(voidPtr1, m_i_poolToken);
if (voidPtr1 == nullptr) {
throw std::runtime_error("Could not get object for token = " + m_i_poolToken->toString());
}
DataHeader_p6* pObj = reinterpret_cast<DataHeader_p6*>(voidPtr1);
// see if the DataHeaderForm is already cached
dh_form = m_persFormMap[ pObj->dhFormToken() ];
if( !dh_form ) {
// we need to read a new DHF
void* voidPtr2 = nullptr;
Token mapToken;
mapToken.fromString(pObj->dhFormToken());
if (mapToken.classID() != Guid::null()) {
m_athenaPoolCnvSvc->setObjPtr(voidPtr2, &mapToken);
if (voidPtr2 == nullptr) {
throw std::runtime_error("Could not get object for token = " + mapToken.toString());
}
}
m_persFormMap[ pObj->dhFormToken() ] = dh_form = reinterpret_cast<DataHeaderForm_p6*>(voidPtr2);
}
return pObj;
}
//______________________________________________________________________________
DataHeader_p5* DataHeaderCnv::createPersistent(DataHeader* transObj) {
DataHeader_p5* persObj = m_TPconverter.createPersistent(transObj);
......@@ -207,10 +283,17 @@ DataHeader* DataHeaderCnv::createTransient() {
dh->insert(dhe);
return(dh);
}
static const pool::Guid p6_guid("4DDBD295-EFCE-472A-9EC8-15CD35A9EB8D");
static const pool::Guid p5_guid("D82968A1-CF91-4320-B2DD-E0F739CBC7E6");
static const pool::Guid p4_guid("9630EB7B-CCD7-47D9-A39B-CBBF4133CDF2");
static const pool::Guid p3_guid("EC1318F0-8E28-45F8-9A2D-2597C1CC87A6");
if (this->compareClassGuid(p5_guid)) {
if( compareClassGuid(p6_guid) ) {
DataHeaderForm_p6* dh_form = nullptr;
std::auto_ptr<DataHeader_p6> obj( poolReadObject_p6( dh_form ) );
auto dh = m_tpInConverter_p6.createTransient( obj.get(), *dh_form );
// To dump DH: ostringstream ss; dh->dump(ss); cout << ss.str() << endl;
return dh;
} else if (this->compareClassGuid(p5_guid)) {
std::auto_ptr<DataHeader_p5> obj_p5(this->poolReadObject_p5());
return(m_TPconverter.createTransient(obj_p5.get()));
} else if (this->compareClassGuid(p4_guid)) {
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef DATAHEADERCNV_H
......@@ -9,35 +9,56 @@
* @file DataHeaderCnv.h
* @brief This file contains the class definition for the DataHeaderCnv class.
* @author Peter van Gemmeren <gemmeren@anl.gov>
* $Id: DataHeaderCnv.h,v 1.9 2009-04-21 22:04:51 gemmeren Exp $
**/
#include "AthenaPoolCnvSvc/T_AthenaPoolCustomCnv.h"
#include "PersistentDataModel/DataHeader.h"
#include "PersistentDataModelTPCnv/DataHeader_p5.h"
#include "PersistentDataModelTPCnv/DataHeaderCnv_p5.h"
#include "PersistentDataModelTPCnv/DataHeaderCnv_p6.h"
#include "GaudiKernel/IIncidentListener.h"
#include <map>
class DataHeaderForm_p6;
typedef T_AthenaPoolCustomCnv<DataHeader, DataHeader_p5> DataHeaderCnvBase;
/** @class DataHeaderCnv
* @brief This class provides the converter to customize the saving of DataHeader.
**/
class DataHeaderCnv : public T_AthenaPoolCustomCnv<DataHeader, DataHeader_p5> {
class DataHeaderCnv : public DataHeaderCnvBase, virtual public IIncidentListener
{
friend class CnvFactory<DataHeaderCnv>;
public:
DataHeaderCnv(ISvcLocator* svcloc);
~DataHeaderCnv();
virtual StatusCode initialize() override;
/// Extend base-class conversion methods
virtual StatusCode updateRep(IOpaqueAddress* pAddress, DataObject* pObject);
virtual StatusCode updateRepRefs(IOpaqueAddress* pAddress, DataObject* pObject);
virtual StatusCode DataObjectToPool(DataObject* pObj, const std::string& tname);
virtual DataHeader_p5* poolReadObject_p5();
DataHeader_p5* poolReadObject_p5();
DataHeader_p6* poolReadObject_p6( DataHeaderForm_p6*& );
virtual DataHeader_p5* createPersistent(DataHeader* transObj);
virtual DataHeader* createTransient();
private:
/// Incident service handle listening for EndFile.
virtual void handle(const Incident& incident) override;
protected:
DataHeaderCnv_p6 m_tpInConverter_p6;
/// Local DHForm cache indexed by filename or reference
std::map<std::string, DataHeaderForm_p6*> m_persFormMap;
DataHeaderCnv_p5 m_TPconverter;
RootType m_mapClassDesc;
mutable std::string m_dhFormMdx;
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef PERSISTENTDATAMODELTPCNV_DATAHEADERCNV_P6_H
......@@ -7,58 +7,33 @@
/**
* @file DataHeaderCnv_p6.h
* @brief This file contains the class definition for the DataHeaderCnv_p6 and DataHeaderElementCnv_p6 classes.
* @brief This file contains the class definition for DataHeaderCnv_p6
* @author Peter van Gemmeren <gemmeren@anl.gov>
* $Id: DataHeaderCnv_p6.h,v 1.1 2009-04-21 21:48:34 gemmeren Exp $
**/
#include "PersistentDataModel/DataHeader.h"
#include "PersistentDataModelTPCnv/DataHeader_p6.h"
#include <map>
/** @class DataHeaderElementCnv_p6
* @brief This class provides the converter to customize the saving of DataHeaderElement_p6.
**/
class DataHeaderElementCnv_p6 {
public:
DataHeaderElementCnv_p6();
virtual ~DataHeaderElementCnv_p6();
void persToTrans(const DataHeaderElement_p6* pers, DataHeaderElement* trans, const DataHeaderForm_p6& form);
void transToPers(const DataHeaderElement* trans, DataHeaderElement_p6* pers, DataHeaderForm_p6& form);
friend class DataHeaderCnv_p6;
};
class DataHeader;
class DataHeader_p6;
class DataHeaderForm_p6;
/** @class DataHeaderCnv_p6
* @brief This class provides the converter to customize the saving of DataHeader_p6.
**/
class DataHeaderCnv_p6 {
public:
DataHeaderCnv_p6();
virtual ~DataHeaderCnv_p6();
DataHeader* createTransient(const DataHeader_p6* persObj);
void persToTrans(const DataHeader_p6* pers, DataHeader* trans);
DataHeader_p6* createPersistent(const DataHeader* transObj);
void transToPers(const DataHeader* trans, DataHeader_p6* pers);
void insertDHRef(DataHeader_p6* pers, const std::string& key, const std::string& strToken);
private:
DataHeaderElementCnv_p6 m_elemCnv;
DataHeaderCnv_p6() {}
DataHeader* createTransient(const DataHeader_p6* persObj, const DataHeaderForm_p6& form);
DataHeader_p6* createPersistent(const DataHeader* transObj, DataHeaderForm_p6& form);
/// convert single DH element to persistent represenation
void elemToPers(const DataHeaderElement* trans, DataHeader_p6* pers, DataHeaderForm_p6& form);
/// restore single DH element from persistent represenation
void persToElem(const DataHeader_p6* pers, unsigned p_idx, DataHeaderElement* trans,
const DataHeaderForm_p6& form );
void insertDHRef( DataHeader_p6* pers,
const std::string& key, const std::string& strToken,
DataHeaderForm_p6& form );
};
inline DataHeader* DataHeaderCnv_p6::createTransient(const DataHeader_p6* persObj) {
DataHeader* trans = new DataHeader();
persToTrans(persObj, trans);
return(trans);
}
inline DataHeader_p6* DataHeaderCnv_p6::createPersistent(const DataHeader* transObj){
DataHeader_p6* pers = new DataHeader_p6();
transToPers(transObj, pers);
return(pers);
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef PERSISTENTDATAMODELTPCNV_DATAHEADER_P6_H
#define PERSISTENTDATAMODELTPCNV_DATAHEADER_P6_H
/** @file DataHeader_p6.h
* @brief This file contains the class definition for the DataHeader_p6,
* DataHeaderForm_p6 and DataHeaderElement_p6 classes.
* @author Peter van Gemmeren <gemmeren@anl.gov>
* $Id: DataHeader_p6.h,v 1.1 2009-04-21 21:48:34 gemmeren Exp $
* @brief This file contains the class definitions for the
* DataHeader_p6 and DataHeaderForm_p6
* @author Peter van Gemmeren <gemmeren@anl.gov>, Marcin Nowak
**/
#include "PersistentDataModel/Guid.h"
......@@ -18,46 +17,32 @@
#include <set>
#include <string>
/** @class DataHeaderElement_p6
* @brief This class provides a persistent representation for the DataHeaderElement class.
**/
class DataHeaderElement_p6 {
public: // Constructor and Destructor
DataHeaderElement_p6();
DataHeaderElement_p6(const DataHeaderElement_p6& rhs);
virtual ~DataHeaderElement_p6();
DataHeaderElement_p6& operator=(const DataHeaderElement_p6& rhs);
friend class DataHeaderCnv_p6;
friend class DataHeaderElementCnv_p6;
const std::string& token() const;
unsigned long long oid1() const;
unsigned long long oid2() const;
void overwriteOid2(unsigned long long oid2);
private:
std::string m_token;
unsigned long long m_oid1;
unsigned long long m_oid2;
unsigned int m_dbIdx; // entry with GUID & technology
unsigned int m_objIdx; // Will get entry with ClassId and transient CLID/key, direct clid for now...
};
class Token;
/** @class DataHeaderForm_p6
* @brief This class provides storage for the constant fields of the persistent DataHeader class.
**/
class DataHeaderForm_p6 {
public:
typedef std::pair<Guid, unsigned int> DbRecord;
typedef std::pair<std::string, unsigned int> SgRecord;
typedef std::pair<Guid, SgRecord> ObjRecord;
struct DbRecord {
Guid fid; unsigned tech;
DbRecord() {}
DbRecord( const Guid& f, unsigned t) : fid(f), tech(t) {}
bool operator==(const DbRecord& rhs) const { return fid==rhs.fid && tech==rhs.tech; }
};
struct ObjRecord {
Guid guid; std::string key; unsigned clid; long long oid1;
ObjRecord() {}
ObjRecord( const Guid& g, const std::string& k, unsigned id, long long o)
: guid(g), key(k), clid(id), oid1(o) {}
bool operator==(const ObjRecord& rhs) const
{ return clid == rhs.clid && key == rhs.key && oid1 == rhs.oid1; }
};
public: // Constructor and Destructor
DataHeaderForm_p6();
DataHeaderForm_p6() {}
DataHeaderForm_p6(const DataHeaderForm_p6& rhs);
virtual ~DataHeaderForm_p6();
~DataHeaderForm_p6();
DataHeaderForm_p6& operator=(const DataHeaderForm_p6& rhs);
......@@ -76,56 +61,72 @@ friend class DataHeaderCnv_p6;
std::string getObjKey(unsigned int index) const;
unsigned int getObjType(unsigned int index) const;
Guid getObjClassId(unsigned int index) const;
long long getObjOid1(unsigned int index) const { return m_objRecords[index].oid1; }
std::set<std::string> getObjAlias(unsigned int index) const;
std::set<unsigned int> getObjSymLinks(unsigned int index) const;
std::vector<unsigned int> getObjHashes(unsigned int index) const;
const std::vector<unsigned int>& params() const;
void insertParam(unsigned int param);
unsigned int entry() const;
void start() const;
void next() const;
unsigned int size() const;
std::string calculateMdx();
bool wasModified() const;
void clearModified();
void setToken(Token *tok);
Token* getToken() const;
void resize(unsigned int size);
private:
std::vector<std::vector<unsigned int> > m_uints;
std::vector<DbRecord> m_dbRecords;
std::vector<ObjRecord> m_objRecords;
std::vector<std::vector<std::string> > m_objAlias;
std::vector<std::vector<unsigned int> > m_objSymLinks;
std::vector<std::vector<unsigned int> > m_objHashes;
mutable unsigned int m_entry;
/// In case we need ot handle encoding changes later
unsigned m_version { 600 };
// transient members
/// indicates that the last event was somehow different and a new DHForm needs to be written
bool m_modified { true };
/// Reference to self in the persistent storage
Token* m_token { nullptr };
};
/** @class DataHeader_p6
* @brief This class provides a persistent representation for the DataHeader class.
**/
class DataHeader_p6 {
public: // Constructor and Destructor
DataHeader_p6();
DataHeader_p6(const DataHeader_p6& rhs);
virtual ~DataHeader_p6();
DataHeader_p6& operator=(const DataHeader_p6& rhs);
friend class DataHeaderCnv_p6;
const std::vector<DataHeaderElement_p6>& elements() const;
const DataHeaderForm_p6& dhForm() const;
void setDhForm(const DataHeaderForm_p6& form);
Version P6 optimized FOR references pointing to the same OID2 in the same Database
**/
class DataHeader_p6
{
friend class DataHeaderCnv_p6;
public:
struct FullElement {
FullElement() : oid2(0), dbIdx(0), objIdx(0) {}
FullElement(unsigned long long o2, unsigned db, unsigned obj) : oid2(o2), dbIdx(db), objIdx(obj) {}
unsigned long long oid2;
unsigned int dbIdx; // index to DHForm entry with DB GUID & technology
unsigned int objIdx; // index to DHForm entry with object data
};
DataHeader_p6() {};
const std::string& dhFormToken() const;
void setDhFormToken(const std::string& formToken);
void calculateDhFormMdx();
const std::string& dhFormMdx() const;
private:
std::vector<DataHeaderElement_p6> m_dataHeader;
unsigned int m_provenanceSize;
DataHeaderForm_p6 m_dhForm;
std::string m_dhFormToken;
std::string m_dhFormMdx;
/// common DB entry index used by all short DH elements
unsigned m_commonDbIndex;
unsigned long long m_commonOID2;
std::vector<int> m_shortElements;
std::vector<FullElement> m_fullElements;
unsigned int m_provenanceSize;
std::string m_dhFormToken;
};
#endif