///------------------------------------------------------------------------ /// /// Description: Example using the popen command to run a script and /// read the output. /// /// Author: Francesca Di Lodovico /// ///------------------------------------------------------------------------ #include #include #include #include #include #include #include "IDataQuality.hxx" using namespace std; int *runCommand(string type, int timeStamp) { FILE *fp; char path[200]; string commandPath = string(getenv("OADATAQUALITYROOT")) + "/src/GetDQ.py "; string command; int location; int newlocation; int loc; int lengthstring; bool resultsFlag = false; int * returnData = new int[7]; for (int i = 0 ; i < 7; i++)returnData[i] = -1; string returnString; int count = 0; std::stringstream timeStr; timeStr << timeStamp; command = commandPath + " -p -s " + type + " " + timeStr.str(); fp = popen(command.c_str(), "r"); if (fp == NULL) { printf("Failed to run command\n"); exit(1); } // Returned string is flag, subdetector, starttime, endtime, createtime // with spaces between the strings. We need to split these and get // the flag. There are other strings returned, but the results of // interest appear after the --- RESULTS --- string while (fgets(path, sizeof(path)-1, fp) != NULL) { returnString = path; // Have found the result string. Lines after contain the // results loc = returnString.find("- RESULTS -"); if (loc > 0) { resultsFlag = true; continue; } if (resultsFlag) { // Returned string contains seven space-separated values // flag startime endtime createtime location = returnString.find(" "); lengthstring = location; returnData[0] = atoi(returnString.substr(0, lengthstring).c_str()); //cout<<"String "<= *(TPCData+nflags) && timeStamp <= *(TPCData+(nflags+1)))) { cout << "**** TPC re-reading from database" << endl; TPCData = runCommand("TPC", timeStamp); } } else { cout << "**** have not read the database for TPC will read it" << endl; TPCData = runCommand("TPC", timeStamp); } // Get FGD status (approach is same as for TPC subdetector). if (FGDData != NULL) { if (!(timeStamp >= *(FGDData+nflags) && timeStamp <= *(FGDData+(nflags+1)))) { cout << "**** FGD re-reading from database" << endl; FGDData = runCommand("FGD", timeStamp); } } else { cout << "**** have not read the database for FGD will read it" << endl; FGDData = runCommand("FGD", timeStamp); } // Get ECAL status (approach is same as for TPC subdetector). if (ECALData != NULL) { if (!(timeStamp >= *(ECALData+nflags) && timeStamp <= *(ECALData+(nflags+1)))) { cout << "**** ECAL re-reading from database" << endl; ECALData = runCommand("ECAL", timeStamp); } } else { cout << "**** have not read the database for ECAL will read it" << endl; ECALData = runCommand("ECAL", timeStamp); } // Get P0D status (approach is same as for TPC subdetector). if (P0DData != NULL) { if (!(timeStamp >= *(P0DData+nflags) && timeStamp <= *(P0DData+(nflags+1)))) { cout << "**** P0D re-reading from database" << endl; P0DData = runCommand("P0D", timeStamp); } } else { cout << "**** have not read the database for P0D will read it" << endl; P0DData = runCommand("P0D", timeStamp); } // Get SMRD status (approach is same as for TPC subdetector). if (SMRDData != NULL) { if (!(timeStamp >= *(SMRDData+nflags) && timeStamp <= *(SMRDData+(nflags+1)))) { cout << "**** SMRD re-reading from database" << endl; SMRDData = runCommand("SMRD", timeStamp); } } else { cout << "**** have not read the database for SMRD will read it" << endl; SMRDData = runCommand("SMRD", timeStamp); } // Get MAGNET status (approach is same as for TPC subdetector). if (MAGNETData != NULL) { if (!(timeStamp >= *(MAGNETData+nflags) && timeStamp <= *(MAGNETData+(nflags+1)))) { cout << "**** MAGNET re-reading from database" << endl; MAGNETData = runCommand("MAGNET", timeStamp); } } else { cout << "**** have not read the database for MAGNET will read it" << endl; MAGNETData = runCommand("MAGNET", timeStamp); } // Get INGRID status (approach is same as for TPC subdetector). if (INGRIDData != NULL) { if (!(timeStamp >= *(INGRIDData+nflags) && timeStamp <= *(INGRIDData+(nflags+1)))) { cout << "**** INGRID re-reading from database" << endl; INGRIDData = runCommand("INGRID", timeStamp); } } else { cout << "**** have not read the database for INGRID will read it" << endl; INGRIDData = runCommand("INGRID", timeStamp); } // Load the flags TPCFlag = TPCData[0]; TPC1Flag = TPCData[1]; TPC2Flag = TPCData[2]; TPC3Flag = TPCData[3]; FGDFlag = FGDData[0]; FGD1Flag = FGDData[1]; FGD2Flag = FGDData[2]; ECALFlag = ECALData[0]; DSECALFlag = ECALData[1]; P0DECALFlag = ECALData[2]; BarECALFlag = ECALData[3]; P0DFlag = P0DData[0]; SMRDFlag = SMRDData[0]; MAGNETFlag = MAGNETData[0]; INGRIDFlag = INGRIDData[0]; // Add the flags to get the total COMET off-axis flag if(TPCFlag>-1 && FGDFlag>-1 && ECALFlag>-1 && P0DFlag>-1 && SMRDFlag>-1 && MAGNETFlag>-1){ allFlags = TPCFlag + FGDFlag + ECALFlag + P0DFlag + SMRDFlag + MAGNETFlag; if(allFlags>0) allFlags=1; //the info regarding each subdetector can be obtained from the subdetectors themselves } }