Index: trunk/FACT++/src/dataLogger.cc
===================================================================
--- trunk/FACT++/src/dataLogger.cc	(revision 10672)
+++ trunk/FACT++/src/dataLogger.cc	(revision 10675)
@@ -143,9 +143,11 @@
 	///run number (-1 means no run number specified)
 	int fRunNumber; 
+	///previous run number. to check if changed while logging
+	int fPreviousRunNumber;
 	///Current Service Quality
 	int fQuality;
 	///Modified Julian Date
 	double fMjD;
-	
+public:
 	///Define all the static names
 	static const char* fConfigDay;
@@ -165,4 +167,5 @@
 	static const char* fStartStopOpenedFiles;
 	static const char* fStartStopNumSubsAndFits;
+private:
 	//overloading of DIM's infoHandler function
 	void infoHandler(); 
@@ -315,5 +318,7 @@
 	inline void NotifyOpenedFile(std::string name, int type, DimDescribedService* service);
 public:	
-	void setBlackWhiteList(const std::string& , bool);
+//	void setBlackWhiteList(const std::string& , bool);
+	void Setup(Configuration& conf);
+
 private:
 	std::set<std::string> fGreyList;
@@ -330,6 +335,92 @@
 	///boolean to prevent DIM update while desctructing the dataLogger
 	bool fDestructing;	
+
+	///Small function for calculating the total size written so far
+	void calculateTotalSizeWritten(DataLoggerStats& statVar, bool& shouldWarn, bool isPrinting);
 }; //DataLogger
 
+void DataLogger::calculateTotalSizeWritten(DataLoggerStats& statVar, bool& shouldWarn, bool isPrinting)
+{
+#ifdef HAS_FITS
+	if (isPrinting)
+	{
+		stringstream str;
+		str.str("");
+		str << "There are " << fNumSubAndFitsData.numOpenFits << " FITS files open:";
+		Message(str.str());
+	}
+	SubscriptionsListType::iterator x;
+	std::map<std::string, SubscriptionType>::iterator y;
+	bool runFileDone = false;
+	for (x=fServiceSubscriptions.begin(); x != fServiceSubscriptions.end(); x++)
+	{
+		for (y=x->second.begin(); y != x->second.end(); y++)
+		{
+			if (y->second.runFile.IsOpen() && !runFileDone)
+			{
+					fFileSizesMap[y->second.runFile.fFileName] = y->second.runFile.GetWrittenSize();
+					if (isPrinting)
+						Message("-> "+y->second.runFile.fFileName);
+#ifdef ONE_FITS_ONLY
+					runFileDone = true;
+#endif
+			}
+			if (y->second.nightlyFile.IsOpen())
+			{
+				fFileSizesMap[y->second.nightlyFile.fFileName] = y->second.nightlyFile.GetWrittenSize();
+				if (isPrinting)
+					Message("-> "+y->second.nightlyFile.fFileName);
+			}
+		}
+	}
+#else
+	if (isPrinting)
+		Message("FITS output disabled at compilation");
+#endif
+	struct stat st;
+	//gather log and report files sizes on disk
+	if (fNightlyLogFile.is_open())
+	{
+		stat(fFullNightlyLogFileName.c_str(), &st);
+		fFileSizesMap[fFullNightlyLogFileName] = st.st_size;
+	}
+	if (fNightlyReportFile.is_open())
+	{
+		stat(fFullNightlyReportFileName.c_str(), &st);
+		fFileSizesMap[fFullNightlyReportFileName] = st.st_size;
+	}
+	if (fRunLogFile.is_open())
+	{
+		stat(fFullRunLogFileName.c_str(), &st);
+		fFileSizesMap[fFullRunLogFileName] = st.st_size;
+	}
+	if (fRunReportFile.is_open())
+	{
+		stat(fFullRunReportFileName.c_str(), &st);
+		fFileSizesMap[fFullRunReportFileName] = st.st_size;
+	}
+	struct statvfs vfs;
+	if (!statvfs(fNightlyFileName.c_str(), &vfs))
+	{
+		statVar.freeSpace = vfs.f_bsize*vfs.f_bavail;
+		shouldWarn = false;
+	}
+	else
+	{
+		stringstream str;
+		str.str("");
+		str << "Unable to retrieve stats for " << fNightlyFileName << ". Reason: " << strerror(errno) << " [" << errno << "]";
+		if (!shouldWarn)
+			Error(str);
+		shouldWarn = true;
+		statVar.freeSpace = -1;
+	}
+	//sum up all the file sizes. past and present
+	statVar.sizeWritten = 0;
+	for (std::map<std::string, long>::iterator it=fFileSizesMap.begin(); it != fFileSizesMap.end();  it++)
+		statVar.sizeWritten += it->second;
+	statVar.sizeWritten -= fBaseSizeNightly;
+	statVar.sizeWritten -= fBaseSizeRun;
+}
 //static members initialization
 //since I do not check the transition/config names any longer, indeed maybe these could be hard-coded... but who knows what will happen in the future ?
@@ -381,4 +472,5 @@
 				sleep(fStatsPeriodDuration);
 			//update the fits files sizes
+			calculateTotalSizeWritten(statVar, statWarning, false);/*
 #ifdef HAS_FITS
 			SubscriptionsListType::iterator x;
@@ -445,4 +537,5 @@
 			statVar.sizeWritten -= fBaseSizeNightly;
 			statVar.sizeWritten -= fBaseSizeRun;
+			*/
 			if (fStatsPeriodDuration == 0.0f)
 				continue;
@@ -481,5 +574,6 @@
 		fNightlyFileName = ".";//"/home/lyard/log";//
 		fRunFileName = ".";//"/home/lyard/log";
-		fRunNumber = 12345;
+		fRunNumber = -1;
+		fPreviousRunNumber = fRunNumber;
 #ifdef HAS_FITS
 #ifdef ONE_RUN_FITS_ONLY
@@ -545,5 +639,10 @@
 		
 		//Provide a print command
-                AddConfiguration(fPrintCommand, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_BadNightlyConfig, kSM_BadRunConfig)
+                stringstream str;
+                str << 	kSM_Ready << " " << kSM_NightlyOpen << " " << kSM_WaitingRun << " " << kSM_Logging << " " << kSM_BadNightlyConfig;
+                str << " " << kSM_BadRunConfig;
+
+				AddConfiguration(fPrintCommand, str.str().c_str(), "")
+//                AddConfiguration(fPrintCommand, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_BadNightlyConfig, kSM_BadRunConfig)
                     (boost::bind(&DataLogger::PrintStatePlease, this, _1))
                     ("Print information about the internal status of the data logger.");
@@ -583,5 +682,5 @@
 	
 		//services parameters
-		fDebugIsOn = false;
+		fDebugIsOn = true;//false;
 		fStatsPeriodDuration = 1.0f;
 		fOpenedFilesIsOn = true;
@@ -793,5 +892,5 @@
 		return;
 
-        DimInfo* I = getInfo();
+    DimInfo* I = getInfo();
 	SubscriptionsListType::iterator x;
 	std::map<std::string, SubscriptionType>::iterator y;
@@ -843,4 +942,12 @@
 
 	CheckForRunNumber(I);
+
+	if (fPreviousRunNumber != fRunNumber)
+	{//run number has changed. close and reopen run files.
+		StopRunPlease();
+		StartRunPlease();
+		fPreviousRunNumber = fRunNumber;
+	}
+
 	ReportPlease(I, y->second);
 
@@ -1183,4 +1290,7 @@
 	else
 		Message("Run Report.........CLOSED");
+	bool statWarning = false;
+	DataLoggerStats statVar;
+	calculateTotalSizeWritten(statVar, statWarning, false);/*
 #ifdef HAS_FITS
 	str.str("");
@@ -1254,4 +1364,5 @@
 	statVar.sizeWritten -= fBaseSizeNightly;
 	statVar.sizeWritten -= fBaseSizeRun;
+	*/
 	Message("-----------------STATS-------------------");
 	str.str("");
@@ -1261,5 +1372,10 @@
 	str << "Disk free space:    " << statVar.freeSpace   << " bytes.";
         Message(str.str());
-
+    str.str("");
+    str << "Statistics are updated every " << fStatsPeriodDuration << " seconds";
+    if (fStatsPeriodDuration != 0)
+    	Message(str);
+    else
+    	Message("Statistics updates are currently disabled");
 	Message("------------DIM SUBSCRIPTIONS------------");
 
@@ -1274,6 +1390,11 @@
 			Message("-> "+it2->first);
 	}
-	Message("-----------------------------------------");
-	
+	if (fIsBlackList)
+		Message("------------BLOCK LIST-------------------");
+	else
+		if (fGreyList.size() != 0)
+			Message("------------ALLOW LIST-------------------");
+	for (set<string>::iterator it=fGreyList.begin(); it != fGreyList.end(); it++)
+		Message(*it);
 	return GetCurrentState();
 }
@@ -1778,6 +1899,6 @@
 	}
 	//attempt to open run file with current parameters
-	if (fRunNumber == -1)
-		return kSM_BadRunConfig;
+//	if (fRunNumber == -1)
+//		return kSM_BadRunConfig;
 	std::stringstream sRun;
 	sRun << fRunNumber;
@@ -1870,7 +1991,8 @@
 	if (!fRunLogFile.is_open() || !fRunReportFile.is_open())
 		return kSM_FatalError;
-	
-	fRunLogFile.close();
-	fRunReportFile.close();
+	if (fRunLogFile.is_open())
+		fRunLogFile.close();
+	if (fRunReportFile.is_open())
+		fRunReportFile.close();
 #ifdef HAS_FITS
 	for (SubscriptionsListType::iterator i = fServiceSubscriptions.begin(); i != fServiceSubscriptions.end(); i++)
@@ -1962,4 +2084,36 @@
 }
 
+void DataLogger::Setup(Configuration& conf)
+{
+	//Set the block or allow list
+	fGreyList.clear();
+    if (conf.Has("block"))
+    {
+    	vector<string> vec = conf.Get<vector<string>>("block");
+    	if (vec.size() != 0)
+    	{
+    		fIsBlackList = true;
+    		if (fDebugIsOn)
+				Debug("Setting BLOCK list:");
+    	}
+    	else if (conf.Has("allow"))
+    	{
+    		vec = conf.Get<vector<string>>("allow");
+    		if (vec.size() != 0)
+    		{
+    			fIsBlackList = false;
+    			if (fDebugIsOn)
+    				Debug("Setting ALLOW list:");
+    		}
+    	}
+    	for (vector<string>::iterator it=vec.begin(); it != vec.end(); it++)
+    	{
+    		fGreyList.insert(*it);
+    		if (fDebugIsOn)
+    			Debug("                   " + *it);
+    	}
+    }
+}
+/*
 void DataLogger::setBlackWhiteList(const std::string& black, bool isBlack)
 {
@@ -1980,5 +2134,5 @@
 	fIsBlackList = isBlack;
 }
-
+*/
 // --------------------------------------------------------------------------
 
@@ -2022,13 +2176,6 @@
     DataLogger logger(wout);
     
-    if (conf.Has("black-list"))
-    {	if (conf.Get<std::string>("black-list") != "")
-	    	logger.setBlackWhiteList(conf.Get<std::string>("black-list"), true);
-	    else if (conf.Has("white-list"))
-	    	{
-    			if (conf.Get<std::string>("white-list") != "")
-	    			logger.setBlackWhiteList(conf.Get<std::string>("white-list"), false);
-	    	}
-    }
+    logger.Setup(conf);
+
     shell.SetReceiver(logger);
 
@@ -2065,5 +2212,5 @@
         "All actions are supposed to arrive as DimCommands. Using the -c "
         "option, a local shell can be initialized. With h or help a short "
-        "help message about the usuage can be brought to the screen.\n"
+        "help message about the usage can be brought to the screen.\n"
         "\n"
         "Usage: dataLogger [-c type] [OPTIONS]\n"
@@ -2077,4 +2224,30 @@
     /* Additional help text which is printed after the configuration
      options goes here */
+	cout << "\n"
+			"The Block option has priority over the allow."
+			" i.e. if both are present, only the block list is kept."
+			"If only a server name or service without its server prefix is given "
+			"then all the services of that  server, or all the services that correspond to the given suffix"
+			" are ignored or considered."
+			"\n"
+			"For example, block=DIS_DNS will skip all the services offered by the DIS_DNS server. "
+			"while block=SERVICE_LIST will skip all the SERVICE_LIST services offered by any server."
+			"\n"
+			" The Commands offered by the dataLoger are the following: \n";
+	cout << DataLogger::fConfigDay << " specify the path where to put the nightly files\n";
+	cout << DataLogger::fConfigRun << " specify the path where to put the run files\n";
+	cout << DataLogger::fConfigRunNumber << " specify the run number\n";
+	cout << DataLogger::fConfigLog << " log a particular message\n";
+	cout << DataLogger::fTransStart << " start the nightly logging\n";
+	cout << DataLogger::fTransStop << " stop the nightly logging\n";
+	cout << DataLogger::fTransStartRun << " start the run logging\n";
+	cout << DataLogger::fTransStopRun << " stop the run logging\n";
+	cout << DataLogger::fTransReset << " stop any logging and/or recover from an error state\n";
+	cout << DataLogger::fTransWait << " go to the wait for run number state\n";
+	cout << DataLogger::fPrintCommand << " print the current state of the logger to the shell\n";
+	cout << DataLogger::fDebugOnOff << " turn on or off the debug mode\n";
+	cout << DataLogger::fStatsPeriod << " set the periodicity of the statistics. 0 disable them\n";
+	cout << endl;
+
 }
 
@@ -2088,6 +2261,6 @@
         ("log,l",     var<string>(n), "Write log-file")
         ("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
-        ("black-list,b", var<string>(""), "Black-list of services")
-        ("white-list,w", var<string>(""), "White-list of services")
+        ("block,b", vars<string>(), "Black-list of services")
+        ("allow,a", vars<string>(), "White-list of services")
         ;
 
