QApolloDbBase.hh
Go to the documentation of this file.00001
00002 #ifndef _QAPOLLO_DB_BASE_HH_
00003 #define _QAPOLLO_DB_BASE_HH_
00004
00005 #include <string>
00006 #include <set>
00007
00008 #include "QApolloDbDefs.hh"
00009 #include "QCuore.hh"
00010 #include "QDb.hh"
00011 #include "QApolloDbCache.hh"
00012 #include "QDbDetector.hh"
00013
00049 class QApolloDbBase : public QDb {
00050 public:
00051
00052 virtual ~QApolloDbBase();
00053
00054 private:
00055
00056 enum EnvVarName_t {
00057 DbHost_s,
00058 DbPort_s,
00059 DbUser_s,
00060 DbPwd_s,
00061 DbName_s
00062 };
00063
00064 enum DbMode_t {
00065 UndefMode_s = 0,
00066 MasterMode_s = 1L << 1,
00067 TuningMode_s = 1L << 2,
00069 GuiMode_s = 1L << 3,
00071 ReadMode_s = 1L << 4
00072 };
00073
00077 QApolloDbBase();
00078
00079
00081 static QApolloDbBase& Get();
00082
00087 inline bool Undefined() const { return (UndefMode_s == fMode); }
00088
00093 bool Reset(unsigned int settingsBasket, unsigned int runNumber);
00094
00099 bool Reset(unsigned int settingsBasket);
00100
00105 bool Reset();
00106
00111 bool ResetRun();
00112
00113
00114
00116 const std::map<unsigned int,std::string>& CrateMap() const
00117 { return fActiveCrates; }
00118
00119
00127 int GetListOfChannels(std::vector<unsigned int>& chList,
00128 unsigned int profileId = 0);
00129
00135 unsigned int GetMapping(std::map<unsigned int, QDaqChannel>& cMap);
00136
00145 unsigned int GetActiveChannels(std::map<unsigned int, QDaqChannel>& cMap,
00146 QDaqChannel::SettingsType_t what);
00147
00156 int GetBoards(unsigned int crateId,
00157 std::map<unsigned int,std::string>& boards );
00158
00172 int GetActiveChannels(unsigned int crateId,
00173 unsigned int slot,
00174 QDaqChannel::SettingsType_t what,
00175 std::vector<QDaqChannel>& v );
00176
00189 void GetListOfTriggers(unsigned int lg, std::vector<std::string>& trgList);
00190
00201 const QVdt& GetTrgParameter(unsigned int trgIndex,
00202 const std::string& par_name,
00203 unsigned int lg=0);
00212 const std::map<std::string,QVdt>& GetTrgParameters(unsigned int trgIndex,
00213 unsigned int lg);
00214
00220 bool Dump(unsigned int crateId, bool dump);
00221
00223 inline unsigned int GetCurrentRunNumber() const {return gRunNumber;}
00224
00226 inline unsigned int GetCurrentProfile() const { return fProfile; }
00227
00229 QDbDetector::RunType GetCurrentRunType() const { return fRunType; }
00230
00235 unsigned int GetPulserPeriod();
00236
00240 void GetRunTypes(std::map<unsigned int, std::string>& runTypes);
00241
00246 void GetRuns(std::vector<int>& runs);
00247
00253 unsigned int GetLastRun();
00254
00262 void
00263 GetSettingsBaskets(int howMany,
00264 std::map<std::string,std::vector<QVdt> >& basketsMap);
00265
00272 unsigned int
00273 GetSettingsBasketIds(std::vector<int>& baskets);
00274
00284 unsigned int GetSettingsBasket(unsigned int id, std::string& comment);
00285
00291 unsigned int GetDefaultSettingsBasket();
00292
00299 bool GetStartDateOfRun(unsigned int runNumber, std::string& startDate);
00300
00304 bool BasketHasPulsers(unsigned int basket);
00305
00311
00315 void UpdateStart(unsigned int shifterSet);
00316
00320 void UpdateStop(StopStatus_t stopStatus, unsigned int shifterSet,
00321 unsigned int nFiles);
00322
00327 void InsertStartComments(const std::string& comment);
00328
00333 void InsertStopComments(const std::string& comment);
00334
00340
00342 void Clear();
00343
00345 void Init();
00346
00353 void GuessCurrentRun();
00354
00356 void InsertNewRun();
00357
00366 void UndoInsertRun();
00367
00372 void SanitizeRunsTable();
00373
00375 bool LoadHardwareProfile(unsigned int crateId);
00376
00378 void Load(QDaqChannel::SettingsType_t what);
00379
00381 void Load(QDaqChannel::SettingsType_t what, unsigned int crateId);
00382
00384 void LoadHwSettings(QDaqChannel::SettingsType_t setType,
00385 unsigned int crateId);
00386
00388 void LoadTriggerSettings(unsigned int crateId);
00389
00391 void LoadDefaultTriggerSettings();
00392
00393 static std::string GetDbEnv(EnvVarName_t name);
00394
00402 std::string EscapeString(const std::string& inputString,
00403 const char& toBeEscaped,
00404 const char& escapeChar) const;
00405
00412 std::string CleanString(const std::string& inputString) const;
00413
00418 bool GetPasswordHash(const std::string& user, std::string& hash);
00419
00424 QApolloUserLevel GetUserLevel(const std::string& user);
00425
00430 void GetListOfUsers(std::set<std::string>& users,
00431 QApolloUserLevel minLevel,
00432 QApolloUserLevel maxLevel);
00433
00437 static bool gCanWrite;
00439 static unsigned int gRunNumber;
00441 static unsigned int gSettingsBasket;
00443 unsigned int fProfile;
00445 unsigned int fDaqSet;
00447 unsigned int fTrgSet;
00449 unsigned int fFESet;
00451 unsigned int fBesSet;
00453 QDbDetector::RunType fRunType;
00455 unsigned int fPulserSet;
00457 std::map<unsigned int,std::string> fActiveCrates;
00459 std::map<unsigned int,unsigned int> fActiveChannels;
00461 std::vector<unsigned int> fLoadedHwCrates;
00463 std::vector<unsigned int> fLoadedTrgCrates;
00465 std::vector<unsigned int> fLoadedDaqCrates;
00467 std::vector<unsigned int> fLoadedBesCrates;
00469 std::vector<unsigned int> fLoadedFECrates;
00471 std::vector<unsigned int> fLoadedPulserCrates;
00473 QApolloDbCache fCache;
00474
00476 unsigned int fMode;
00477
00479 bool fRunningMode;
00480
00481
00482 const unsigned int fLowerRunExcluded;
00483
00484 const unsigned int fUpperRunExcluded;
00485
00486 friend class QApolloDb;
00487 friend class QApolloDbServer;
00488 friend class QApolloDbGui;
00489 friend class QApolloDbDaq;
00490 friend class QApolloDbSlow;
00491 };
00492
00493 #endif // _QAPOLLO_DB_BASE_HH_