CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1RPCHwConfigSourceHandler.cc
Go to the documentation of this file.
5 
7  m_name(ps.getUntrackedParameter<std::string>("name","L1RPCHwConfigSourceHandler")),
8  m_dummy(ps.getUntrackedParameter<int>("WriteDummy",0)),
9  m_validate(ps.getUntrackedParameter<int>("Validate",0)),
10  m_disableCrates(ps.getUntrackedParameter<std::vector<int> >("DisabledCrates")),
11  m_disableTowers(ps.getUntrackedParameter<std::vector<int> >("DisabledTowers")),
12  m_connect(ps.getUntrackedParameter<std::string>("OnlineConn","")),
13  m_authpath(ps.getUntrackedParameter<std::string>("OnlineAuthPath","."))
14 {
15 }
16 
18 {
19 }
20 
22 {
23 
24  std::cout << "L1RPCHwConfigSourceHandler: L1RPCHwConfigSourceHandler::getNewObjects begins\n";
26 
27 // std::cerr << "------- " << m_name
28 // << " - > getNewObjects" << std::endl;
29 // std::cerr<<"Got offlineInfo, tag: "<<std::endl;
30 // std::cerr << tagInfo().name << " , last object valid from "
31 // << tagInfo().lastInterval.first << " to "
32 // << tagInfo().lastInterval.second << " , token is "
33 // << tagInfo().token << " and this is the payload "
34 // << tagInfo().lastPayloadToken << std::endl;
35 
36 // first check what is already there in offline DB
37  Ref payload;
38 
39  if(m_validate==1) {
40  std::cout<<" Validation was requested, so will check present contents"<<std::endl;
41  std::cout<<"Name of tag : "<<tagInfo().name << ", tag size : " << tagInfo().size
42  << ", last object valid since "
43  << tagInfo().lastInterval.first << std::endl;
44  payload = lastPayload();
45  } else {
46  std::cout << "L1RPCHwConfigSourceHandler: no validation requested"<<std::endl;
47  }
48 
49 // now construct new object from online DB
50  disabledDevs = new L1RPCHwConfig();
51  if (m_dummy==1) {
52  std::vector<int>::iterator crIt = m_disableCrates.begin();
53  for (; crIt!=m_disableCrates.end(); ++crIt){
54  disabledDevs->enableCrate(*crIt,false);
55  }
56  std::vector<int>::iterator twIt = m_disableTowers.begin();
57  for (; twIt!=m_disableTowers.end(); ++twIt){
58  disabledDevs->enableTower(*twIt,false);
59  }
60  } else {
61  ConnectOnlineDB(m_connect,m_authpath);
62  readHwConfig1();
63  DisconnectOnlineDB();
64  }
65 
66  cond::Time_t snc=mydbservice->currentTime();
67 
68 // look for recent changes
69  int difference=1;
70  if (m_validate==1) difference=Compare2Configs(payload,disabledDevs);
71  if (!difference) std::cout<<"No changes - will not write anything!!!"<<std::endl;
72  if (difference==1) {
73  std::cout<<"Will write new object to offline DB!!!"<<std::endl;
74  m_to_transfer.push_back(std::make_pair((L1RPCHwConfig*)disabledDevs,snc+1));
75  }
76 
77  std::cout << "L1RPCHwConfigSourceHandler: L1RPCHwConfigSourceHandler::getNewObjects ends\n";
78 }
79 
81 {
82  std::cout << "L1RPCHwConfigSourceHandler: connecting to " << connect << "..." << std::flush;
83  connection = new cond::DbConnection() ;
84 // session->configuration().setAuthenticationMethod(cond::XML);
85  connection->configuration().setAuthenticationPath( authPath ) ;
86  connection->configure();
87  session = new cond::DbSession(connection->createSession());
88  session->open(connect,true) ;
89  std::cout << "Done." << std::endl;
90 }
91 
93 {
94  connection->close() ;
95  delete connection ;
96  session->close();
97  delete session ;
98 }
99 
101 {
102  session->transaction().start( true );
103  coral::ISchema& schema = session->nominalSchema();
104  std::string condition="";
105  coral::AttributeList conditionData;
106  std::cout << std::endl <<"L1RPCHwConfigSourceHandler: start to build L1RPC Hw Config..." << std::flush << std::endl << std::endl;
107 
108 // get disabled crates and translate into towers/sectors/segments
109  coral::IQuery* query1 = schema.newQuery();
110  query1->addToTableList( "CRATEDISABLED" );
111  query1->addToTableList( "CRATE" );
112  query1->addToTableList( "BOARD" );
113  query1->addToTableList( "TRIGGERBOARD" );
114  query1->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
115  query1->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
116  query1->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
117  query1->addToOrderList( "TOWERTO" );
118  query1->addToOrderList( "SECTOR" );
119  condition = "CRATE.CRATEID=CRATEDISABLED.CRATE_CRATEID AND BOARD.CRATE_CRATEID=CRATE.CRATEID AND BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID AND CRATE.TYPE='TRIGGERCRATE'";
120  query1->setCondition( condition, conditionData );
121  coral::ICursor& cursor1 = query1->execute();
122  while ( cursor1.next() ) {
123 // cursor1.currentRow().toOutputStream( std::cout ) << std::endl;
124  const coral::AttributeList& row = cursor1.currentRow();
125  int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
126  int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
127  int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
128  for (int iTower=first; iTower<=last; iTower++) {
129  for (int jSegment=0; jSegment<12; jSegment++) {
130  disabledDevs->enablePAC(iTower,sector,jSegment,false);
131  }
132  }
133  }
134  delete query1;
135 
136 // get disabled triggerboards and translate into towers/sectors/segments
137  coral::IQuery* query2 = schema.newQuery();
138  query2->addToTableList( "BOARDDISABLED" );
139  query2->addToTableList( "BOARD" );
140  query2->addToTableList( "TRIGGERBOARD" );
141  query2->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
142  query2->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
143  query2->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
144  query2->addToOrderList( "TOWERTO" );
145  query2->addToOrderList( "SECTOR" );
146  condition = "BOARD.BOARDID=BOARDDISABLED.BOARD_BOARDID AND BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID";
147  query2->setCondition( condition, conditionData );
148  coral::ICursor& cursor2 = query2->execute();
149  while ( cursor2.next() ) {
150 // cursor2.currentRow().toOutputStream( std::cout ) << std::endl;
151  const coral::AttributeList& row = cursor2.currentRow();
152  int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
153  int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
154  int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
155  for (int iTower=first; iTower<=last; iTower++) {
156  for (int jSegment=0; jSegment<12; jSegment++) {
157  disabledDevs->enablePAC(iTower,sector,jSegment,false);
158  }
159  }
160  }
161  delete query2;
162 
163 // get disabled links - this is not usable here
164 /*
165  coral::IQuery* query3 = schema.newQuery();
166  query3->addToTableList( "LINKDISABLED" );
167  query3->addToTableList( "LINKCONN" );
168  query3->addToTableList( "TRIGGERBOARD" );
169  query3->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
170  query3->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
171  query3->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
172  query3->addToOutputList("LINKCONN.TRIGGERBOARDINPUTNUM","TBINPUTNUM");
173  query3->addToOrderList( "TOWERTO" );
174  query3->addToOrderList( "SECTOR" );
175  query3->addToOrderList( "TBINPUTNUM" );
176  condition = "LINKCONN.LINKCONNID=LINKDISABLED.LINK_LINKCONNID AND LINKCONN.TB_TRIGGERBOARDID=TRIGGERBOARD.TRIGGERBOARDID";
177  query3->setCondition( condition, conditionData );
178  coral::ICursor& cursor3 = query3->execute();
179  while ( cursor3.next() ) {
180 // cursor3.currentRow().toOutputStream( std::cout ) << std::endl;
181  const coral::AttributeList& row = cursor3.currentRow();
182  int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
183  int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
184  int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
185  for (int iTower=first; iTower<=last; iTower++) {
186  for (int jSegment=0; jSegment<12; jSegment++) {
187  disabledDevs->enablePAC(iTower,sector,jSegment,false);
188  }
189  }
190  }
191  delete query3;*/
192 
193 // get disabled chips and translate into towers/sectors
194 // for the moment assume that chip position 8 corresponds to lowest tower number
195 // and so on, ignoring bogus chip at position 11 if given TB operates 3 towers.
196  coral::IQuery* query4 = schema.newQuery();
197  query4->addToTableList( "CHIPDISABLED" );
198  query4->addToTableList( "CHIP" );
199  query4->addToTableList( "BOARD" );
200  query4->addToTableList( "TRIGGERBOARD" );
201  query4->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
202  query4->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
203  query4->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
204  query4->addToOutputList("CHIP.POSITION","POSITION");
205  query4->addToOrderList( "TOWERTO" );
206  query4->addToOrderList( "SECTOR" );
207  query4->addToOrderList( "POSITION" );
208  condition = "CHIP.CHIPID=CHIPDISABLED.CHIP_CHIPID AND CHIP.BOARD_BOARDID=BOARD.BOARDID AND BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID AND CHIP.TYPE='PAC'";
209  query4->setCondition( condition, conditionData );
210  coral::ICursor& cursor4 = query4->execute();
211  while ( cursor4.next() ) {
212 // cursor4.currentRow().toOutputStream( std::cout ) << std::endl;
213  const coral::AttributeList& row = cursor4.currentRow();
214  int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
215  int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
216  int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
217  int chipPos=row["POSITION"].data<short>();
218  int tower=first+chipPos-8;
219  if (tower<=last) {
220  for (int jSegment=0; jSegment<12; jSegment++) {
221  disabledDevs->enablePAC(tower,sector,jSegment,false);
222  }
223  }
224  }
225  delete query4;
226 
227 }
228 
230 {
231  Ref set1 = _set1;
232  std::cout<<"Size of new object is : "<<std::flush;
233  std::cout<<set2->size()<<std::endl;
234  std::cout<<"Size of ref object is : "<<std::flush;
235  std::cout<<set1->size()<<std::endl;
236 
237  if (set1->size() != set2->size()) {
238  std::cout<<" Number of disabled devices changed "<<std::endl;
239  return 1;
240  }
241  for (int tower=-16; tower<17; tower++) {
242  for (int sector=0; sector<12; sector++) {
243  for (int segment=0; segment<12; segment++)
244  if (set1->isActive(tower,sector,segment) != set2->isActive(tower,sector,segment)) {
245  std::cout<<" Configuration changed for tower "<<tower<<", sector "<<sector<<", segment "<<segment<<std::endl;
246  return 1;
247  }
248  }
249  }
250  return 0;
251 }
int Compare2Configs(const Ref &set1, L1RPCHwConfig *set2)
bool isActive(int tower, int sector, int segment) const
Definition: L1RPCHwConfig.h:79
unsigned long long Time_t
Definition: Time.h:16
int size() const
Definition: L1RPCHwConfig.h:99
void ConnectOnlineDB(std::string connect, std::string authPath)
tuple cout
Definition: gather_cfg.py:121
L1RPCHwConfigSourceHandler(const edm::ParameterSet &ps)