Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_dump_config.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 // get the cwb parameters.C used in the last stage : used by the cwb_dump command
20 
21 {
23 
24  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
25 
27  if(gSystem->Getenv("CWB_DUMP_HIST_FILE_NAME")==NULL) {
28  cout << "Error : environment CWB_DUMP_HIST_FILE_NAME is not defined!!!" << endl;exit(1);
29  } else {
30  cwb_dump_hist_file_name=TString(gSystem->Getenv("CWB_DUMP_HIST_FILE_NAME"));
31  }
32  if(cwb_dump_hist_file_name.Contains(".root")==0) {
33  cout << "Error : " << cwb_dump_hist_file_name.Data() << " is not a root file!!!" << endl;exit(1);
34  }
35 
37  if(gSystem->Getenv("CWB_DUMP_HIST_MODE")!=NULL) {
38  cwb_dump_hist_mode=TString(gSystem->Getenv("CWB_DUMP_HIST_MODE"));
39  }
40 
41  TFile *ifile = TFile::Open(cwb_dump_hist_file_name);
42  if(ifile==NULL) {cout << "Failed to open " << cwb_dump_hist_file_name.Data() << endl;exit(-1);}
43 
44  CWB::History* ihistory = (CWB::History*)ifile->Get("history");
45  if(ihistory==NULL) {
46  cout << "Error : history is not present!!!" << endl;exit(1);
47  }
48 
52  if(ihistory) {
53  TList* stageList = ihistory->GetStageNames(); // get stage list
54  for(int i=0;i<stageList->GetSize();i++) { // get lib versions
55  TObjString* stageObjString = (TObjString*)stageList->At(i);
56  TString stageName = stageObjString->GetString();
57  // check if stage belong to processing stages (skip pp stages)
58  bool isProcessingStage=false;
59  for(int j=0;j<=nStages;j++) {
60  if(cwb::GetStageString((CWB_STAGE)j).Contains(stageName)) isProcessingStage=true;
61  }
62  if(!isProcessingStage) continue;
63  char* stage = const_cast<char*>(stageName.Data());
64  TString log = ihistory->GetHistory(stage,const_cast<char*>("PARAMETERS"));
65  if(log!="") {
66  config = log;
67  config_md5 = ihistory->GetHistory(stage,const_cast<char*>("PARAMETERS_MD5"));
68  }
69  }
70  }
71 
72  if((cwb_dump_hist_mode=="view")||(cwb_dump_hist_mode=="dump")) {
73 
74  TString label = (cwb_dump_hist_mode=="dump") ? "config" : "view";
75 
76  char configFile[512];
77  TObjArray* token = TString(cwb_dump_hist_file_name).Tokenize(TString("/"));
78 
79  TString odir = (cwb_dump_hist_mode=="view") ? "/tmp" : dump_dir;
80  sprintf(configFile,"%s/%s_%s",odir.Data(),label.Data(),
81  TString(((TObjString*)token->At(token->GetEntries()-1))->GetString()).ReplaceAll(".root",".C").Data());
82 
83  ofstream out;
84  out.open(configFile,ios::out);
85  if (!out.good()) {cout << "Error Opening File : " << configFile << endl;exit(1);}
86  out << config.Data();
87  out.close();
88 
89  if(cwb_dump_hist_mode=="view") {
90  char cmd[1024];
91  sprintf(cmd,"vim %s",configFile);
92  cout << cmd << endl;
93  gSystem->Exec(cmd);
94  sprintf(cmd,"rm %s",configFile);
95  cout << cmd << endl;
96  gSystem->Exec(cmd);
97  } else {
98  cout << "Write : " << configFile << endl;
99  }
100 
101  } else {
102  cout << endl << "Config MD5 : " << config_md5.Data() << endl << endl;
103  }
104 
105  exit(0);
106 }
exit(0)
TString("c")
ofstream out
Definition: cwb_merge.C:214
char odir[1024]
CWB::Toolbox TB
int j
Definition: cwb_net.C:28
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
static TString GetStageString(CWB_STAGE jstage)
Definition: cwb.cc:2206
TString label
Definition: MergeTrees.C:21
TString config_md5
bool log
Definition: WaveMDC.C:41
TList * GetStageNames()
Definition: History.cc:427
TString cwb_dump_hist_mode
int nStages
static int GetStageSize()
Definition: cwb.hh:162
TObjArray * token
TFile * ifile
condor_log_dir ReplaceAll("X_HOME", uhome.Data())
TString cwb_dump_hist_file_name
char configFile[1024]
Definition: cwb_merge.C:213
char dump_dir[512]
Definition: test_config1.C:156
char cmd[1024]
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
char * GetHistory(char *StageName, char *Type)
Definition: History.cc:273
TString config
CWB::History * ihistory
CWB_STAGE
Definition: cwb.hh:122