GTS/TFndGtsMon.cxx

00001 // @(#)fROOT/GTS:$Name:  $:$Id: TFndGtsMon.cxx,v 1.32 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Revision Author: Diego Faso <mailto:faso@to.infn.it>, 2005/06/24
00003 // Original Author: P. Cerello <mailto:cerello@to.infn.it>, 2001
00004 
00006 //                                          //
00007 //               TFndGtsMon                 //
00008 //                                          //
00009 //  Consumer histograms and shared memories //          
00010 //  Don't create objects of this class if   //
00011 //  you use the TFndGtsMonFrame class,      //
00012 //  otherwise you would open twice the file //
00013 //                                          //
00015 
00016 #include <Riostream.h>
00017 #include <TROOT.h>
00018 #include <TSystem.h>
00019 #include <TDirectory.h>
00020 //#include <TObjArray.h>
00021 
00022 //#include "FROOT.h"
00023 #include "TFndRun.h"
00024 #include "TFndGtsMon.h"
00025 
00026 #include "TFndGtsMon.h"
00027 
00028 ClassImp(TFndGtsMon)
00029 
00030   // TClonesArray *TFndGtsMon::fgHisNam = 0;
00031 
00032 //___________________________________________
00033 TFndGtsMon::TFndGtsMon(const TString &fmode):
00034   shmflg(),fout(),fgts(),fGtsMapFile(),
00035   fHMaluPattern(),fHMaluMult(),fHPU_cont(),fHPU_mult(),fHTrigSel(),
00036   fHTofinoLow_MT_Patt(),fHTofinoHigh_MT_Patt(),fHTofinoLow_MT_Mult(),fHTofinoHigh_MT_Mult(),
00037   fHTofone_MT_Patt(),fHTofone_MT_Mult(),
00038   fMustRecoverHistos(kFALSE),fSharedMemName(),fSharedFileName()
00039 {
00040   // this the constructor for histogram producer:
00041   // All histograms are created here, since they must
00042   // be stored inside the TMapFile pointed by the fGtsMapFile data member
00043   
00044   Init();
00045   OpenSharedFiles(fmode);
00046   InitHistos();
00047 }
00048 
00049 //___________________________________________
00050 TFndGtsMon::TFndGtsMon():
00051   shmflg(),fout(),fgts(),fGtsMapFile(),
00052   fHMaluPattern(),fHMaluMult(),fHPU_cont(),fHPU_mult(),fHTrigSel(),
00053   fHTofinoLow_MT_Patt(),fHTofinoHigh_MT_Patt(),fHTofinoLow_MT_Mult(),fHTofinoHigh_MT_Mult(),
00054   fHTofone_MT_Patt(),fHTofone_MT_Mult(),
00055   fMustRecoverHistos(kFALSE),fSharedMemName(),fSharedFileName()
00056 {
00057   // This constructor was used by the consumer,
00058   // but now there is no need to open the shared memory
00059   // in read/update mode here... commented all (Diego - 03/03/2005)
00060 
00061   Init();
00062   
00063 }
00064 
00065 //___________________________________________
00066 TFndGtsMon::TFndGtsMon(TString *filename):
00067   shmflg(),fout(),fgts(),fGtsMapFile(),
00068   fHMaluPattern(),fHMaluMult(),fHPU_cont(),fHPU_mult(),fHTrigSel(),
00069   fHTofinoLow_MT_Patt(),fHTofinoHigh_MT_Patt(),fHTofinoLow_MT_Mult(),fHTofinoHigh_MT_Mult(),
00070   fHTofone_MT_Patt(),fHTofone_MT_Mult(),
00071   fMustRecoverHistos(kFALSE),fSharedMemName(),fSharedFileName()
00072 {
00073   // Start Monitor in read-mode (from a produced ".root" file)
00074   // You need to use this constructor only if you want to use
00075   // saved histograms without using thr standard froot GUI.
00076   // Don't call this constructor if you use the TFndGtsMonFrame class,
00077   // otherwise you would open twice the file
00078 
00079   Init();  
00080   fgts = new TFile(filename->Data());
00081 
00082 }
00083 
00084 //___________________________________________
00085 TFndGtsMon::~TFndGtsMon() {
00086 
00087   //   fHistoNames->Delete();
00088   //   delete fgHisNam; fgHisNam = 0;
00089   
00090   delete fHMaluPattern;
00091   delete fHMaluMult;
00092   for(Int_t i=0;i < K_N_GTS_P_UNITS ; i++){
00093     delete fHPU_cont[i];
00094     delete fHPU_mult[i];
00095   }
00096   for(Int_t i=0;i < K_N_GTS_SELECTORS ; i++) delete fHTrigSel[i];
00097   
00098   if(fgts) fgts->Close();
00099   delete fgts;
00100   
00101   if(fout) fout->Close(); 
00102   delete fout;
00103   
00104   if(fGtsMapFile){ fGtsMapFile->Close(); fGtsMapFile = 0; }
00105   else delete fGtsMapFile;
00106 }
00107 
00108 //___________________________________________
00109 void TFndGtsMon::Init(){
00110   
00111   fSharedMemName = FROOT::ExpandPathName("$FND_SHR/gts.map");
00112   fSharedFileName = FROOT::ExpandPathName("./gts.file.map");
00113 }
00114 
00115 //___________________________________________
00116 void TFndGtsMon::OpenSharedFiles(const TString &fmode){
00117   
00118   TString fhist = "_gts.root";
00119   
00120   shmflg = fndrun->Onlflg();
00121   cout << "Gts Shm flag is " << shmflg << endl;
00122   
00123   TString gtsnam_str = (fmode.IsNull()) ? "ONLM": fmode;
00124   gtsnam_str+=fhist;
00125   
00127   fgts = new TFile(gtsnam_str.Data(),"RECREATE","Gts Histogram File");   
00128   if(shmflg) {
00129 #if defined _FND_ONL_USE_MAP_FILES_
00130     fGtsMapFile = TMapFile::Create(fSharedMemName,"RECREATE",(Int_t)(1048576*FROOT::K_GtsMapSize),"Gts memory mapped file with histograms");
00131     fGtsMapFile->Print();    
00132 #elif defined _FND_ONL_USE_SHARED_FILES_
00133     if(gSystem->AccessPathName(fSharedFileName)){
00134       cout << "Shared file missing: creating it now..." << endl;
00135       fGtsMapFile = new TFile(fSharedFileName,"RECREATE");
00136     }
00137     else{
00138       cout << "Shared file found: histograms will be recovered..." << endl;
00139       fGtsMapFile = TFile::Open(fSharedFileName,"UPDATE");
00140       fMustRecoverHistos = kTRUE;
00141       //fGtsMapFile->ls();
00142     }  
00143 #endif
00144   }
00145   
00146 }
00147 
00148 //___________________________________________
00149 void TFndGtsMon::InitHistos(){
00150   
00151   if(shmflg && !fGtsMapFile){
00152     Warning("InitHistos","fGtsMapFile not available: exiting method");
00153     return;
00154   }
00155   TString hname;
00156   TString htitle;
00157 
00158   if(shmflg) fGtsMapFile->cd();
00159   
00160   hname = "GtsHist_MaluPattern";
00161   htitle = "Malu TOF Pattern";
00162   fHMaluPattern = (fMustRecoverHistos) ?
00163     ((TH1F*) (fGtsMapFile->Get(hname))) :
00164     new TH1F(hname,htitle,72,0.5,72.5);
00165   
00166   hname = "GtsHist_MaluMultiplicity";
00167   htitle = "Malu TOF Multiplicity";
00168   fHMaluMult = (fMustRecoverHistos) ?
00169     ((TH1F*) (fGtsMapFile->Get(hname))) :
00170     new TH1F(hname,htitle,72,0.5,72.5);
00171   
00172   for(Int_t i=0;i < K_N_GTS_P_UNITS ; i++){
00173     hname.Form("GtsHist_PU_cont_%d",i+1);
00174     htitle.Form("Pattern Unit %d (bits content)",i+1);
00175     fHPU_cont[i] = (fMustRecoverHistos) ? 
00176       ((TH1F*) (fGtsMapFile->Get(hname))) :
00177       new TH1F(hname,htitle,18,-0.5,17.5);
00178     
00179     hname.Form("GtsHist_PU_mult_%d",i+1);
00180     htitle.Form("Pattern Unit %d (multiplicity)",i+1);
00181     fHPU_mult[i] =  (fMustRecoverHistos) ?
00182       ((TH1F*) (fGtsMapFile->Get(hname))) :
00183       new TH1F(hname,htitle,16,-0.5,15.5);
00184   }
00185   
00186   for(Int_t i=0;i < K_N_GTS_SELECTORS ; i++){
00187     hname.Form("GtsHist_TrigSel_%d",i+1);
00188     htitle.Form("Trigger Selector %d",i+1);
00189     fHTrigSel[i] = (fMustRecoverHistos) ? 
00190       ((TH1F*) (fGtsMapFile->Get(hname))) :
00191       new TH1F(hname,htitle,16,-0.5,15.5);
00192   }
00193   //--- 
00194   // histograms from TOF
00195 
00196   hname  = "GtsHist_TofinoLow_MT_Patt";
00197   htitle = "TOFINO Mean-timer patt (low th)";
00198   fHTofinoLow_MT_Patt = (fMustRecoverHistos) ? 
00199       ((TH1F*) (fGtsMapFile->Get(hname))) :
00200        new TH1F(hname,htitle,14,-0.5,13.5);
00201 
00202   hname  = "GtsHist_TofinoHigh_MT_Patt";
00203   htitle = "TOFINO Mean-timer patt (high th)";
00204   fHTofinoHigh_MT_Patt = (fMustRecoverHistos) ? 
00205       ((TH1F*) (fGtsMapFile->Get(hname))) :
00206         new TH1F(hname,htitle,14,-0.5,13.5);
00207 
00208   hname  = "GtsHist_TofinoLow_MT_Mult";
00209   htitle = "TOFINO Mean-timer mult (low th)";
00210   fHTofinoLow_MT_Mult = (fMustRecoverHistos) ? 
00211       ((TH1F*) (fGtsMapFile->Get(hname))) :
00212          new TH1F(hname,htitle,13,-0.5,12.5);
00213 
00214   hname  = "GtsHist_TofinoHigh_MT_Mult";
00215   htitle = "TOFINO Mean-timer mult (high th)";
00216   fHTofinoHigh_MT_Mult = (fMustRecoverHistos) ? 
00217       ((TH1F*) (fGtsMapFile->Get(hname))) :
00218          new TH1F(hname,htitle,13,-0.5,12.5);
00219 
00220   hname  = "GtsHist_Tofone_MT_Patt";
00221   htitle = "TOFONE Mean-timer patt";
00222   fHTofone_MT_Patt = (fMustRecoverHistos) ? 
00223       ((TH1F*) (fGtsMapFile->Get(hname))) :
00224          new TH1F(hname,htitle,74,-0.5,73.5);
00225 
00226   hname  = "GtsHist_Tofone_MT_Mult";
00227   htitle = "TOFONE Mean-timer mult";
00228   fHTofone_MT_Mult = (fMustRecoverHistos) ? 
00229       ((TH1F*) (fGtsMapFile->Get(hname))) :
00230          new TH1F(hname,htitle,73,-0.5,72.5);
00231   
00232   //--- 
00233 
00234 }
00235 
00236 //___________________________________________
00237 void TFndGtsMon::Fill() {
00238   
00239   TFndTrig *fTrig = fndrun->GetCurrentHdt()->GetGts();
00240   if(fTrig) Fill(fTrig);
00241 
00242   TClonesArray *cl = fndrun->GetCurrentHdt()->GetTofHits();
00243   if(cl) Fill(*cl);
00244 
00245 }
00246 
00247 //___________________________________________
00248 void TFndGtsMon::Fill(TFndTrig *fTrig) {
00249   
00250   Int_t malu_mult = 0;
00251   Int_t x_id = 0;
00252   for(Int_t mnum=0;mnum<K_N_GTS_MALU;mnum++){
00253     if(x_id > 72) break;
00254     for(Int_t bit=0;bit<32;bit++){
00255       x_id = 1 + mnum*32+bit; // slabs numbering starts from 1
00256       if(x_id > 72) break;
00257       Short_t content = fTrig->GetMalu_bit(mnum,bit);
00258       if(content > 0) malu_mult++;
00259       fHMaluPattern->Fill(x_id,content);
00260     }
00261   }
00262   fHMaluMult->Fill(malu_mult);
00263   
00264   Int_t pu_mult[K_N_GTS_P_UNITS] = {0};
00265   for(Int_t i=0;i < K_N_GTS_P_UNITS ; i++){
00266     for(Int_t bit=0;bit<16;bit++){
00267       Short_t content = fTrig->GetPU_cont_bit(i,bit);
00268       fHPU_cont[i]->Fill(bit+1,content);
00269       if(content > 0) pu_mult[i]++;
00270     }
00271     //      fHPU_mult[i]->Fill(fTrig->GetPU_mult(i));
00272     fHPU_mult[i]->Fill(pu_mult[i]);
00273   }
00274   // ---
00275   for(Int_t i=0;i < K_N_GTS_SELECTORS ; i++){
00276     //    for(Int_t bit=0;bit<16;bit++) fHTrigSel[i]->Fill(bit,fTrig->GetTriggerSelector_bit(i,bit));
00277     fHTrigSel[i]->Fill(fTrig->GetTriggerSelector(i)); // fill with the word content
00278   }  
00279 }
00280 
00281 //___________________________________________
00282 void TFndGtsMon::Fill(const TClonesArray &TofHits){
00283   // Fill Monitor histograms (from TOF hits)
00284   
00285   Int_t sladiv = 12;
00286   Int_t nhtof = TofHits.GetEntries();
00287   
00288   Int_t MT_MulLowFino = 0;
00289   Int_t MT_MulHighFino = 0;
00290 
00291   Int_t MT_MulFone = 0;
00292 
00293   for (Int_t j=0; j<nhtof; j++) {
00294     if(nhtof>84) cout << "TFndGtsMon WARNING: TOF number of hits= " << nhtof << " (greater than 84)!!!" << endl;
00295     TFndHTof *htof = (TFndHTof*) TofHits[j];
00296     Float_t slb = htof->GetChannel();
00297     if(slb==0){
00298       Warning("TFndTofMon","slab out of range...skipping hit");
00299       continue;
00300     }
00301     // --- filling from TOF  
00302     if(slb <= K_N_TOFINO_SLABS){ // tofino MT
00303       if(htof->GetLowMeanTimer() > 0){
00304         fHTofinoLow_MT_Patt->Fill(slb);
00305         MT_MulLowFino++;
00306       }
00307       if(htof->GetHighMeanTimer() > 0){
00308         fHTofinoHigh_MT_Patt->Fill(slb);
00309         MT_MulHighFino++;
00310       }
00311       
00312     }
00313     else if(slb >100 && slb <= 100 + K_N_TOFONE_SLABS){ // tofone MT
00314       if(htof->GetLowMeanTimer() > 0){
00315         MT_MulFone++;
00316         fHTofone_MT_Patt->Fill(slb-100);
00317       }
00318     }
00319     
00320     //
00321   }// tof hits loop completed
00322   fHTofinoLow_MT_Mult->Fill(MT_MulLowFino);
00323   fHTofinoHigh_MT_Mult->Fill(MT_MulHighFino);
00324   fHTofone_MT_Mult->Fill(MT_MulFone);
00325 }
00326 
00327 //___________________________________________
00328 void TFndGtsMon::Update(Bool_t purge) {
00329   // Method used by the producer to update
00330   // the shared memories content (not needed by the consumer)
00331   
00332   //  fGtsMapFile->Print();
00333 #if defined _FND_ONL_USE_MAP_FILES_
00334   if(fGtsMapFile && fGtsMapFile->IsWritable() ) fGtsMapFile->Update();
00335 #elif defined _FND_ONL_USE_SHARED_FILES_
00336   WriteToFile(0,kTRUE);
00337   fGtsMapFile->cd();
00338   if(purge) fGtsMapFile->Purge();
00339   fGtsMapFile->Flush();
00340   TString comm_cp = "";
00341   comm_cp.Form("cp ./gts.file.map %s",FROOT::ExpandPathName("$FND_SHR/gts.file.map").Data());
00342   gSystem->Exec(comm_cp);
00343 
00344 #endif
00345 
00346   Info("Update","GTS histograms updated (producer)");
00347 
00348 }
00349 
00350 //___________________________________________
00351 void TFndGtsMon::ResetHistos(){
00352   
00353   if(fHMaluPattern) fHMaluPattern->Reset();
00354   if(fHMaluMult) fHMaluMult->Reset();
00355   for(Int_t i=0;i < K_N_GTS_P_UNITS ; i++){
00356     if(fHPU_cont[i]) fHPU_cont[i]->Reset();
00357     if(fHPU_mult[i]) fHPU_mult[i]->Reset();
00358   }
00359   for(Int_t i=0;i < K_N_GTS_SELECTORS ; i++) if(fHTrigSel[i]) fHTrigSel[i]->Reset();
00360 
00361   fHTofinoLow_MT_Patt->Reset();
00362   fHTofinoHigh_MT_Patt->Reset();
00363   fHTofinoLow_MT_Mult->Reset();
00364   fHTofinoHigh_MT_Mult->Reset();
00365 
00366   fHTofone_MT_Patt->Reset();
00367   fHTofone_MT_Mult->Reset();
00368 }
00369 
00370 //___________________________________________
00371 void TFndGtsMon::WriteToFile(TString filename,Bool_t IsShared) {
00372   // IsShared is used to provide support for shared files instead of shared memories
00373   if(IsShared){
00374     //    Info("TFndGtsMon::WriteToFile","Writing histograms in on-line mode");
00375     fGtsMapFile->cd();
00376   }
00377   else{
00378     if(filename.IsNull()) 
00379       fgts->cd();
00380     else {
00381       fout = new TFile(filename.Data(),"RECREATE","Gts Histogram File");
00382       fout->cd();
00383     }  
00384   }
00385 
00386   if(fHMaluPattern) fHMaluPattern->Write();
00387   if(fHMaluMult) fHMaluMult->Write();
00388   for(Int_t i=0;i < K_N_GTS_P_UNITS ; i++){
00389     if(fHPU_cont[i]) fHPU_cont[i]->Write();
00390     if(fHPU_mult[i]) fHPU_mult[i]->Write();
00391   }
00392   for(Int_t i=0;i < K_N_GTS_SELECTORS ; i++) if(fHTrigSel[i]) fHTrigSel[i]->Write();
00393 
00394   fHTofinoLow_MT_Patt->Write();
00395   fHTofinoHigh_MT_Patt->Write();
00396   fHTofinoLow_MT_Mult->Write();
00397   fHTofinoHigh_MT_Mult->Write();
00398 
00399   fHTofone_MT_Patt->Write();
00400   fHTofone_MT_Mult->Write();
00401   
00402 }
00403 
00404 //___________________________________________
00405 void TFndGtsMon::Add(TFndGtsMon *gtsmon) {
00406   // If the object has been created in read-mode (TString ctor)
00407   // you can use this method to sum histograms of different files
00408 
00409   cout << "adding new gtsmon" << endl;
00410 
00411 }

Generated on Tue Oct 16 15:40:46 2007 by  doxygen 1.5.2