From 16e819ce92a0f8ec3a899936cfd11838fd29d727 Mon Sep 17 00:00:00 2001
From: Martin Errenst <martin.errenst@cern.ch>
Date: Tue, 10 Apr 2018 08:15:16 +0200
Subject: [PATCH 1/3] Fix m_uidsX loops to use m_uids

---
 GaudiSvc/src/THistSvc/THistSvc.cpp | 158 +++++++++++++++--------------
 1 file changed, 81 insertions(+), 77 deletions(-)

diff --git a/GaudiSvc/src/THistSvc/THistSvc.cpp b/GaudiSvc/src/THistSvc/THistSvc.cpp
index 989d7c6a5..9de269509 100644
--- a/GaudiSvc/src/THistSvc/THistSvc.cpp
+++ b/GaudiSvc/src/THistSvc/THistSvc.cpp
@@ -1219,35 +1219,35 @@ StatusCode THistSvc::io_reinit()
     }
 
     // loop over all uids and migrate them to the new file
-    // XXX FIXME: this double loop sucks...
-    for ( auto& uid : m_uidsX ) {
-      THistID& hid = uid.second;
-      if ( hid.file != f ) continue;
-      TDirectory* olddir = this->changeDir( hid );
-      hid.file           = newfile;
-      // side-effect: create needed directories...
-      TDirectory* newdir = this->changeDir( hid );
-      TClass* cl         = hid.obj->IsA();
-
-      // migrate the objects to the new file.
-      // thanks to the object model of ROOT, it is super easy.
-      if ( cl->InheritsFrom( "TTree" ) ) {
-        dynamic_cast<TTree*>( hid.obj )->SetDirectory( newdir );
-        dynamic_cast<TTree*>( hid.obj )->Reset();
-      } else if ( cl->InheritsFrom( "TH1" ) ) {
-        dynamic_cast<TH1*>( hid.obj )->SetDirectory( newdir );
-        dynamic_cast<TH1*>( hid.obj )->Reset();
-      } else if ( cl->InheritsFrom( "TGraph" ) ) {
-        olddir->Remove( hid.obj );
-        newdir->Append( hid.obj );
-      } else {
-        error() << "id: \"" << hid.id << "\" is not a inheriting from a class "
-                << "we know how to handle (received [" << cl->GetName() << "], "
-                << "expected [TTree, TH1 or TGraph]) !" << endmsg << "attaching to current dir [" << newdir->GetPath()
-                << "] "
-                << "nonetheless..." << endmsg;
-        olddir->Remove( hid.obj );
-        newdir->Append( hid.obj );
+    for ( auto& uid : m_uids ) {
+      for ( auto& hid : *uid.second ) {
+        if ( hid.file != f ) continue;
+        TDirectory* olddir = this->changeDir( hid );
+        hid.file           = newfile;
+        // side-effect: create needed directories...
+        TDirectory* newdir = this->changeDir( hid );
+        TClass* cl         = hid.obj->IsA();
+
+        // migrate the objects to the new file.
+        // thanks to the object model of ROOT, it is super easy.
+        if ( cl->InheritsFrom( "TTree" ) ) {
+          dynamic_cast<TTree*>( hid.obj )->SetDirectory( newdir );
+          dynamic_cast<TTree*>( hid.obj )->Reset();
+        } else if ( cl->InheritsFrom( "TH1" ) ) {
+          dynamic_cast<TH1*>( hid.obj )->SetDirectory( newdir );
+          dynamic_cast<TH1*>( hid.obj )->Reset();
+        } else if ( cl->InheritsFrom( "TGraph" ) ) {
+          olddir->Remove( hid.obj );
+          newdir->Append( hid.obj );
+        } else {
+          error() << "id: \"" << hid.id << "\" is not a inheriting from a class "
+                  << "we know how to handle (received [" << cl->GetName() << "], "
+                  << "expected [TTree, TH1 or TGraph]) !" << endmsg << "attaching to current dir [" << newdir->GetPath()
+                  << "] "
+                  << "nonetheless..." << endmsg;
+          olddir->Remove( hid.obj );
+          newdir->Append( hid.obj );
+        }
       }
     }
     f->ReOpen( "READ" );
@@ -1293,69 +1293,73 @@ void THistSvc::updateFiles()
 
   if ( msgLevel( MSG::DEBUG ) ) debug() << "updateFiles()" << endmsg;
 
-  for ( auto uitr = m_uidsX.begin(); uitr != m_uidsX.end(); ++uitr ) {
+  for ( auto uitr = m_uids.begin(); uitr != m_uids.end(); ++uitr ) {
+    for ( auto& hid : *(uitr->second) ) {
 #ifndef NDEBUG
-    if ( msgLevel( MSG::VERBOSE ) )
-      verbose() << " update: " << uitr->first << " " << uitr->second.id << " " << uitr->second.mode << endmsg;
+      if ( msgLevel( MSG::VERBOSE ) )
+        verbose() << " update: " << uitr->first << " " << hid.id << " " << hid.mode << endmsg;
 #endif
-    TObject* to    = uitr->second.obj;
-    TFile* oldFile = uitr->second.file;
-    if ( !to ) {
-      warning() << uitr->first << ": TObject == 0" << endmsg;
-    } else if ( uitr->second.temp || uitr->second.mode == READ ) {
-// do nothing - no need to check how big the file is since we
-// are just reading it.
+      TObject* to    = hid.obj;
+      TFile* oldFile = hid.file;
+      if ( !to ) {
+        warning() << uitr->first << ": TObject == 0" << endmsg;
+      } else if ( hid.temp || hid.mode == READ ) {
+  // do nothing - no need to check how big the file is since we
+  // are just reading it.
 #ifndef NDEBUG
-      if ( msgLevel( MSG::VERBOSE ) ) verbose() << "     skipping" << endmsg;
+        if ( msgLevel( MSG::VERBOSE ) ) verbose() << "     skipping" << endmsg;
 #endif
-    } else if ( to->IsA()->InheritsFrom( "TTree" ) ) {
-      TTree* tr      = dynamic_cast<TTree*>( to );
-      TFile* newFile = tr->GetCurrentFile();
-
-      if ( oldFile != newFile ) {
-        std::string newFileName = newFile->GetName();
-        std::string oldFileName, streamName, rem;
-        TFile* dummy = nullptr;
-        findStream( uitr->second.id, streamName, rem, dummy );
-
-        for ( auto& itr : m_files ) {
-          if ( itr.second.first == oldFile ) {
-            itr.second.first = newFile;
+      } else if ( to->IsA()->InheritsFrom( "TTree" ) ) {
+        TTree* tr      = dynamic_cast<TTree*>( to );
+        TFile* newFile = tr->GetCurrentFile();
+
+        if ( oldFile != newFile ) {
+          std::string newFileName = newFile->GetName();
+          std::string oldFileName, streamName, rem;
+          TFile* dummy = nullptr;
+          findStream( hid.id, streamName, rem, dummy );
+
+          for ( auto& itr : m_files ) {
+            if ( itr.second.first == oldFile ) {
+              itr.second.first = newFile;
+            }
           }
-        }
 
-        for ( auto uitr2 = uitr; uitr2 != m_uidsX.end(); ++uitr2 ) {
-          if ( uitr2->second.file == oldFile ) {
-            uitr2->second.file = newFile;
+          for ( auto uitr2 = uitr; uitr2 != m_uids.end(); ++uitr2 ) {
+            for ( auto& hid2 : *(uitr2->second) ) {
+              if ( hid2.file == oldFile ) {
+                hid2.file = newFile;
+              }
+            }
           }
-        }
 
-        auto sitr = std::find_if( std::begin( m_fileStreams ), std::end( m_fileStreams ),
-                                  [&]( streamMap::const_reference s ) { return s.second == streamName; } );
-        if ( sitr != std::end( m_fileStreams ) ) oldFileName = sitr->first;
+          auto sitr = std::find_if( std::begin( m_fileStreams ), std::end( m_fileStreams ),
+                                    [&]( streamMap::const_reference s ) { return s.second == streamName; } );
+          if ( sitr != std::end( m_fileStreams ) ) oldFileName = sitr->first;
 
 #ifndef NDEBUG
-        if ( msgLevel( MSG::DEBUG ) ) {
-          debug() << "migrating uid: " << uitr->second.id << "   stream: " << streamName
-                  << "   oldFile: " << oldFileName << "   newFile: " << newFileName << endmsg;
-        }
+          if ( msgLevel( MSG::DEBUG ) ) {
+            debug() << "migrating uid: " << hid.id << "   stream: " << streamName
+                    << "   oldFile: " << oldFileName << "   newFile: " << newFileName << endmsg;
+          }
 #endif
 
-        if ( !oldFileName.empty() ) {
-          auto i = m_fileStreams.lower_bound( oldFileName );
-          while ( i != std::end( m_fileStreams ) && i->first == oldFileName ) {
+          if ( !oldFileName.empty() ) {
+            auto i = m_fileStreams.lower_bound( oldFileName );
+            while ( i != std::end( m_fileStreams ) && i->first == oldFileName ) {
 #ifndef NDEBUG
-            if ( msgLevel( MSG::DEBUG ) ) {
-              debug() << "changing filename \"" << i->first << "\" to \"" << newFileName << "\" for stream \""
-                      << i->second << "\"" << endmsg;
-            }
+              if ( msgLevel( MSG::DEBUG ) ) {
+                debug() << "changing filename \"" << i->first << "\" to \"" << newFileName << "\" for stream \""
+                        << i->second << "\"" << endmsg;
+              }
 #endif
-            std::string nm = std::move( i->second );
-            i              = m_fileStreams.erase( i );
-            m_fileStreams.emplace( newFileName, std::move( nm ) );
+              std::string nm = std::move( i->second );
+              i              = m_fileStreams.erase( i );
+              m_fileStreams.emplace( newFileName, std::move( nm ) );
+            }
+          } else {
+            error() << "Problems updating fileStreams with new file name" << endmsg;
           }
-        } else {
-          error() << "Problems updating fileStreams with new file name" << endmsg;
         }
       }
     }
-- 
GitLab


From 1e0c90f3ac072f005752afc5ee04d95e48bb0ed0 Mon Sep 17 00:00:00 2001
From: Martin Errenst <martin.errenst@cern.ch>
Date: Tue, 10 Apr 2018 07:55:23 +0200
Subject: [PATCH 2/3] Remove unused typedefs and attributes

---
 GaudiSvc/src/THistSvc/THistSvc.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/GaudiSvc/src/THistSvc/THistSvc.h b/GaudiSvc/src/THistSvc/THistSvc.h
index a2f799a74..9e0a97114 100644
--- a/GaudiSvc/src/THistSvc/THistSvc.h
+++ b/GaudiSvc/src/THistSvc/THistSvc.h
@@ -234,13 +234,6 @@ private:
   /// registered by the setupOutputFile callback method
   std::set<std::string> m_alreadyConnectedOutFiles;
 
-  typedef std::map<std::string, THistID> uidXMap;
-  typedef std::multimap<std::string, THistID> idXMap;
-  typedef std::multimap<std::string, std::string> streamMap;
-
-  uidXMap m_uidsX;
-  idXMap m_idsX;
-
   // containers for fast lookups
   // same uid for all elements in vec
   typedef std::vector<THistID> vhid_t;
@@ -260,6 +253,7 @@ private:
   objMap_t m_tobjs;
 
   std::map<std::string, std::pair<TFile*, Mode>> m_files; // stream->file
+  typedef std::multimap<std::string, std::string> streamMap;
   streamMap m_fileStreams;                                // fileName->streams
 
   // stream->filename of shared files
-- 
GitLab


From 0cdd272439dc89701a55e2ede34ae4a600f32ac3 Mon Sep 17 00:00:00 2001
From: Martin Errenst <martin.errenst@cern.ch>
Date: Tue, 10 Apr 2018 13:27:15 +0200
Subject: [PATCH 3/3] apply clang formatting patch

---
 GaudiSvc/src/THistSvc/THistSvc.cpp | 12 ++++++------
 GaudiSvc/src/THistSvc/THistSvc.h   |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/GaudiSvc/src/THistSvc/THistSvc.cpp b/GaudiSvc/src/THistSvc/THistSvc.cpp
index 9de269509..07c847ccb 100644
--- a/GaudiSvc/src/THistSvc/THistSvc.cpp
+++ b/GaudiSvc/src/THistSvc/THistSvc.cpp
@@ -1294,7 +1294,7 @@ void THistSvc::updateFiles()
   if ( msgLevel( MSG::DEBUG ) ) debug() << "updateFiles()" << endmsg;
 
   for ( auto uitr = m_uids.begin(); uitr != m_uids.end(); ++uitr ) {
-    for ( auto& hid : *(uitr->second) ) {
+    for ( auto& hid : *( uitr->second ) ) {
 #ifndef NDEBUG
       if ( msgLevel( MSG::VERBOSE ) )
         verbose() << " update: " << uitr->first << " " << hid.id << " " << hid.mode << endmsg;
@@ -1304,8 +1304,8 @@ void THistSvc::updateFiles()
       if ( !to ) {
         warning() << uitr->first << ": TObject == 0" << endmsg;
       } else if ( hid.temp || hid.mode == READ ) {
-  // do nothing - no need to check how big the file is since we
-  // are just reading it.
+// do nothing - no need to check how big the file is since we
+// are just reading it.
 #ifndef NDEBUG
         if ( msgLevel( MSG::VERBOSE ) ) verbose() << "     skipping" << endmsg;
 #endif
@@ -1326,7 +1326,7 @@ void THistSvc::updateFiles()
           }
 
           for ( auto uitr2 = uitr; uitr2 != m_uids.end(); ++uitr2 ) {
-            for ( auto& hid2 : *(uitr2->second) ) {
+            for ( auto& hid2 : *( uitr2->second ) ) {
               if ( hid2.file == oldFile ) {
                 hid2.file = newFile;
               }
@@ -1339,8 +1339,8 @@ void THistSvc::updateFiles()
 
 #ifndef NDEBUG
           if ( msgLevel( MSG::DEBUG ) ) {
-            debug() << "migrating uid: " << hid.id << "   stream: " << streamName
-                    << "   oldFile: " << oldFileName << "   newFile: " << newFileName << endmsg;
+            debug() << "migrating uid: " << hid.id << "   stream: " << streamName << "   oldFile: " << oldFileName
+                    << "   newFile: " << newFileName << endmsg;
           }
 #endif
 
diff --git a/GaudiSvc/src/THistSvc/THistSvc.h b/GaudiSvc/src/THistSvc/THistSvc.h
index 9e0a97114..87968d54a 100644
--- a/GaudiSvc/src/THistSvc/THistSvc.h
+++ b/GaudiSvc/src/THistSvc/THistSvc.h
@@ -254,7 +254,7 @@ private:
 
   std::map<std::string, std::pair<TFile*, Mode>> m_files; // stream->file
   typedef std::multimap<std::string, std::string> streamMap;
-  streamMap m_fileStreams;                                // fileName->streams
+  streamMap m_fileStreams; // fileName->streams
 
   // stream->filename of shared files
   std::map<std::string, std::string> m_sharedFiles;
-- 
GitLab