// g++ -Wall -O3 -g List_Formatter.cpp -o List_Formatter && ./List_Formatter #include #include #include #include #include using namespace std; int main(){ string sample_name = "Au"; //A prefix for the TTOFSort output file histogram names, e.g. Zn1 is the first block of zinc runs int runlist[]={118026, 118027, 118028, -1}; for(int detn = 1; detn <= 4; detn++){ //Loop over 4 C6D6 detectors string outname = sample_name; //Create output file name in the format Sample_C6D6#_HistList.dat outname += "_C6D6"; stringstream formatter; formatter << detn; outname += formatter.str(); //This string stream now contains detector name integer converted to string outname += "_HistList.dat"; ofstream ofile; ofile.open(outname.c_str()); if(!ofile.is_open()){cout << "ERROR: Cannot open output file " << outname << endl; return 0;} for(int run_index = 0; run_index < (int)(sizeof(runlist) / sizeof(int)); run_index++){ //Loop over each of the runs if(runlist[run_index] != -1){ stringstream run_str; run_str << runlist[run_index]; //Save run number as string string histname1 = sample_name; histname1 += "_T_u"; histname1 += formatter.str(); histname1 += "_C6D6_run"; histname1 += run_str.str(); string histname2 = sample_name; histname2 += "_A_u"; histname2 += formatter.str(); histname2 += "_SILI_run"; histname2 += run_str.str(); string histname3 = sample_name; histname3 += "_h_info_C6D6_run"; histname3 += run_str.str(); run_str.str(""); //Clear the stringstream ofile << histname1 << " " << histname2 << " " << histname3 << endl; } } formatter.str(""); //Clear the stringstream ofile.close(); } return 0; }