[Rivet-svn] r4270 - trunk/src/Core

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon May 13 21:15:22 BST 2013


Author: buckley
Date: Mon May 13 21:15:22 2013
New Revision: 4270

Log:
Placeholder code for yaml-cpp v3/v5 alternative API use in AnalysisInfo -- yaml-cpp 3 code needs to be re-added

Modified:
   trunk/src/Core/AnalysisInfo.cc

Modified: trunk/src/Core/AnalysisInfo.cc
==============================================================================
--- trunk/src/Core/AnalysisInfo.cc	Sun May 12 17:21:07 2013	(r4269)
+++ trunk/src/Core/AnalysisInfo.cc	Mon May 13 21:15:22 2013	(r4270)
@@ -37,7 +37,12 @@
     MSG_DEBUG("Reading analysis data from " << datapath);
     YAML::Node doc;
     try {
+      #if YAMLCPP_API_VERSION == 3
+      std::ifstream file(datapath);
+      doc = YAML::Load(file);
+      #elif YAMLCPP_API_VERSION == 5
       doc = YAML::LoadFile(datapath);
+      #endif
     } catch (const YAML::ParserException& ex) {
       MSG_ERROR("Parse error when reading analysis data from " << datapath << " (" << ex.what() << ")");
       return ai;
@@ -46,7 +51,12 @@
     #define THROW_INFOERR(KEY) throw InfoError("Problem in info parsing while accessing key " + string(KEY) + " in file " + datapath)
 
     // Simple scalars (test for nullness before casting)
+    #if YAMLCPP_API_VERSION == 3
+    /// @todo Fix
+    #define TRY_GETINFO(KEY, VAR) try { if (doc[KEY] { string val; doc[KEY].second >> val; ai->_ ## VAR = val; } catch (...) { THROW_INFOERR(KEY); }
+    #elif YAMLCPP_API_VERSION == 5
     #define TRY_GETINFO(KEY, VAR) try { if (doc[KEY] && !doc[KEY].IsNull()) ai->_ ## VAR = doc[KEY].as<string>(); } catch (...) { THROW_INFOERR(KEY); }
+    #endif
     TRY_GETINFO("Name", name);
     TRY_GETINFO("Summary", summary);
     TRY_GETINFO("Status", status);
@@ -62,27 +72,45 @@
     #undef TRY_GETINFO
 
     // Sequences (test the seq *and* each entry for nullness before casting)
+    #if YAMLCPP_API_VERSION == 3
+    /// @todo Fix
+    #define TRY_GETINFO_SEQ(KEY, VAR) try { \
+        if (doc[KEY]) {                                                 \
+          const YAML::Node& VAR = doc[KEY];                             \
+          for (size_t i = 0; i < VAR.size(); ++i)                       \
+            if (!VAR[i].IsNull()) ai->_ ## VAR += VAR[i].as<string>();  \
+        } } catch (...) { THROW_INFOERR(KEY); }
+    #elif YAMLCPP_API_VERSION == 5
     #define TRY_GETINFO_SEQ(KEY, VAR) try { \
         if (doc[KEY] && !doc[KEY].IsNull()) {                           \
           const YAML::Node& VAR = doc[KEY];                             \
           for (size_t i = 0; i < VAR.size(); ++i)                       \
             if (!VAR[i].IsNull()) ai->_ ## VAR += VAR[i].as<string>();  \
         } } catch (...) { THROW_INFOERR(KEY); }
+    #endif
     TRY_GETINFO_SEQ("Authors", authors);
     TRY_GETINFO_SEQ("References", references);
     TRY_GETINFO_SEQ("ToDo", todos);
     #undef TRY_GETINFO_SEQ
 
+
     // A boolean with some name flexibility
     try {
+      #if YAMLCPP_API_VERSION == 3
+      /// @todo Fix
+      #elif YAMLCPP_API_VERSION == 5
       if (doc["NeedsCrossSection"]) ai->_needsCrossSection = doc["NeedsCrossSection"].as<bool>();
       else if (doc["NeedsCrossSection"]) ai->_needsCrossSection = doc["NeedCrossSection"].as<bool>();
+      #endif
     } catch (...) {
       THROW_INFOERR("NeedsCrossSection|NeedCrossSection");
     }
 
+
     // Beam particle identities
     try {
+      #if YAMLCPP_API_VERSION == 3
+
       if (doc["Beams"]) {
         const YAML::Node& beams = doc["Beams"];
         vector<PdgIdPair> beam_pairs;
@@ -98,10 +126,19 @@
         }
         ai->_beams = beam_pairs;
       }
-    } catch (...) { THROW_INFOERR("beams"); }
+
+      #elif YAMLCPP_API_VERSION == 5
+
+      /// @todo Fix
+
+      #endif
+    } catch (...) { THROW_INFOERR("Beams"); }
+
 
     // Beam energies
     try {
+      #if YAMLCPP_API_VERSION == 3
+
       if (doc["Energies"]) {
         vector< pair<double,double> > beam_energy_pairs;
         for (size_t i = 0; i < doc["Energies"].size(); ++i) {
@@ -119,10 +156,18 @@
         }
         ai->_energies = beam_energy_pairs;
       }
+
+      #elif YAMLCPP_API_VERSION == 5
+
+      /// @todo Fix
+
+      #endif
+
     } catch (...) { THROW_INFOERR("Energies"); }
 
     #undef THROW_INFOERR
 
+
     MSG_TRACE("AnalysisInfo pointer = " << ai);
     return ai;
   }


More information about the Rivet-svn mailing list