STEER/FROOT.h

00001 // @(#)fROOT/STEER:$Name:  $:$Id: FROOT.h,v 1.74 2007/10/16 12:03:43 Diego_Faso Exp $
00002 // Author: H. So, Diego Faso <mailto:faso@to.infn.it>, 2006/05/19
00003 
00004 #ifndef FROOT_FROOT
00005 #define FROOT_FROOT
00006 
00008 // Declarations
00010 
00011 #include <TString.h>
00012 #include <TApplication.h>
00013 #include <TThread.h>
00014 #include <TMath.h>
00015 #include <Riostream.h>
00016 
00017 // uncomment the following line in order to enable
00018 //  the automatic sub-directory handling of output files
00019 #define _FND_OUTPUTS_USE_SUBDIR
00020 
00021 // enable following symbol for TFndEvd
00022 // to look for tracks into pre-analysis trees
00023 #define FNDEVD_USE_PREAN
00024 
00025 //#define _FND_ONL_USE_MAP_FILES_ // no support for this option
00026 #define _FND_ONL_USE_SHARED_FILES_
00027 
00028 //#define _FND_USE_TOUCH_MAP_FILES // no support for this option
00029 //#define _FND_USE_HANDLE_CONSUMER_ACTIONS // testing purposes only
00030 
00032 //                                                                                 //
00033 //              RECONSTRUCTION METHOD CUSTOMIZATION (as "sel" in cmz)              //
00034 //                                                                                 //
00036 //                                                                                 //
00037 // Just comment/uncomment following lines according to the chosen                  //
00038 // reconstruction method.                                                          //
00039 //                                                                                 //
00040 // NOTE:                                                                           //
00041 //      You must have compiled the (linked) fidarc-libraries                       //
00042 //      according to the same customization you are setting here                   //
00043 //                                                                                 //
00044 
00045 #define FIDA_USE_SHORT // if defined ===> using short tracks (default from v_603 on)
00046 //#define FIDA_USE_KALMAN // if defined ===> using Kalman filter (default from v_603 on)
00047 
00048 //
00052 
00053 namespace FROOT {
00054 
00055 #if defined _FND_ONL_USE_MAP_FILES_ && defined _FND_ONL_USE_SHARED_FILES_
00056 # error "FROOT.h error: <_FND_ONL_USE_[...]_FILES_> is unbiguous!"
00057 #elif !defined _FND_ONL_USE_MAP_FILES_ && !defined _FND_ONL_USE_SHARED_FILES_
00058 # error "TFndGtsMon error: <_FND_ONL_USE_[...]_FILES_> undefined!"
00059 #endif
00060   
00061   // comment the required line to disable the
00062   //   raw-event decoding for a specific detector
00063   //   (see TFndRdt::RdtToHdt)
00064   // 
00065   // following selections shall be changed by expert users only:
00066 #define _FND_ENABLE_RAW_GTS
00067 #define _FND_ENABLE_RAW_TOF
00068 #define _FND_ENABLE_RAW_ISIM
00069 #define _FND_ENABLE_RAW_OSIM
00070 #define _FND_ENABLE_RAW_LMD
00071 #define _FND_ENABLE_RAW_STB
00072 
00073   TString GetFrootVersion();
00074   Float_t GetFrootVersionID();
00075 
00076   static const UInt_t Fee_Lmd_NewTdcsTime = 1045868400;  // Sat Feb, 2003; 22 00:00:00
00077   static const UInt_t DTak_2006_SftwStartTime = 1145138400; // Sun Apr 16, 2006;  00:00:00 (Start time for TOFDB2 database)
00078   static const UInt_t Fee_2006_NewSilDB_StartTime  = 1154383200; // Tue Aug 01,2006; 00:00:00 (Start time for TOFDB2 database)
00079   static const UInt_t DTak_2006_SftwStopTime = 1183500000; //  Wed July 4, 2007; 00:00:00
00081   // GENERAL description
00082   enum E_Fnd_Layer {
00083     E_FIN_INNER_LAYER = 1,
00084     E_FIN_OUTER_LAYER = 2
00085   }; // used for LMD/TOF/SIL (stb have their 6 layers [num:1-6])
00086   
00087   enum E_Fnd_Side {
00088     E_FIN_SIDE_E = 0,
00089     E_FIN_SIDE_P = 1
00090   };
00091   enum E_Fnd_Sil_Side {
00092     E_FIN_SIL_SIDE_PH = 0,
00093     E_FIN_SIL_SIDE_ZA = 1,
00094     E_FIN_SIL_SIDE_ZB = 2
00095   };
00096     
00097   TString SilSide_Name(Int_t id);
00098 
00099   static const Int_t K_N_TOFINO_SLABS =  12;
00100   static const Int_t K_N_TOFONE_SLABS =  72;
00101 
00102   static const Int_t K_N_LMD_LAYERS = 2;      // Number of LMD layers
00103   static const Int_t K_N_LMD_CHAMS_PER_LAYER = 8;        // Number of Drift Chambers / Layer
00104   static const Int_t K_N_LMD_INNER_WIRES = 12;      // Number of wires / chamber in the ineer layer
00105   static const Int_t K_N_LMD_OUTER_WIRES = 22;      // Number of wires / chamber in the outer layer
00106   static const Int_t K_N_LMD_TOT_CHAMS = 16;  // Total number of chambers 
00107 
00108   inline Int_t GetDataTakingFromTime(UInt_t runtime){
00109     if(runtime < DTak_2006_SftwStartTime) return 1;
00110     else if(runtime <= DTak_2006_SftwStopTime) return 2;
00111     else return 0;
00112   }
00113 
00114 
00115   inline Double_t TofinoZetaFromCharge(Int_t dtak,const Double_t &adcE,const Double_t &adcP)
00116     {
00117       if(! adcE || !adcP){
00118         cerr << "Error in FROOT::TofinoZetaFromCharge: NULL value received." << endl;
00119         return -1;
00120       }
00121       Double_t chdiv = adcE / adcP;
00122       Double_t logch = 0;
00123       switch(dtak){
00124       case 1:
00125         logch = TMath::Log(chdiv);
00126         //      cout << "RETURNING " << logch << endl;
00127         return (Double_t) (17.5 * logch);
00128       case 2:
00129         logch = TMath::Log( 0.136 * (chdiv + 0.1854) );
00130         //      return 1.181 + ( 7.94 * logch ); // first test
00131         return (chdiv > 0.1 && chdiv < 3.5) ?
00132           (Double_t) ( ( 2.7 - ( 3.3 * chdiv ) )  * logch ) : 
00133           -999.;
00134       default:
00135         cerr << "FROOT::TofinoZetaFromCharge ---> Data-taking " << dtak << " not available." << endl;
00136         return 0.;
00137       }
00138     }
00139   
00140   inline Double_t TofoneZetaFromTime(Int_t dtak,const Double_t &tdcE,const Double_t &tdcP)
00141     {
00142       switch(dtak){
00143       case 1:
00144         return (Double_t) ( (  tdcP -  tdcE ) / (2 ) * 16.639 );
00145       case 2:
00146         return (Double_t) ( (  tdcP -  tdcE ) / (2 ) * 16.639 );
00147       default:
00148         cerr << "FROOT::TofoneZetaFromTime ---> Data-taking " << dtak << " not available." << endl;
00149         return 0.;
00150       }
00151     }
00152 
00153 
00154   /*   Double_t TofZetaGeoAdjust(const Int_t &layer); // effective light propagation speed */
00155   /*   Double_t TofZetaGeoAdjust(const E_Fnd_Layer &layer); // effective light propagation speed */
00156   
00157   Double_t LmdZetaGeoAdjust(const Int_t &layer);
00158   Double_t LmdZetaGeoAdjust(const E_Fnd_Layer &layer);
00159   
00160   static const Int_t K_N_STB_CROWNS   =   6;   // STB: Number of Stb crowns
00161   static const Int_t K_N_STB_TUBES    = 404;   // STB: Number of Stb tubes/crown
00162 
00164   // FEE description
00165   enum E_Fnd_Gts_Constants{
00166     K_N_GTS_SELECTORS  =  2,    // N_Words in Trigger Selector (gated with TOFINO low/high thr.)
00167     K_N_GTS_TRIG_TYPES = 12,    // Number of trigger types
00168     K_N_GTS_P_UNITS    =  4,    // Number of Words in Trigger Selector (3 for the 2003 data-taking)
00169     K_N_GTS_SCALER_CHANNELS = 16, // Number of Channels/Scaler-module
00170     K_N_GTS_SCALER_MODULES  = 5,  // Number of Scaler Modules
00171     K_N_GTS_MALU      = 3,     // Number of MALU modules
00172   };
00173   
00174   enum E_Fnd_Gts_TrigTypes{
00175     K_TRIG_HYP      = 0,
00176     K_TRIG_BHABHA   = 1,
00177     K_TRIG_BTB_LOW  = 2,
00178     K_TRIG_OR_LOW   = 3,
00179     K_TRIG_BTB_HIGH = 4,
00180     K_TRIG_ORtofino_ORtofone = 5,
00181     K_TRIG_LASER    = 6,
00182     K_TRIG_PULSER   = 7,
00183     K_TRIG_TCALIB   = 8,
00184     K_TRIG_ORtofone = 9,
00185     K_TRIG_MULTtofone = 10,
00186     K_TRIG_BTB_LOW_ORtofone = 11,
00187   };
00188   
00189   TString TriggerType(E_Fnd_Gts_TrigTypes type);
00190 
00191   static const Int_t K_N_Tof_AdcMod =  9;  // TOF: Number of ADC modules
00192   static const Int_t K_N_Tof_AdcCha = 64;  // TOF: Number of ADC channels for each module
00193   static const Int_t K_N_Tof_TdcMod =  6;  // TOF: Number of TDC modules
00194   static const Int_t K_N_Tof_TdcCha = 96;  // TOF: Number of TDC channels for each module
00195   
00196   enum E_Fnd_Sil_Hardware{
00197     K_N_Sil_Crams = 27,    // SIL: Number of CRAMS (15 OSM + 12 ISM)
00198     K_N_Sil_Sects =  2,    // SIL: Number of Sections for each CRAM
00199     K_N_Sil_Sides = 3,     // SIL: Number of SIDES for each Module (see E_Fnd_Sil_Side)
00200     K_N_Sil_AdcCha = 1024, // SIL: Number of ADC channels for each section of ADC
00201     K_N_Sil_AdcChips = 8, // SIL: Number of Chips for each section of ADC
00202     K_N_Sil_Strips = 1920, // SIL: Max number of strips for both side
00203     K_N_Sil_Phi_Strips = 1021, // SIL: Number of strips for Phi side
00204     K_N_Sil_Z_Strips = 1920, // SIL: Number of strips for Z Side
00205     K_N_Sil_ChaOnChip = 128, // SIL: Number of ADC Cannels for each Chip
00206     K_N_Sil_Modules = 10,  // Number of hybrid modules (OSIM) (also for ISIM [8])
00207     K_N_Sil_FixPede = 50,  // Fix Pedestal to be structed from signals 
00208     K_N_Sil_MulNoise = 10,  // Noise Multiplier Constant (Noise has to be divided by this value) 
00209     K_N_Sil_Sigma_Cut = 3,  // Low Threshold for Cluster Finding
00210     K_N_Sil_Sigma_Pre = 5,  // High Threshold for Cluster Finding
00211     K_N_Sil_Noise_Cut = 8,  // Noise Threshold ( * 10 ) for Cluster Finding  
00212   };
00213   
00214   static const Int_t K_Sil_Crams_BaseAddress_03 = 0xD0A0;    // Base address used by microstrips CRAMS (data-takink 2003)
00215   static const Int_t K_Sil_Crams_BaseAddress_06 = 0xA0;    // Base address used by microstrips CRAMS (data-takink 2003)
00216   //  static const Int_t K_N_Sil_Crams = 27;    // SIL: Number of CRAMS (15 OSM + 12 ISM)
00217   //  static const Int_t K_N_Sil_Sects =  2;     // SIL: Number of Sections for each CRAM
00218   //  static const Int_t K_N_Sil_Sides = 3;     // SIL: Number of SIDES for each Module (0=Phi, 1 = Za, 2 = Zb)
00219   //  static const Int_t K_N_Sil_AdcCha = 1024;  // SIL: Number of ADC channels for each section of ADC
00220   //  static const Int_t K_N_Sil_Chips = 8;     // SIL: Number of CHIPS for each Module
00221   
00222   static const Int_t K_N_Lmd_AdcMod =  9;  // LMD: Number of ADC modules
00223   static const Int_t K_N_Lmd_AdcCha = 64;  // LMD: Number of ADC channels/module
00224   static const Int_t K_N_Lmd_TdcMod =  9;  // LMD: Number of TDC modules
00225   static const Int_t K_N_Lmd_TdcCha = 96;  // LMD: Number of TDC channels/module
00226   
00227   static const Int_t K_N_Stb_Crates =  2;   // STB: Number of TDC crates
00228   static const Int_t K_N_Stb_Mod   =  21;   // STB: Number of TDC modules/crate
00229   static const Int_t K_N_Stb_Cha   =  96;   // STB: Number of TDC channels/module
00230 
00232   // Raw data and equipments constants
00233 #define FIN_RAW_DATA_SOCK_LEN 0x10000
00234 #define FIN_RAW_DATA_BUF_SIZE 0x12000
00235   //#define FIN_DAQ_RAW_UDP_PORT 2007
00236 
00237   enum E_Fnd_DaqRaw_Udp_Ports {
00238     FIN_DAQ_RAW_UDP_PORT = 2007,
00239     FIN_GTS_DAQ_RAW_UDP_PORT = 2001, 
00240     FIN_TOF_DAQ_RAW_UDP_PORT = 2002,
00241     FIN_SIL_DAQ_RAW_UDP_PORT = 2003,
00242     FIN_LMD_DAQ_RAW_UDP_PORT = 2004,
00243     FIN_STB_DAQ_RAW_UDP_PORT = 2005,
00244   };
00245 
00246   /*   enum EDaqStatus { // for monitors "K_DAQ_Active" means stopped (active but not running) */
00247   /*     K_DAQ_Active = 0, */
00248   /*     K_DAQ_Crashed = 1, */
00249   /*     K_DAQ_Running  = 5, */
00250   /*     K_DAQ_NotMonitored = 6, */
00251   /*   }; */
00252   
00253   enum E_Fnd_Raw_Header_Struct {  // GLOBAL EVENT HEADER
00254     E_FndRawHead_Length =  0,
00255     E_FndRawHead_Nev_Hw =  1, // starts from 0
00256     E_FndRawHead_Nev_Sw =  2, // starts from 1
00257     E_FndRawHead_RunTyp =  3,
00258     E_FndRawHead_RunNum =  4,
00259     E_FndRawHead_RStart =  5,
00260     E_FndRawHead_TElaps =  6,
00261     E_FndRawHead_GTSptr =  7,
00262     E_FndRawHead_TOFptr =  8,
00263     E_FndRawHead_ISIptr =  9,
00264     E_FndRawHead_OSIptr = 10,
00265     E_FndRawHead_LMDptr = 11,
00266     E_FndRawHead_STBptr = 12,
00267     E_FndRawHead_DAQmsg = 15, // see EDaqStatus for details
00268   };
00269   
00270 
00271   static const UInt_t K_MAX_EQP_LEN = 100000; // maximum length for every equipment (to be checked)
00272   enum {
00273     //    K_SecondsPerDay = 86400,
00274     k_EvHeaderLen   = 16,      // length of the Global Event Header
00275     K_VmeScalBufLen = 82,      // length of the VME scaler buffers in total */
00276     K_GtsBufLen     = 36,      // length of the GTS buffer
00277   };
00278 
00279   enum EFndDaqDetectors { FIN_GTS = 0, FIN_TOF, FIN_ISM, FIN_OSM, FIN_LMD, FIN_STB }; // description of all acquired detectors
00280   enum EFndDetNameMode{ FIN_D_MOD_SHORT = 0, FIN_D_MOD_HDT, FIN_D_MOD_COMPLETE }; // SHORT: 3 chars, HDT: hdt branch name, COMPLETE: complete name
00281   TString AcquiredDetName(Int_t det,Int_t mode = 0); // det : see FROOT::EFndDaqDetectors ; mode: see FROOT::EFndDetNameMode
00282 
00284   // database
00285   static const Int_t K_N_DB_HOSTS = 3;
00286   TString DB_Host_Name(Int_t id);
00287 
00289   // monitoring constants
00290   //  static const Int_t K_N_RUN_TYPES = 7;
00291   static const Int_t K_N_FND_MON_DETECTORS = 5; // number of monitored detectors
00292   TString RunType_Name(Int_t id);
00293   TString MonDetName(Int_t i);
00294 
00295   enum EFndOnlineFlags { ONL_OFF = 0, ONL_GTS, ONL_TOF, ONL_ISM, ONL_OSM, ONL_LMD, ONL_STB, ONL_ALL };
00296   enum EFndRunTypes { RT_FINU = 0, RT_COSM, RT_PULS, RT_PEDE, RT_CALI, RT_PLAT, RT_ONLM }; // description of all monitored detectors
00297   enum EFndMonDetectors { D_GTS = 0, D_TOF, D_SIL, D_LMD, D_STB }; // description of all monitored detectors
00298   enum EFndDevice { DEV_DISK = 0, DEV_TAPE, DEV_SOCKET};
00299   enum EFndDBFetchSource { K_DB_SOURCE_HOST = 0, K_DB_SOURCE_FILE }; // K_DB_SOURCE_HOST requires a previous connection
00300 
00301   static const Int_t K_MAX_BINS_ADC = 4000; // used to prevent overfull of memory
00302   static const Int_t K_MAX_BINS_TDC = 4000; // used to prevent overfull of memory
00303 
00304 #ifdef _FND_ONL_USE_MAP_FILES_
00305   // --- Shared memories management (be very careful!)
00306   // --- sizes are expressed in MB
00307   const Int_t K_GtsMapSize = 1;     // GTS
00308   const Int_t K_TofMapSize = 20;    // TOF
00309   const Int_t K_TofAdcMapSize = 30;
00310   const Int_t K_TofTdcMapSize = 30;
00311   const Int_t K_IsimMapSize = 30;   // SIL
00312   const Int_t K_OsimMapSize = 30;
00313   const Int_t K_LmdMapSize = 5;     // LMD
00314   const Int_t K_LmdIadcMapSize = 5;
00315   const Int_t K_LmdItdcMapSize = 5;
00316   const Int_t K_LmdOadcMapSize = 7;
00317   const Int_t K_LmdOtdcMapSize = 7;
00318   const Int_t K_StbMapSize = 3;    // STB
00319   const Int_t K_StbC1MapSize = 5;
00320   const Int_t K_StbC2MapSize = 5;
00321   const Int_t K_StbC3MapSize = 5;
00322   const Int_t K_StbC4MapSize = 5;
00323   const Int_t K_StbC5MapSize = 5;
00324   const Int_t K_StbC6MapSize = 5;
00325 #endif  
00326 
00327   TString BuildRunName(const TString &run_type,const Int_t run_num,Bool_t use_subdir=kFALSE);
00328 #if defined _FND_OUTPUTS_USE_SUBDIR
00329   // method used only if sub-dir support is enabled
00330   Int_t CreateGrpSubDir(const TString &run_type,const Int_t run_num,const TString &start_pth);
00331 #endif
00332 
00333   TString DecodeRunType(UInt_t r_type_raw);
00334 
00335   Int_t CheckFileExistence(const TString &filename); // 1 if file exists
00336   // ---
00337   Float_t GetRamUsage(Bool_t verbose=kFALSE); // return percent of used RAM
00338   //
00339   enum E_FROOT_MEM_DESCR {
00340     E_FROOT_MemRes   = 0,
00341     E_FROOT_MemVirt  = 1
00342     /*     E_FROOT_MemTot   = 2 */
00343   };
00344   Float_t GetProcMemUsage(E_FROOT_MEM_DESCR mode=E_FROOT_MemVirt,Bool_t verbose=kFALSE);
00345   // ---
00346 
00347   void CompleteString(TString &str, Int_t size, const char *add_char, Bool_t after);
00348   // add the content of add_char n-times (until size is reached),
00349   // according to the boolean "after" (true: append; false: prepend)
00350   
00351   // wrapper function for TSystem->ConcatFileName() to suppress memory leaks
00352   TString ConcatFileName(const char *dir, const char *name);
00353 
00354   // convert two 32-bit words into a 64-bit quad.
00355   ULong64_t Convert64(UInt_t high, UInt_t low);
00356 
00357   // extract a bit from a UInt_t (32-bit) number
00358   UShort_t ExtractBit(const UInt_t &number, const UInt_t bit,const UInt_t limit);
00359 
00360   // wrapper function for TSystem->ExpandPathName() to suppress memory leaks
00361   TString ExpandPathName(const char *path);
00362 
00363   // convert an IP-address string to integer (for socket connections), in host
00364   // byte order (i.e. LSB first on Intel machines)
00365   Int_t Ip2Int(const char *ip);
00366   
00367   void SayToUser(const TString &Message, Int_t ntimes=1);
00368 
00369   void TerminateFroot(Int_t arg=0,const TString &Error=0);
00370 }
00371 
00373 // Inline implementations
00375 
00376 // the following lines are required in order to compile under Mac-OS
00377 //#ifdef __CINT__
00378 #if !defined(linux) && !defined(__linux) && !defined(__linux__)
00379 #undef __GNUC__
00380 #endif
00381 
00382 #if !defined(__CINT__)
00383 #include <netinet/in.h>           // for in_addr_t
00384 #include <arpa/inet.h>            // for inet_addr(), ntohl()
00385 #endif
00386 
00387 #include <TSystem.h>
00388 #include <TInterpreter.h>
00389 #include <TROOT.h>
00390 #include "Varargs.h" // used by Printf method
00391 
00392 
00393 #if defined(USE_BOOST)
00394 #  include <boost/scoped_array.hpp> // for boost::scoped_array template class
00395 #endif
00396 
00397 inline TString FROOT::GetFrootVersion() { return "9.01/02"; }
00398 inline Float_t FROOT::GetFrootVersionID() { return 901.02; }
00399 
00400 inline Double_t FROOT::LmdZetaGeoAdjust(const Int_t &layer){
00401   return LmdZetaGeoAdjust((E_Fnd_Layer)layer);
00402 }
00403 
00404 inline Double_t FROOT::LmdZetaGeoAdjust(const E_Fnd_Layer &layer){
00405   switch (layer){
00406   case E_FIN_INNER_LAYER: return 58.0;
00407   case E_FIN_OUTER_LAYER: return 88.04;
00408   default:
00409     gROOT->Error("FROOT::LmdZetaGeoAdjust","Layer \"%d\" not available",(Int_t)(layer) );
00410     return -1;
00411   } 
00412 }
00413 
00414 inline  TString FROOT::TriggerType(E_Fnd_Gts_TrigTypes type){
00415   switch(type){
00416   case K_TRIG_HYP: return "HYPE";
00417   case K_TRIG_BHABHA: return "BHABHA";
00418   case K_TRIG_BTB_LOW: return "BTB_LowThreshold";
00419   case K_TRIG_OR_LOW: return "OR_tofino_LowThreshold";
00420   case K_TRIG_BTB_HIGH: return "BTB_HighThreshold";
00421   case K_TRIG_ORtofino_ORtofone: return "OR_tofino_And_OR_tofone";
00422   case K_TRIG_LASER: return "LASER";
00423   case K_TRIG_PULSER: return "PULSER";
00424   case K_TRIG_TCALIB: return "Time_Calibration";
00425   case K_TRIG_ORtofone: return "OR_tofone";
00426   case K_TRIG_MULTtofone: return "MULT_tofone > 1";
00427   case K_TRIG_BTB_LOW_ORtofone: return "BTB_LowThreshold_And_OR_tofone";
00428     default: gROOT->Warning("FROOT::TriggerType","Trigger id not defined (%d)",type); return "";
00429   }
00430 }
00431 
00432 inline TString FROOT::SilSide_Name(Int_t id)
00433 {
00434   
00435   switch (id){
00436   case (Int_t) E_FIN_SIL_SIDE_PH: return "PHI";
00437   case (Int_t) E_FIN_SIL_SIDE_ZA: return "ZA";
00438   case (Int_t) E_FIN_SIL_SIDE_ZB: return "ZB";
00439   default: return "";
00440   }
00441   
00442 }
00443 
00444 inline TString FROOT::DB_Host_Name(Int_t id)
00445 {
00446   // check the K_N_DB_HOSTS constant
00447   // before modyfying the following entries
00448   switch (id){
00449   case 0: return "fnddiskfe.lnf.infn.it";
00450   case 1: return "localhost";
00451   case 2: return "tozsxl.to.infn.it";
00452   default: return "localhost";
00453   }
00454 }
00455 
00456 inline TString FROOT::RunType_Name(Int_t id)
00457 {
00458   // before modyfying the following entries
00459   switch (id){
00460   case RT_FINU: return "FINU";
00461   case RT_COSM: return "COSM";
00462   case RT_PULS: return "PULS";
00463   case RT_PEDE: return "PEDE";
00464   case RT_CALI: return "CALI";
00465   case RT_ONLM: return "ONLM";
00466   case RT_PLAT: return "PLAT";
00467     //  case RT_BHAB: return "BHAB";
00468   default: return "ONLM";
00469   }
00470 }
00471 
00472 inline TString FROOT::MonDetName(Int_t i) {
00473   switch(i){
00474   case D_GTS: return "GTS";
00475   case D_TOF: return "TOF";
00476   case D_SIL: return "SIL";
00477   case D_LMD: return "LMD";
00478   case D_STB: return "STB";
00479   default: return "BUG"; // this case should never occur
00480   }
00481 }
00482 
00483 inline TString FROOT::AcquiredDetName(Int_t det,Int_t mode){
00484   // det : see FROOT::EFndDaqDetectors
00485   // mode: see FROOT::EFndDetNameMode
00486 
00487   switch(det){
00488   case FIN_GTS: 
00489     switch(mode){ 
00490     case FIN_D_MOD_SHORT: return "GTS"; 
00491     case FIN_D_MOD_HDT : return "fHGts";
00492     case FIN_D_MOD_COMPLETE: return "Global Trigger Supervisor";
00493     default: return "BUG"; // this case should never occur
00494     }
00495   case FIN_TOF: 
00496     switch(mode){ 
00497     case FIN_D_MOD_SHORT: return "TOF"; 
00498     case FIN_D_MOD_HDT : return "fHTof";
00499     case FIN_D_MOD_COMPLETE: return "Time Of Flight system";
00500     default: return "BUG"; // this case should never occur
00501     }
00502   case FIN_ISM: 
00503     switch(mode){ 
00504     case FIN_D_MOD_SHORT: return "ISM"; 
00505     case FIN_D_MOD_HDT : return "fHIsm";
00506     case FIN_D_MOD_COMPLETE: return "Isim";
00507     default: return "BUG"; // this case should never occur
00508     }
00509   case FIN_OSM: 
00510     switch(mode){ 
00511     case FIN_D_MOD_SHORT: return "OSM"; 
00512     case FIN_D_MOD_HDT : return "fHOsm";
00513     case FIN_D_MOD_COMPLETE: return "Osim";
00514     default: return "BUG"; // this case should never occur
00515     }
00516   case FIN_LMD: 
00517     switch(mode){ 
00518     case FIN_D_MOD_SHORT: return "LMD"; 
00519     case FIN_D_MOD_HDT : return "fHLmd";
00520     case FIN_D_MOD_COMPLETE: return "Low Mass Drift Chambers";
00521     default: return "BUG"; // this case should never occur
00522     }
00523   case FIN_STB: 
00524     switch(mode){ 
00525     case FIN_D_MOD_SHORT: return "STB"; 
00526     case FIN_D_MOD_HDT : return "fHStb";
00527     case FIN_D_MOD_COMPLETE: return "Straw Tubes";
00528     default: return "BUG"; // this case should never occur
00529     }
00530   default: return "BUG"; // this case should never occur
00531   }  
00532 }
00533 
00534 inline TString FROOT::DecodeRunType(UInt_t r_type_raw){
00535 
00536   char r_type[5]="";
00537   r_type[0]=r_type_raw  & 0xff;
00538   r_type[1]=(r_type_raw & 0xff00)>>8;
00539   r_type[2]=(r_type_raw & 0xff0000)>>16;
00540   r_type[3]=(r_type_raw & 0xff000000)>>24;
00541   r_type[4]='\0';
00542   return TString(r_type);
00543 }
00544 
00545 inline TString FROOT::BuildRunName(const TString &run_type,const Int_t run_num,Bool_t use_subdir)
00546 {
00547   // used to build the run-filename (without extension)
00548   // starting from run-type and run-number
00549   
00550   Bool_t consider_run_type = kFALSE; // hard-coded
00551 
00552   TString str;
00553   if(run_num>=0) str.Form("%d",run_num);
00554   else  str = ""+0; // needed in online-mode
00555   CompleteString(str,5,"0",kFALSE);
00556   str.Prepend(run_type);
00557   
00558   if(use_subdir){
00559     TString subdir = "";
00560     UInt_t numdir = 1000 * (UInt_t) (run_num / 1000);
00561     TString strn;
00562     strn.Form("%u",numdir);
00563     CompleteString(strn,5,"0",kFALSE);
00564 
00565     if(consider_run_type) subdir.Form("run_group_%s_%s/",run_type.Data(),strn.Data());
00566     else subdir.Form("run_group_%s/",strn.Data());
00567 
00568     str.Prepend(subdir);
00569   }
00570   return str;
00571 }
00572 
00573 #if defined _FND_OUTPUTS_USE_SUBDIR
00574 inline Int_t FROOT::CreateGrpSubDir(const TString &run_type,const Int_t run_num,const TString &start_pth){
00575   // this method is used only if sub-dir support is enabled
00576   // - environmental variables are accepted
00577   // - a check on directory existence is performed first
00578   // 
00579   // return value:
00580   //               0: (ok)    directory not found and created
00581   //               1: (ok)    directory found (already existing)
00582   //              -1: (error) start_pth does not exist
00583   //              -2: (error) can not create directory
00584   //  
00585   // the consider_run_type variable (hard-coded) can be used in order
00586   //  to separate different run-types.
00587   
00588   Bool_t consider_run_type = kFALSE;
00589 
00590   TString st_pt_cmp = ExpandPathName(start_pth);
00591   if(st_pt_cmp.IsNull() || gSystem->AccessPathName(st_pt_cmp) ){
00592     gROOT->Error("FROOT::CreateGrpSubDir","Start Path not found (\"%s\")",st_pt_cmp.Data());
00593     return -1;
00594   }
00595 
00596   // remove "/" if found at the end of the given path
00597   if( st_pt_cmp.EndsWith("/") ) st_pt_cmp.Resize(st_pt_cmp.Sizeof()-2);
00598 
00599   TString ndir = "";
00600   UInt_t numdir = 1000 * (UInt_t) (run_num / 1000);
00601   TString strn;
00602   strn.Form("%u",numdir);
00603   CompleteString(strn,5,"0",kFALSE);
00604 
00605   if(consider_run_type) ndir.Form("%s/run_group_%s_%s",st_pt_cmp.Data(),run_type.Data(),strn.Data());
00606   else ndir.Form("%s/run_group_%s",st_pt_cmp.Data(),strn.Data());
00607 
00608   if( !gSystem->AccessPathName(ndir) ){
00609     gROOT->Info("FROOT::CreateGrpSubDir","directory \"%s\" already existing.",ndir.Data());
00610     return 1;
00611   }
00612 
00613   Int_t res = gSystem->MakeDirectory(ndir);
00614   if(res != 0) {
00615     gROOT->Error("FROOT::CreateGrpSubDir","Can not create directory \"%s\"",ndir.Data());
00616     return -2;
00617   }
00618   return 0;
00619 }
00620 #endif
00621 
00622 inline Int_t FROOT::CheckFileExistence(const TString &filename) {
00623   // 0 if file does not exist
00624   // 1 if file exists
00625 
00626   Bool_t filefound = kTRUE;
00627   if (gSystem->AccessPathName(ExpandPathName(filename)) && gSystem->AccessPathName(ExpandPathName(filename + ".gz")))
00628     filefound = kFALSE;
00629   if (!filefound) {
00630     gROOT->Warning("FROOT::CheckFileExistence", "file \"%s\" not found.",filename.Data());
00631     return 0;
00632   }
00633   return 1;
00634 }
00635 
00636 inline Float_t FROOT::GetRamUsage(Bool_t verbose){ 
00637   // return percent of used RAM
00638   MemInfo_t *im = new MemInfo_t();
00639   gSystem->GetMemInfo(im);
00640   Float_t tot = (Float_t)im->fMemTotal;
00641   Float_t used = (Float_t)im->fMemUsed;
00642   Float_t perc = 100. * (used / tot);
00643   if(verbose) cout << "used memory: " << used << " (" << perc << " %)" << endl;
00644   delete im; 
00645   return perc;
00646 }
00647 
00648 inline Float_t FROOT::GetProcMemUsage(E_FROOT_MEM_DESCR mode,Bool_t verbose){ 
00649   // return value:
00650   //              >=0 : percent of memory used by current process
00651   //               -1 : error
00652   MemInfo_t *im = new MemInfo_t();
00653   gSystem->GetMemInfo(im);
00654   ProcInfo_t *ipr = new ProcInfo_t();
00655   gSystem->GetProcInfo(ipr);
00656 
00657   Float_t tot = (Float_t)im->fMemTotal;
00658   Float_t mem = 0;
00659   TString descr_str = "";
00660   Float_t perc = 0;
00661   
00662   switch(mode){
00663   case E_FROOT_MemRes: 
00664     descr_str = "resident";
00665     mem = (Float_t)ipr->fMemResident;
00666     break;
00667   case E_FROOT_MemVirt:
00668     descr_str = "virtual";
00669     mem = (Float_t)(ipr->fMemVirtual);
00670     break;
00671   default:
00672     gROOT->Error("FROOT::GetProcMemUsage","Wrong argument: %d",(Int_t)(mode) );
00673     break;
00674   }
00675   if(mem < 0){
00676     gROOT->Error("FROOT::GetProcMemUsage","Negative value obtained: %f",mem );
00677     return -1;
00678   }
00679   mem = mem / 1024.; // MB
00680   //
00681   perc = 100. * ( mem / tot);
00682   if(verbose) cout << descr_str.Data() << " memory: " << mem << " (" << perc << " %)" << endl;
00683   //
00684   delete im; 
00685   delete ipr; 
00686   return perc;
00687 }
00688 
00689 inline void FROOT::CompleteString(TString &str, Int_t size, const char *add_char, Bool_t after)
00690 {
00691   while (str.Sizeof() < size + 1) {
00692     if (after)
00693       str.Append(add_char);
00694     else
00695       str.Prepend(add_char);
00696   }
00697 }
00698 
00699 inline TString FROOT::ConcatFileName(const char *dir, const char *name)
00700 {
00701 #if defined(USE_BOOST)
00702   boost::scoped_array<const char> s(gSystem->ConcatFileName(dir, name));
00703   return TString(s.get());
00704 #else
00705   const char *s = gSystem->ConcatFileName(dir, name);
00706   TString ret = s;
00707   delete[] s;
00708   return ret;
00709 #endif
00710 }
00711 
00712 inline ULong64_t FROOT::Convert64(UInt_t high, UInt_t low)
00713 {
00714   return ((ULong64_t) high << (CHAR_BIT * sizeof(UInt_t))) | low;
00715 }
00716 
00717 inline UShort_t FROOT::ExtractBit(const UInt_t &number, const UInt_t bit,const UInt_t limit){
00718   // extract a bit from a UInt_t (32-bit) number
00719   // bit range [0;limit-1]
00720   
00721   if(bit > limit-1){
00722     gROOT->Error("ExtractBit","requested bit (%u) not available (limit=%u)",bit,limit); return 0;
00723   }
00724   
00725   UShort_t result = (UShort_t) ( (number & ((UInt_t)TMath::Power(2,bit))) >> bit );
00726   return result;
00727 }
00728 
00729 
00730 inline TString FROOT::ExpandPathName(const char *path)
00731 {
00732 #if defined(USE_BOOST)
00733   boost::scoped_array<const char> s(gSystem->ExpandPathName(path));
00734   return TString(s.get());
00735 #else
00736   const char *s = gSystem->ExpandPathName(path);
00737   TString ret = s;
00738   delete[] s;
00739   return ret;
00740 #endif
00741 }
00742 
00743 inline Int_t FROOT::Ip2Int(const char *ip)
00744 {
00745   in_addr_t addr = inet_addr(ip);
00746   return ntohl(addr);
00747 }
00748 
00749 inline void FROOT::SayToUser(const TString &Message, Int_t ntimes){
00750   
00751   TString command;
00752   command.Form("echo \'(SayText \"%s\")\' |festival --pipe",Message.Data());
00753   
00754   for(Int_t i=0;i<ntimes;i++){
00755     gSystem->Exec(command);
00756     if(ntimes>1) usleep(500000);
00757   }
00758   
00759 }
00760 
00761 inline void FROOT::TerminateFroot(Int_t arg,const TString &Error)
00762 {
00763   Printf("");
00764   Printf(" --------------------------------------------------");
00765 
00766   if(Error.IsNull()){
00767     gROOT->Error("FROOT termination","fROOT has been terminated due to an internal error.");
00768     Printf("fROOT has been terminated due to an internal error.");
00769   }
00770   else gROOT->Error("FROOT termination",Error.Data());
00771   Printf(" --------------------------------------------------");
00772   Printf("");
00773   gSystem->Exit(arg);
00774   gApplication->Terminate(arg); // I want to be realy sure to quit
00775   gInterpreter->ProcessLine(".q"); // not really needed
00776 }
00777 
00778 
00779 #endif // FROOT_FROOT

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