![]() |
ENSDF++ 1.1
An easy, fast and simple way to run querys towards the ENSDF database, written in C++.
|
00001 #include "ENSDFProcessor.h" 00002 00003 ENSDFProcessor::ENSDFProcessor(string ENSDFDirectory, string MassTableDirectory, VerbosePrinter * toRegister, unsigned int nbrOfThreads) 00004 { 00005 registerListener(toRegister); 00006 vector<string> myDirectory = getDirectoryContent(ENSDFDirectory); 00007 for(unsigned int i = 0; i<myDirectory.size(); i++) 00008 { 00009 myDirectory[i]=ENSDFDirectory + "/" + myDirectory[i]; 00010 } 00011 myENSDF = new ENSDF(myDirectory, toRegister, nbrOfThreads); 00012 vector<string> myMassDirectory = getDirectoryContent(MassTableDirectory); 00013 myTable = new MassTable(MassTableDirectory + "/" + myMassDirectory.front(), toRegister); 00014 00015 00016 registerChild(myTable); 00017 registerChild(myENSDF); 00018 } 00019 00020 ENSDFProcessor::~ENSDFProcessor() 00021 { 00022 delete myTable; 00023 myTable = NULL; 00024 delete myENSDF; 00025 myENSDF = NULL; 00026 } 00027 00028 void ENSDFProcessor::runBetaGammaQuery(double minBetaDecayTime, double maxBetaDecayTime, double minBetaBranchStrength, double minGammaBranchStrength, string outputFileName) 00029 { 00030 vPrint(2,"Running query to file.\n"); 00031 FILE * myFile = fopen (outputFileName.c_str(), "w"); 00032 if(myFile!=NULL) 00033 { 00034 vPrint(3,"File was successfully created.\n"); 00035 list<InterestingDecayBetaGamma* > myDecays = runBetaGammaQuery(minBetaDecayTime, maxBetaDecayTime); 00036 for(list<InterestingDecayBetaGamma* >::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00037 { 00038 fprintf(myFile, "%s\n", (*it)->toString(minBetaBranchStrength, minGammaBranchStrength).c_str()); 00039 } 00040 vPrint(3,"Wrote %d posts to the file.\n", myDecays.size()); 00041 vPrint(3,"Closing file.\n"); 00042 fclose(myFile); 00043 for(list<InterestingDecayBetaGamma*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00044 { 00045 delete *it; 00046 *it = NULL; 00047 } 00048 } 00049 } 00050 00051 void ENSDFProcessor::runBetaGammaQuery_GenerateGammaList(double minBetaDecayTime, double maxBetaDecayTime, double minGammaBranchStrength, string outputFileName) 00052 { 00053 vPrint(2, "Running GammaList query to file.\n"); 00054 FILE * myFile = fopen(outputFileName.c_str(), "w"); 00055 if(myFile!=NULL) 00056 { 00057 vPrint(3,"File was successfully created.\n"); 00058 list<InterestingDecayBetaGamma* > myDecays = runBetaGammaQuery(minBetaDecayTime, maxBetaDecayTime); 00059 for(list<InterestingDecayBetaGamma*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00060 { 00061 fprintf(myFile, "%s", (*it)->toGammaString(minGammaBranchStrength).c_str()); 00062 } 00063 vPrint(3,"Wrote %d posts to the file.\n", myDecays.size()); 00064 vPrint(3,"Closing file.\n"); 00065 fclose(myFile); 00066 for(list<InterestingDecayBetaGamma*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00067 { 00068 delete *it; 00069 *it = NULL; 00070 } 00071 } 00072 else 00073 vPrint(1,"Could not create file!"); 00074 } 00075 00076 void ENSDFProcessor::runBetaGammaQuery_GenerateChartList(double minBetaDecayTime, double maxBetaDecayTime, double minGammaBranchStrength, string outputFileName) 00077 { 00078 vPrint(2, "Running ChartList query to file.\n"); 00079 FILE * myFile = fopen(outputFileName.c_str(), "w"); 00080 if(myFile!=NULL) 00081 { 00082 vPrint(3,"File was successfully created.\n"); 00083 list<InterestingDecayBetaGamma* > myDecays = runBetaGammaQuery(minBetaDecayTime, maxBetaDecayTime); 00084 for(list<InterestingDecayBetaGamma*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00085 { 00086 fprintf(myFile, "%s", (*it)->toChartString(minGammaBranchStrength).c_str()); 00087 } 00088 vPrint(3,"Wrote %d posts to the file.\n", myDecays.size()); 00089 vPrint(3,"Closing file.\n"); 00090 fclose(myFile); 00091 for(list<InterestingDecayBetaGamma*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00092 { 00093 delete *it; 00094 *it = NULL; 00095 } 00096 } 00097 else 00098 vPrint(1,"Could not create file!"); 00099 } 00100 00101 00102 void ENSDFProcessor::runBetaGammaQuery_GenerateTexList(double minBetaDecayTime, double maxBetaDecayTime, double minGammaBranchStrength, string outputFileName) 00103 { 00104 vPrint(2, "Running ChartList query to file.\n"); 00105 FILE * myFile = fopen(outputFileName.c_str(), "w"); 00106 if(myFile!=NULL) 00107 { 00108 vPrint(3,"File was successfully created.\n"); 00109 list<InterestingDecayBetaGamma* > myDecays = runBetaGammaQuery(minBetaDecayTime, maxBetaDecayTime); 00110 for(list<InterestingDecayBetaGamma*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00111 { 00112 fprintf(myFile, "%s", (*it)->toTexString(minGammaBranchStrength).c_str()); 00113 vPrint(3,"%s",(*it)->toTexString(minGammaBranchStrength).c_str()); 00114 } 00115 vPrint(3,"Wrote %d posts to the file.\n", myDecays.size()); 00116 vPrint(3,"Closing file.\n"); 00117 fclose(myFile); 00118 for(list<InterestingDecayBetaGamma*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00119 { 00120 delete *it; 00121 *it = NULL; 00122 } 00123 } 00124 else 00125 vPrint(1,"Could not create file!"); 00126 } 00127 00128 00129 00130 void ENSDFProcessor::runIsomerQuery(double tLower, double tUpper, string outputFileName) 00131 { 00132 vPrint(2,"Running Isomer query to file.\n"); 00133 FILE * myFile = fopen (outputFileName.c_str(), "w"); 00134 if(myFile!=NULL) 00135 { 00136 vPrint(3,"File was successfully created.\n"); 00137 list<InterestingDecayIsomer*> myDecays = runIsomerQuery(tLower, tUpper); 00138 for(list<InterestingDecayIsomer*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00139 { 00140 fprintf(myFile, "%s\n", (*it)->toString().c_str()); 00141 } 00142 vPrint(3,"Closing file.\n"); 00143 fclose(myFile); 00144 for(list<InterestingDecayIsomer*>::iterator it = myDecays.begin(); it!=myDecays.end(); it++) 00145 { 00146 delete *it; 00147 *it = NULL; 00148 } 00149 } 00150 vPrint(2,"Done with query.\n"); 00151 } 00152 00153 list<InterestingDecayIsomer*> ENSDFProcessor::runIsomerQuery(double tLower, double tUpper) 00154 { 00155 vPrint(2, "Creating Isomer query.\n"); 00156 DataQueryIsomer * myQuery = new DataQueryIsomer(myENSDF, myPrinter); 00157 registerChild(myQuery); 00158 list<InterestingDecayIsomer*> myDecayList = myQuery->RunQuery(tLower, tUpper); 00159 00160 delete myQuery; 00161 myQuery = NULL; 00162 00163 return myDecayList; 00164 } 00165 00166 list<InterestingDecayBetaGamma*> ENSDFProcessor::runBetaGammaQuery(double minBetaDecayTime, double maxBetaDecayTime) 00167 { 00168 vPrint(2,"Creating BetaGamma data query.\n"); 00169 DataQueryBetaGamma * myQuery = new DataQueryBetaGamma(myENSDF, myTable, myPrinter); 00170 registerChild(myQuery); 00171 00172 list<InterestingDecayBetaGamma*> myDecayList = myQuery->RunQuery(minBetaDecayTime, maxBetaDecayTime); 00173 00174 delete myQuery; 00175 myQuery = NULL; 00176 00177 return myDecayList; 00178 } 00179 00180 00181 //lists the content of a directory 00182 vector<string> ENSDFProcessor::getDirectoryContent(string directoryName) 00183 { 00184 vPrint(3,"Loading directory content of %s\n",directoryName.c_str()); 00185 vector<string> toReturn; 00186 00187 struct dirent **eps; 00188 int n; 00189 00190 n = scandir (directoryName.c_str(), &eps, one, alphasort); 00191 if (n >= 0) 00192 { 00193 int cnt; 00194 for (cnt = 0; cnt < n; ++cnt) 00195 { 00196 string tmp(eps[cnt]->d_name); 00197 if(!(tmp.compare(".")==0 || tmp.compare("..")==0 || tmp.compare(".svn")==0)) 00198 toReturn.push_back(eps[cnt]->d_name); 00199 } 00200 } 00201 else 00202 perror ("Couldn't open the directory"); 00203 vPrint(3,"Found %d entries in folder %s\n", (int)toReturn.size(), directoryName.c_str()); 00204 return toReturn; 00205 }