CMS 3D CMS Logo

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