90 coral::AttributeList conditionData;
92 std::cout << std::endl <<
"RPCEMapSourceHandler: start to build RPC e-Map..." << std::flush << std::endl << std::endl;
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 );
104 coral::ICursor& cursor1 = query1->execute();
106 std::pair<int,int> tmp_tbl;
107 std::vector< std::pair<int,int> > theDAQ;
108 while ( cursor1.next() ) {
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);
117 for(
unsigned int iFED=0;iFED<theDAQ.size();iFED++) {
118 thisDcc.
theId=theDAQ[iFED].second;
119 std::vector<std::pair<int,int> > theTB;
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();
131 while ( cursor2.next() ) {
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);
140 for(
unsigned int iTB=0;iTB<theTB.size();iTB++) {
141 thisTB.
theNum=theTB[iTB].second;
142 std::vector<std::pair<int,int> > theLink;
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();
154 while (cursor3.next()) {
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);
162 for(
unsigned int iLink=0;iLink<theLink.size();iLink++) {
163 int boardId=theLink[iLink].first;
165 std::vector<std::pair<int,std::string> > theLB;
166 std::pair<int,std::string> tmpLB;
169 coral::IQuery* query4 = schema.newQuery();
170 query4->addToTableList(
"BOARD");
171 query4->addToOutputList(
"BOARD.NAME",
"NAME");
173 query4->setCondition( condition, conditionData );
174 coral::ICursor& cursor4 = query4->execute();
176 while (cursor4.next()) {
178 const coral::AttributeList& row = cursor4.currentRow();
179 tmpLB.first=theLink[iLink].first;
181 theLB.push_back(tmpLB);
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()) {
196 const coral::AttributeList& row = cursor5.currentRow();
197 tmpLB.first=row[
"LINKBOARDID"].data<
long long>();
199 theLB.push_back(tmpLB);
202 for(
unsigned int iLB=0; iLB<theLB.size(); iLB++) {
203 thisLB.
theMaster = (theLB[iLB].first==boardId);
206 int slength = theName.length();
208 int wheel=atoi((theName.substr(6,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");
221 int sector=atoi((theName.substr(slength-n1,n2)).c_str());
224 std::string char4Val[9]={
"0",
"1",
"2",
"3",
"A",
"B",
"C",
"D",
"E"};
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;
230 std::vector<FEBStruct> theFEB;
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();
250 while (cursor6.next()) {
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);
264 for(
unsigned int iFEB=0; iFEB<theFEB.size(); iFEB++) {
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;
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>();
308 for (
int i=0; i<5; i++)
if (temp==subsVal[i]) subsector=
i;
311 if (temp==
"+z") febZOrnt=1;
315 for (
int i=0; i<3; i++)
if (temp==febZRVal[i]) febZRadOrnt=
i;
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;
323 coral::IQuery* query8 = schema.newQuery();
324 query8->addToTableList(
"CHAMBERSTRIP");
325 query8->addToOutputList(
"CHAMBERSTRIP.CABLECHANNELNUM",
"CABLECHANNELNUM");
326 query8->addToOutputList(
"CHAMBERSTRIP.CHAMBERSTRIPNUMBER",
"CHAMBERSTRIPNUM");
328 query8->addToOrderList(
"CABLECHANNELNUM");
329 condition =
"CHAMBERSTRIP.FC_FEBCONNECTORID="+
IntToString(theFEB[iFEB].connectorId);
330 query8->setCondition( condition, conditionData );
331 coral::ICursor& cursor8 = query8->execute();
335 int firstChamberStrip=0;
337 int lastChamberStrip=0;
339 while (cursor8.next()) {
340 const coral::AttributeList& row = cursor8.currentRow();
341 lastChamberStrip=row[
"CHAMBERSTRIPNUM"].data<
int>();
342 lastPin=row[
"CABLECHANNELNUM"].data<
short>();
344 firstChamberStrip=lastChamberStrip;
351 if (firstPin == 1 && lastPin == nstrips)
353 else if (firstPin == 2 && lastPin == nstrips+1)
355 else if (firstPin == 3 && lastPin == nstrips+2)
357 else if (firstPin == 2 && lastPin == nstrips+2)
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;
378 std::cout << std::endl <<
"Building RPC e-Map done!" << std::flush << std::endl << std::endl;
int theTriggerBoardInputNumber
std::string IntToString(int num)
DbTransaction & transaction()
std::vector< tbItem > theTBs
int theLinkBoardNumInLink
int start(bool readOnly=false)
start transaction
std::vector< dccItem > theDccs
std::vector< febItem > theFebs
std::vector< linkItem > theLinks
cond::DbSession * session
coral::ISchema & nominalSchema()
std::vector< lbItem > theLBs