main in moenchReadDataMT [multi threading]

This commit is contained in:
cartier_s 2015-05-28 14:28:17 +02:00
parent c9269d0f21
commit 7e8cf810fb
3 changed files with 37 additions and 6 deletions

View File

@ -16,6 +16,7 @@
#include <fstream>
#include "moench02ModuleData.h"
#include "moenchCommonMode.h"
#define MYROOT1
#include "singlePhotonDetector.h"
//#include "MovingStat.h"
@ -26,7 +27,7 @@ using namespace std;
#define NR 160
#define MY_DEBUG 1
//#define MY_DEBUG 1
#ifdef MY_DEBUG
#include <TCanvas.h>
#endif
@ -215,7 +216,7 @@ THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nb
#endif
nf++;
cout << "=" ;
cout << "=" << decoder->getFrameNumber(buff);
delete [] buff;
}
cout << nph << endl;

View File

@ -1,5 +1,6 @@
#include <TFile.h>
#include <TThread.h>
#include <THStack.h>
#include "moenchReadData.C"
typedef struct task_s{
@ -9,6 +10,7 @@ typedef struct task_s{
int runmin;
int runmax;
int treeIndex;
double xTalk;
} Task;
void *moenchMakeTreeTask(void *p){
@ -19,13 +21,16 @@ void *moenchMakeTreeTask(void *p){
TFile *f = new TFile(fname,"RECREATE");
cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<")" << endl;
TThread::UnLock();
moenchReadData(t->fformat,t->tname,t->runmin,t->runmax);
THStack *s = moenchReadData(t->fformat,t->tname,t->runmin,t->runmax, 1500, -500, 1000, 1, t->xTalk);
s->Write();
if(f && f->IsOpen()){
f->Close();
}
return 0;
}
void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0){
void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0, double xTalk=0.044){
char threadName[1000];
TThread *threads[nThreads];
for(int i = 0; i < nThreads; i++){
@ -37,6 +42,7 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo
t->runmin = runmin + i*runoffset;
t->runmax = runmin + (i+1)*runoffset - 1;
t->treeIndex = treeIndexStart + i;
t->xTalk = xTalk;
cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl;
threads[i] = new TThread(threadName, moenchMakeTreeTask, t);
threads[i]->Run();
@ -50,3 +56,27 @@ void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runo
//to compile: g++ -DMYROOT -DMYROOT1 -g `root-config --cflags --glibs` -o moenchReadDataMT moenchReadDataMT.C
int main(int argc, char **argv){
if(argc < 8){
cout << "Usage: " << argv[0] << " fformat tit tdir runmin runoffset nThreads treeIndexStart [xTalkFactor]" << endl;
exit(-1);
}
char *fformat = argv[1];
char *tit = argv[2];
char *tdir = argv[3];
int runmin = atoi(argv[4]);
int runoffset = atoi(argv[5]);
int nThreads = atoi(argv[6]);
int treeIndexStart = atoi(argv[7]);
double xTalkFactor = 0.044;
if(argc == 9)
xTalkFactor = atof(argv[8]);
moenchReadDataMT(fformat, tit, tdir,runmin,runoffset,nThreads,treeIndexStart, xTalkFactor);
}

View File

@ -96,7 +96,7 @@ class slsDetectorData {
for (int iy=0; iy<ny; iy++)
for (int ix=0; ix<nx; ix++) {
dataMap[iy][ix]=dMap[iy][ix];
cout << ix << " " << iy << endl;
//cout << ix << " " << iy << endl;
}
}