/////////////////////////////////////////////////////////////////////////////// // query DB for the new runs taken over the last 2 days // update list of input files in book/input // assume that dataset=sopr00 book=cdfopr /////////////////////////////////////////////////////////////////////////////// #include "ctime" #include "time.h" #include "TSystem.h" int update_list_of_runs(int n_days_back = 2, int RunNumber=-1, int Debug=0) { tm broken_time, *tm1, *tm2; char old_date[200], new_date[200], subdir_name[100], file_name[200], catalog_file[200]; char cmd[200], buf[200]; int rc; TStnRunSummary* rs; char* catalog_dir = "/cdf/home/www/usr/cdfopr/Stntuple/cafdfc/stntuple/sopr00"; char* dataset = "sopr00"; const char* task_dir = gSystem->Getenv("TASK_DIR"); if (task_dir == 0) { printf(" update_list_of_runs.C: TASK_DIR is not defined, exit\n"); } sprintf(catalog_file,"%s/%s.files",catalog_dir,dataset); if (Debug) printf(" TASK_DIR = %s, catalog_file = %s\n",task_dir, catalog_file); TObjArray* list_of_runs = new TObjArray(100); TObjArray* list_of_files = new TObjArray(100); if (RunNumber == -1) { // strptime(old_date,"%Y.%m.%d",&broken_time); // time_t t = mktime(&broken_time) - 24*3600*2; // converted back to seconds, subtract 2 days time_t t1 = time(0) - 24*3600*n_days_back; time_t t2 = time(0) + 24*3600; strftime(old_date,200, "%Y.%m.%d",localtime(&t1)); strftime(new_date,200, "%Y.%m.%d",localtime(&t2)); if (Debug) printf("%s %s\n",old_date,new_date); cdfofprd.GetListOfRuns(list_of_runs,old_date,new_date); } else { rs = new TStnRunSummary(); cdfofprd.GetRunSummary(RunNumber,rs); list_of_runs->Add((TObject*) rs); } int nruns = list_of_runs->GetEntriesFast(); if (Debug) printf(">>> update_list_of_runs : nruns = %i <<< \n",nruns); for (int i=0; iAt(i); int rn = rs->RunNumber(); if (Debug) printf("%i .%s.\n",rn,rs->TriggerTableName().Data()); //----------------------------------------------------------------------------- // inquire physics runs only //----------------------------------------------------------------------------- if (rs->TriggerTableName().Index("PHYSICS") >= 0) { cdfofprd.GetListOfFiles(list_of_files,"aphysr",rn,rn); if (Debug) printf("%i %s\n",rn,rs->TriggerTableName().Data()); int nf = list_of_files->GetEntries(); if (nf <= 0) { if (Debug) printf( " no files for run %i\n",rn); } else { //----------------------------------------------------------------------------- // check if there is a file .done/xxxxxx.aphysr //----------------------------------------------------------------------------- if (Debug) printf("good run: %i %s\n",rn,rs->TriggerTableName().Data()); sprintf(subdir_name,"%s/book/input/%i",task_dir,rn/1000); gSystem->Exec(Form("mkdir -p %s/.done",subdir_name)); //----------------------------------------------------------------------------- // create file with the list of files to process //----------------------------------------------------------------------------- sprintf(file_name,"%s/.done/%i.aphysr",subdir_name,rn); FILE* f = fopen(file_name,"r"); if (f) { // run already processed fclose(f); if (Debug) { printf(" run %i already processed\n",rn); goto NEXT_RUN; } } //----------------------------------------------------------------------------- // file with list of RAW stream A files for this run doesn't exist in .done, // check if it exists //----------------------------------------------------------------------------- else { sprintf(file_name,"%s/%i.aphysr",subdir_name,rn); f = fopen(file_name,"r"); if (! f) { // first time considering this run if (Debug) printf(" --- create input file for run %i \n",rn); f = fopen(file_name,"w"); fprintf(f,"#---------------------------------------------\n"); fprintf(f,"# file name Express Production Stntuple \n"); fprintf(f,"#---------------------------------------------\n"); for (int j=0; jAt(j); fprintf(f,"%17s no no \n", fr->fFILE_NAME.Data()); } fclose(f); //----------------------------------------------------------------------------- // update catalog of SOPR00 //----------------------------------------------------------------------------- f = fopen(catalog_file,"a"); for (int j=0; jAt(j); strcpy(buf,fr->fFILE_NAME.Data()); buf[1] = 'a'; fprintf(f,"%s.last %17s.s -1\n",dataset,buf); } fclose(f); //----------------------------------------------------------------------------- // and at the same time update web-browsable file //----------------------------------------------------------------------------- } else { //----------------------------------------------------------------------------- // file exists, see if there are new files in the DB // make sure we are not corrupting anything //----------------------------------------------------------------------------- if (Debug) printf(" --- file %s exists\n",file_name); fclose(f); for (int j=0; jAt(j); const char* f_aphysr = fr->fFILE_NAME.Data(); sprintf(cmd,"grep %s %s >& /dev/null",f_aphysr,file_name); if (Debug) printf(" exec: %s\n",cmd); rc = gSystem->Exec(cmd); if (rc != 0) { //----------------------------------------------------------------------------- // grep didn't find raw file in already existing list of files for a given run // need to update input file //----------------------------------------------------------------------------- f = fopen(file_name,"a+"); if (Debug) printf(" run %i: new file %s\n",rs->RunNumber(),f_aphysr); // append the file fprintf(f,"%-17s no no \n",f_aphysr); fclose(f); //----------------------------------------------------------------------------- // update catalog of SOPR00 //----------------------------------------------------------------------------- f = fopen(catalog_file,"a"); strcpy(buf,f_aphysr); buf[1] = 'a'; fprintf(f,"sopr00.last %17s.s -1\n",buf); fclose(f); } else { //----------------------------------------------------------------------------- // RAW file already listed //----------------------------------------------------------------------------- if (Debug) printf("data file %s already listed in %s\n", f_aphysr,file_name); } } } } } } } if (Debug) printf(">>> update_list_of_runs : finished <<< \n"); return 0; }