diff --git a/Software/Monitoring/PlotTrends.C b/Software/Monitoring/PlotTrends.C index 5e3f7c5..5fa5b0c 100644 --- a/Software/Monitoring/PlotTrends.C +++ b/Software/Monitoring/PlotTrends.C @@ -128,45 +128,53 @@ // Do not comment this line. gROOT->ProcessLine("#include "); - - - // Convert the string with date and time to something that is interpreted as date and time. tm_from is a tm object, t_from is a time_t object and corresponds to the number of seconds since epoch. The format specifier %c stands for date and time representation. - + // Adjust time format for output ROOT file and figures. + string s_from = ""; + string s_to = ""; + struct tm tm_from; - memset(&tm_from, 0, sizeof(struct tm)); - strptime(from,"%c",&tm_from); - time_t t_from = mktime(&tm_from); - - /* - cout << tm_from.tm_year << endl; - cout << t_from << endl; - */ + time_t t_from; struct tm tm_to; - memset(&tm_to, 0, sizeof(struct tm)); - strptime(to,"%c",&tm_to); - time_t t_to = mktime(&tm_to); + time_t t_to; - /* - cout << tm_to.tm_year << endl; - cout << t_to << endl; - */ - - // Check that the starting time is earlier than the stopping time. - if (t_from >= t_to) + if ((from != 0) && (to != 0)) { - cout << "Error! Starting time earlier than stopping time..." << endl; - return; + s_from = string(from); + s_to = string(to); + + // Remove white spaces from s_from and s_to. + s_from.erase(remove(s_from.begin(), s_from.end(), ' '), s_from.end()); + s_to.erase(remove(s_to.begin(), s_to.end(), ' '), s_to.end()); + + // Convert the string with date and time to something that is interpreted as date and time. tm_from is a tm object, t_from is a time_t object and corresponds to the number of seconds since epoch. The format specifier %c stands for date and time representation. + + memset(&tm_from, 0, sizeof(struct tm)); + strptime(from,"%c",&tm_from); + t_from = mktime(&tm_from); + + /* + cout << tm_from.tm_year << endl; + cout << t_from << endl; + */ + + memset(&tm_to, 0, sizeof(struct tm)); + strptime(to,"%c",&tm_to); + t_to = mktime(&tm_to); + + /* + cout << tm_to.tm_year << endl; + cout << t_to << endl; + */ + + // Check that the starting time is earlier than the stopping time. + if (t_from >= t_to) + { + cout << "Error! Starting time earlier than stopping time..." << endl; + return; + } } - // Adjust time format for output ROOT file and figures. - string s_from = string(from); - string s_to = string(to); - - // Remove white spaces from s_from and s_to. - s_from.erase(remove(s_from.begin(), s_from.end(), ' '), s_from.end()); - s_to.erase(remove(s_to.begin(), s_to.end(), ' '), s_to.end()); - // Do some fanciness to get the directory right. string inputDirectory = "/disk/groups/hep/flionett/TestStand/Data/"+string(sensor)+"/Monitoring"; string outputDirectory = "/disk/groups/hep/flionett/TestStand/AnalysisResults/"+string(sensor)+"/Monitoring"; @@ -183,10 +191,10 @@ // Create a directory named Figures inside the directory named outputDirectory if it does not exist. string path_to_make_figures = "mkdir -p "+outputDirectory+"/Figures"; - if ((from != 0) && (to !=0)) + if ((from != 0) && (to != 0)) path_to_make_figures = path_to_make_figures+"/PlotTrends-"+"from"+s_from+"to"+s_to; else - path_to_make_figures = path_to_make_figures+"/PlotTrends-all.root"; + path_to_make_figures = path_to_make_figures+"/PlotTrends-all"; system(path_to_make_figures.c_str()); TString path_to_figures = (string(path_to_make_figures)).substr((string(path_to_make_figures)).find_last_of(' ')+1); @@ -216,7 +224,10 @@ vector list_of_selected_files; list_of_files = open(inputDirectory); - list_of_selected_files = SelectFiles(inputDirectory, list_of_files, t_from, t_to); + if ((from != 0) && (to != 0)) + list_of_selected_files = SelectFiles(inputDirectory, list_of_files, t_from, t_to); + else + list_of_selected_files = list_of_files; if (list_of_selected_files.size() == 0) { cout << "Error! No input text file selected..." << endl; @@ -248,8 +259,24 @@ memset(&tm_time_in_line, 0, sizeof(struct tm)); strptime(line.c_str(),"%c",&tm_time_in_line); t_time_in_line = mktime(&tm_time_in_line); - - if ((t_time_in_line <= t_to) && (t_time_in_line >= t_from)) + + if ((from != 0) && (to != 0)) + { + if ((t_time_in_line <= t_to) && (t_time_in_line >= t_from)) + { + // cout << "Time in line: " << t_time_in_line << " from epoch time" << endl; + time = new TDatime(tm_time_in_line.tm_year,tm_time_in_line.tm_mon+1,tm_time_in_line.tm_mday,tm_time_in_line.tm_hour+1,tm_time_in_line.tm_min,tm_time_in_line.tm_sec); + // cout << "Time going in the ROOT file: " << time->Convert() << endl; + // Get time, temperature, humidity, and dew point. + istringstream iss(line); + iss >> trash1 >> trash2 >> trash3 >> trash4 >> trash5 >> T >> RH >> DP; + vtime.push_back(time->Convert()); + vT.push_back(T); + vRH.push_back(RH); + vDP.push_back(DP); + } + } + else { // cout << "Time in line: " << t_time_in_line << " from epoch time" << endl; time = new TDatime(tm_time_in_line.tm_year,tm_time_in_line.tm_mon+1,tm_time_in_line.tm_mday,tm_time_in_line.tm_hour+1,tm_time_in_line.tm_min,tm_time_in_line.tm_sec); diff --git a/Software/Tools/UsefulFunctions.C b/Software/Tools/UsefulFunctions.C new file mode 100644 index 0000000..ca9a13c --- /dev/null +++ b/Software/Tools/UsefulFunctions.C @@ -0,0 +1,79 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 10/04/2015 +//************************************************ + +/* +List of useful functions. +*/ + +// Header guard. +#ifndef __USEFULFUNCTIONS_C_INCLUDED__ +#define __USEFULFUNCTIONS_C_INCLUDED__ + +#include "Lib.C" + +// Declarations. + +// It returns a vector of strings with all the files in a given directory or an error message if the given directory cannot be opened. +vector open(string path = "."); + +// It ignores lines in a text file. +std::istream& ignoreline(std::ifstream& in, std::ifstream::pos_type& pos); + +// It gets the last line of a text file. +std::string getLastLine(std::ifstream& in); + + + +// Definitions. + +// It returns a vector of strings with all the files in a given directory or an error message if the given directory cannot be opened. +vector open(string path) { + DIR *dir = NULL; + dirent *pdir = NULL; + vector files; + + dir = opendir(path.c_str()); + if (dir) { + + while (pdir = readdir(dir)) { + if ((strcmp(pdir->d_name,".") != 0) && (strcmp(pdir->d_name,"..") != 0)) + files.push_back(pdir->d_name); + } + closedir(dir); + } + else + { + cout << "Error! Unable to open input directory..." << endl; + } + + return files; +} + +// It ignores lines in a text file. +std::istream& ignoreline(std::ifstream& in, std::ifstream::pos_type& pos) +{ + pos = in.tellg(); + return in.ignore(std::numeric_limits::max(), '\n'); +} + +// It gets the last line of a text file. +std::string getLastLine(std::ifstream& in) +{ + std::ifstream::pos_type pos = in.tellg(); + + std::ifstream::pos_type lastPos; + while (in >> std::ws && ignoreline(in, lastPos)) + pos = lastPos; + + in.clear(); + in.seekg(pos); + + std::string line; + std::getline(in, line); + return line; +} + +#endif +