EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairDbRollbackDates.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairDbRollbackDates.cxx
1 
2 #include <cstring>
3 
4 #include "TString.h"
5 
6 #include "FairDb.h"
7 #include "FairDbRollbackDates.h"
8 #include "FairRegistry.h"
9 #include "FairDbString.h"
10 #include "ValTimeStamp.h"
11 
13 
15  : fTableToDate(), fTableToType()
16 {
17 }
18 
20 {
21 
22 }
23 
24 const std::string& FairDbRollbackDates::GetDate(const std::string& tableName) const
25 {
26  static std::string date;
27 
28  name_map_t::const_reverse_iterator itr = fTableToDate.rbegin();
29  name_map_t::const_reverse_iterator itrEnd = fTableToDate.rend();
30  for (; itr != itrEnd; ++itr)
31  if ( ! FairUtilString::cmp_wildcard(tableName,itr->first)
32  ) { return itr->second; }
33  return date;
34 }
35 
36 const std::string& FairDbRollbackDates::GetType(const std::string& tableName) const
37 {
38 
39  static std::string type("INSERTDATE"); // The default type
40 
41  name_map_t::const_reverse_iterator itr = fTableToType.rbegin();
42  name_map_t::const_reverse_iterator itrEnd = fTableToType.rend();
43  for (; itr != itrEnd; ++itr)
44  if ( ! FairUtilString::cmp_wildcard(tableName,itr->first)
45  ) { return itr->second; }
46  return type;
47 }
48 
50 {
51 
52  FairRegistry::FairRegistryKey keyItr(&reg);
53 
54  Bool_t hasChanged = kFALSE;
55 
56  const char* key = keyItr();
57  while ( key ) {
58 
59  const char* nextKey = keyItr();
60 
61  // Process Rollback keys
62 
63  if ( ! strncmp("Rollback:",key,9) ) {
64  std::string tableName = key+9;
65  std::string date;
66  const char* dateChars = 0;
67  bool ok = reg.Get(key,dateChars);
68  if ( ok ) {
69  date = dateChars;
70  ValTimeStamp ts(FairDb::MakeTimeStamp(date,&ok));
71  date = FairDb::MakeDateTimeString(ts);
72  }
73  if ( ok ) {
74 
75  // Prune away any trailing spaces - they cause SQL
76  // to fail expressions involving the date.
77  int loc = date.size()-1;
78  while ( loc && date[loc] == ' ' ) { date.erase(loc--); }
79 
80  fTableToDate[tableName] = date;
81  hasChanged = kTRUE;
82 
83  } else
84  cout << "Illegal Rollback registry item: " << key
85  << " = " << dateChars << endl;
86  reg.RemoveKey(key);
87  }
88 
89  // Process RollbackType keys
90 
91  else if ( ! strncmp("RollbackType:",key,13) ) {
92  std::string tableName = key+13;
93  TString type;
94  const char* typeChars = 0;
95  bool ok = reg.Get(key,typeChars);
96  if ( ok ) {
97  // Convert to upper case and remove any leading or trailing spaces
98  type = typeChars;
99  type.ToUpper();
100  type = type.Strip(TString::kBoth);
101  ok = ! type.CompareTo("INSERTDATE") || ! type.CompareTo("CREATIONDATE");
102  }
103  if ( ok ) {
104  fTableToType[tableName] = type.Data();
105  hasChanged = kTRUE;
106  } else
107  cout << "Illegal RollbackType registry item: " << key
108  << " = " << typeChars << endl;
109  reg.RemoveKey(key);
110  }
111  key = nextKey;
112  }
113 
114  if ( hasChanged ) { this->Show(); }
115 }
116 
118 {
119 
120  cout << "\n\nRollback Status: ";
121  if ( fTableToDate.size() == 0 ) { cout <<"Not enabled" << endl; }
122  else {
123  cout << "\n\n Dates:- " << endl;
124  name_map_t::const_reverse_iterator itr = fTableToDate.rbegin();
125  name_map_t::const_reverse_iterator itrEnd = fTableToDate.rend();
126  for (; itr != itrEnd; ++itr) {
127  std::string name = itr->first;
128  if ( name.size() < 30 ) { name.append(30-name.size(),' '); }
129  cout <<" " << name << " " << itr->second << endl;
130  }
131  cout << "\n Rollback Type is 'INSERTDATE'";
132  if ( fTableToType.size() ) {
133  cout << " except as follows:- " << endl;
134  itr = fTableToType.rbegin();
135  itrEnd = fTableToType.rend();
136  for (; itr != itrEnd; ++itr) {
137  std::string name = itr->first;
138  if ( name.size() < 30 ) { name.append(30-name.size(),' '); }
139  cout <<" " << name << " " << itr->second << endl;
140  }
141  }
142  cout << endl;
143  }
144 }
145 
146