Diana Software
QGlobalLabel.cc
Go to the documentation of this file.
1 #include "QGlobalLabel.hh"
2 #include <iomanip>
3 #include <sstream>
4 
5 //ClassImp(Diana::QGlobalLabel);
6 
8 
10 {
11  fOwner = "";
12  fName = "";
19  fExtraKeys.clear();
20 }
21 
22 QGlobalLabel::QGlobalLabel(const std::string& label)
23 {
30  fExtraKeys.clear();
31 
32  size_t und = label.find_first_of("@");
33  if(und != std::string::npos) {
34  fOwner = label.substr(0,und);
35  size_t lowestUnd = std::string::npos;
36  size_t nameBegin = und+1;
37  und = label.rfind("_runs");
38  if(und != std::string::npos) {
39  std::string srun = label.substr(und+5,und+5+6);
40  fBeginRun = atoi(srun.c_str());
41  srun = label.substr(und+5+6+1,und+5+6+1+6);
42  fEndRun = atoi(srun.c_str());
43  if(und < lowestUnd) lowestUnd = und;
44  } else {
45  und = label.rfind("_run");
46  if(und != std::string::npos) {
47  std::string srun = label.substr(und+4,und+4+6);
48  fBeginRun = atoi(srun.c_str());
50  }
51  if(und < lowestUnd) lowestUnd = und;
52  }
53  und = label.rfind("_dss");
54  if(und != std::string::npos) {
55  std::string srun = label.substr(und+4,und+4+4);
56  fBeginDataset = atoi(srun.c_str());
57  srun = label.substr(und+4+4+1,und+4+4+1+4);
58  fEndDataset = atoi(srun.c_str());
59  if(und < lowestUnd) lowestUnd = und;
60  } else {
61  und = label.rfind("_ds");
62  if(und != std::string::npos) {
63  std::string srun = label.substr(und+3,und+3+4);
64  fBeginDataset = atoi(srun.c_str());
66  }
67  if(und < lowestUnd) lowestUnd = und;
68  }
69  und = label.rfind("_chan");
70  if(und != std::string::npos) {
71  std::string sch = label.substr(und+5,und+5+4);
72  fChannel = atoi(sch.c_str());
73  if(und < lowestUnd) lowestUnd = und;
74  }
75  und = label.rfind("_2ndChan");
76  if(und != std::string::npos) {
77  std::string sch2 = label.substr(und+8,und+8+4);
78  fChannel2 = atoi(sch2.c_str());
79  if(und < lowestUnd) lowestUnd = und;
80  }
81  fName = label.substr(nameBegin,lowestUnd-nameBegin);
82  }
83  else {
84  fOwner = "";
85  fName = label;
86  }
87 }
88 
89 
90 bool QGlobalLabel::operator<(const QGlobalLabel& other) const
91 {
92  if(fOwner < other.fOwner) return true;
93  if(other.fOwner < fOwner) return false;
94  if(fName < other.fName) return true;
95  if(other.fName < fName) return false;
96  if(fBeginRun < other.fBeginRun) return true;
97  if(other.fBeginRun < fBeginRun) return false;
98  if(fEndRun < other.fEndRun) return true;
99  if(other.fEndRun < fEndRun) return false;
100  if(fChannel < other.fChannel) return true;
101  if(other.fChannel < fChannel) return false;
102  if(fChannel2 < other.fChannel2) return true;
103  if(other.fChannel2 < fChannel2) return false;
104  if(fBeginDataset < other.fBeginDataset) return true;
105  if(other.fBeginDataset < fBeginDataset) return false;
106  if(fEndDataset < other.fEndDataset) return true;
107  if(other.fEndDataset < fEndDataset) return false;
108  std::map<std::string,ExtraKey>::const_iterator iter = fExtraKeys.begin();
109  while(iter != fExtraKeys.end()) {
110  const std::string& prefix = iter->first;
111  if(other.fExtraKeys.find(prefix) != other.fExtraKeys.end()) {
112  const ExtraKey& key = fExtraKeys.find(prefix)->second;
113  const ExtraKey& otherKey = other.fExtraKeys.find(prefix)->second;
114  if(key < otherKey) return true;
115  if(otherKey < key) return false;
116  }
117  iter++;
118  }
119 
120  return false;
121 }
122 
123 bool QGlobalLabel::operator==(const QGlobalLabel& other) const
124 {
125  if(*this < other) return false;
126  if(other < *this) return false;
127  return true;
128 }
129 
130 std::string QGlobalLabel::GetStringLabel() const
131 {
132  std::stringstream strstr;
133  int chandig = 4;
134  bool isOld = false;
135  if(fOwner != "Old")
136  strstr<<this->fOwner<<"@"<<this->fName;
137  else {
138  strstr<<this->fName;
139  isOld = true;
140  chandig = 2;
141  }
142  if(fBeginRun == fEndRun && fEndRun != Q_INT_DEFAULT) {
143  if(isOld) strstr<<"_";
144  else strstr<<"_run";
145  strstr<<std::setfill('0')<<std::setw(6)<<fEndRun;
146  } else if(fBeginRun != fEndRun) {
147  // never used in old diana
148  strstr<<"_runs"<<std::setfill('0')<<std::setw(6)<<fBeginRun;
149  strstr<<":"<<std::setfill('0')<<std::setw(6)<<fEndRun;
150  }
152  strstr<<"_ds";
153  strstr<<std::setfill('0')<<std::setw(4)<<fEndDataset;
154  } else if(fBeginDataset != fEndDataset) {
155  // never used in old diana
156  strstr<<"_dss"<<std::setfill('0')<<std::setw(4)<<fBeginDataset;
157  strstr<<":"<<std::setfill('0')<<std::setw(4)<<fEndDataset;
158  }
159  if(fChannel != Q_INT_DEFAULT) {
160  if(isOld) strstr<<"_";
161  else strstr<<"_chan";
162  strstr<<std::setfill('0')<<std::setw(chandig)<<fChannel;
163  }
164  if(fChannel2 != Q_INT_DEFAULT) {
165  // never used in old diana
166  strstr<<"_2ndChan"<<std::setfill('0')<<std::setw(chandig)<<fChannel2;
167  }
168 
169  std::map<std::string,ExtraKey>::const_iterator iter = fExtraKeys.begin();
170  while(iter != fExtraKeys.end()) {
171  const ExtraKey& key = iter->second;
172  if(key.fValue != Q_INT_DEFAULT) {
173  strstr<<"_"<<iter->first<<std::setfill('0')<<std::setw(key.fDigits)<<key.fValue;
174  }
175  iter++;
176  }
177 
178  return strstr.str();
179 }
180 
181 void QGlobalLabel::GetBareOwnerAndExtraLabel(std::string& bOwner, std::string& el) const
182 {
183  size_t pos = fOwner.find_last_of("_");
184  bOwner = fOwner.substr(0,pos);
185  if(pos != std::string::npos) {
186  el = fOwner.substr(pos+1,std::string::npos);
187  } else {
188  el = "";
189  }
190 }
191 
192 
193 
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
#define Q_INT_DEFAULT
Definition: QDiana.hh:26
Label for global QObject's.
Definition: QGlobalLabel.hh:19
std::map< std::string, ExtraKey > fExtraKeys
Definition: QGlobalLabel.hh:73
QGlobalLabel()
ctor
Definition: QGlobalLabel.cc:9
void GetBareOwnerAndExtraLabel(std::string &bOwner, std::string &el) const
split extra label and bare module name
bool operator==(const QGlobalLabel &other) const
comparison operator
std::string fName
Object name.
Definition: QGlobalLabel.hh:44
std::string fOwner
Object owner.
Definition: QGlobalLabel.hh:42
std::string GetStringLabel() const
convert label to string
bool operator<(const QGlobalLabel &other) const
less operator
Definition: QGlobalLabel.cc:90
int fBeginRun
begin validity
Definition: QGlobalLabel.hh:46