CMS 3D CMS Logo

DTCCBConfig.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Paolo Ronchese INFN Padova
5  *
6  */
7 
8 //-----------------------
9 // This Class' Header --
10 //-----------------------
11 #include <memory>
12 
14 
15 //-------------------------------
16 // Collaborating Class Headers --
17 //-------------------------------
19 
20 //---------------
21 // C++ Headers --
22 //---------------
23 
24 //-------------------
25 // Initializations --
26 //-------------------
27 
28 //----------------
29 // Constructors --
30 //----------------
31 DTCCBConfig::DTCCBConfig() : timeStamp(0), dataVersion(" "), dBuf(new DTBufferTreeUniquePtr) { dataList.reserve(1000); }
32 
34  : timeStamp(0), dataVersion(version), dBuf(new DTBufferTreeUniquePtr) {
35  dataList.reserve(1000);
36 }
37 
38 DTCCBId::DTCCBId() : wheelId(0), stationId(0), sectorId(0) {}
39 
40 DTConfigKey::DTConfigKey() : confType(0), confKey(0) {}
41 
42 //--------------
43 // Destructor --
44 //--------------
46 
48 
50 
51 //--------------
52 // Operations --
53 //--------------
54 std::vector<DTConfigKey> DTCCBConfig::fullKey() const { return fullConfigKey; }
55 
56 int DTCCBConfig::stamp() const { return timeStamp; }
57 
58 int DTCCBConfig::configKey(int wheelId, int stationId, int sectorId, std::vector<int>& confKey) const {
59  confKey.clear();
60 
61  std::vector<int> chanKey{wheelId, stationId, sectorId};
62  std::vector<int> const* confPtr;
63  int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), confPtr);
64  if (!searchStatus)
65  confKey = *confPtr;
66 
67  return searchStatus;
68 }
69 
70 int DTCCBConfig::configKey(const DTChamberId& id, std::vector<int>& confKey) const {
71  return configKey(id.wheel(), id.station(), id.sector(), confKey);
72 }
73 
75  ccb_config_map keyList;
76  std::vector<std::pair<DTCCBId, int>*> tempList;
77  const_iterator d_iter = begin();
78  const_iterator d_iend = end();
79  while (d_iter != d_iend)
80  tempList.push_back(new std::pair<DTCCBId, int>(*d_iter++));
81  std::vector<std::pair<DTCCBId, int>*>::iterator t_iter = tempList.begin();
82  std::vector<std::pair<DTCCBId, int>*>::iterator t_iend = tempList.end();
83  while (t_iter != t_iend) {
84  std::pair<DTCCBId, int>* ptr = *t_iter++;
85  if (ptr == nullptr)
86  continue;
87  DTCCBId& ccbId = ptr->first;
88  std::vector<int> cfgKeys;
89  cfgKeys.push_back(ptr->second);
90  std::vector<std::pair<DTCCBId, int>*>::iterator n_iter(t_iter);
91  while (n_iter != t_iend) {
92  std::pair<DTCCBId, int>*& pck = *n_iter++;
93  if (pck == nullptr)
94  continue;
95  DTCCBId& chkId = pck->first;
96  if ((chkId.wheelId == ccbId.wheelId) && (chkId.stationId == ccbId.stationId) &&
97  (chkId.sectorId == ccbId.sectorId)) {
98  cfgKeys.push_back(pck->second);
99  delete pck;
100  pck = nullptr;
101  }
102  }
103  keyList.push_back(std::pair<DTCCBId, std::vector<int> >(ccbId, cfgKeys));
104  delete ptr;
105  }
106  return keyList;
107 }
108 
109 const std::string& DTCCBConfig::version() const { return dataVersion; }
110 
112 
114  dataList.clear();
115  initialize();
116  return;
117 }
118 
119 void DTCCBConfig::setFullKey(const std::vector<DTConfigKey>& key) { fullConfigKey = key; }
120 
122 
123 int DTCCBConfig::setConfigKey(int wheelId, int stationId, int sectorId, const std::vector<int>& confKey) {
124  std::vector<int> chanKey{wheelId, stationId, sectorId};
125 
126  std::vector<int>* confPtr;
127  int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), confPtr);
128 
129  if (!searchStatus) {
130  std::vector<std::pair<DTCCBId, int> > tempList;
131  const_iterator iter = dataList.begin();
132  const_iterator iend = dataList.end();
133  while (iter != iend) {
134  const DTCCBId& ccbId(iter->first);
135  if ((ccbId.wheelId != wheelId) || (ccbId.stationId != stationId) || (ccbId.sectorId != sectorId))
136  tempList.push_back(*iter);
137  ++iter;
138  }
139  dataList = tempList;
140  DTCCBId ccbId;
141  ccbId.wheelId = wheelId;
142  ccbId.stationId = stationId;
143  ccbId.sectorId = sectorId;
144  std::vector<int>::const_iterator cfgIter = confKey.begin();
145  std::vector<int>::const_iterator cfgIend = confKey.end();
146  while (cfgIter != cfgIend)
147  dataList.push_back(std::pair<DTCCBId, int>(ccbId, *cfgIter++));
148  *confPtr = confKey;
149  return -1;
150  } else {
151  dBuf->insert(chanKey.begin(), chanKey.end(), std::make_unique<std::vector<int> >(confKey));
152  DTCCBId ccbId;
153  ccbId.wheelId = wheelId;
154  ccbId.stationId = stationId;
155  ccbId.sectorId = sectorId;
156  std::vector<int>::const_iterator cfgIter = confKey.begin();
157  std::vector<int>::const_iterator cfgIend = confKey.end();
158  while (cfgIter != cfgIend)
159  dataList.push_back(std::pair<DTCCBId, int>(ccbId, *cfgIter++));
160  return 0;
161  }
162 }
163 
164 int DTCCBConfig::setConfigKey(const DTChamberId& id, const std::vector<int>& confKey) {
165  return setConfigKey(id.wheel(), id.station(), id.sector(), confKey);
166 }
167 
168 int DTCCBConfig::appendConfigKey(int wheelId, int stationId, int sectorId, const std::vector<int>& confKey) {
169  std::vector<int> chanKey{wheelId, stationId, sectorId};
170 
171  DTCCBId ccbId;
172  ccbId.wheelId = wheelId;
173  ccbId.stationId = stationId;
174  ccbId.sectorId = sectorId;
175  std::vector<int>::const_iterator iter = confKey.begin();
176  std::vector<int>::const_iterator iend = confKey.end();
177  int key;
178 
179  std::vector<int>* confPtr;
180  int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), confPtr);
181 
182  if (searchStatus) {
183  std::unique_ptr<std::vector<int> > newVector(new std::vector<int>);
184  confPtr = newVector.get();
185  dBuf->insert(chanKey.begin(), chanKey.end(), std::move(newVector));
186  }
187 
188  while (iter != iend) {
189  key = *iter++;
190  dataList.push_back(std::pair<DTCCBId, int>(ccbId, key));
191  confPtr->push_back(key);
192  }
193 
194  if (!searchStatus) {
195  return -1;
196  } else {
197  return 0;
198  }
199 }
200 
201 int DTCCBConfig::appendConfigKey(const DTChamberId& id, const std::vector<int>& confKey) {
202  return appendConfigKey(id.wheel(), id.station(), id.sector(), confKey);
203 }
204 
206 
208 
210  dBuf->clear();
211 
212  const_iterator iter = dataList.begin();
213  const_iterator iend = dataList.end();
214  std::vector<int> chanKey;
215  chanKey.reserve(3);
216  while (iter != iend) {
217  const DTCCBId& chan = iter->first;
218 
219  chanKey.clear();
220  chanKey.push_back(chan.wheelId);
221  chanKey.push_back(chan.stationId);
222  chanKey.push_back(chan.sectorId);
223  std::vector<int>* ccbConfPtr;
224  int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ccbConfPtr);
225 
226  if (searchStatus) {
227  std::unique_ptr<std::vector<int> > newVector(new std::vector<int>);
228  ccbConfPtr = newVector.get();
229  dBuf->insert(chanKey.begin(), chanKey.end(), std::move(newVector));
230  }
231  ccbConfPtr->push_back(iter->second);
232 
233  iter++;
234  }
235 }
std::vector< std::pair< DTCCBId, std::vector< int > > > ccb_config_map
Definition: DTCCBConfig.h:73
int wheelId
Definition: DTCCBConfig.h:42
std::vector< std::pair< DTCCBId, int > > dataList
Definition: DTCCBConfig.h:104
const std::string & version() const
access version
Definition: DTCCBConfig.cc:109
void setStamp(int s)
Definition: DTCCBConfig.cc:121
std::vector< DTConfigKey > fullConfigKey
Definition: DTCCBConfig.h:103
int sectorId
Definition: DTCCBConfig.h:44
std::vector< std::pair< DTCCBId, int > >::const_iterator const_iterator
Access methods to data.
Definition: DTCCBConfig.h:94
int stationId
Definition: DTCCBConfig.h:43
int stamp() const
Definition: DTCCBConfig.cc:56
std::string dataVersion
Definition: DTCCBConfig.h:102
virtual ~DTCCBConfig()
Definition: DTCCBConfig.cc:45
ccb_config_map configKeyMap() const
Definition: DTCCBConfig.cc:74
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
void initialize()
Definition: DTCCBConfig.cc:209
int find(ElementKey fKey, ElementKey lKey, typename DTBufferTreeTrait< Content >::outputTypeOfConstFind &cont) const
int insert(ElementKey fKey, ElementKey lKey, Content cont)
int configKey(int wheelId, int stationId, int sectorId, std::vector< int > &confKey) const
Definition: DTCCBConfig.cc:58
void clear()
reset content
Definition: DTCCBConfig.cc:113
edm::ConstRespectingPtr< DTBufferTreeUniquePtr > dBuf
Definition: DTCCBConfig.h:106
std::vector< DTConfigKey > fullKey() const
Definition: DTCCBConfig.cc:54
const_iterator end() const
Definition: DTCCBConfig.cc:207
const_iterator begin() const
Definition: DTCCBConfig.cc:205
int setConfigKey(int wheelId, int stationId, int sectorId, const std::vector< int > &confKey)
Definition: DTCCBConfig.cc:123
void setFullKey(const std::vector< DTConfigKey > &)
Definition: DTCCBConfig.cc:119
def move(src, dest)
Definition: eostools.py:511
int appendConfigKey(int wheelId, int stationId, int sectorId, const std::vector< int > &confKey)
Definition: DTCCBConfig.cc:168