#ifndef THaScalerDB_ #define THaScalerDB_ ///////////////////////////////////////////////////////////////////// // // THaScalerDB // // Scaler database. See implementation for comments. // // author Robert Michaels (rom@jlab.org) // ///////////////////////////////////////////////////////////////////// #include "Rtypes.h" #include #include #include #include #include #include #define ADB_DEBUG 0 class Bdate { // Utility class of date information. public: Int_t day,month,year; Bdate(Int_t d=0, Int_t m=0, Int_t y=0) : day(d), month(m), year(y) { } ~Bdate() { } void load(Int_t d, Int_t m, Int_t y) { day = d; month = m; year = y; }; void load(std::vector strvect) { day = atoi(strvect[1].c_str()); month = atoi(strvect[2].c_str()); year = atoi(strvect[3].c_str()); }; void Print() const { std::cout << "\nBdate : day = "< pkey = make_pair(crate, key); std::map, std::map >::iterator pm = directives.find(pkey); if (pm == directives.end()) return none; std::map stemp = pm->second; std::map::iterator ps = stemp.find(subkey); if (ps == stemp.end()) return none; return ps->second; }; Int_t GetDirectiveSize(Int_t crate, std::string key) { std::pair pkey = make_pair(crate, key); std::map, std::map >::iterator pm = directives.find(pkey); if (pm == directives.end()) return 0; std::map stemp = pm->second; return stemp.size(); } void Load(std::string key, Int_t crate, std::vector& direct) { std::map stemp; bool ok = false; for (std::vector::iterator str = direct.begin(); str != direct.end(); str++) { std::string sdir = *str; if (ParseDir(sdir)) { stemp.insert(make_pair(fSkey, fSdata)); ok = true; } } if (ok) { std::pair pkey = make_pair(crate, key); std::map, std::map >::iterator pm = directives.find(pkey); if (pm != directives.end()) { (pm->second).insert(make_pair(fSkey, fSdata)); } else { directives.insert(make_pair(make_pair(crate,key), stemp)); } } }; void Print() { std::cout << std::endl << " -- Directives -- "<, std::map >::iterator dm = directives.begin(); dm != directives.end(); dm++) { std::pair is = dm->first; std::cout << "key i = "<second<, std::map > directives; bool ParseDir(std::string sdir) { fSkey = ""; fSdata = ""; std::string::size_type pos1; pos1 = sdir.find(":"); if (pos1 != std::string::npos) { fSkey.assign(sdir.substr(0,pos1)); fSdata.assign(sdir.substr(pos1+1,sdir.length())); } return true; } std::string fSkey, fSdata; }; class THaScalerDB { public: THaScalerDB(); virtual ~THaScalerDB(); bool extract_db(const Bdate& bdate); std::string GetLongDesc(Int_t crate, std::string desc, Int_t helicity=0); std::string::size_type FindNoCase(const std::string s1, const std::string s2); Int_t GetSlot(Int_t crate, std::string desc, Int_t helicity=0); Int_t GetSlot(Int_t crate, Int_t tgtstate, Int_t helicity); Int_t GetChan(Int_t crate, std::string desc, Int_t helicity=0, Int_t chan=0); std::vector GetShortNames(Int_t crate, Int_t slot, Int_t chan); Int_t GetNumDirectives(Int_t craet, std::string directive); Int_t GetIntDirectives(Int_t crate, std::string directive, std::string key); std::string GetStringDirectives(Int_t crate, std::string directive, std::string key); void LoadCrateToInt(const char *bank, Int_t cr); Bool_t UsesTargetState(Int_t crate); Int_t CrateToInt(const std::string& scrate); void PrintChanMap(); void PrintDirectives(); private: THaScalerDB(const THaScalerDB &bk); THaScalerDB& operator=(const THaScalerDB &bk); bool found_date; UInt_t fgnfar; std::string scomment, sdate; std::vector directnames; std::map< SDB_chanKey, SDB_chanDesc > chanmap; std::map< std::string, Int_t > crate_strtoi; std::map< std::pair, Int_t>, std::vector< std::string> > channame; SDB_directive *direct; bool LoadMap(std::string sinput); bool LoadDirective(std::string sinput); std::string GetLineType(const std::string sline); void Init(); SDB_chanDesc GetChanDesc(Int_t crate, std::string desc, Int_t helicity=0); Bool_t IsHelicityTied(Int_t crate, Int_t helicity); Int_t TiedCrate(Int_t crate, Int_t helicity); Int_t GetSlotOffset(Int_t crate, Int_t helicity); Int_t AmtSpace(const std::string& s); std::vector vsplit(const std::string& s); ClassDef(THaScalerDB,0) // Text-based time-dependent database for scaler map and directives }; #endif