From 7aa3016c936e5010e6d9b1aa82c3652a8ed593c4 Mon Sep 17 00:00:00 2001
From: Peter van Gemmeren <gemmeren@anl.gov>
Date: Fri, 23 Oct 2020 12:26:29 -0500
Subject: [PATCH] Make ROOT TMemFile string a property to allow custom ports
 when running multiple instances.

---
 .../AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx   |  8 ++++----
 .../AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.h     |  2 ++
 .../src/AthenaRootSharedWriterSvc.cxx           | 17 +++++++++++++----
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx b/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx
index e4a19aa45a8..6ee02a6d051 100644
--- a/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx
+++ b/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx
@@ -314,7 +314,7 @@ StatusCode AthenaPoolCnvSvc::connectOutput(const std::string& outputConnectionSp
    }
 
    if (!m_outputStreamingTool.empty() && m_outputStreamingTool[0]->isClient() && m_streamMetaDataOnly) {
-      outputConnection = outputConnection + "?pmerge=localhost:1095";
+      outputConnection = outputConnection + m_streamPortString.value();
    }
    unsigned int contextId = outputContextId(outputConnection);
    try {
@@ -607,7 +607,7 @@ StatusCode AthenaPoolCnvSvc::commitOutput(const std::string& outputConnectionSpe
          doCommit = true;
          ATH_MSG_DEBUG("commitOutput sending data.");
       }
-      outputConnection = outputConnection + "?pmerge=localhost:1095";
+      outputConnection = outputConnection + m_streamPortString.value();
    }
    unsigned int contextId = outputContextId(outputConnection);
    if (!processPoolAttributes(m_domainAttr, outputConnection, contextId).isSuccess()) {
@@ -683,7 +683,7 @@ StatusCode AthenaPoolCnvSvc::disconnectOutput(const std::string& outputConnectio
       ATH_MSG_DEBUG("disconnectOutput not SKIPPED for server: " << m_streamServer);
    }
    if (!m_outputStreamingTool.empty() && m_outputStreamingTool[0]->isClient() && m_streamMetaDataOnly) {
-      outputConnection = outputConnection + "?pmerge=localhost:1095";
+      outputConnection = outputConnection + m_streamPortString.value();
    }
    unsigned int contextId = outputContextId(outputConnection);
    StatusCode sc = m_poolSvc->disconnect(contextId);
@@ -830,7 +830,7 @@ Token* AthenaPoolCnvSvc::registerForWrite(Placement* placement, const void* obj,
          }
       } else {
          if (!m_outputStreamingTool.empty() && m_outputStreamingTool[0]->isClient() && m_streamMetaDataOnly) {
-            placement->setFileName(placement->fileName() + "?pmerge=localhost:1095");
+            placement->setFileName(placement->fileName() + m_streamPortString.value());
          }
          if (m_persSvcPerOutput) {
             char text[32];
diff --git a/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.h b/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.h
index 0f1420668e6..630766b5b97 100644
--- a/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.h
+++ b/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.h
@@ -251,6 +251,8 @@ private: // properties
    IntegerProperty m_makeStreamingToolClient{this,"MakeStreamingToolClient",0};
    /// Use Athena Object sharing for metadata only, event data is collected and send via ROOT TMemFile
    BooleanProperty m_streamMetaDataOnly{this,"StreamMetaDataOnly",false};
+   /// Extension to use ROOT TMemFile for event data, "?pmerge=<host>:<port>"
+   StringProperty  m_streamPortString{this,"StreamPortString","?pmerge=localhost:1095"};
    /// When using TMemFile call Write on number of Events, respecting CollectionTree auto_flush
    IntegerProperty m_numberEventsPerWrite{this,"NumberEventsPerWrite",10};
 };
diff --git a/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaRootSharedWriterSvc.cxx b/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaRootSharedWriterSvc.cxx
index ae52fa8e12e..0ecf216f801 100644
--- a/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaRootSharedWriterSvc.cxx
+++ b/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaRootSharedWriterSvc.cxx
@@ -162,15 +162,24 @@ StatusCode AthenaRootSharedWriterSvc::initialize() {
       BooleanProperty streamMetaDataOnlyProp(propertyName, streamMetaDataOnly);
       if (propertyServer->getProperty(&streamMetaDataOnlyProp).isFailure()) {
          ATH_MSG_INFO("Conversion service does not have StreamMetaDataOnly property");
-      } else if(streamMetaDataOnlyProp.value()) {
-         m_rootServerSocket = new TServerSocket(1095, true, 100);
+      } else if (streamMetaDataOnlyProp.value()) {
+         int streamPort = 1095;
+         propertyName = "StreamPortString";
+         std::string streamPortString("");
+         StringProperty streamPortStringProp(propertyName, streamPortString);
+         if (propertyServer->getProperty(&streamPortStringProp).isFailure()) {
+            ATH_MSG_INFO("Conversion service does not have StreamPortString property, using default: " << streamPort);
+         } else {
+            streamPort = atoi(streamPortStringProp.value().substr(streamPortStringProp.value().find(":") + 1).c_str());
+         }
+         m_rootServerSocket = new TServerSocket(streamPort, true, 100);
          if (m_rootServerSocket == nullptr || !m_rootServerSocket->IsValid()) {
-            ATH_MSG_FATAL("Could not create ROOT TServerSocket");
+            ATH_MSG_FATAL("Could not create ROOT TServerSocket: " << streamPort);
             return StatusCode::FAILURE;
          }
          m_rootMonitor = new TMonitor;
          m_rootMonitor->Add(m_rootServerSocket);
-         ATH_MSG_DEBUG("Successfully created ROOT TServerSocket and added it to TMonitor: ready to accept connections!");
+         ATH_MSG_DEBUG("Successfully created ROOT TServerSocket and added it to TMonitor: ready to accept connections, " << streamPort);
       }
    }
 
-- 
GitLab