Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_fix_slag_missed.C
Go to the documentation of this file.
1 {
2  // this fix must be used if live tree has been produced without slag leaf
3 
4  #include <vector>
5 
7 
8  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
9  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
10  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
11 
13  if(gSystem->Getenv("CWB_MERGE_LABEL")==NULL) {
14  cout << "Error : environment CWB_MERGE_LABEL is not defined!!!" << endl;exit(1);
15  } else {
16  cwb_merge_label=TString(gSystem->Getenv("CWB_MERGE_LABEL"));
17  }
18 
19  char net_file_name[256];
20  char liv_file_name[256];
21 
22  if(simulation) {
23  cout << "Error : cwb_fix_slag_missed.C must be applied only to production files !!!" << endl;exit(1);
24  } else {
25  sprintf(net_file_name,"%s/wave_%s.%s.root",merge_dir,data_label,cwb_merge_label.Data());
26  sprintf(liv_file_name,"%s/live_%s.%s.root",merge_dir,data_label,cwb_merge_label.Data());
27  cout << net_file_name << endl;
28  cout << liv_file_name << endl;
29 
30  // Check if files exist
31  TB.checkFile(net_file_name);
32  TB.checkFile(liv_file_name);
33  }
34 
35  // open wave tree
36  TFile *fwave = TFile::Open(net_file_name);
37  if(fwave==NULL) {cout << "Error opening file " << net_file_name << endl;exit(1);}
38  TTree* twave = (TTree *) gROOT->FindObject("waveburst");
39  if(twave==NULL) {cout << "Error opening tree wave" << endl;exit(1);}
40 
41  // check if slag is presents in wave tree
42  TBranch* branch;
43  bool net_slag=false;
44  TIter next(twave->GetListOfBranches());
45  while ((branch=(TBranch*)next())) {
46  if (TString("slag").CompareTo(branch->GetName())==0) net_slag=true;
47  }
48  next.Reset();
49 
50  // open live tree
51  TFile *flive = TFile::Open(liv_file_name);
52  if(flive==NULL) {cout << "Error opening file " << liv_file_name << endl;exit(1);}
53  TTree* tlive = (TTree *) gROOT->FindObject("liveTime");
54  if(tlive==NULL) {cout << "Error opening tree livetime" << endl;exit(1);}
55 
56  // check if slag is presents in live tree
57  TBranch* branch;
58  bool liv_slag=false;
59  TIter next(tlive->GetListOfBranches());
60  while ((branch=(TBranch*)next())) {
61  if (TString("slag").CompareTo(branch->GetName())==0) liv_slag=true;
62  }
63  next.Reset();
64  if(liv_slag&&net_slag) {
65  cout << "Files " << endl;
66  cout << liv_file_name << endl;
67  cout << net_file_name << endl;
68  cout << "already contains slag leaf, exit" << endl;
69  exit(1);
70  }
71 
72  if(!liv_slag&&net_slag) {
73  cout << "File " << net_file_name << " aleady contains slag leaf" << endl;
74  cout << "only " << liv_file_name << " needs to be fixed" << endl;
75  cout << "apply cwb_fix_live_slag_missed.C " << endl;
76  exit(1);
77  }
78 
79  if(liv_slag&&!net_slag) {
80  cout << "File " << liv_file_name << " aleady contains slag leaf" << endl;
81  cout << "only " << net_file_name << " needs to be fixed" << endl;
82  cout << "something wrong during production, please check" << endl;
83  exit(1);
84  }
85 
86  // insert slag=0 in wave and live trees
87  // tree has been produced without slag
88  bool fixit=false;
89  if (!liv_slag) {
90  char answer[256];
91  strcpy(answer,"");
92  do {
93  cout << "File " << net_file_name << " do not contains slag leaf" << endl;
94  cout << "File " << liv_file_name << " do not contains slag leaf" << endl;
95  cout << "Do you want to fix them ? (y/n) ";
96  cin >> answer;
97  cout << endl << endl;
98  } while ((strcmp(answer,"y")!=0)&&(strcmp(answer,"n")!=0));
99  if (strcmp(answer,"y")==0) fixit=true;
100  }
101  if(!fixit) exit(0);
102 
103  // -------------------------------------------------------------------------
104  // create slag fix live root file
105  // -------------------------------------------------------------------------
106 
107  TString fix_liv_file_name(liv_file_name);
108  fix_liv_file_name.ReplaceAll(".root",".FIX.root");
109  cout << "Fixed live file : " << fix_liv_file_name.Data() << endl;
110 
111  TFile* flive_fix = new TFile(fix_liv_file_name,"RECREATE");
112  if (flive_fix->IsZombie()) {
113  cout << "CWB::Toolbox::setVeto - Error opening file " << fix_liv_file_name.Data() << endl;
114  exit(1);
115  }
116  TTree *tlive_fix = (TTree*)tlive->CloneTree(0);
117  tlive_fix->SetMaxTreeSize(5000000000);
118  // add slag leaf
119  float xslag[6];
120  tlive_fix->Branch("slag",xslag,"slag[6]/F");
121  tlive_fix->Write();
122 
123  Int_t xrun;
124  tlive->SetBranchAddress("run",&xrun);
125  int ntrg_live = tlive->GetEntries();
126  for(int i=0; i<ntrg_live; i++) {
127  if(i%100000==0) cout << i << "/" << ntrg_live << endl;
128  tlive->GetEntry(i);
129  for (int n=0;n<nIFO;n++) xslag[n] = 0.;
130  xslag[nIFO] = 0.;
131  for (int n=nIFO+1;n<6;n++) xslag[n] = -1;
132  tlive_fix->Fill();
133  }
134 
135  tlive_fix->Write();
136  flive_fix->Close();
137 
138 
139  // -------------------------------------------------------------------------
140  // create slag fix wave root file
141  // -------------------------------------------------------------------------
142 
143  TString fix_net_file_name(net_file_name);
144  fix_net_file_name.ReplaceAll(".root",".FIX.root");
145  cout << "Fixed wave file : " << fix_net_file_name.Data() << endl;
146 
147  TFile* fwave_fix = new TFile(fix_net_file_name,"RECREATE");
148  if (fwave_fix->IsZombie()) {
149  cout << "CWB::Toolbox::setVeto - Error opening file " << fix_net_file_name.Data() << endl;
150  exit(1);
151  }
152  TTree *twave_fix = (TTree*)twave->CloneTree(0);
153  twave_fix->SetMaxTreeSize(5000000000);
154  // add slag leaf
155  float xslag[6];
156  twave_fix->Branch("slag",xslag,"slag[6]/F");
157  twave_fix->Write();
158 
159  int ntrg_wave = twave->GetEntries();
160  for(int i=0; i<ntrg_wave; i++) {
161  if(i%100000==0) cout << i << "/" << ntrg_wave << endl;
162  twave->GetEntry(i);
163  for (int n=0;n<nIFO;n++) xslag[n] = 0.;
164  xslag[nIFO] = 0.;
165  for (int n=nIFO+1;n<6;n++) xslag[n] = -1;
166  twave_fix->Fill();
167  }
168 
169  twave_fix->Write();
170  fwave_fix->Close();
171 
172  // -------------------------------------------------------------------------
173  // create a symbolic link to merge*.lst file name
174  // -------------------------------------------------------------------------
175  vector<int> jobList;
176  char ilstfname[1024];
177  sprintf(ilstfname,"merge_%s.%s.lst",data_label,cwb_merge_label.Data());
179  olstfname.ReplaceAll("wave_","merge_");
180  olstfname.ReplaceAll(".root",".lst");
181  olstfname.Remove(0,olstfname.Last('/')+1); // strip path
182  cout << olstfname << endl;
183  int estat;
184  Long_t id,size,flags,mt;
185  estat = gSystem->GetPathInfo(TString(merge_dir)+"/"+ilstfname,&id,&size,&flags,&mt);
186  if (estat==0) {
187  char cmd[1024];
188  sprintf(cmd,"cd %s;ln -sf %s %s",merge_dir,ilstfname,olstfname.Data());
189  cout << cmd << endl;
190  gSystem->Exec(cmd);
191  }
192 
193  exit(0);
194 }
char liv_file_name[256]
char cmd[1024]
sprintf(liv_file_name,"%s/live_%s.%s.root", merge_dir, data_label, cwb_merge_label.Data())
int n
Definition: cwb_net.C:10
Int_t xrun
TString("c")
TString fix_liv_file_name(liv_file_name)
Long_t flags
Long_t size
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
CWB::Toolbox TB
Definition: ComputeSNR.C:5
int ntrg_live
#define nIFO
char data_label[512]
Definition: test_config1.C:160
TIter next(twave->GetListOfBranches())
char net_file_name[256]
vector< int > jobList
TTree * tlive
bool liv_slag
exit(0)
bool net_slag
char merge_dir[512]
Definition: test_config1.C:147
TBranch * branch
bool fixit
char answer[256]
TString fix_net_file_name(net_file_name)
TFile * flive
int estat
strcpy(RunLabel, RUN_LABEL)
char ilstfname[1024]
Long_t mt
float xslag[6]
TString olstfname
Long_t id
TString cwb_merge_label
simulation
Definition: cwb_eced.C:9
int ntrg_wave