// Utilisation de SOPHYA pour faciliter les tests ... #include //#include #include #include "sopnamsp.h" #include "machdefs.h" #include #include #include // include standard c/c++ #include #include #include #include #include #include #include #include #include #include // include sophya mesure ressource CPU/memoire ... #include "resusage.h" #include "ctimer.h" #include "timing.h" #include "timestamp.h" #include "strutilxx.h" #include "ntuple.h" #include "fioarr.h" #include "tarrinit.h" #include "histinit.h" #include "fitsioserver.h" #include "fiosinit.h" #include "ppersist.h" //----------------------------------------------- char *regexp (const char *string, const char *patrn, int *begin, int *end) { int i, w=0, len; char *word = NULL; regex_t rgT; regmatch_t match; regcomp(&rgT,patrn,REG_EXTENDED); if ((regexec(&rgT,string,1,&match,0)) == 0) { *begin = (int)match.rm_so; *end = (int)match.rm_eo; len = *end-*begin; word=(char*)malloc(len+1); for (i=*begin; i<*end; i++) { word[w] = string[i]; w++; } word[w]=0; } regfree(&rgT); return word; } //------------------------------------------------ struct Param { string debuglev_; string inPath_; string outPath_; string sourceName_; string filePattern_; } para; //----- sa_size_t round_sa(r_4 r) { return static_cast((r > 0.0) ? (r + 0.5) : (r - 0.5)); } //----- string StringToLower(string strToConvert){ //change each element of the string to lower case for(unsigned int i=0;i tolower( *rit ) ) return false; return false; } //----- list ListOfFileInDir(string dir, string filePettern) throw(string) { list theList; DIR *dip; struct dirent *dit; string msg; string fileName; string fullFileName; size_t found; if ((dip=opendir(dir.c_str())) == NULL ) { msg = "opendir failed on directory "+dir; throw msg; } while ( (dit = readdir(dip)) != NULL ) { fileName = dit->d_name; found=fileName.find(filePettern); if (found != string::npos) { fullFileName = dir + "/"; fullFileName += fileName; theList.push_back(fullFileName); } }//eo while if (closedir(dip) == -1) { msg = "closedir failed on directory "+dir; throw msg; } theList.sort(stringCompare); return theList; } // class StringMatch : public unary_function { public: StringMatch(const string& pattern): pattern_(pattern){} bool operator()(const string& aStr) const { int b,e; regexp(aStr.c_str(),pattern_.c_str(),&b,&e); cout << "investigate " << aStr << " to find " << pattern_ << "[" < listOfFiles; string directoryName; directoryName = para.inPath_ + "/" + para.sourceName_; listOfFiles = ListOfFileInDir(directoryName,para.filePattern_); list::const_iterator iFile, iFileEnd; iFileEnd = listOfFiles.end(); StringMatch match("specONOFFRaw[0-9]+"); for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) { cout << "load file <" << *iFile << ">" << endl; PInPersist fin(*iFile); vector vec = fin.GetNameTags(); vector listOfSpectra; std::remove_copy_if( vec.begin(), vec.end(), back_inserter(listOfSpectra), not1(match) ); for (size_t i=0; i" << endl; } } } //------------------------------------------------------- int main(int narg, char* arg[]) { int rc = 0; //return code string msg; //message used in Exceptions string debuglev = "0"; string action = "default"; string inputPath = "."; string outputPath = "."; string sourceName = "Abell85"; string filePattern; // bool okarg=false; int ka=1; while (ka<(narg-1)) { if (strcmp(arg[ka],"-debug")==0) { debuglev=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-act")==0) { action=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-inPath")==0) { inputPath=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-outPath")==0) { outputPath=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-source")==0) { sourceName=arg[ka+1]; ka+=2; } else if (strcmp(arg[ka],"-filePattern")==0) { filePattern=arg[ka+1]; ka+=2; } else ka++; }//eo while para.debuglev_ = debuglev; para.inPath_ = inputPath; para.outPath_ = outputPath; para.sourceName_ = sourceName; para.filePattern_ = filePattern; cout << "Dump Initial parameters ............" << endl; cout << " action = " << action << "\n" << " inputPath = " << inputPath << "\n" << " outputPath = " << outputPath << "\n" << " sourceName = " << sourceName << "\n" << " filePattern = " << filePattern << "\n" << " debuglev = " << debuglev << "\n"; cout << "...................................." << endl; try { int b,e; char *match=regexp("truc0machin","[a-z]+[0-9]*",&b,&e); printf("->%s<-\n(b=%d e=%d)\n",match,b,e); if ( action == "default" ) { meanOnCycles(); } } catch (std::exception& sex) { cerr << "mergeRawOnOff.cc std::exception :" << (string)typeid(sex).name() << "\n msg= " << sex.what() << endl; rc = 78; } catch ( string str ) { cerr << "mergeRawOnOff.cc Exception raised: " << str << endl; } catch (...) { cerr << "mergeRawOnOff.cc catched unknown (...) exception " << endl; rc = 79; } return 0; }