19 #include "CoralBase/AttributeList.h"
20 #include "CoralBase/Attribute.h"
22 #include "GaudiKernel/IIncidentSvc.h"
23 #include "GaudiKernel/FileIncident.h"
41 if( incSvc.retrieve().isSuccess() ) {
42 incSvc->removeListener(
this, IncidentType::EndInputFile);
50 bool doFilterDHAliases =
true;
51 SmartIF<IProperty> cnvSvc{service(
"AthenaPoolCnvSvc")};
54 if( cnvSvc->getProperty(&sizeProp).isSuccess() ) {
57 BooleanProperty aliasFilterProp(
"doFilterDHAliases", doFilterDHAliases);
58 if( cnvSvc->getProperty(&aliasFilterProp).isSuccess() ) {
59 doFilterDHAliases = aliasFilterProp.value();
61 BooleanProperty oneDHForm(
"OneDataHeaderForm",
m_oneDHForm);
62 if( cnvSvc->getProperty(&oneDHForm).isSuccess() ) {
67 if( doFilterDHAliases ) {
78 incSvc->addListener(
this, IncidentType::EndInputFile, 0);
79 incSvc->addListener(
this,
"PreFork", 0);
81 incSvc->addListener(
this,
"WriteDataHeaderForms", 0);
88 if( incident.type() ==
"PreFork" ) {
91 if( incident.type() == IncidentType::EndInputFile ) {
93 const std::string&
guid =
static_cast<const FileIncident&
>(incident).fileGuid();
96 if( incident.type() ==
"WriteDataHeaderForms" ) {
98 const std::string&
fileName =
static_cast<const FileIncident*
>(&incident)->
fileName();
100 std::vector<std::string> toWrite;
101 auto pos =
fileName.find(
"[OutputCollection=MetaDataHdr]");
102 bool metaDataCommit = (
pos != std::string::npos);
103 std::string justFileName =
fileName.substr(0,
pos);
107 const std::string& placementStr = elem.first;
113 if( (placementStr.find(
"[CONT=MetaData") != std::string::npos) == metaDataCommit ) {
114 toWrite.push_back( placementStr );
119 for( std::size_t
n = 0;
const std::string& placementStr : toWrite ) {
123 if( form_ptr->isModified() ) {
124 static const RootType dhFormType(
typeid( *form_ptr ) );
128 std::string errmsg =
std::format(
"Failed to write {} {}", dhFormType.
Name(), placementStr);
130 throw GaudiException(errmsg,
"DataHeaderCnv::WriteDataHeaderForms", StatusCode::FAILURE);
132 ATH_MSG_DEBUG(
"Wrote DatHeaderForm, placeemnt was " << placementStr <<
" token=" << form_token->
toString());
133 form_token->
release(); form_token =
nullptr;
134 bool doCommit = (++
n == toWrite.size());
137 throw GaudiException(
"WriteDataHeaderForms failed",
"DataHeaderCnv::WriteDataHeaderForms", StatusCode::FAILURE);
150 size_t dbpos = iter->first.find(
"[DB=");
151 if( dbpos != std::string::npos && iter->first.compare(dbpos+4, dbpos+36, dbGuid) == 0 ) {
164 if(
start == std::string::npos )
189 if( lval != rval )
return lval < rval;
193 if( lval.empty() or rval.empty() )
return false;
194 return std::stoul( lval ) < std::stoul( rval );
208 auto dataHeader =
reinterpret_cast<DataHeader_p6*
>( pObject );
209 const std::string dhRef = pAddress->par()[0];
210 const std::string dhPlacementStr = pAddress->par()[1];
213 dhFormPlacement.
fromString( dataHeader->dhFormToken() );
216 if( !clientN.empty() ) {
220 dataHeader->setDhFormToken( dhFormNewRef );
228 ATH_MSG_ERROR(
"updateRep called but the previous DataHeader was not yet processed."
231 return StatusCode::FAILURE;
236 std::size_t tagBeg = dhPlacementStr.find(
"[KEY=") + 5;
237 std::size_t tagSize = dhPlacementStr.find(
']', tagBeg) - tagBeg;
240 return StatusCode::SUCCESS;
254 static const pool::Guid dhf_p6_guid(
"7BE56CEF-C866-4BEE-9348-A5F34B5F1DAD");
255 std::string dhid = pAddress->par()[1];
257 this->
setToken( pAddress->par()[0] );
259 ATH_MSG_ERROR(
"updateRepRefs called without DataHeaderForm" );
260 return StatusCode::FAILURE;
268 ATH_MSG_ERROR(
"updateRepRefs: missing DataHeaderForm for DH ID=" << dhid );
269 return StatusCode::FAILURE;
282 return(StatusCode::SUCCESS);
290 ATH_MSG_ERROR(
"Failed to cast DataHeader to transient type" );
291 return(StatusCode::FAILURE);
295 std::string form_placement_str = dhf_placement.
toString();
297 std::unique_ptr<DataHeaderForm_p6>& dhForm =
m_persFormMap[form_placement_str];
298 if (dhForm ==
nullptr) {
300 dhForm = std::make_unique<DataHeaderForm_p6>();
307 const std::string connection = dh_placement.
fileName();
313 ATH_MSG_FATAL(
"Failed to convert DataHeader to persistent type: " <<
e.what());
314 return(StatusCode::FAILURE);
318 if (dh_token ==
nullptr) {
320 return(StatusCode::FAILURE);
330 static const RootType dhFormType(
typeid(*dhForm));
332 if (dhf_token ==
nullptr) {
334 return(StatusCode::FAILURE);
343 dhf_token->
release(); dhf_token =
nullptr;
354 dhForm->
setToken( form_placement_str );
356 form_placement_str = dhForm->
getToken();
359 auto b = form_placement_str.find(
"[FILE=");
360 auto e = form_placement_str.find(
"]",
b);
361 form_placement_str.erase(
b,
e-
b+1);
367 if (
list !=
nullptr) {
371 obj->getEvtRefTokenStr().c_str(),
373 delete ref_token; ref_token =
nullptr;
374 for (coral::AttributeList::const_iterator iter =
list->begin(), last =
list->end(); iter != last; ++iter) {
375 attr_placement = this->
setPlacementWithType(
"AttributeList", (*iter).specification().name(), *pAddr->par());
377 (*iter).addressOfData(),
378 RootType((*iter).specification().type()) );
379 delete attr_token; attr_token =
nullptr;
383 if (tokAddr !=
nullptr) {
384 tokAddr->
setToken(dh_token); dh_token =
nullptr;
386 delete dh_token; dh_token =
nullptr;
387 return(StatusCode::FAILURE);
389 return(StatusCode::SUCCESS);
395 void* voidPtr1 =
nullptr;
397 if (voidPtr1 ==
nullptr) {
402 void* voidPtr2 =
nullptr;
409 if (voidPtr2 ==
nullptr) {
410 throw std::runtime_error(
"Could not get object for token = " + mapToken.
toString());
424 void* voidPtr1 =
nullptr;
425 std::string error_message;
430 error_message =
err.what();
432 if (voidPtr1 ==
nullptr) {
433 throw std::runtime_error(
"Could not get object for token = " +
m_i_poolToken->
toString() +
", " + error_message);
438 std::string dhFormToken =
header->dhFormToken();
441 size_t dbpos = dhFormToken.find(
"[DB=");
442 if( dbpos != std::string::npos ) {
443 const std::string dbGuid = dhFormToken.substr(dbpos+4, dbpos+36);
451 void* voidPtr2 =
nullptr;
453 if( dhFormToken.empty() ) {
456 formToken.
setClassID(
Guid(
"7BE56CEF-C866-4BEE-9348-A5F34B5F1DAD") );
457 }
else if( dhFormToken.find(
"[OID=") != std::string::npos ) {
469 formToken.
setClassID(
Guid(
"7BE56CEF-C866-4BEE-9348-A5F34B5F1DAD") );
471 oid2 >>= 32; oid2 <<= 32;
474 if( !swn.empty() ) oid2 += std::stoul( swn ) - 1;
475 formToken.
setOid( {0,oid2} );
483 error_message =
err.what();
485 if (voidPtr2 ==
nullptr) {
491 void* firstPtr1 =
nullptr;
496 error_message =
err.what();
498 if (firstPtr1 ==
nullptr)
throw std::runtime_error(
"Could not get first DataHeader for token = " + firstToken.
toString() +
", " + error_message);
501 std::unique_ptr<DataHeader_p6> firstHeader(
reinterpret_cast<DataHeader_p6*
>(firstPtr1) );
511 error_message =
err.what();
513 if (voidPtr2 ==
nullptr)
throw std::runtime_error(
"Could not get DataHeaderForm for token = " + formToken.
toString() +
", " + error_message);
516 ATH_MSG_WARNING(
"DataHeaderForm read exception: " << error_message <<
" - reusing the last good DHForm");
519 ATH_MSG_WARNING(
"DataHeaderForm read exception: " << error_message <<
" - reusing the last good DHForm");
524 if (voidPtr2 ==
nullptr) {
525 throw std::runtime_error(
"Could not get object for token = " + formToken.
toString());
543 auto iter =
dh->m_inputDataHeader.begin();
544 while( iter !=
dh->m_inputDataHeader.end() ) {
545 if( iter->getToken()->dbID() ==
Guid::null() ) {
547 iter =
dh->m_inputDataHeader.erase(iter);
561 std::string bestPfn, fileType;
568 static const pool::Guid p6_guid(
"4DDBD295-EFCE-472A-9EC8-15CD35A9EB8D");
569 static const pool::Guid p5_guid(
"D82968A1-CF91-4320-B2DD-E0F739CBC7E6");
570 static const pool::Guid p4_guid(
"9630EB7B-CCD7-47D9-A39B-CBBF4133CDF2");
571 static const pool::Guid p3_guid(
"EC1318F0-8E28-45F8-9A2D-2597C1CC87A6");
585 std::unique_ptr<DataHeader_p4> obj_p4(this->poolReadObject<DataHeader_p4>());
589 std::unique_ptr<DataHeader_p3> obj_p3(this->poolReadObject<DataHeader_p3>());
595 std::string
error =
e.what();
596 throw std::runtime_error(
error);