#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //Declaration of all functions Int_t HandleInputPar(Int_t argc, char **argv, TMap* optmap); Bool_t IsOption(TList* optlist, TString word); // command line parser void PrintOptions(TMap* optmap); //Making TH2D with LT profiles TH2D* MakeLTmaskHisto(TObject* path_to_rig, Int_t nmasks, TimeVec* tm_vec, Int_t bun); //Make TimeVector from textfile TimeVec * MakeTimeVec( TObject* path_to_textfile); Int_t FindMaskIDinList(TList *lmsk, VKmask* msk); //general loop. Returns List of lists to store in root-files TList * DoMasksProfile( TObject* inp_path_o, TObject* inp_pattern, TObject* path_to_rig, TimeVec* tm_vec, Double_t cut_f, Double_t b_min, Double_t b_max ); void SaveResult( TObject* out_path_o, TList* out_list); Int_t main(Int_t argc, char **argv){ // Arguments are following: // // --inp_dir /// input directory with root files // --rigbin_file /// file with left edges of rigidity bins // --cutof_factor /// factor to cut in SVL. Typycal value is 1.3 // --babs_min /// minimum value of magnetic field. 0.26 to exclude SAA // --babs_max /// maximum value of m.f. usually 1000000 to include everything // --bunch_file /// textfile with bunches with start-stop values //Default values Double_t cut_f = 1.3; Double_t babs_min = 0.26; Double_t babs_max = 10000000.; TMap* optmap = new TMap(); //map with options HandleInputPar(argc,argv, optmap); PrintOptions(optmap); TBenchmark* bench = new TBenchmark(); bench->Start("client"); //Making TimeVec TimeVec * tm_vec = MakeTimeVec( optmap->GetValue("--bunch_file") ); tm_vec->Print(); TList *lout = DoMasksProfile( optmap->GetValue("--inp_dir"), optmap->GetValue("--inp_pattern"), optmap->GetValue("--rigbin_file"), tm_vec, cut_f, babs_min, babs_max ); SaveResult( optmap->GetValue("--out_dir"), lout); // report a benchmark message to the server bench->Stop("client"); TString benchresult = " job"; benchresult.Remove(0, 1); benchresult += " finished ("; TDatime d; benchresult += d.AsSQLString(); benchresult += " | cpu time = "; benchresult += floor((Double_t) bench->GetCpuTime("client")); benchresult += " s = "; benchresult += floor(((Double_t)bench->GetCpuTime("client"))/((Double_t) bench->GetRealTime("client"))*100.); benchresult += " % real time)"; cout<Add(new TObjString(optname)); optname = "--inp_pattern"; // pattern of files to make chain allowed_opt->Add(new TObjString(optname)); optname="--out_dir"; //output path to store root-files allowed_opt->Add(new TObjString(optname)); optname = "--rigbin_file"; // full path to textfile with rigidity bins allowed_opt->Add(new TObjString(optname)); optname = "--cutoff_factor"; // factor for SVL. Typ. is 1.3 allowed_opt->Add(new TObjString(optname)); optname = "--babs_min"; // cut to remove SAA and polar regions. Typ 0.26 allowed_opt->Add(new TObjString(optname)); optname = "--babs_max"; // allowed_opt->Add(new TObjString(optname)); optname = "--bunch_file"; // file with start-stop abstime allowed_opt->Add(new TObjString(optname)); TString arg=""; if(argc>1){ if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){ return(1); }; for (Int_t i = 1; i < argc; i++){ if(IsOption(allowed_opt,argv[i])){ TObjString* option =(TObjString*)allowed_opt->FindObject(argv[i]); arg=""; i++; while((iFindObject(option->GetName())){ arg.ReplaceAll(" ",""); optmap->Add(new TObjString(*option), new TObjString(arg)); } else{ cout<<"! Error, you specified one option " <GetName()<<" 2 times"<FindObject(word)) return kFALSE; return kTRUE; } //Printing user options void PrintOptions(TMap* optmap){ cout<<"Application will be executed with next options: "<MakeIterator(); TObject *o; while( (o=(TObject *) n->Next())) { cout<<" option: "<GetName() <<" value: " <<((TObjString*)optmap->GetValue(o))->GetName()<GetName() ); const Int_t nrb = h_templ_r->GetNbinsX(); Double_t *r_bins = new Double_t[nrb+1]; for(Int_t k = 0; kGetBinLowEdge(k+1); delete h_templ_r; //mask bins Double_t *m_bins = new Double_t[nmasks+1]; for(Int_t k = 0; kGetStartStop( bun, start, stop ); title += Pa::PrintTime( start ); title += " To "; title += Pa::PrintTime( stop ); return new TH2D(name, title, nrb, r_bins, nmasks, m_bins); } TimeVec * MakeTimeVec( TObject* path_to_textfile){ if( !path_to_textfile ){ cout<<" No path to TimeVec textfile specified. Check --bunch_file option "<GetName(); ifstream bun_list; bun_list.open(path.Data()); if(!bun_list){ cout<<"! Error, Text file with start-stop abstime: "<>start_s; bun_list>>stop_s; if(start_s != ""){ v_out->Add( start_s.Atoll(), stop_s.Atoll()); } } return v_out; } TList * DoMasksProfile( TObject* inp_path_o, TObject* inp_pattern, TObject* path_to_rig, TimeVec* tm_vec, Double_t cut_f, Double_t b_min, Double_t b_max ){ if( !inp_path_o ){ cout<<"No input directory defined, check --inp_dir option"<GetName() ); //Here I'm making chain and define some variables Double_t babs, svlcutoff, ltime; UInt_t abstime; UInt_t mask[12]; TChain* ch = new TChain("mask_vk_tree"); ch->SetBranchAddress("abstime",&abstime); ch->SetBranchAddress("babs",&babs); ch->SetBranchAddress("ltime",<ime); ch->SetBranchAddress("svlcutoff",&svlcutoff); ch->SetBranchAddress("VKmask",&mask); //Adding files to chain TSystemDirectory* dir = new TSystemDirectory("dir", ((TObjString*)inp_path_o)->GetName()); TList* ldir = dir->GetListOfFiles(); TString pattern = ((TObjString*)inp_pattern)->GetName(); TRegexp re ( pattern, pattern.MaybeWildcard() ); for(int i=0; iGetEntries(); i++) { TSystemFile* sysf = (TSystemFile*) ldir->At(i); if(sysf->IsDirectory()) continue; TString nm = sysf->GetName(); TString path = sysf->GetTitle(); TString s = nm; if ((nm!=pattern) && s.Index(re) == kNPOS) continue; path += sysf->GetName(); cout<AddFile( path ); } delete ldir; delete dir; ch->Add( ((TObjString*)inp_path_o)->GetName() ); cout<<"entries: "<GetEntries()<GetSize(); bun++){ //fi TList *lbun = new TList(); //first list is list to be saved: TH2D + List of masks lbun->Add(new TList() ); //second list is aux list, not to be saved. Here I'll put TH1Ds for specific mask as function of rigidity cutoff lbun->Add(new TList() ); lout->Add( lbun ); } VKmask *probe_mask = new VKmask(); for(UInt_t ev = 0; ev < ch->GetEntries(); ev++){ ch->GetEntry(ev); if(ev%1000000==0) cout<GetIntervalId( abstime ); if (nb < 0 ) continue; if ( ( babs < b_min) || ( babs > b_max) ) continue; //Filling up current mask for(Int_t j =0; j<12; j++) probe_mask->SetMaskRow(j, mask[j]); //Compare with already stored masks TList *lb = (TList*)lout->At( nb ); TList *lb_msk =(TList*)lb->At(0); TList *lb_hst =(TList*)lb->At(1); Int_t id = FindMaskIDinList( lb_msk, probe_mask); //if nothing found... if(id < 0 ){ cout<<"-->A new mask... for interval:"<SetMaskRow( j, probe_mask->GetMaskRow(j) ); lb_msk->Add( nm ); Int_t msk_count = lb_msk->GetEntries(); TString nm_prof = "bunch_"; nm_prof += nb; nm_prof += "_mask_"; nm_prof += msk_count; TH1D* lt_prof = (TH1D*)lt_templ->Clone( nm_prof ); Int_t r_b = lt_templ->FindBin( svlcutoff * cut_f ); for(Int_t i = r_b + 1; iGetNbinsX()+1; i++) lt_prof->AddBinContent( i, ltime ); lb_hst->Add( lt_prof ); cout<<"<--A new mask..."<At( id ); Int_t r_b = lt_templ->FindBin( svlcutoff * cut_f ); for(Int_t i = r_b + 1; iGetNbinsX()+1; i++) lt_prof->AddBinContent( i, ltime ); } } //After everything we will create TH2D profiles for each bunch //TH2D will be added to 1st list (where we have masks) as last object for(Int_t bun = 0; bunGetSize(); bun++){ TList *lb = (TList*)lout->At(bun); TList *lb_msk =(TList*)lb->At(0); TList *lb_hst =(TList*)lb->At(1); const Int_t nmasks = lb_hst->GetEntries(); cout<<"Number of mask for bunch "<At(msk); for(Int_t r_b = 0; r_bGetNbinsX()+1; r_b ++ ) h2_mask_prof->SetBinContent( r_b+1, msk+1, h_prof->GetBinContent(r_b+1)); } lb_msk->Add( h2_mask_prof ); } return lout; } Int_t FindMaskIDinList(TList *lmsk, VKmask* msk){ for(Int_t j = 0; jGetEntries(); j++){ VKmask *tms = (VKmask*)lmsk->At(j); if (*tms==*msk) return j; } return -1; } void SaveResult( TObject* out_path_o, TList* out_list){ if( !out_path_o ){ cout<<"No input directory defined, check --out_dir option"<GetName(); for(Int_t bun = 0; bun < out_list->GetEntries(); bun++){ TString file = path; file += "/out_bun_"; file += bun; file += ".root"; TList *lb = (TList*)out_list->At(bun); TList *lb_msk =(TList*)lb->At(0); TFile *fout = new TFile (file, "recreate" ); lb_msk->Write("masks", TObject::kSingleKey); fout->Close(); } }