CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCEMapSourceHandler.cc
Go to the documentation of this file.
5 
7  m_name(ps.getUntrackedParameter<std::string>("name","RPCEMapSourceHandler")),
8  m_dummy(ps.getUntrackedParameter<int>("WriteDummy",0)),
9  m_validate(ps.getUntrackedParameter<int>("Validate",0)),
10  m_connect(ps.getUntrackedParameter<std::string>("OnlineConn","")),
11  m_authpath(ps.getUntrackedParameter<std::string>("OnlineAuthPath","."))
12 {
13 }
14 
16 {
17 }
18 
20 {
21 
22 // std::cout << "RPCEMapSourceHandler: RPCEMapSourceHandler::getNewObjects begins\n";
23 
25 
26 // first check what is already there in offline DB
27  Ref payload;
28  if(m_validate==1 && tagInfo().size>0) {
29  std::cout<<" Validation was requested, so will check present contents"<<std::endl;
30  std::cout<<"Name of tag : "<<tagInfo().name << ", tag size : " << tagInfo().size
31  << ", last object valid since "
32  << tagInfo().lastInterval.first << std::endl;
33  payload = lastPayload();
34  }
35 
36 // now construct new cabling map from online DB
37  time_t rawtime;
38  time(&rawtime); //time since January 1, 1970
39  tm * ptm = gmtime(&rawtime);//GMT time
40  char buffer[20];
41  strftime(buffer,20,"%d/%m/%Y_%H:%M:%S",ptm);
42  std::string eMap_version=(std::string)buffer;
43 
44  eMap = new RPCEMap(eMap_version);
45  if (m_dummy==0) {
46  ConnectOnlineDB(m_connect,m_authpath);
47  readEMap1();
48  DisconnectOnlineDB();
49  }
50 
51  cond::Time_t snc=mydbservice->currentTime();
52 
53 // look for recent changes
54  int difference=1;
55  if (m_validate==1) difference=Compare2EMaps(payload,eMap);
56  if (!difference) std::cout<<"No changes - will not write anything!!!"<<std::endl;
57  if (difference==1) {
58  std::cout<<"Will write new object to offline DB!!!"<<std::endl;
59  m_to_transfer.push_back(std::make_pair((RPCEMap*)eMap,snc));
60  }
61 
62 // std::cout << "RPCEMapSourceHandler: RPCEMapSourceHandler::getNewObjects ends\n";
63 }
64 
66 {
67  std::cout << "RPCEMapConfigSourceHandler: connecting to " << connect << "..." << std::flush;
68  connection = new cond::DbConnection() ;
69 // session->configuration().setAuthenticationMethod(cond::XML);
70  connection->configuration().setAuthenticationPath( authPath ) ;
71  connection->configure();
72  session = new cond::DbSession(connection->createSession());
73  session->open(connect,true) ;
74  std::cout << "Done." << std::endl;
75 }
76 
78 {
79  connection->close() ;
80  delete connection ;
81  session->close();
82  delete session ;
83 }
84 
86 {
87  session->transaction().start( true );
88  coral::ISchema& schema = session->nominalSchema();
89  std::string condition="";
90  coral::AttributeList conditionData;
91 
92  std::cout << std::endl <<"RPCEMapSourceHandler: start to build RPC e-Map..." << std::flush << std::endl << std::endl;
93 
94  // Get FEDs
95  RPCEMap::dccItem thisDcc;
96  coral::IQuery* query1 = schema.newQuery();
97  query1->addToTableList( "DCCBOARD" );
98  query1->addToOutputList("DCCBOARD.DCCBOARDID","DCCBOARDID");
99  query1->addToOutputList("DCCBOARD.FEDNUMBER","FEDNUMBER");
100  query1->addToOrderList("FEDNUMBER");
101  condition = "DCCBOARD.DCCBOARDID>0";
102  query1->setCondition( condition, conditionData );
103 // std::cout<<"Getting DCCBOARD...";
104  coral::ICursor& cursor1 = query1->execute();
105  std::cout<<"OK"<<std::endl;
106  std::pair<int,int> tmp_tbl;
107  std::vector< std::pair<int,int> > theDAQ;
108  while ( cursor1.next() ) {
109 // cursor1.currentRow().toOutputStream( std::cout ) << std::endl;
110  const coral::AttributeList& row = cursor1.currentRow();
111  tmp_tbl.first=row["DCCBOARDID"].data<long long>();
112  tmp_tbl.second=row["FEDNUMBER"].data<long long>();
113  theDAQ.push_back(tmp_tbl);
114  }
115  delete query1;
116 
117  for(unsigned int iFED=0;iFED<theDAQ.size();iFED++) {
118  thisDcc.theId=theDAQ[iFED].second;
119  std::vector<std::pair<int,int> > theTB;
120 // get TBs
121  RPCEMap::tbItem thisTB;
122  coral::IQuery* query2 = schema.newQuery();
123  query2->addToTableList( "TRIGGERBOARD" );
124  query2->addToOutputList("TRIGGERBOARD.TRIGGERBOARDID","TRIGGERBOARDID");
125  query2->addToOutputList("TRIGGERBOARD.DCCINPUTCHANNELNUM","DCCCHANNELNUM");
126  query2->addToOrderList("DCCCHANNELNUM");
127  condition = "TRIGGERBOARD.DCCBOARD_DCCBOARDID="+IntToString(theDAQ[iFED].first);
128  query2->setCondition( condition, conditionData );
129  coral::ICursor& cursor2 = query2->execute();
130  int ntbs=0;
131  while ( cursor2.next() ) {
132  ntbs++;
133 // cursor2.currentRow().toOutputStream( std::cout ) << std::endl;
134  const coral::AttributeList& row = cursor2.currentRow();
135  tmp_tbl.first=row["TRIGGERBOARDID"].data<long long>();
136  tmp_tbl.second=row["DCCCHANNELNUM"].data<long long>();
137  theTB.push_back(tmp_tbl);
138  }
139  delete query2;
140  for(unsigned int iTB=0;iTB<theTB.size();iTB++) {
141  thisTB.theNum=theTB[iTB].second;
142  std::vector<std::pair<int,int> > theLink;
143 // get links
144  RPCEMap::linkItem thisLink;
145  coral::IQuery* query3 = schema.newQuery();
146  query3->addToTableList("BOARDBOARDCONN");
147  query3->addToOutputList("BOARDBOARDCONN.BOARD_BOARDID","BOARDID");
148  query3->addToOutputList("BOARDBOARDCONN.COLLECTORBOARDINPUTNUM","TBINPUTNUM");
149  query3->addToOrderList("TBINPUTNUM");
150  condition = "BOARDBOARDCONN.BOARD_COLLECTORBOARDID="+IntToString(theTB[iTB].first);
151  query3->setCondition( condition, conditionData );
152  coral::ICursor& cursor3 = query3->execute();
153  int nlinks=0;
154  while (cursor3.next()) {
155  nlinks++;
156  const coral::AttributeList& row = cursor3.currentRow();
157  tmp_tbl.first=row["BOARDID"].data<long long>();
158  tmp_tbl.second=row["TBINPUTNUM"].data<long long>();
159  theLink.push_back(tmp_tbl);
160  }
161  delete query3;
162  for(unsigned int iLink=0;iLink<theLink.size();iLink++) {
163  int boardId=theLink[iLink].first;
164  thisLink.theTriggerBoardInputNumber=theLink[iLink].second;
165  std::vector<std::pair<int,std::string> > theLB;
166  std::pair<int,std::string> tmpLB;
167  // Get master LBs first...
168  RPCEMap::lbItem thisLB;
169  coral::IQuery* query4 = schema.newQuery();
170  query4->addToTableList("BOARD");
171  query4->addToOutputList("BOARD.NAME","NAME");
172  condition = "BOARD.BOARDID="+IntToString(theLink[iLink].first);
173  query4->setCondition( condition, conditionData );
174  coral::ICursor& cursor4 = query4->execute();
175  int nlbs=0;
176  while (cursor4.next()) {
177  nlbs++;
178  const coral::AttributeList& row = cursor4.currentRow();
179  tmpLB.first=theLink[iLink].first;
180  tmpLB.second=row["NAME"].data<std::string>();
181  theLB.push_back(tmpLB);
182  }
183  delete query4;
184  // then slaves
185  coral::IQuery* query5 = schema.newQuery();
186  query5->addToTableList("LINKBOARD");
187  query5->addToTableList("BOARD");
188  query5->addToOutputList("LINKBOARD.LINKBOARDID","LINKBOARDID");
189  query5->addToOutputList("BOARD.NAME","NAME");
190  query5->addToOrderList("LINKBOARDID");
191  condition = "LINKBOARD.MASTERID="+IntToString(theLink[iLink].first)+" AND BOARD.BOARDID=LINKBOARD.LINKBOARDID AND LINKBOARD.MASTERID<>LINKBOARD.LINKBOARDID";
192  query5->setCondition( condition, conditionData );
193  coral::ICursor& cursor5 = query5->execute();
194  while (cursor5.next()) {
195  nlbs++;
196  const coral::AttributeList& row = cursor5.currentRow();
197  tmpLB.first=row["LINKBOARDID"].data<long long>();
198  tmpLB.second=row["NAME"].data<std::string>();
199  theLB.push_back(tmpLB);
200  }
201  delete query5;
202  for(unsigned int iLB=0; iLB<theLB.size(); iLB++) {
203  thisLB.theMaster = (theLB[iLB].first==boardId);
204 // extract all relevant information from BOARD.NAME
205  std::string theName = theLB[iLB].second;
206  int slength = theName.length();
207  thisLB.theLinkBoardNumInLink=atoi((theName.substr(slength-1,1)).c_str());
208  int wheel=atoi((theName.substr(6,1)).c_str());
209  std::string char1=(theName.substr(4,1)).c_str();
210  std::string char2=(theName.substr(slength-7,1)).c_str();
211  int num3=atoi((theName.substr(slength-6,1)).c_str());
212  std::string char4=(theName.substr(slength-5,1)).c_str();
213  bool itsS1to9=(theName.substr(slength-11,1)=="S");
214  int n1=10;
215  int n2=1;
216  int n3=0;
217  if (!itsS1to9) {
218  n1=11;
219  n2=2;
220  }
221  int sector=atoi((theName.substr(slength-n1,n2)).c_str());
222  std::string char1Val[2]={"B","E"}; // 1,2
223  std::string char2Val[3]={"N","M","P"}; // 0,1,2
224  std::string char4Val[9]={"0","1","2","3","A","B","C","D","E"}; // 0,...,8
225  for (int i=0; i<2; i++) if (char1==char1Val[i]) n1=i+1;
226  for (int i=0; i<3; i++) if (char2==char2Val[i]) n2=i;
227  for (int i=0; i<9; i++) if (char4==char4Val[i]) n3=i;
228  thisLB.theCode=n3+num3*10+n2*100+n1*1000+wheel*10000+sector*100000;
229  FEBStruct tmpFEB;
230  std::vector<FEBStruct> theFEB;
231 // get FEBs
232  RPCEMap::febItem thisFeb;
233  coral::IQuery* query6 = schema.newQuery();
234  query6->addToTableList("FEBLOCATION");
235  query6->addToTableList("FEBCONNECTOR");
236  query6->addToOutputList("FEBLOCATION.FEBLOCATIONID","FEBLOCATIONID");
237  query6->addToOutputList("FEBLOCATION.CL_CHAMBERLOCATIONID","CHAMBERLOCATIONID");
238  query6->addToOutputList("FEBCONNECTOR.FEBCONNECTORID","FEBCONNECTORID");
239  query6->addToOutputList("FEBLOCATION.FEBLOCALETAPARTITION","LOCALETAPART");
240  query6->addToOutputList("FEBLOCATION.POSINLOCALETAPARTITION","POSINLOCALETAPART");
241  query6->addToOutputList("FEBLOCATION.FEBCMSETAPARTITION","CMSETAPART");
242  query6->addToOutputList("FEBLOCATION.POSINCMSETAPARTITION","POSINCMSETAPART");
243  query6->addToOutputList("FEBCONNECTOR.LINKBOARDINPUTNUM","LINKBOARDINPUTNUM");
244  query6->addToOrderList("FEBLOCATIONID");
245  query6->addToOrderList("FEBCONNECTORID");
246  condition = "FEBLOCATION.LB_LINKBOARDID="+IntToString(theLB[iLB].first)+" AND FEBLOCATION.FEBLOCATIONID=FEBCONNECTOR.FL_FEBLOCATIONID";
247  query6->setCondition( condition, conditionData );
248  coral::ICursor& cursor6 = query6->execute();
249  int nfebs=0;
250  while (cursor6.next()) {
251  nfebs++;
252  const coral::AttributeList& row = cursor6.currentRow();
253  tmpFEB.febId=row["FEBLOCATIONID"].data<long long>();
254  tmpFEB.chamberId=row["CHAMBERLOCATIONID"].data<long long>();
255  tmpFEB.connectorId=row["FEBCONNECTORID"].data<long long>();
256  tmpFEB.localEtaPart=row["LOCALETAPART"].data<std::string>();
257  tmpFEB.posInLocalEtaPart=row["POSINLOCALETAPART"].data<short>();
258  tmpFEB.cmsEtaPart=row["CMSETAPART"].data<std::string>();
259  tmpFEB.posInCmsEtaPart=row["POSINCMSETAPART"].data<short>();
260  tmpFEB.lbInputNum=row["LINKBOARDINPUTNUM"].data<short>();
261  theFEB.push_back(tmpFEB);
262  }
263  delete query6;
264  for(unsigned int iFEB=0; iFEB<theFEB.size(); iFEB++) {
265  std::string temp=theFEB[iFEB].localEtaPart;
266  std::string localEtaVal[6]={"Forward","Central","Backward","A","B","C"};
267  char localEtaPartition=0;
268  for (int i=0; i<6; i++) if (temp==localEtaVal[i]) localEtaPartition=i+1;
269  char positionInLocalEtaPartition=theFEB[iFEB].posInLocalEtaPart;
270  temp=theFEB[iFEB].cmsEtaPart;
271  std::string cmsEtaVal[6]={"1","2","3","A","B","C"};
272  char cmsEtaPartition=0;
273  for (int i=0; i<6; i++) if (temp==cmsEtaVal[i]) cmsEtaPartition=i+1;
274  char positionInCmsEtaPartition=theFEB[iFEB].posInCmsEtaPart;
275  thisFeb.thePartition=positionInLocalEtaPartition+10*localEtaPartition+100*positionInCmsEtaPartition+1000*cmsEtaPartition;
276  thisFeb.theLinkBoardInputNum=theFEB[iFEB].lbInputNum;
277  // Get chamber
278  coral::IQuery* query7 = schema.newQuery();
279  query7->addToTableList("CHAMBERLOCATION");
280  query7->addToOutputList("CHAMBERLOCATION.DISKORWHEEL","DISKORWHEEL");
281  query7->addToOutputList("CHAMBERLOCATION.LAYER","LAYER");
282  query7->addToOutputList("CHAMBERLOCATION.SECTOR","SECTOR");
283  query7->addToOutputList("CHAMBERLOCATION.SUBSECTOR","SUBSECTOR");
284  query7->addToOutputList("CHAMBERLOCATION.CHAMBERLOCATIONNAME","NAME");
285  query7->addToOutputList("CHAMBERLOCATION.FEBZORNT","FEBZORNT");
286  query7->addToOutputList("CHAMBERLOCATION.FEBRADORNT","FEBRADORNT");
287  query7->addToOutputList("CHAMBERLOCATION.BARRELORENDCAP","BARRELORENDCAP");
288  condition = "CHAMBERLOCATION.CHAMBERLOCATIONID="+IntToString(theFEB[iFEB].chamberId);
289  query7->setCondition( condition, conditionData );
290  coral::ICursor& cursor7 = query7->execute();
291  while (cursor7.next()) {
292  const coral::AttributeList& row = cursor7.currentRow();
293  char diskOrWheel=row["DISKORWHEEL"].data<short>()+3;
294  char layer=row["LAYER"].data<short>();
295  int sector=row["SECTOR"].data<short>();
296  temp=row["SUBSECTOR"].data<std::string>();
297 // TEMPORARY TO CORRECT A LITTLE BUG IN OMDS
298 // std::string chname=row["NAME"].data<std::string>();
299 // if (layer==6 && (sector==9 || sector==11)) {
300 // if (temp=="+") {
301 // temp="";
302 // std::cout<<"Changed subsector + to null for "<<chname<<std::endl;
303 // }
304 // }
305 
306  std::string subsVal[5]={"--","-","","+","++"};
307  char subsector=0;
308  for (int i=0; i<5; i++) if (temp==subsVal[i]) subsector=i;
309  temp=row["FEBZORNT"].data<std::string>();
310  char febZOrnt=0;
311  if (temp=="+z") febZOrnt=1;
312  temp=row["FEBRADORNT"].data<std::string>();
313  char febZRadOrnt=0;
314  std::string febZRVal[3]={"","IN","OUT"};
315  for (int i=0; i<3; i++) if (temp==febZRVal[i]) febZRadOrnt=i;
316  temp=row["BARRELORENDCAP"].data<std::string>();
317  char barrelOrEndcap=0;
318  if (temp=="Barrel") barrelOrEndcap=1;
319  thisFeb.theChamber=sector+100*subsector+1000*febZRadOrnt+5000*febZOrnt+10000*diskOrWheel+100000*layer+1000000*barrelOrEndcap;
320  }
321  delete query7;
322  // Get Strips
323  coral::IQuery* query8 = schema.newQuery();
324  query8->addToTableList("CHAMBERSTRIP");
325  query8->addToOutputList("CHAMBERSTRIP.CABLECHANNELNUM","CABLECHANNELNUM");
326  query8->addToOutputList("CHAMBERSTRIP.CHAMBERSTRIPNUMBER","CHAMBERSTRIPNUM");
327 // query8->addToOutputList("CHAMBERSTRIP.CMSSTRIPNUMBER","CMSSTRIPNUM");
328  query8->addToOrderList("CABLECHANNELNUM");
329  condition = "CHAMBERSTRIP.FC_FEBCONNECTORID="+IntToString(theFEB[iFEB].connectorId);
330  query8->setCondition( condition, conditionData );
331  coral::ICursor& cursor8 = query8->execute();
332 // NEW: do not store all the strip information as goes, only the minimum data needed to
333 // reproduce it later on
334  int nstrips=0;
335  int firstChamberStrip=0;
336  int firstPin=0;
337  int lastChamberStrip=0;
338  int lastPin=0;
339  while (cursor8.next()) {
340  const coral::AttributeList& row = cursor8.currentRow();
341  lastChamberStrip=row["CHAMBERSTRIPNUM"].data<int>();
342  lastPin=row["CABLECHANNELNUM"].data<short>();
343  if (nstrips==0) {
344  firstChamberStrip=lastChamberStrip;
345  firstPin=lastPin;
346  }
347  nstrips++;
348  }
349  delete query8;
350  int algo = -1;
351  if (firstPin == 1 && lastPin == nstrips)
352  { algo = 1; }
353  else if (firstPin == 2 && lastPin == nstrips+1)
354  { algo = 2; }
355  else if (firstPin == 3 && lastPin == nstrips+2)
356  { algo = 3; }
357  else if (firstPin == 2 && lastPin == nstrips+2)
358  { algo = 0;}
359  else
360  { std::cout<<" Unknown algo : "<<firstPin<<" "<<lastPin<<std::endl; }
361  if ((lastPin-firstPin)*(lastChamberStrip-firstChamberStrip) < 0) algo=algo+4;
362  thisFeb.theAlgo=algo+100*firstChamberStrip+10000*nstrips;
363  eMap->theFebs.push_back(thisFeb);
364  }
365  thisLB.nFebs=nfebs;
366  eMap->theLBs.push_back(thisLB);
367  }
368  thisLink.nLBs=nlbs;
369  eMap->theLinks.push_back(thisLink);
370  }
371  thisTB.nLinks=nlinks;
372  eMap->theTBs.push_back(thisTB);
373  }
374  thisDcc.nTBs=ntbs;
375  std::cout<<"DCC added"<<std::endl;
376  eMap->theDccs.push_back(thisDcc);
377  }
378  std::cout << std::endl <<"Building RPC e-Map done!" << std::flush << std::endl << std::endl;
379 }
380 
382  RPCReadOutMapping* oldmap1 = map1->convert();
383  RPCReadOutMapping* oldmap2 = map2->convert();
384  std::vector<const DccSpec *> dccs1 = oldmap1->dccList();
385  std::vector<const DccSpec *> dccs2 = oldmap2->dccList();
386  if(dccs1.size()!=dccs2.size()) {
387  return 1;
388  }
389  std::pair<int,int> dccRange1 = oldmap1->dccNumberRange();
390  std::pair<int,int> dccRange2 = oldmap2->dccNumberRange();
391  if(dccRange1.first!=dccRange2.first) {
392  return 1;
393  }
394  if(dccRange1.second!=dccRange2.second) {
395  return 1;
396  }
397  typedef std::vector<const DccSpec *>::const_iterator IDCC;
398  IDCC idcc2 = dccs2.begin();
399  for (IDCC idcc1 = dccs1.begin(); idcc1 != dccs1.end(); idcc1++) {
400  int dccNo = (**idcc1).id();
401  std::string dccContents = (**idcc1).print(4);
402  if ((**idcc2).id()!=dccNo) {
403  return 1;
404  }
405  if ((**idcc2).print(4)!=dccContents) {
406  return 1;
407  }
408  idcc2++;
409  }
410  return 0;
411 }
int i
Definition: DBlmapReader.cc:9
int Compare2EMaps(Ref map1, RPCEMap *map2)
int theTriggerBoardInputNumber
Definition: RPCEMap.h:31
int theLinkBoardInputNum
Definition: RPCEMap.h:41
void ConnectOnlineDB(std::string connect, std::string authPath)
RPCReadOutMapping * convert() const
Definition: RPCEMap.h:53
std::vector< const DccSpec * > dccList() const
all FEDs in map
int theLinkBoardNumInLink
Definition: RPCEMap.h:36
RPCEMapSourceHandler(const edm::ParameterSet &ps)
unsigned long long Time_t
Definition: Time.h:16
std::pair< int, int > dccNumberRange() const
Range of FED IDs in map (min and max id)
bool first
Definition: L1TdeRCT.cc:79
int thePartition
Definition: RPCEMap.h:42
bool theMaster
Definition: RPCEMap.h:35
tuple connect
process.AlignmentProducer.algoConfig.uvarFile = &#39;.
Definition: align_tpl.py:66
tuple cout
Definition: gather_cfg.py:41
tuple size
Write out results.