8 m_name(ps.getUntrackedParameter<
std::
string>(
"name",
"RPCEMapSourceHandler")),
9 m_dummy(ps.getUntrackedParameter<
int>(
"WriteDummy",0)),
10 m_validate(ps.getUntrackedParameter<
int>(
"Validate",0)),
11 m_connect(ps.getUntrackedParameter<
std::
string>(
"OnlineConn",
"")),
12 m_authpath(ps.getUntrackedParameter<
std::
string>(
"OnlineAuthPath",
"."))
30 std::cout<<
" Validation was requested, so will check present contents"<<std::endl;
32 <<
", last object valid since " 40 tm *
ptm = gmtime(&rawtime);
42 strftime(buffer,20,
"%d/%m/%Y_%H:%M:%S",ptm);
57 if (!difference)
std::cout<<
"No changes - will not write anything!!!"<<std::endl;
59 std::cout<<
"Will write new object to offline DB!!!"<<std::endl;
69 std::cout <<
"RPCEMapConfigSourceHandler: connecting to " << connect <<
"..." << std::flush;
86 coral::AttributeList conditionData;
88 std::cout << std::endl <<
"RPCEMapSourceHandler: start to build RPC e-Map..." << std::flush << std::endl << std::endl;
92 coral::IQuery* query1 = schema.newQuery();
93 query1->addToTableList(
"DCCBOARD" );
94 query1->addToOutputList(
"DCCBOARD.DCCBOARDID",
"DCCBOARDID");
95 query1->addToOutputList(
"DCCBOARD.FEDNUMBER",
"FEDNUMBER");
96 query1->addToOrderList(
"FEDNUMBER");
97 condition =
"DCCBOARD.DCCBOARDID>0";
98 query1->setCondition( condition, conditionData );
100 coral::ICursor& cursor1 = query1->execute();
102 std::pair<int,int> tmp_tbl;
103 std::vector< std::pair<int,int> > theDAQ;
104 while ( cursor1.next() ) {
106 const coral::AttributeList& row = cursor1.currentRow();
107 tmp_tbl.first=row[
"DCCBOARDID"].data<
long long>();
108 tmp_tbl.second=row[
"FEDNUMBER"].data<
long long>();
109 theDAQ.push_back(tmp_tbl);
113 for(
unsigned int iFED=0;iFED<theDAQ.size();iFED++) {
114 thisDcc.
theId=theDAQ[iFED].second;
115 std::vector<std::pair<int,int> > theTB;
118 coral::IQuery* query2 = schema.newQuery();
119 query2->addToTableList(
"TRIGGERBOARD" );
120 query2->addToOutputList(
"TRIGGERBOARD.TRIGGERBOARDID",
"TRIGGERBOARDID");
121 query2->addToOutputList(
"TRIGGERBOARD.DCCINPUTCHANNELNUM",
"DCCCHANNELNUM");
122 query2->addToOrderList(
"DCCCHANNELNUM");
123 condition =
"TRIGGERBOARD.DCCBOARD_DCCBOARDID="+
IntToString(theDAQ[iFED].
first);
124 query2->setCondition( condition, conditionData );
125 coral::ICursor& cursor2 = query2->execute();
127 while ( cursor2.next() ) {
130 const coral::AttributeList& row = cursor2.currentRow();
131 tmp_tbl.first=row[
"TRIGGERBOARDID"].data<
long long>();
132 tmp_tbl.second=row[
"DCCCHANNELNUM"].data<
long long>();
133 theTB.push_back(tmp_tbl);
136 for(
unsigned int iTB=0;iTB<theTB.size();iTB++) {
137 thisTB.
theNum=theTB[iTB].second;
138 std::vector<std::pair<int,int> > theLink;
141 coral::IQuery* query3 = schema.newQuery();
142 query3->addToTableList(
"BOARDBOARDCONN");
143 query3->addToOutputList(
"BOARDBOARDCONN.BOARD_BOARDID",
"BOARDID");
144 query3->addToOutputList(
"BOARDBOARDCONN.COLLECTORBOARDINPUTNUM",
"TBINPUTNUM");
145 query3->addToOrderList(
"TBINPUTNUM");
146 condition =
"BOARDBOARDCONN.BOARD_COLLECTORBOARDID="+
IntToString(theTB[iTB].first);
147 query3->setCondition( condition, conditionData );
148 coral::ICursor& cursor3 = query3->execute();
150 while (cursor3.next()) {
152 const coral::AttributeList& row = cursor3.currentRow();
153 tmp_tbl.first=row[
"BOARDID"].data<
long long>();
154 tmp_tbl.second=row[
"TBINPUTNUM"].data<
long long>();
155 theLink.push_back(tmp_tbl);
158 for(
unsigned int iLink=0;iLink<theLink.size();iLink++) {
159 int boardId=theLink[iLink].first;
161 std::vector<std::pair<int,std::string> > theLB;
162 std::pair<int,std::string> tmpLB;
165 coral::IQuery* query4 = schema.newQuery();
166 query4->addToTableList(
"BOARD");
167 query4->addToOutputList(
"BOARD.NAME",
"NAME");
168 condition =
"BOARD.BOARDID="+
IntToString(theLink[iLink].first);
169 query4->setCondition( condition, conditionData );
170 coral::ICursor& cursor4 = query4->execute();
172 while (cursor4.next()) {
174 const coral::AttributeList& row = cursor4.currentRow();
175 tmpLB.first=theLink[iLink].first;
177 theLB.push_back(tmpLB);
181 coral::IQuery* query5 = schema.newQuery();
182 query5->addToTableList(
"LINKBOARD");
183 query5->addToTableList(
"BOARD");
184 query5->addToOutputList(
"LINKBOARD.LINKBOARDID",
"LINKBOARDID");
185 query5->addToOutputList(
"BOARD.NAME",
"NAME");
186 query5->addToOrderList(
"LINKBOARDID");
187 condition =
"LINKBOARD.MASTERID="+
IntToString(theLink[iLink].first)+
" AND BOARD.BOARDID=LINKBOARD.LINKBOARDID AND LINKBOARD.MASTERID<>LINKBOARD.LINKBOARDID";
188 query5->setCondition( condition, conditionData );
189 coral::ICursor& cursor5 = query5->execute();
190 while (cursor5.next()) {
192 const coral::AttributeList& row = cursor5.currentRow();
193 tmpLB.first=row[
"LINKBOARDID"].data<
long long>();
195 theLB.push_back(tmpLB);
198 for(
unsigned int iLB=0; iLB<theLB.size(); iLB++) {
199 thisLB.
theMaster = (theLB[iLB].first==boardId);
202 int slength = theName.length();
204 int wheel=atoi((theName.substr(6,1)).c_str());
207 int num3=atoi((theName.substr(slength-6,1)).c_str());
209 bool itsS1to9=(theName.substr(slength-11,1)==
"S");
217 int sector=atoi((theName.substr(slength-n1,n2)).c_str());
220 std::string char4Val[9]={
"0",
"1",
"2",
"3",
"A",
"B",
"C",
"D",
"E"};
221 for (
int i=0;
i<2;
i++)
if (char1==char1Val[
i]) n1=i+1;
222 for (
int i=0; i<3; i++)
if (char2==char2Val[i]) n2=
i;
223 for (
int i=0; i<9; i++)
if (char4==char4Val[i]) n3=
i;
224 thisLB.
theCode=n3+num3*10+n2*100+n1*1000+wheel*10000+sector*100000;
226 std::vector<FEBStruct> theFEB;
229 coral::IQuery* query6 = schema.newQuery();
230 query6->addToTableList(
"FEBLOCATION");
231 query6->addToTableList(
"FEBCONNECTOR");
232 query6->addToOutputList(
"FEBLOCATION.FEBLOCATIONID",
"FEBLOCATIONID");
233 query6->addToOutputList(
"FEBLOCATION.CL_CHAMBERLOCATIONID",
"CHAMBERLOCATIONID");
234 query6->addToOutputList(
"FEBCONNECTOR.FEBCONNECTORID",
"FEBCONNECTORID");
235 query6->addToOutputList(
"FEBLOCATION.FEBLOCALETAPARTITION",
"LOCALETAPART");
236 query6->addToOutputList(
"FEBLOCATION.POSINLOCALETAPARTITION",
"POSINLOCALETAPART");
237 query6->addToOutputList(
"FEBLOCATION.FEBCMSETAPARTITION",
"CMSETAPART");
238 query6->addToOutputList(
"FEBLOCATION.POSINCMSETAPARTITION",
"POSINCMSETAPART");
239 query6->addToOutputList(
"FEBCONNECTOR.LINKBOARDINPUTNUM",
"LINKBOARDINPUTNUM");
240 query6->addToOrderList(
"FEBLOCATIONID");
241 query6->addToOrderList(
"FEBCONNECTORID");
242 condition =
"FEBLOCATION.LB_LINKBOARDID="+
IntToString(theLB[iLB].first)+
" AND FEBLOCATION.FEBLOCATIONID=FEBCONNECTOR.FL_FEBLOCATIONID";
243 query6->setCondition( condition, conditionData );
244 coral::ICursor& cursor6 = query6->execute();
246 while (cursor6.next()) {
248 const coral::AttributeList& row = cursor6.currentRow();
249 tmpFEB.
febId=row[
"FEBLOCATIONID"].data<
long long>();
250 tmpFEB.
chamberId=row[
"CHAMBERLOCATIONID"].data<
long long>();
251 tmpFEB.
connectorId=row[
"FEBCONNECTORID"].data<
long long>();
256 tmpFEB.
lbInputNum=row[
"LINKBOARDINPUTNUM"].data<
short>();
257 theFEB.push_back(tmpFEB);
260 for(
unsigned int iFEB=0; iFEB<theFEB.size(); iFEB++) {
262 std::string localEtaVal[6]={
"Forward",
"Central",
"Backward",
"A",
"B",
"C"};
263 char localEtaPartition=0;
264 for (
int i=0; i<6; i++)
if (temp==localEtaVal[i]) localEtaPartition=i+1;
265 char positionInLocalEtaPartition=theFEB[iFEB].posInLocalEtaPart;
266 temp=theFEB[iFEB].cmsEtaPart;
267 std::string cmsEtaVal[6]={
"1",
"2",
"3",
"A",
"B",
"C"};
268 char cmsEtaPartition=0;
269 for (
int i=0; i<6; i++)
if (temp==cmsEtaVal[i]) cmsEtaPartition=i+1;
270 char positionInCmsEtaPartition=theFEB[iFEB].posInCmsEtaPart;
271 thisFeb.
thePartition=positionInLocalEtaPartition+10*localEtaPartition+100*positionInCmsEtaPartition+1000*cmsEtaPartition;
274 coral::IQuery* query7 = schema.newQuery();
275 query7->addToTableList(
"CHAMBERLOCATION");
276 query7->addToOutputList(
"CHAMBERLOCATION.DISKORWHEEL",
"DISKORWHEEL");
277 query7->addToOutputList(
"CHAMBERLOCATION.LAYER",
"LAYER");
278 query7->addToOutputList(
"CHAMBERLOCATION.SECTOR",
"SECTOR");
279 query7->addToOutputList(
"CHAMBERLOCATION.SUBSECTOR",
"SUBSECTOR");
280 query7->addToOutputList(
"CHAMBERLOCATION.CHAMBERLOCATIONNAME",
"NAME");
281 query7->addToOutputList(
"CHAMBERLOCATION.FEBZORNT",
"FEBZORNT");
282 query7->addToOutputList(
"CHAMBERLOCATION.FEBRADORNT",
"FEBRADORNT");
283 query7->addToOutputList(
"CHAMBERLOCATION.BARRELORENDCAP",
"BARRELORENDCAP");
284 condition =
"CHAMBERLOCATION.CHAMBERLOCATIONID="+
IntToString(theFEB[iFEB].chamberId);
285 query7->setCondition( condition, conditionData );
286 coral::ICursor& cursor7 = query7->execute();
287 while (cursor7.next()) {
288 const coral::AttributeList& row = cursor7.currentRow();
289 char diskOrWheel=row[
"DISKORWHEEL"].data<
short>()+3;
290 char layer=row[
"LAYER"].data<
short>();
291 int sector=row[
"SECTOR"].data<
short>();
304 for (
int i=0; i<5; i++)
if (temp==subsVal[i]) subsector=
i;
307 if (temp==
"+z") febZOrnt=1;
311 for (
int i=0; i<3; i++)
if (temp==febZRVal[i]) febZRadOrnt=
i;
313 char barrelOrEndcap=0;
314 if (temp==
"Barrel") barrelOrEndcap=1;
315 thisFeb.
theChamber=sector+100*subsector+1000*febZRadOrnt+5000*febZOrnt+10000*diskOrWheel+100000*layer+1000000*barrelOrEndcap;
319 coral::IQuery* query8 = schema.newQuery();
320 query8->addToTableList(
"CHAMBERSTRIP");
321 query8->addToOutputList(
"CHAMBERSTRIP.CABLECHANNELNUM",
"CABLECHANNELNUM");
322 query8->addToOutputList(
"CHAMBERSTRIP.CHAMBERSTRIPNUMBER",
"CHAMBERSTRIPNUM");
324 query8->addToOrderList(
"CABLECHANNELNUM");
325 condition =
"CHAMBERSTRIP.FC_FEBCONNECTORID="+
IntToString(theFEB[iFEB].connectorId);
326 query8->setCondition( condition, conditionData );
327 coral::ICursor& cursor8 = query8->execute();
331 int firstChamberStrip=0;
333 int lastChamberStrip=0;
335 while (cursor8.next()) {
336 const coral::AttributeList& row = cursor8.currentRow();
337 lastChamberStrip=row[
"CHAMBERSTRIPNUM"].data<
int>();
338 lastPin=row[
"CABLECHANNELNUM"].data<
short>();
340 firstChamberStrip=lastChamberStrip;
347 if (firstPin == 1 && lastPin == nstrips)
349 else if (firstPin == 2 && lastPin == nstrips+1)
351 else if (firstPin == 3 && lastPin == nstrips+2)
353 else if (firstPin == 2 && lastPin == nstrips+2)
356 {
std::cout<<
" Unknown algo : "<<firstPin<<
" "<<lastPin<<std::endl; }
357 if ((lastPin-firstPin)*(lastChamberStrip-firstChamberStrip) < 0) algo=algo+4;
358 thisFeb.
theAlgo=algo+100*firstChamberStrip+10000*nstrips;
374 std::cout << std::endl <<
"Building RPC e-Map done!" << std::flush << std::endl << std::endl;
378 const Ref& map1 = _map1;
381 std::vector<const DccSpec *> dccs1 = oldmap1->
dccList();
382 std::vector<const DccSpec *> dccs2 = oldmap2->
dccList();
383 if(dccs1.size()!=dccs2.size()) {
388 if(dccRange1.first!=dccRange2.first) {
391 if(dccRange1.second!=dccRange2.second) {
394 typedef std::vector<const DccSpec *>::const_iterator IDCC;
395 IDCC idcc2 = dccs2.begin();
396 for (IDCC idcc1 = dccs1.begin(); idcc1 != dccs1.end(); idcc1++) {
397 int dccNo = (**idcc1).id();
399 if ((**idcc2).id()!=dccNo) {
402 if ((**idcc2).print(4)!=dccContents) {
void getNewObjects() override
int theTriggerBoardInputNumber
edm::Ref< Container > Ref
void ConnectOnlineDB(std::string connect, std::string authPath)
std::string IntToString(int num)
std::vector< tbItem > theTBs
void start(bool readOnly=true)
void DisconnectOnlineDB()
std::vector< const DccSpec * > dccList() const
all FEDs in map
Transaction & transaction()
OldContainer m_to_transfer
int theLinkBoardNumInLink
RPCEMapSourceHandler(const edm::ParameterSet &ps)
~RPCEMapSourceHandler() override
cond::ValidityInterval lastInterval
unsigned long long Time_t
std::vector< dccItem > theDccs
std::vector< febItem > theFebs
coral::ISchema & nominalSchema()
Session createSession(const std::string &connectionString, bool writeCapable=false)
std::pair< int, int > dccNumberRange() const
Range of FED IDs in map (min and max id)
int Compare2EMaps(const Ref &map1, RPCEMap *map2)
std::vector< linkItem > theLinks
cond::persistency::Session session
edm::Handle< T > connect(const T *&ptr, edm::EDGetTokenT< T > token, const edm::Event &evt)
std::vector< lbItem > theLBs
cond::Time_t currentTime() const
RPCReadOutMapping const * convert() const
void setAuthenticationPath(const std::string &p)
cond::TagInfo_t const & tagInfo() const