From 35ba4fedeb9ff0c79f6d43c7dbf5671802d35da0 Mon Sep 17 00:00:00 2001
From: matta <matta@npt>
Date: Fri, 16 Oct 2009 03:14:38 +0000
Subject: [PATCH] * Fixing support of comment in input file 	- Wrong token
 sequence is no more issued when a comment is insert within the input file *
 Adding comment support for AnnularS1

---
 NPSimulation/src/AnnularS1.cc                 | 82 ++++++++++++-------
 NPSimulation/src/EventGeneratorBeam.cc        |  6 +-
 NPSimulation/src/EventGeneratorIsotropic.cc   |  5 +-
 NPSimulation/src/EventGeneratorTransfert.cc   |  3 +-
 .../src/EventGeneratorTransfertToResonance.cc |  3 +-
 NPSimulation/src/MUST2Array.cc                |  2 +-
 NPSimulation/src/Plastic.cc                   |  4 +-
 NPSimulation/src/Target.cc                    |  4 +-
 NPSimulation/src/ThinSi.cc                    |  6 +-
 9 files changed, 74 insertions(+), 41 deletions(-)

diff --git a/NPSimulation/src/AnnularS1.cc b/NPSimulation/src/AnnularS1.cc
index f91826528..9b39717d9 100644
--- a/NPSimulation/src/AnnularS1.cc
+++ b/NPSimulation/src/AnnularS1.cc
@@ -9,7 +9,7 @@
  * Original Author: N. de Sereville  contact address: deserevi@ipno.in2p3.fr *
  *                                                                           *
  * Creation Date  : 21/07/09                                                 *
- * Last update    : 11/10/09                                                 *
+ * Last update    : 16/10/09                                                 *
  *---------------------------------------------------------------------------*
  * Decription: Define the S1 detector from Micron                            *
  *                                                                           *
@@ -251,39 +251,63 @@ void AnnularS1::ReadConfiguration(string Path)
    string LineBuffer, DataBuffer;
 
    G4double Z = 0;
-   bool check_Z = false;
+   bool check_Z = false , check_VIS=false,ReadingStatus = false ;
 
    while (!ConfigFile.eof()) {
       getline(ConfigFile, LineBuffer);
-      if (LineBuffer.compare(0, 9, "AnnularS1") == 0) {
-         G4cout << "///" << G4endl           ;
-         G4cout << "Annular element found: " << G4endl   ;
 
-         ConfigFile >> DataBuffer;
-         //Position method
-         if (DataBuffer.compare(0, 2, "Z=") == 0) {
-            check_Z = true;
-            ConfigFile >> DataBuffer ;
-            Z = atof(DataBuffer.c_str()) ;
-            Z = Z * mm;
-            cout << "Z:  " << Z / mm << endl;
-         }
-
-         ConfigFile >> DataBuffer;
-         if (DataBuffer.compare(0, 4, "VIS=") == 0) {
-            ConfigFile >> DataBuffer;
-            if (DataBuffer.compare(0, 3, "all") == 0) m_non_sensitive_part_visiualisation = true;
-         }
 
-         //Add The previously define telescope
-         //With position method
-         if (check_Z) {
-            AddModule(Z);
-         }
-         else {
-            G4cout << "Wrong Token, AnnularS1 Annular Element not added" << G4endl;
-         }
-      }
+		if (LineBuffer.compare(0, 9, "AnnularS1") == 0) {
+         G4cout << "///" << G4endl           ;
+         G4cout << "Annular element found: " << G4endl   ;
+					ReadingStatus = true ;
+			}
+	
+		else ReadingStatus = false ;
+
+		while(ReadingStatus)
+			{
+				ConfigFile >> DataBuffer;
+
+				//Search for comment Symbol %
+	      if (DataBuffer.compare(0, 1, "%") == 0) {	ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );}
+
+	      //Position method
+	      else if (DataBuffer.compare(0, 2, "Z=") == 0) {
+	            check_Z = true;
+	            ConfigFile >> DataBuffer ;
+	            Z = atof(DataBuffer.c_str()) ;
+	            Z = Z * mm;
+	            cout << "Z:  " << Z / mm << endl;
+	         }
+
+	       else if (DataBuffer.compare(0, 4, "VIS=") == 0) {
+							check_VIS = true ;
+	            ConfigFile >> DataBuffer;
+	            if (DataBuffer.compare(0, 3, "all") == 0) m_non_sensitive_part_visiualisation = true;
+	         }
+
+
+					///////////////////////////////////////////////////
+					//	If no Detector Token and no comment, toggle out
+					else 
+						{ReadingStatus = false; G4cout << "Wrong Token Sequence: Getting out " << DataBuffer << G4endl ;}
+
+
+	         //Add The previously define telescope
+	         //With position method
+	         if (check_Z&&check_VIS) {
+	            AddModule(Z);
+							check_Z = false ;
+							check_VIS=false	;
+							ReadingStatus = false 			;	
+							cout << "///"<< endl ;	    
+	         }
+
+			}
+
+			
+      
    }
 }
 
diff --git a/NPSimulation/src/EventGeneratorBeam.cc b/NPSimulation/src/EventGeneratorBeam.cc
index 664ccf1d5..1b83395f5 100644
--- a/NPSimulation/src/EventGeneratorBeam.cc
+++ b/NPSimulation/src/EventGeneratorBeam.cc
@@ -19,6 +19,10 @@
  *                                                                           *
  *                                                                           *
  *****************************************************************************/
+
+// C++
+#include <limits>
+
 // G4 header
 #include "G4ParticleTable.hh"
 
@@ -91,7 +95,7 @@ void EventGeneratorBeam::ReadConfiguration(string Path)
 			 ReactionFile >> DataBuffer;
 	
       		//Search for comment Symbol %
-      		if (DataBuffer.compare(0, 1, "%") == 0) {/*Do Nothing*/;}
+      		if (DataBuffer.compare(0, 1, "%") == 0) {	ReactionFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );}
 
 	        else if (DataBuffer.compare(0, 10, "ParticleZ=") == 0) {
 	         	check_Z = true ;
diff --git a/NPSimulation/src/EventGeneratorIsotropic.cc b/NPSimulation/src/EventGeneratorIsotropic.cc
index c60482c04..b2814747a 100644
--- a/NPSimulation/src/EventGeneratorIsotropic.cc
+++ b/NPSimulation/src/EventGeneratorIsotropic.cc
@@ -19,6 +19,9 @@
  *                                                                           *
  *                                                                           *
  *****************************************************************************/
+// C++
+#include<limits>
+
 // G4 headers
 #include "G4ParticleTable.hh"
 
@@ -99,7 +102,7 @@ void EventGeneratorIsotropic::ReadConfiguration(string Path)
 	    		 ReactionFile >> DataBuffer;
 	    	
 	    		 //Search for comment Symbol %
-			     if (DataBuffer.compare(0, 1, "%") == 0) {/*Do Nothing*/;}
+			     if (DataBuffer.compare(0, 1, "%") == 0) {	ReactionFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );}
 
 		         else if (DataBuffer.compare(0, 10, "EnergyLow=") == 0) {
 		         	check_EnergyLow = true ;
diff --git a/NPSimulation/src/EventGeneratorTransfert.cc b/NPSimulation/src/EventGeneratorTransfert.cc
index 87bba8e11..d0b3b32b6 100644
--- a/NPSimulation/src/EventGeneratorTransfert.cc
+++ b/NPSimulation/src/EventGeneratorTransfert.cc
@@ -24,6 +24,7 @@
 // C++ headers
 #include <iostream>
 #include <fstream>
+#include <limits>
 
 // G4 header defining G4 types
 #include "globals.hh"
@@ -174,7 +175,7 @@ while(ReadingStatus){
  			 ReactionFile >> DataBuffer;
  			 
  			 //Search for comment Symbol %
-	      	 if (DataBuffer.compare(0, 1, "%") == 0) {/* Do Nothing */;}
+	      	 if (DataBuffer.compare(0, 1, "%") == 0) {	ReactionFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );}
  			 
 	         else if (DataBuffer.compare(0, 5, "Beam=") == 0) {
 	         	check_Beam = true ;
diff --git a/NPSimulation/src/EventGeneratorTransfertToResonance.cc b/NPSimulation/src/EventGeneratorTransfertToResonance.cc
index 07742f8c9..c199ed8fe 100644
--- a/NPSimulation/src/EventGeneratorTransfertToResonance.cc
+++ b/NPSimulation/src/EventGeneratorTransfertToResonance.cc
@@ -25,6 +25,7 @@
 // C++ headers
 #include <iostream>
 #include <fstream>
+#include <limits>
 
 // G4 header defining G4 types
 #include "globals.hh"
@@ -190,7 +191,7 @@ while(ReadingStatus){
  			 ReactionFile >> DataBuffer;
  			 
  			 //Search for comment Symbol %
-	      	 if (DataBuffer.compare(0, 1, "%") == 0) {/* Do Nothing */;}
+	      	 if (DataBuffer.compare(0, 1, "%") == 0) {	ReactionFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );}
  			 
 	         else if (DataBuffer.compare(0, 5, "Beam=") == 0) {
 	         	check_Beam = true ;
diff --git a/NPSimulation/src/MUST2Array.cc b/NPSimulation/src/MUST2Array.cc
index 5571d5266..83c65039c 100644
--- a/NPSimulation/src/MUST2Array.cc
+++ b/NPSimulation/src/MUST2Array.cc
@@ -9,7 +9,7 @@
  * Original Author: Adrien MATTA  contact address: matta@ipno.in2p3.fr       *
  *                                                                           *
  * Creation Date  : January 2009                                             *
- * Last update    :                                                          *
+ * Last update    : October 2009                                             *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
  *  This file describe the MUST2 charge particle Detector                    *
diff --git a/NPSimulation/src/Plastic.cc b/NPSimulation/src/Plastic.cc
index 698be1e4f..5c569b85e 100644
--- a/NPSimulation/src/Plastic.cc
+++ b/NPSimulation/src/Plastic.cc
@@ -22,7 +22,7 @@
 // C++ headers
 #include <sstream>
 #include <cmath>
-
+#include <limits>
 //G4 Geometry object
 #include "G4Tubs.hh"
 
@@ -152,7 +152,7 @@ void Plastic::ReadConfiguration(string Path)
 					ConfigFile >> DataBuffer ;
 
 					//	Comment Line 
-					if (DataBuffer.compare(0, 1, "%") == 0) {/*do nothing */;}
+					if (DataBuffer.compare(0, 1, "%") == 0) {	ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );}
 
 						//	Finding another telescope (safety), toggle out
 					else if (DataBuffer.compare(0, 6, "Plastic") == 0) {
diff --git a/NPSimulation/src/Target.cc b/NPSimulation/src/Target.cc
index 589f643d4..e176eae06 100644
--- a/NPSimulation/src/Target.cc
+++ b/NPSimulation/src/Target.cc
@@ -25,7 +25,7 @@
  *****************************************************************************/
 // C++ header
 #include <fstream>
-
+#include <limits>
 // G4 geometry header
 #include "G4Tubs.hh"
 
@@ -232,7 +232,7 @@ void Target::ReadConfiguration(string Path)
          ConfigFile >> DataBuffer;
 	
       		//Search for comment Symbol %
-      		if (DataBuffer.compare(0, 1, "%") == 0) {/*Do Nothing*/;}
+      		if (DataBuffer.compare(0, 1, "%") == 0) {	ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );}
       		
 	        else if (DataBuffer.compare(0, 10, "THICKNESS=") == 0) {
 	        	check_Thickness = true ;
diff --git a/NPSimulation/src/ThinSi.cc b/NPSimulation/src/ThinSi.cc
index e03aeaf94..a196e5632 100644
--- a/NPSimulation/src/ThinSi.cc
+++ b/NPSimulation/src/ThinSi.cc
@@ -9,7 +9,7 @@
  * Original Author: Adrien MATTA  contact address: matta@ipno.in2p3.fr       *
  *                                                                           *
  * Creation Date  : January 2009                                             *
- * Last update    :                                                          *
+ * Last update    : October 2009                                             *
  *---------------------------------------------------------------------------*
  * Decription:                                                               *
  *  This class describe a 20um Silicium detector                             *
@@ -22,7 +22,7 @@
 // C++ headers
 #include <sstream>
 #include <cmath>
-
+#include <limits>
 //G4 Geometry object
 #include "G4Trd.hh"
 #include "G4Box.hh"
@@ -309,7 +309,7 @@ void ThinSi::ReadConfiguration(string Path)
 					ConfigFile >> DataBuffer ;
 
 					//	Comment Line 
-					if (DataBuffer.compare(0, 1, "%") == 0) {/*do nothing */;}
+					if (DataBuffer.compare(0, 1, "%") == 0) {	ConfigFile.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );}
 
 						//	Finding another telescope (safety), toggle out
 					else if (DataBuffer.compare(0, 6, "ThinSi") == 0) {
-- 
GitLab