From f81c6f351559ff9b1ec92732d3b72c3f8092e059 Mon Sep 17 00:00:00 2001
From: schaffer <R.D.Schaffer@cern.ch>
Date: Mon, 11 May 2020 23:11:53 +0200
Subject: [PATCH] hopefully final fix for IOVDbMetaDataTool to correctly
 override the IOV

---
 .../src/IOVDbMetaDataTool.cxx                 | 41 +++++++++++--------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/Database/IOVDbMetaDataTools/src/IOVDbMetaDataTool.cxx b/Database/IOVDbMetaDataTools/src/IOVDbMetaDataTool.cxx
index 8a2bb85e48e..43ee27d7033 100755
--- a/Database/IOVDbMetaDataTools/src/IOVDbMetaDataTool.cxx
+++ b/Database/IOVDbMetaDataTools/src/IOVDbMetaDataTool.cxx
@@ -427,11 +427,11 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
 
   StatusCode sc = m_inputStore->retrieve(cont, contEnd);
   if (!sc.isSuccess()) {
-    ATH_MSG_DEBUG("Could not retrieve IOVMetaDataContainer objects from InputMetaDataStore - cannot process input file meta data");
+    ATH_MSG_DEBUG("processInputFileMetaData: Could not retrieve IOVMetaDataContainer objects from InputMetaDataStore - cannot process input file meta data");
     return StatusCode::SUCCESS;
   }
 
-  ATH_MSG_DEBUG("Retrieved from IOVMetaDataContainer(s) from InputMetaDataStore");
+  ATH_MSG_DEBUG("processInputFileMetaData: Retrieved from IOVMetaDataContainer(s) from InputMetaDataStore");
 
   // For each container, merge its contents into the MetaDataStore 
   unsigned int ncolls    = 0;
@@ -457,7 +457,7 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
     for (SG::ObjectWithVersion<IOVMetaDataContainer>& obj : allVersions) {
       const IOVPayloadContainer*  payload = obj.dataObject->payloadContainer();
 
-      ATH_MSG_DEBUG("New container: payload size " << payload->size() << " version key " << obj.versionedKey);
+      ATH_MSG_DEBUG("processInputFileMetaData: New container: payload size " << payload->size() << " version key " << obj.versionedKey);
 
       // detailed printout before merge
       if (msgLvl(MSG::VERBOSE)) {
@@ -481,7 +481,7 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
         
     // Detailed printout
     if (msgLvl(MSG::DEBUG)) {
-      ATH_MSG_DEBUG("Current payload before merge " << contMaster->folderName());
+      ATH_MSG_DEBUG("processInputFileMetaData: Current payload before merge " << contMaster->folderName());
       IOVPayloadContainer::const_iterator itColl1    = contMaster->payloadContainer()->begin();
       IOVPayloadContainer::const_iterator itCollEnd1 = contMaster->payloadContainer()->end();
       std::ostringstream stream;
@@ -513,7 +513,7 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
           StatusCode sc ATLAS_THREAD_SAFE =
             modifyPayload (contMaster->folderName(), coll);
           if (!sc.isSuccess()) {
-            ATH_MSG_ERROR("Could not modify the payload for folder " << contMaster->folderName());
+            ATH_MSG_ERROR("processInputFileMetaData: Could not modify the payload for folder " << contMaster->folderName());
             return StatusCode::FAILURE;
           }
         }
@@ -524,7 +524,7 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
           StatusCode sc ATLAS_THREAD_SAFE =
             modifyPayload (newCont4Sid->folderName(), coll);
           if (!sc.isSuccess()) {
-            ATH_MSG_ERROR("Could not modify the payload for folder " << newCont4Sid->folderName());
+            ATH_MSG_ERROR("processInputFileMetaData: Could not modify the payload for folder " << newCont4Sid->folderName());
             return StatusCode::FAILURE;
           }
         }
@@ -532,7 +532,7 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
 	// Before starting merging, make a copy for newCont4Sid
 	CondAttrListCollection* collCopy = new CondAttrListCollection(*coll);
 
-	ATH_MSG_VERBOSE(" merge minRange: " << coll->minRange());
+	ATH_MSG_VERBOSE("processInputFileMetaData: merge minRange: " << coll->minRange());
 	if (!contMaster->merge(coll)) {
 	  // Did not merge it in - was a duplicate, so we need to delete it 
 	  delete coll;
@@ -544,7 +544,7 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
 	  ATH_MSG_VERBOSE(" => merged ");
 	}
 
-	ATH_MSG_VERBOSE(" merge for MetaCont minRange: " << collCopy->minRange());
+	ATH_MSG_VERBOSE("processInputFileMetaData:  merge for MetaCont minRange: " << collCopy->minRange());
 	if (!newCont4Sid->merge(collCopy)) {
 	  // Did not merge it in - was a duplicate, so we need to delete it 
 	  delete collCopy;
@@ -555,7 +555,7 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
 	}
 
       }
-      ATH_MSG_DEBUG("Merged together containers for folder " << cont->folderName() << " ncoll/ndup " 
+      ATH_MSG_DEBUG("processInputFileMetaData: Merged together containers for folder " << cont->folderName() << " ncoll/ndup " 
 		    << ncolls << " " << ndupColls);
 
       // Check for consistency after merge
@@ -587,14 +587,14 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
 
       // Insert the merged container into MetaCont
       if(fillMetaCont(fileName,newCont4Sid).isFailure()) {
-	ATH_MSG_ERROR("Failed to insert the merged IOVMetaDataContainer into MetaCont");
+	ATH_MSG_ERROR("processInputFileMetaData: Failed to insert the merged IOVMetaDataContainer into MetaCont");
 	return StatusCode::FAILURE;
       }
 
       // detailed printout after merge
       if (msgLvl(MSG::VERBOSE)) {
 	const IOVPayloadContainer*  payloadMaster = contMaster->payloadContainer();
-	ATH_MSG_VERBOSE("After merge, payload minRange ");
+	ATH_MSG_VERBOSE("processInputFileMetaData: After merge, payload minRange ");
 	if (payloadMaster) {
 	  // Loop over AttrColls and print out minRange
 	  IOVPayloadContainer::const_iterator itColl    = payloadMaster->begin();
@@ -610,13 +610,13 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
       
       // Detailed printout
       if (msgLvl(MSG::DEBUG)) {
-	ATH_MSG_DEBUG("Input payload " << cont->folderName());
+	ATH_MSG_DEBUG("processInputFileMetaData: Input payload " << cont->folderName());
 	std::ostringstream streamInp;
 	itColl    = payload->begin();
 	itCollEnd = payload->end();
 	for (; itColl != itCollEnd; ++itColl) (*itColl)->dump(streamInp);
 	ATH_MSG_DEBUG(streamInp.str());
-	ATH_MSG_DEBUG("Output payload " << contMaster->folderName());
+	ATH_MSG_DEBUG("processInputFileMetaData: Output payload " << contMaster->folderName());
 	std::ostringstream streamOut;
 	itColl    = contMaster->payloadContainer()->begin();
 	itCollEnd = contMaster->payloadContainer()->end();
@@ -626,7 +626,7 @@ StatusCode IOVDbMetaDataTool::processInputFileMetaData(const std::string& fileNa
     }
   }
 
-  ATH_MSG_DEBUG("Total number of attribute collections  merged together " << ncolls
+  ATH_MSG_DEBUG("processInputFileMetaData: Total number of attribute collections  merged together " << ncolls
 		<< " Number of duplicate collections " << ndupColls);
   return StatusCode::SUCCESS;
 }
@@ -662,16 +662,25 @@ IOVDbMetaDataTool::overrideIOV (CondAttrListCollection*& coll) const
             ATH_MSG_ERROR("overrideIOV: old run number does not match. Old run number " << m_oldRunNumber << " IOVRange: " << testIOV);
             return StatusCode::SUCCESS;
         }
-        // Now over ride IOVs
-        if (iovSizeIsZero) { 
+
+        ATH_MSG_DEBUG("overrideIOV: overrideMinMaxRunNumber: " << (int)m_overrideMinMaxRunNumber
+                      << " overrideRunNumber " << (int)m_overrideRunNumber
+                      << " iovSizeIsZero: " << (int)iovSizeIsZero
+                      << " newRange " << newRange);
+        
+        // Now over ride IOVs - two cases: 1) single IOV for full collection, 2) IOVs for individual channels.
+        // Must treat the reset of collection IOV differently
+        if (iovSizeIsZero) {
             // Only add in overall range if channels do not have
             // IOVs - otherwise this is automatically calculated
+            coll->resetMinRange(); // must first reset to 'full range' and then reduce the IOVRange accordingly
             coll->addNewStart(newRange.start());
             coll->addNewStop (newRange.stop());
         }
         else {
             // Add in channels
             unsigned int nchans = coll->size();
+            ATH_MSG_DEBUG("overrideIOV: nchans " << nchans);
             for (unsigned int ichan = 0; ichan < nchans; ++ichan) {
                 // FIXME: O(N^2)!
                 CondAttrListCollection::ChanNum chan = coll->chanNum(ichan);
-- 
GitLab