Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_fix_live_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  if(!net_slag) {cout << "File " << net_file_name << " not contains slag leaf, apply cwb_fix_slag_missed.C " << endl;exit(1);}
50 
51  // open live tree
52  TFile *flive = TFile::Open(liv_file_name);
53  if(flive==NULL) {cout << "Error opening file " << liv_file_name << endl;exit(1);}
54  TTree* tlive = (TTree *) gROOT->FindObject("liveTime");
55  if(tlive==NULL) {cout << "Error opening tree livetime" << endl;exit(1);}
56 
57  // check if slag is presents in live tree
58  TBranch* branch;
59  bool liv_slag=false;
60  TIter next(tlive->GetListOfBranches());
61  while ((branch=(TBranch*)next())) {
62  if (TString("slag").CompareTo(branch->GetName())==0) liv_slag=true;
63  }
64  next.Reset();
65 
66  bool fixit=false;
67  char answer[256];
68  strcpy(answer,"");
69  do {
70  if (!liv_slag) {
71  cout << "File " << liv_file_name << " do not contains slag leaf" << endl;
72  cout << "Do you want to fix it ? (y/n) ";
73  } else {
74  cout << "File " << liv_file_name << " already contains slag leaf" << endl;
75  cout << "Do you want to fix it anyway ? (y/n) ";
76  }
77  cin >> answer;
78  cout << endl << endl;
79  } while ((strcmp(answer,"y")!=0)&&(strcmp(answer,"n")!=0));
80  if (strcmp(answer,"y")==0) fixit=true;
81  if(!fixit) exit(0);
82 
83  vector<waveSegment> cat1List=TB.readSegList(nDQF, DQF, CWB_CAT1);
84  int slagSegs=TB.getSlagJobList(cat1List, segLen).size();
85  vector<slag> slagList=TB.getSlagList(nIFO, slagSize, slagSegs, slagOff, slagMin, slagMax, slagSite);
86 
87  int nIFO = slagList[0].segId.size();
88 
89  int* ind = new int[slagList.size()+1];
90  for(int j=0; j<slagList.size(); j++) {
91 // slagList[j].jobId; // jobID
92 // slagList[j].slagId[0]; // slagID
93 // slagList[j].segId[0]; // segID
94  ind[slagList[j].jobId] = j;
95 //cout << j << " " << slagList[j].jobId << " " << slagList[j].slagId[0] << endl;
96  }
97 
98  // -------------------------------------------------------------------------
99  // create slag fix live root file
100  // -------------------------------------------------------------------------
101 
102  TString fix_liv_file_name(liv_file_name);
103  fix_liv_file_name.ReplaceAll(".root",".FIX.root");
104  cout << "Fixed live file : " << fix_liv_file_name.Data() << endl;
105 
106  TFile* flive_fix = new TFile(fix_liv_file_name,"RECREATE");
107  if (flive_fix->IsZombie()) {
108  cout << "CWB::Toolbox::setVeto - Error opening file " << fix_liv_file_name.Data() << endl;
109  exit(1);
110  }
111  TTree *tlive_fix = (TTree*)tlive->CloneTree(0);
112  tlive_fix->SetMaxTreeSize(5000000000);
113  // add slag leaf
114  float xslag[6];
115  if (!liv_slag) {
116  tlive_fix->Branch("slag",xslag,"slag[6]/F");
117  tlive_fix->Write();
118  } else {
119  tlive_fix->SetBranchAddress("slag",xslag);
120  }
121 
122  Int_t xrun;
123  tlive->SetBranchAddress("run",&xrun);
124  int ntrg = tlive->GetEntries();
125  for(int i=0; i<ntrg; i++) {
126  if(i%100000==0) cout << i << "/" << ntrg << endl;
127  tlive->GetEntry(i);
128  int j = ind[xrun];
129  for (int n=0;n<nIFO;n++) xslag[n] = segLen*(slagList[j].segId[n]-slagList[j].segId[0]);
130  xslag[nIFO] = slagList[j].slagId[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  delete [] ind;
139 
140  // -------------------------------------------------------------------------
141  // create link slag fix wave root file
142  // -------------------------------------------------------------------------
143 
144  char cmd[256];
145  TString fix_net_file_name(net_file_name);
146  fix_net_file_name.ReplaceAll(".root",".FIX.root");
147  cout << "Fixed wave file : " << fix_net_file_name.Data() << endl;
148  sprintf(cmd,"cp --remove-destination %s %s",net_file_name,fix_net_file_name.Data());
149  //sprintf(cmd,"ln -sf %s %s",net_file_name,fix_net_file_name.Data());
150  cout << cmd << endl;
151  gSystem->Exec(cmd);
152 
153  exit(0);
154 }
TString fix_net_file_name(net_file_name)
int slagSize
Definition: test_config1.C:65
size_t * slagSite
Definition: test_config1.C:69
int slagOff
Definition: test_config1.C:68
sprintf(liv_file_name,"%s/live_%s.%s.root", merge_dir, data_label, cwb_merge_label.Data())
int n
Definition: cwb_net.C:10
TString("c")
float xslag[6]
int slagMax
Definition: test_config1.C:67
TString fix_liv_file_name(liv_file_name)
bool liv_slag
TFile * flive
int j
Definition: cwb_net.C:10
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
CWB::Toolbox TB
Definition: ComputeSNR.C:5
char cmd[256]
nDQF
Definition: cwb_eced.C:92
char data_label[512]
Definition: test_config1.C:160
dqfile DQF[12]
Definition: test_config1.C:171
exit(0)
bool net_slag
static vector< waveSegment > getSlagJobList(vector< waveSegment > ilist, int seglen=600)
Definition: Toolbox.cc:1771
TIter next(twave->GetListOfBranches())
segLen
Definition: cwb_eced.C:7
char merge_dir[512]
Definition: test_config1.C:147
vector< slag > slagList
cout<< endl<< endl;}while((strcmp(answer,"y")!=0)&&(strcmp(answer,"n")!=0));if(strcmp(answer,"y")==0) fixit=true;if(!fixit) exit(0);vector< waveSegment > cat1List
char net_file_name[256]
char liv_file_name[256]
static vector< slag > getSlagList(size_t nIFO, size_t slagSize, int slagSegs, int slagOff, size_t slagMin, size_t slagMax, size_t *slagSite, char *slagFile=NULL)
Definition: Toolbox.cc:790
static vector< waveSegment > readSegList(dqfile DQF)
Definition: Toolbox.cc:391
char answer[256]
TTree * tlive
TBranch * branch
TString cwb_merge_label
int slagMin
Definition: test_config1.C:66
simulation
Definition: cwb_eced.C:9
strcpy(answer,"")