8 #define DB_WRITE_SUPPORT
30 #ifdef DB_WRITE_SUPPORT
33 #endif //DB_WRITE_SUPPORT defined
45 : dcc1stSample_(ps.getParameter<
int>(
"dcc1stSample")),
46 sampleToSkip_(ps.getParameter<
int>(
"sampleToSkip")),
47 nDccWeights_(ps.getParameter<
int>(
"nDccWeights")),
48 inputWeights_(ps.getParameter<
vector<double> >(
"inputWeights")),
49 mode_(ps.getParameter<
string>(
"mode")),
50 dccWeightsWithIntercalib_(ps.getParameter<
bool>(
"dccWeightsWithIntercalib")),
51 writeToDB_(ps.getParameter<
bool>(
"writeToDB")),
52 writeToAsciiFile_(ps.getParameter<
bool>(
"writeToAsciiFile")),
53 writeToRootFile_(ps.getParameter<
bool>(
"writeToRootFile")),
54 asciiOutputFileName_(ps.getParameter<
string>(
"asciiOutputFileName")),
55 rootOutputFileName_(ps.getParameter<
string>(
"rootOutputFileName")),
56 dbSid_(ps.getParameter<
string>(
"dbSid")),
57 dbUser_(ps.getParameter<
string>(
"dbUser")),
58 dbPassword_(ps.getUntrackedParameter<
string>(
"dbPassword",
"")),
59 dbTag_(ps.getParameter<
string>(
"dbTag")),
60 dbVersion_(ps.getParameter<
int>(
"dbVersion")),
61 sqlMode_(ps.getParameter<
bool>(
"sqlMode")),
62 calibMap_(emptyCalibMap_) {
63 if (
mode_ ==
"weightsFromConfig") {
66 throw cms::Exception(
"Config") <<
"Inconsistent configuration. 'nDccWeights' parameters indicated "
67 <<
nDccWeights_ <<
" weights while parameter 'inputWeights_' contains "
70 }
else if (
mode_ ==
"computeWeights") {
74 <<
"Valid values are: 'weightsFromConfig' and 'computeWeights'\n";
121 vector<DetId> detIds(ebDetIds.size() + eeDetIds.size());
122 copy(ebDetIds.begin(), ebDetIds.end(), detIds.begin());
123 copy(eeDetIds.begin(), eeDetIds.end(), detIds.begin() + ebDetIds.size());
125 vector<double> baseWeights(nw);
126 vector<double>
w(nw);
135 for (vector<DetId>::const_iterator it = detIds.begin(); it != detIds.end(); ++it) {
141 cout << __FILE__ <<
":" << __LINE__ <<
": ";
144 <<
" iphi = " << setw(4) << ((
EBDetId)(*it)).
iphi() <<
" ";
146 cout <<
"ix = " << setw(3) << ((
EEDetId)(*it)).ix()
147 <<
" iy = " << setw(3) << ((
EEDetId)(*it)).iy()
148 <<
" iz = " << setw(1) << ((
EEDetId)(*it)).iy() <<
" ";
151 <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": "
152 <<
"Got a detId which is neither tagged as ECAL Barrel "
153 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
156 cout <<
" -> binOfMax: " << binOfMax <<
"\n";
160 bool useDBShape =
true;
170 throw cms::Exception(
"EcalDccWeightBuilder") <<
"Bug found in " << __FILE__ <<
":" << __LINE__ <<
": "
171 <<
"Got a detId which is neither tagged as ECAL Barrel "
172 <<
"not ECAL endcap while looping on ECAL cell detIds\n";
175 if (
phase != prevPhase) {
183 for (
int i = 0;
i < nw; ++
i) {
184 w[
i] = baseWeights[
i];
191 cout << __FILE__ <<
":" << __LINE__ <<
": ";
196 cout <<
"ix = " << setw(3) << ((
EEDetId)(*it)).ix() <<
" iy = " << setw(3) << ((
EEDetId)(*it)).iy()
197 <<
" iz = " << setw(1) << ((
EEDetId)(*it)).iy() <<
" ";
199 cout <<
"DetId " << (uint32_t)(*it);
218 int nActualWeights = 0;
222 for (
int i = 0;
i < nWeights; ++
i) {
223 double t_ns =
tzero + (iFirst +
i) * 25;
224 double s = shape(t_ns);
233 for (
int i = 0;
i < nWeights; ++
i) {
257 bool changed =
false;
259 for (
unsigned i = 0;
i <
a.size(); ++
i)
265 for (
unsigned i = 0;
i <
a.size() - 1; ++
i) {
267 const int nextj =
s[
i + 1];
268 if ((decreasingOrder && (
a[
j] <
a[nextj])) || (!decreasingOrder && (
a[
j] >
a[nextj]))) {
284 const unsigned nw =
weights.size();
287 vector<double> dw(nw);
290 for (
unsigned i = 0;
i < nw; ++
i) {
314 int wsumSign = wsum > 0 ? 1 : -1;
315 int i = wsum > 0 ? 0 : (nw - 1);
317 W[iw[
i]] -= wsumSign;
320 if (i < 0 || i >= (
int)nw) {
322 for (
unsigned i = 0;
i < nw; ++
i) {
342 if (encodedWeights !=
nullptr)
343 encodedWeights->resize(nw);
344 for (
unsigned i = 0;
i < nw; ++
i) {
347 (*encodedWeights)[
i] = W[
i];
359 std::cout << (uint32_t)detId <<
" not found in EcalIntercalibConstantMap" << std::endl;
362 cout << __FILE__ <<
":" << __LINE__ <<
": ";
365 <<
" iphi = " << ((
EBDetId)detId).iphi();
368 <<
" iy = " << ((
EEDetId)detId).iy()
369 <<
" iz = " << ((
EEDetId)detId).zside();
371 cout <<
" coef = " << coef <<
"\n";
380 throw cms::Exception(
"Output") <<
"Failed to open file '" <<
fName <<
"'for writing DCC weights\n";
383 const char* comment =
sqlMode_ ?
"-- " :
"# ";
385 file << comment <<
"List of weights for amplitude estimation to be used in DCC for\n"
386 << comment <<
"zero suppresssion.\n\n";
388 file << comment <<
"Note: RU: trigger tower in EB, supercrystal in EE\n"
389 << comment <<
" xtl: crystal electronic channel id in RU, from 1 to 25\n\n"
390 << comment <<
" DetId SM FED RU xtl weights[0..5]...\n";
394 file <<
"variable recid number;\n"
395 "exec select COND2CONF_INFO_SQ.NextVal into :recid from DUAL;\n"
396 "insert into weights_info (rec_id,tag,version) values (:recid,'"
400 <<
"index of first sample used in the weighting sum\n"
405 " insert into dcc_weightsample_dat (rec_id, logic_id, sample_id, \n"
407 " values(:recid,fedid,"
417 file <<
"\n" << comment <<
"list of weights per crystal channel\n";
421 const DetId& detId = it->first;
434 file <<
"-- detId " << detId.
rawId() <<
"\n"
435 <<
"insert into dcc_weights_dat(rec_id,sm_id,fed_id,"
437 "weight_0,weight_1,weight_2,weight_3,weight_4,weight_5) \n"
441 const vector<int>&
weights = it->second;
444 file << delim << setw(2) << smId;
446 file << delim << setw(2) << ruId;
447 file << delim << setw(2) << xtalId;
449 for (
unsigned i = 0;
i <
weights.size(); ++
i) {
457 throw cms::Exception(
"Output") <<
"Error while writing DCC weights to '" <<
fName <<
"' file.";
463 if (
file.IsZombie()) {
464 throw cms::Exception(
"Output") <<
"Failed to open file '" <<
fName <<
"'for writing DCC weights\n";
466 TTree
t(
"dccWeights",
"Weights for DCC ZS filter");
467 const int nWeightMax = 20;
486 "weights[n_weights]/I");
489 buf.detId = it->first.rawId();
490 buf.n_weights = it->second.size();
495 if (
buf.n_weights > nWeightMax) {
496 throw cms::Exception(
"EcalDccWeight") <<
"Number of weights (" <<
buf.n_weights <<
") for DetId " <<
buf.detId
497 <<
" exceeded maximum limit (" << nWeightMax <<
") of root output format. ";
499 copy(it->second.begin(), it->second.end(),
buf.weights);
506 #ifndef DB_WRITE_SUPPORT
508 throw cms::Exception(
"DccWeight") <<
"Code was compiled without support for writing dcc weights directly "
509 " into configuration DB. Configurable writeToDB must be set to False. "
510 "sqlMode can be used to produce an SQL*PLUS script to fill the DB\n";
512 #else //DB_WRITE_SUPPORT defined
514 cout <<
"going to write to the online DB " <<
dbSid_ <<
" user " <<
dbUser_ << endl;
519 cout <<
"Making connection..." << flush;
520 const string& filePrefix =
string(
"file:");
532 cout <<
"Done." << endl;
533 }
catch (runtime_error&
e) {
534 cerr <<
e.what() << endl;
541 cout <<
"Inserting in DB..." << endl;
543 econn->insertConfigSet(&weight_info);
545 int weight_id = weight_info.
getId();
546 cout <<
"WeightInfo inserted with ID " << weight_id << endl;
548 vector<ODWeightsDat> datadel;
551 vector<ODWeightsSamplesDat> dcc1stSampleConfig(
nDccs);
553 dcc1stSampleConfig[
i].setId(weight_id);
554 dcc1stSampleConfig[
i].setFedId(601 +
i);
556 dcc1stSampleConfig[
i].setWeightNumber(-1);
558 econn->insertConfigDataArraySet(dcc1stSampleConfig, &weight_info);
562 const DetId& detId = it->first;
563 const unsigned nWeights = 6;
566 for (
unsigned i = 0;
i <
weights.size(); ++
i) {
569 const vector<int>&
w = it->second;
574 one_dat.
setId(weight_id);
596 datadel.push_back(one_dat);
598 econn->insertConfigDataArraySet(datadel, &weight_info);
599 std::cout <<
" .. done insertion in DB " << endl;
601 cout <<
"closed DB connection ... done" << endl;
603 #endif //DB_WRITE_SUPPORT not defined
614 smId = 10000 -
fedId;
617 const int stripLength = 5;
618 xtalId = (elecId.
stripId() - 1) * stripLength + elecId.
xtalId();
621 cout << __FILE__ <<
":" << __LINE__ <<
": FED ID "
624 cout << __FILE__ <<
":" << __LINE__ <<
": SM logical ID "
627 cout << __FILE__ <<
":" << __LINE__ <<
": RU ID (TT or SC): "
630 cout << __FILE__ <<
":" << __LINE__ <<
": strip:"
633 cout << __FILE__ <<
":" << __LINE__ <<
": xtal in strip: "
634 << elecId.
xtalId() <<
"\n";
636 cout << __FILE__ <<
":" << __LINE__ <<
": xtalId in RU: "