CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTPGParameters.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2010/01/20 18:20:08 $
5  * $Revision: 1.3 $
6  * \author Paolo Ronchese INFN Padova
7  *
8  */
9 
10 //----------------------
11 // This Class' Header --
12 //----------------------
14 
15 //-------------------------------
16 // Collaborating Class Headers --
17 //-------------------------------
18 //#include "CondFormats/DTObjects/interface/DTDataBuffer.h"
19 
20 //---------------
21 // C++ Headers --
22 //---------------
23 #include <iostream>
24 #include <sstream>
25 
26 //-------------------
27 // Initializations --
28 //-------------------
29 
30 
31 //----------------
32 // Constructors --
33 //----------------
35  dataVersion( " " ),
36  nsPerCount( 25.0 / 32.0 ),
37  clockLength( 32 ) {
38  dataList.reserve( 250 );
39  dBuf = 0;
40 }
41 
42 
44  dataVersion( version ),
45  nsPerCount( 25.0 / 32.0 ),
46  clockLength( 32 ) {
47  dataList.reserve( 250 );
48  dBuf = 0;
49 }
50 
51 
53  wheelId( 0 ),
54  stationId( 0 ),
55  sectorId( 0 ) {
56 }
57 
58 
60  nClock( 0 ),
61  tPhase( 0.0 ) {
62 }
63 
64 
65 //--------------
66 // Destructor --
67 //--------------
69 // DTDataBuffer<int,int>::dropBuffer( mapName() );
70  delete dBuf;
71 }
72 
73 
75 }
76 
77 
79 }
80 
81 
82 //--------------
83 // Operations --
84 //--------------
85 int DTTPGParameters::get( int wheelId,
86  int stationId,
87  int sectorId,
88  int& nc,
89  float& ph,
90  DTTimeUnits::type unit ) const {
91 
92  nc = 0;
93  ph = 0.0;
94 
95 // std::string mName = mapName();
96 // DTBufferTree<int,int>* dBuf =
97 // DTDataBuffer<int,int>::findBuffer( mName );
98 // if ( dBuf == 0 ) {
99 // cacheMap();
100 // dBuf =
101 // DTDataBuffer<int,int>::findBuffer( mName );
102 // }
103  if ( dBuf == 0 ) cacheMap();
104 
105  std::vector<int> chanKey;
106  chanKey.reserve(3);
107  chanKey.push_back( wheelId );
108  chanKey.push_back( stationId );
109  chanKey.push_back( sectorId );
110  int ientry;
111  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
112  if ( !searchStatus ) {
113  const DTTPGParametersData& data( dataList[ientry].second );
114  nc = data.nClock;
115  ph = data.tPhase;
116  if ( unit == DTTimeUnits::ns ) {
117  ph *= nsPerCount;
118  }
119  }
120 
121  return searchStatus;
122 
123 }
124 
125 
127  int& nc,
128  float& ph,
129  DTTimeUnits::type unit ) const {
130  return get( id.wheel(),
131  id.station(),
132  id.sector(),
133  nc, ph, unit );
134 }
135 
136 
137 float DTTPGParameters::totalTime( int wheelId,
138  int stationId,
139  int sectorId,
140  DTTimeUnits::type unit ) const {
141  int cl = 0;
142  float ph = 0.0;
143  get( wheelId, stationId, sectorId, cl, ph, unit );
144  if ( unit == DTTimeUnits::ns ) return ( cl * clock() * nsPerCount ) + ph;
145  else return ( cl * clock() ) + ph;
146 }
147 
148 
150  DTTimeUnits::type unit ) const {
151  return totalTime( id.wheel(),
152  id.station(),
153  id.sector(),
154  unit );
155 }
156 
157 
159  return clockLength;
160 }
161 
162 
163 float DTTPGParameters::unit() const {
164  return nsPerCount;
165 }
166 
167 
168 const
170  return dataVersion;
171 }
172 
173 
175  return dataVersion;
176 }
177 
178 
180 // DTDataBuffer<int,int>::dropBuffer( mapName() );
181  delete dBuf;
182  dBuf = 0;
183  dataList.clear();
184  return;
185 }
186 
187 
188 int DTTPGParameters::set( int wheelId,
189  int stationId,
190  int sectorId,
191  int nc,
192  float ph,
194 
195  if ( unit == DTTimeUnits::ns ) {
196  ph /= nsPerCount;
197  }
198 
199 // std::string mName = mapName();
200 // DTBufferTree<int,int>* dBuf =
201 // DTDataBuffer<int,int>::findBuffer( mName );
202 // if ( dBuf == 0 ) {
203 // cacheMap();
204 // dBuf =
205 // DTDataBuffer<int,int>::findBuffer( mName );
206 // }
207  if ( dBuf == 0 ) cacheMap();
208  std::vector<int> chanKey;
209  chanKey.reserve(3);
210  chanKey.push_back( wheelId );
211  chanKey.push_back( stationId );
212  chanKey.push_back( sectorId );
213  int ientry;
214  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
215 
216  if ( !searchStatus ) {
218  data.nClock = nc;
219  data.tPhase = ph;
220  return -1;
221  }
222  else {
224  key. wheelId = wheelId;
225  key.stationId = stationId;
226  key. sectorId = sectorId;
228  data.nClock = nc;
229  data.tPhase = ph;
230  ientry = dataList.size();
231  dataList.push_back( std::pair<DTTPGParametersId,
232  DTTPGParametersData>( key, data ) );
233  dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
234  return 0;
235  }
236 
237  return 99;
238 
239 }
240 
241 
243  int nc,
244  float ph,
246  return set( id.wheel(),
247  id.station(),
248  id.sector(),
249  nc, ph, unit );
250 }
251 
252 
253 void DTTPGParameters::setClock( int clock ) {
254  clockLength = clock;
255 }
256 
257 
259  nsPerCount = unit;
260 }
261 
262 
264  return dataList.begin();
265 }
266 
267 
269  return dataList.end();
270 }
271 
272 
274  std::stringstream name;
275  name << dataVersion << "_map_TTPG" << this;
276  return name.str();
277 }
278 
279 
281 
282 // std::string mName = mapName();
283 // DTBufferTree<int,int>* dBuf =
284 // DTDataBuffer<int,int>::openBuffer( mName );
285  DTBufferTree<int,int>** pBuf;
286  pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
287  *pBuf = new DTBufferTree<int,int>;
288 
289  int entryNum = 0;
290  int entryMax = dataList.size();
291  std::vector<int> chanKey;
292  chanKey.reserve(3);
293  while ( entryNum < entryMax ) {
294 
295  const DTTPGParametersId& chan = dataList[entryNum].first;
296 
297  chanKey.clear();
298  chanKey.push_back( chan. wheelId );
299  chanKey.push_back( chan.stationId );
300  chanKey.push_back( chan. sectorId );
301  dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
302 
303  }
304 
305  return;
306 
307 }
308 
std::vector< std::pair< DTTPGParametersId, DTTPGParametersData > >::const_iterator const_iterator
Access methods to data.
void clear()
reset content
void setUnit(float unit)
int clock() const
const std::string & version() const
access version
const_iterator begin() const
int set(int wheelId, int stationId, int sectorId, int nc, float ph, DTTimeUnits::type unit)
int insert(ElementKey fKey, ElementKey lKey, const Content &cont)
void setClock(int clock)
U second(std::pair< T, U > const &p)
string unit
Definition: csvLumiCalc.py:46
const_iterator end() const
DTBufferTree< int, int > * dBuf
float totalTime(int wheelId, int stationId, int sectorId, DTTimeUnits::type unit) const
std::string dataVersion
int find(ElementKey fKey, ElementKey lKey, Content &cont)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::string mapName() const
list key
Definition: combine.py:13
float unit() const
std::vector< std::pair< DTTPGParametersId, DTTPGParametersData > > dataList
int get(int wheelId, int stationId, int sectorId, int &nc, float &ph, DTTimeUnits::type unit) const
get content
void cacheMap() const
read and store full content