/** * This application retreives the database values for the TPC gas drift velocity from a TPC monitor chamber * for a range of time and produces a file formated as such: * * [unix time] [drift velocity] * * example: * * 1269936413 7.8232179 * 1269937058 7.7882245 * 1269937714 7.8438646 * 1269938370 7.8351408 * 1269939025 7.8255586 * 1269939670 7.8221024 * * Application takes as input the requested chamber, A or B, and the start date and end date for the requested * database values. * * Authour: Andre Gaudin * EmaiL: agaudin@uvic.ca * * Based on code writen by Blair Jamison. */ #include #include #include #include "ISlowControlDatabase.hxx" // // Variables: // Command line option for which chamber, "A" or "B" std::string chamber; // Start and end times, YYYY MM DD HH MM SS, for range int start_year, start_month, start_day, start_hour, start_minute, start_second, end_year, end_month, end_day, end_hour, end_minute, end_second; // User specified output file name: std::string outputFileName; /** * Take the YYYY MM DD HH MM SS time definition and convert it into the corresponding * unix time stamp. * * This code use the time structure, tm, form time.h to "build" the unix time. */ long GetUnixTime( int year, int month, int day, int hour, int min, int sec){ tm mt; // Offset to 1900: mt.tm_year = year - 1900; mt.tm_mon = month-1; mt.tm_mday = day; mt.tm_hour = hour; mt.tm_min = min; mt.tm_sec = sec; // "Turn off" daylight savings time (will be using GMT/UTC": mt.tm_isdst = -1; return (long) mktime(&mt); } /** * Retrieves the drift velocity values in the time range requested for the specified monitor chamber and * creates the required ASCI output file. */ bool getDriftVelocities(){ // Convert the start and end times to unix time. // Set the timezone to GMT (all information is in GMT for simplicity) to ensure no "time shift" setenv( "TZ", "GMT", 1 ); tzset(); int start_time = (int) GetUnixTime(2010, 3, 30, 8, 0, 0); int end_time = (int) GetUnixTime(2010, 4, 9, 9, 0, 0); // Names of the field to be read: std::vector names; // Vector for storing the values: std::vector > > data; // // Setup based on the specified monitor chamber: if (chamber.compare("A")) { names.push_back("mean_vda"); data = ISlowControlDatabase::Get().QueryGetFieldStartEndTime("gasmonchamber_vda", names, start_time, end_time); } else if (chamber.compare("B")) { names.push_back("mean_vdb"); data = ISlowControlDatabase::Get().QueryGetFieldStartEndTime("gasmonchamber_vdb", names, start_time, end_time); } else { std::cout << "Specified monitor chamber is not valid. Options are \"A\" or \"B\". Exiting..." << std::endl; return false; } // //Write the data out to a file. ofstream output; output.open(outputFileName.c_str()); std::vector > >::iterator it = data.begin(); for (;it != data.end(); it++){ output << std::setprecision(10) << it->first << "\t" << (it->second[0])/10.0 << std::endl; } output.close(); return true; } void printHelp(){ std::cout << "Usage:" << std::endl; std::cout << "\tgetTPCMonChamberDriftVel.exe -h -c [chamber] -s [YYYY MM DD HH MM SS] -e [YYYY MM DD HH MM SS] -o [file name]" << std::endl; std::cout << std::endl; std::cout << "\t-h: print this help message" << std::endl; std::cout << "\t-c: monitor chamber, A or B" << std::endl; std::cout << "\t-s: start time (inclusive) for the range of requested database values, in YYYY MM DD HH MM SS format." << std::endl; std::cout << "\t-e: end time (exclusive) for the range of requested database values, in YYYY MM DD HH MM SS format." << std::endl; std::cout << "\t-o: text output file name" << std::endl; std::cout << std::endl; std::cout << "\tReturns the monitor chamber drift velocity values for the requested period in the form:" << std::endl; std::cout << std::endl; std::cout << "\t\t\t [unix time] [drift velocity (cm/us)]" << std::endl; return; } // // Parses the string commands input at the command line, see printHelp() for descriptions of the options. bool parseCommands (int argc, char *argv[]){ if (argc == 1){ printHelp(); return false; } // Process command line for (int i = 1; i < argc; i++){ if (strcmp(argv[i], "-h") == 0){ printHelp(); return false; } else if (strcmp(argv[i], "-c") == 0) { chamber = argv[++i]; } else if (strcmp(argv[i], "-s") == 0) { start_year = atoi(argv[++i]); start_month = atoi(argv[++i]); start_day = atoi(argv[++i]); start_hour = atoi(argv[++i]); start_minute = atoi(argv[++i]); start_second = atoi(argv[++i]); } else if (strcmp(argv[i], "-e") == 0) { end_year = atoi(argv[++i]); end_month = atoi(argv[++i]); end_day = atoi(argv[++i]); end_hour = atoi(argv[++i]); end_minute = atoi(argv[++i]); end_second = atoi(argv[++i]); } else if (strcmp(argv[i], "-o") == 0) { outputFileName = argv[++i]; } else { std::cout << "A command line option is not recognized: " << argv[i] << std::endl; std::cout << std::endl; printHelp(); return false; } } return true; } int main(int argc, char **argv) { if (!parseCommands(argc, argv)){ return 1; } getDriftVelocities(); }