Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_xnet.C
Go to the documentation of this file.
1 // cwb_xnet : interface to the cwb class for 1G/2G pipelines
2 //
3 // fName : for 1G/(2G jstage=1) analysis it is the user_parameters.C file name
4 // for 2G jstage=2 analysis :
5 // if fName is the (1G jstage=1) output cluster file name
6 // then runID is retrieved from file name
7 // jstage : for 1G jstage=CWB_STAGE_FULL
8 // for 2G jstage=CWB_STAGE_FULL / CWB_STAGE_INIT / CWB_STAGE_STRAIN / CWB_STAGE_CSTRAIN
9 // CWB_STAGE_COHERENCE / CWB_STAGE_SUPERCLUSTER / CWB_STAGE_LIKELIHOOD
10 // uName : used only for (2G jstage=2) -> is an auxiliary user_parameters.C file
11 // batch : true/false -> batch/interactive mode
12 // ced : true/false -> if true the easy ced script cwb_eced.C is executed (used only for easy ced)
13 //
14 
15 #include <unistd.h>
16 
17 void SystemExec(char* command, int maxtry=3);
18 
19 void
20 cwb_xnet(TString fName, CWB_STAGE jstage=CWB_STAGE_FULL, TString uName="", bool batch=false, bool eced=false) {
21 
22  int runID=0;
23  char cmd[1024];
24 
25  char tmpOut[1024]; // temporary out log file name
26  char outLog[1024]; // final out log file name
27  char tmpErr[1024]; // temporary err log file name
28  char errLog[1024]; // final err log file name
29  if(batch) {
30  // job stdout is redirect to local file when job is executed in batch mode (condor)
31  // this is done to avoid network traffic between the execution node and the working user directory
32  // when the job is finished the log file is moved to the log working directory
33 
34  // import nodedir from CINT (used in batch mode in multistages analysis)
35  char nodedir_cint[1024];
36  TGlobal* GLOBAL = (TGlobal*)gROOT->GetGlobal("nodedir",true);
37  if(GLOBAL!=NULL)
38  memcpy((void*)&nodedir_cint,(void*)GLOBAL->GetAddress(),1024*sizeof(char));
39  // makes the nodedir_cint readable from the group
40  sprintf(cmd,"chmod g+r %s",nodedir_cint);
41  cout << cmd << endl;
42  SystemExec(cmd);
43 
44  unsigned int Pid = gSystem->GetPid(); // used to tag in a unique way the temporary files
45 
46  TString srunID = TString(gSystem->Getenv("CWB_JOBID")); // get jobID
47  TString slabel = gSystem->BaseName(work_dir); // get label
48 #ifdef _USE_ROOT6
49  // Warning : Cling will in some cases report an unresolved symbol
50  // This might get fixed in a later version
51  char _sstage[16]; sprintf(_sstage,"%d",jstage);
52  TString sstage = _sstage;
53 #else
54  TString sstage = CWB::cwb::GetStageString(jstage); // get stage name
55 #endif
56 
57  // create tmpOut & outLog
58  sprintf(tmpOut,"%s/%s_%s_%s_%d.out", nodedir_cint,srunID.Data(),slabel.Data(),sstage.Data(),Pid);
59  sprintf(outLog,"%s/%s/%s_%s_%s.out", work_dir,log_dir,srunID.Data(),slabel.Data(),sstage.Data());
60  cout << tmpOut << endl; cout << outLog << endl;
61 
62  // create tmpErr & errLog
63  sprintf(tmpErr,"%s/%s_%s_%s_%d.err", nodedir_cint,srunID.Data(),slabel.Data(),sstage.Data(),Pid);
64  sprintf(errLog,"%s/%s/%s_%s_%s.err", work_dir,log_dir,srunID.Data(),slabel.Data(),sstage.Data());
65  cout << tmpErr << endl; cout << errLog << endl;
66 
67  if(gSystem->Getenv("_USE_PEGASUS")==NULL) {
68  // create in log dir a symbolic link to the temporary log files
69  // the remove is necessary because the command 'ln' fails if the link points to a unavailable node
70  // the command touch it is necessary because condor fails if xxxLog not exist
71  sprintf(cmd,"rm -f %s;ln -sf %s %s;touch %s",outLog,tmpOut,outLog,outLog);
72  cout << cmd << endl;
73  SystemExec(cmd);
74  sprintf(cmd,"rm -f %s;ln -sf %s %s;touch %s",errLog,tmpErr,errLog,errLog);
75  cout << cmd << endl;
76  SystemExec(cmd);
77  }
78 
79  freopen(tmpOut,"w",stdout); // redirect stdout to file
80  freopen(tmpErr,"w",stderr); // redirect stderr to file
81 
82  // Print CWB logo
84  }
85 
86  if(TString(analysis)=="1G") {
87  cwb1G CWB(fName);
88  if(!batch) {
89  CWB::config* cfg = CWB.GetConfig();
90  if(eced) cfg->Import(gSystem->ExpandPathName("$CWB_MACROS/cwb_eced.C")); // easy ced
91  cfg->Import(gSystem->ExpandPathName("$CWB_MACROS/cwb_inet.C"));
92  //runID=1;
93  }
94  //cfg->Print();
95  CWB.run(runID);
96  } else
97  if(TString(analysis)=="2G") {
99 
100  // import nodedir from CINT (used in batch mode in multistages analysis)
101  char nodedir_cint[1024];
102  TGlobal* GLOBAL = (TGlobal*)gROOT->GetGlobal("nodedir",true);
103  if(GLOBAL!=NULL)
104  memcpy((void*)&nodedir_cint,(void*)GLOBAL->GetAddress(),1024*sizeof(char));
105 
106  // create cwb2G object
107  cwb2G CWB(fName,uName,jstage);
108 
109  // set configuration
110  CWB::config* cfg = CWB.GetConfig();
111  if(!batch) {
112  if(eced) gROOT->Macro(gSystem->ExpandPathName("$CWB_MACROS/cwb_eced.C")); // easy ced
113  cfg->Import(gSystem->ExpandPathName("$CWB_MACROS/cwb_inet.C"));
114  //runID=1;
115  } else {
116  // nodedir must be updated because in multistage the nodedir change
117  sprintf(cfg->nodedir,"%s",nodedir_cint);
118  }
119 
120  // set save options for job file
121  CWB.SetupStage(jstage);
122  //cfg->Print();
123 
124  // run analysis
125  CWB.run(runID);
126  } else {
127  cout << "cwb_xnet - Error : analysis must be 1G or 2G" << endl;
128  gSystem->Exit(1);
129  }
130 
131  if(batch) {
132  if(ftell(stdout)!=-1) fclose(stdout); // close stdout
133  if(ftell(stderr)!=-1) fclose(stderr); // close stderr
134 
135  // move condor temporary log files to the working log directory
136  // if size>1000000 it is not copied (to avoid network traffic)
137  int estat;
138  Long_t id,size,flags,mt;
139 
140  estat = gSystem->GetPathInfo(tmpOut,&id,&size,&flags,&mt);
141  if (estat==0 && size<1000000) {
142  sprintf(cmd,"mv %s %s",tmpOut,outLog);
143  cout << cmd << endl;
144  SystemExec(cmd);
145  }
146 
147  estat = gSystem->GetPathInfo(tmpErr,&id,&size,&flags,&mt);
148  if (estat==0 && size<1000000) {
149  sprintf(cmd,"mv %s %s",tmpErr,errLog);
150  cout << cmd << endl;
151  SystemExec(cmd);
152  }
153  }
154 
155  gSystem->Exit(0);
156 }
157 
158 void
159 SystemExec(char* command, int maxtry) {
160 //
161 // Execute System Command
162 //
163 // command : system command
164 // maxtry : number of retry before to exit with error (default=3)
165 //
166 
167  int ntry=0;
168  int ecommand=1;
169  while(ecommand&&(ntry<maxtry)) {
170  ecommand=gSystem->Exec(command);
171  if(ecommand) gSystem->Sleep(int(gRandom->Uniform(1000,3000))); // wait [1,3] sec
172  ntry++;
173  }
174  if(ecommand) {cout << "cwb_xnet.C - Error -> " << command << endl;gSystem->Exit(1);}
175  return;
176 }
177 
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
TString GetLALVersion(TString options="")
Definition: Toolfun.hh:892
char cmd[1024]
TString("c")
Long_t flags
Long_t size
void Import(TString umacro="")
Definition: config.cc:334
char nodedir[1024]
Definition: config.hh:334
CWB::Toolbox TB
Definition: ComputeSNR.C:5
Definition: cwb2G.hh:15
void SetupStage(CWB_STAGE jstage)
Definition: cwb.cc:2223
virtual void run(int runID=0)
Definition: cwb.cc:263
char log_dir[512]
Definition: test_config1.C:151
string command
Definition: cwb_online.py:382
CWB::config * GetConfig()
Definition: cwb.hh:138
Definition: cwb1G.hh:13
int estat
PrintLogoCWB(GetLALVersion())
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
Long_t mt
Long_t id
char work_dir[512]
Definition: test_config1.C:143
fclose(ftrig)
char fName[256]
void cwb_xnet(TString fName, CWB_STAGE jstage=CWB_STAGE_FULL, TString uName="", bool batch=false, bool eced=false)
Definition: cwb_xnet.C:20
CWB_STAGE
Definition: cwb.hh:102
void SystemExec(char *command, int maxtry=3)
Definition: cwb_xnet.C:159