source: BAORadio/AmasNancay/mergeRawOnOff.cc@ 540

Last change on this file since 540 was 540, checked in by campagne, 14 years ago

avoid the link to a specif bao daq date (jec)

File size: 6.5 KB
Line 
1// Utilisation de SOPHYA pour faciliter les tests ...
2#include <regex.h>
3//#include <regexp.h>
4#include <stdio.h>
5
6#include "sopnamsp.h"
7#include "machdefs.h"
8
9#include <stdlib.h>
10#include <dirent.h>
11#include <matharr.h>
12
13// include standard c/c++
14#include <iostream>
15#include <fstream>
16#include <string>
17#include <vector>
18#include <map>
19#include <functional>
20#include <algorithm>
21#include <numeric>
22#include <list>
23#include <exception>
24
25// include sophya mesure ressource CPU/memoire ...
26#include "resusage.h"
27#include "ctimer.h"
28#include "timing.h"
29#include "timestamp.h"
30#include "strutilxx.h"
31#include "ntuple.h"
32#include "fioarr.h"
33#include "tarrinit.h"
34#include "histinit.h"
35#include "fitsioserver.h"
36#include "fiosinit.h"
37#include "ppersist.h"
38
39//-----------------------------------------------
40char *regexp (const char *string, const char *patrn, int *begin, int *end) {
41 int i, w=0, len;
42 char *word = NULL;
43 regex_t rgT;
44 regmatch_t match;
45 regcomp(&rgT,patrn,REG_EXTENDED);
46 if ((regexec(&rgT,string,1,&match,0)) == 0) {
47 *begin = (int)match.rm_so;
48 *end = (int)match.rm_eo;
49 len = *end-*begin;
50 word=(char*)malloc(len+1);
51 for (i=*begin; i<*end; i++) {
52 word[w] = string[i];
53 w++; }
54 word[w]=0;
55 }
56 regfree(&rgT);
57 return word;
58}
59//------------------------------------------------
60
61
62struct Param {
63 string debuglev_;
64 string inPath_;
65 string outPath_;
66 string sourceName_;
67 string filePattern_;
68} para;
69//-----
70sa_size_t round_sa(r_4 r) {
71 return static_cast<sa_size_t>((r > 0.0) ? (r + 0.5) : (r - 0.5));
72}
73//-----
74string StringToLower(string strToConvert){
75 //change each element of the string to lower case
76 for(unsigned int i=0;i<strToConvert.length();i++) {
77 strToConvert[i] = tolower(strToConvert[i]);
78 }
79 return strToConvert;//return the converted string
80}
81//-----
82bool stringCompare( const string &left, const string &right ){
83 if( left.size() < right.size() )
84 return true;
85 for( string::const_iterator lit = left.begin(), rit = right.begin(); lit != left.end() && rit != right.end(); ++lit, ++rit )
86 if( tolower( *lit ) < tolower( *rit ) )
87 return true;
88 else if( tolower( *lit ) > tolower( *rit ) )
89 return false;
90 return false;
91}
92//-----
93list<string> ListOfFileInDir(string dir, string filePettern) throw(string) {
94 list<string> theList;
95
96
97 DIR *dip;
98 struct dirent *dit;
99 string msg; string fileName;
100 string fullFileName;
101 size_t found;
102
103 if ((dip=opendir(dir.c_str())) == NULL ) {
104 msg = "opendir failed on directory "+dir;
105 throw msg;
106 }
107 while ( (dit = readdir(dip)) != NULL ) {
108 fileName = dit->d_name;
109 found=fileName.find(filePettern);
110 if (found != string::npos) {
111 fullFileName = dir + "/";
112 fullFileName += fileName;
113 theList.push_back(fullFileName);
114 }
115 }//eo while
116 if (closedir(dip) == -1) {
117 msg = "closedir failed on directory "+dir;
118 throw msg;
119 }
120
121 theList.sort(stringCompare);
122
123 return theList;
124
125}
126//
127class StringMatch : public unary_function<string,bool> {
128public:
129 StringMatch(const string& pattern): pattern_(pattern){}
130 bool operator()(const string& aStr) const {
131
132
133 int b,e;
134 regexp(aStr.c_str(),pattern_.c_str(),&b,&e);
135
136 cout << "investigate " << aStr << " to find " << pattern_
137 << "[" <<b<<","<<e<<"]"
138 << endl;
139
140
141 if (b != 0) return false;
142 if (e != aStr.size()) return false;
143 return true;
144
145 }
146private:
147 string pattern_;
148};
149//-------------------------------------------------------
150void meanOnCycles() throw(string) {
151 list<string> listOfFiles;
152 string directoryName;
153 directoryName = para.inPath_ + "/" + para.sourceName_;
154
155 listOfFiles = ListOfFileInDir(directoryName,para.filePattern_);
156
157 list<string>::const_iterator iFile, iFileEnd;
158 iFileEnd = listOfFiles.end();
159
160 StringMatch match("specONOFFRaw[0-9]+");
161 for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
162 cout << "load file <" << *iFile << ">" << endl;
163 PInPersist fin(*iFile);
164 vector<string> vec = fin.GetNameTags();
165 vector<string> listOfSpectra;
166
167 std::remove_copy_if(
168 vec.begin(), vec.end(), back_inserter(listOfSpectra),
169 not1(match)
170 );
171
172 for (size_t i=0; i<listOfSpectra.size(); ++i){
173 cout << " spactra <" << listOfSpectra[i] << ">" << endl;
174 }
175 }
176
177}
178//-------------------------------------------------------
179int main(int narg, char* arg[])
180{
181
182 int rc = 0; //return code
183 string msg; //message used in Exceptions
184
185
186 string debuglev = "0";
187 string action = "default";
188 string inputPath = ".";
189 string outputPath = ".";
190 string sourceName = "Abell85";
191 string filePattern;
192
193
194 // bool okarg=false;
195 int ka=1;
196 while (ka<(narg-1)) {
197 if (strcmp(arg[ka],"-debug")==0) {
198 debuglev=arg[ka+1];
199 ka+=2;
200 }
201 else if (strcmp(arg[ka],"-act")==0) {
202 action=arg[ka+1];
203 ka+=2;
204 }
205 else if (strcmp(arg[ka],"-inPath")==0) {
206 inputPath=arg[ka+1];
207 ka+=2;
208 }
209 else if (strcmp(arg[ka],"-outPath")==0) {
210 outputPath=arg[ka+1];
211 ka+=2;
212 }
213 else if (strcmp(arg[ka],"-source")==0) {
214 sourceName=arg[ka+1];
215 ka+=2;
216 }
217 else if (strcmp(arg[ka],"-filePattern")==0) {
218 filePattern=arg[ka+1];
219 ka+=2;
220 }
221 else ka++;
222 }//eo while
223
224 para.debuglev_ = debuglev;
225 para.inPath_ = inputPath;
226 para.outPath_ = outputPath;
227 para.sourceName_ = sourceName;
228 para.filePattern_ = filePattern;
229
230 cout << "Dump Initial parameters ............" << endl;
231 cout << " action = " << action << "\n"
232 << " inputPath = " << inputPath << "\n"
233 << " outputPath = " << outputPath << "\n"
234 << " sourceName = " << sourceName << "\n"
235 << " filePattern = " << filePattern << "\n"
236 << " debuglev = " << debuglev << "\n";
237 cout << "...................................." << endl;
238
239 try {
240
241 int b,e;
242 char *match=regexp("truc0machin","[a-z]+[0-9]*",&b,&e);
243 printf("->%s<-\n(b=%d e=%d)\n",match,b,e);
244
245 if ( action == "default" ) {
246 meanOnCycles();
247 }
248
249 } catch (std::exception& sex) {
250 cerr << "mergeRawOnOff.cc std::exception :" << (string)typeid(sex).name()
251 << "\n msg= " << sex.what() << endl;
252 rc = 78;
253 }
254 catch ( string str ) {
255 cerr << "mergeRawOnOff.cc Exception raised: " << str << endl;
256 }
257 catch (...) {
258 cerr << "mergeRawOnOff.cc catched unknown (...) exception " << endl;
259 rc = 79;
260 }
261
262 return 0;
263
264}
Note: See TracBrowser for help on using the repository browser.