5 #include <xercesc/dom/DOMNode.hpp>
6 #include <xercesc/dom/DOM.hpp>
7 #include <xercesc/parsers/XercesDOMParser.hpp>
9 #include <xercesc/util/XMLString.hpp>
10 #include <xercesc/sax/SAXException.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
34 : m_name(ps.getUntrackedParameter<
std::
string>(
"name",
"EcalSRPHandler")) {
51 std::ostringstream
ss;
54 unsigned long long max_since = 1;
57 max_since =
tagInfo().lastInterval.since;
60 Ref srp_db = lastPayload();
62 std::cout <<
" max_since : " << max_since <<
"\n retrieved last payload " << std::endl;
92 std::cout <<
"Retrieving DAQ status from OMDS DB ... " << std::endl;
94 std::cout <<
"Connection done" << std::endl;
97 std::cout <<
" Problem with OMDS: connection parameters " << m_sid <<
"/" << m_user << std::endl;
114 if (m_firstRun <= (
unsigned long)max_since) {
115 min_run = (
int)max_since + 1;
117 min_run = (
int)m_firstRun;
120 int max_run = (
int)m_lastRun;
122 std::cout <<
"min_run " << min_run <<
" max_run " << max_run << std::endl;
127 sprintf(
outfile,
"SRP_run%d.txt", min_run);
129 fout <<
" ORCOFF last run max_since : " << max_since << std::endl;
130 PrintPayload(*sref,
fout);
134 my_list =
econn->fetchRunListByLocation(my_runtag, min_run, max_run,
my_locdef);
136 std::vector<RunIOV> run_vec = my_list.
getRuns();
137 int num_runs = run_vec.size();
140 fout <<
" number of runs is : " << num_runs << std::endl;
142 unsigned long irun = 0;
144 int fe_conf_id_old = 0;
147 for (
int kr = 0; kr < num_runs; kr++) {
149 std::string geneTag = run_vec[kr].getRunTag().getGeneralTag();
150 if (geneTag !=
"GLOBAL") {
152 fout <<
"\n New run " << irun <<
" with tag " << geneTag <<
" giving up " << std::endl;
156 fout <<
"\n New run " << irun <<
" geneTag " << geneTag << std::endl;
159 std::map<EcalLogicID, RunConfigDat>
dataset;
162 int myconfig_version = 0;
163 std::map<EcalLogicID, RunConfigDat>::const_iterator it;
165 std::cout <<
"\n\n run " << irun <<
" strange number of dataset " <<
dataset.size() << std::endl;
167 fout <<
"\n\n run " << irun <<
" strange number of dataset " <<
dataset.size() <<
" giving up " << std::endl;
175 if (myconfig_tag.substr(0, 15) ==
"ZeroSuppression" || myconfig_tag.substr(0, 11) ==
"FullReadout" ||
176 myconfig_tag.substr(0, 11) ==
"AlmostEmpty") {
178 fout <<
" run " << irun <<
" tag " << myconfig_tag <<
" giving up " << std::endl;
183 typedef std::map<EcalLogicID, RunFEConfigDat>::const_iterator feConfIter;
184 std::map<EcalLogicID, RunFEConfigDat> feconfig;
185 econn->fetchDataSet(&feconfig, &run_vec[kr]);
186 if (feconfig.size() != 1) {
188 fout <<
"\n\n run " << irun <<
" strange number of FE config " << feconfig.size() <<
" giving up "
194 feConfIter
p = feconfig.begin();
200 fout <<
" run " << irun <<
" tag " << myconfig_tag <<
" version " << myconfig_version <<
" Fe config "
201 << fe_conf_id << std::endl;
203 if (myconfig_tag != m_i_tag || myconfig_version != m_i_version || fe_conf_id != fe_conf_id_old) {
205 fout <<
" run= " << irun <<
" different tag ... retrieving last config set from DB" << std::endl;
207 bool FromCLOB =
false;
214 od_run_info.
setTag(myconfig_tag);
218 econn->fetchConfigSet(&od_run_info);
219 int config_id = od_run_info.
getId();
222 seq.setEcalConfigId(config_id);
223 seq.setSequenceNumber(0);
225 int sequenceid =
seq.getSequenceId();
229 econn->fetchConfigSet(&ecal_cycle);
230 int cycle_id = ecal_cycle.
getId();
234 fout <<
" no SRP config for this run, give up " << std::endl;
240 fout <<
" cycleid " << cycle_id <<
" SRP id " << srp_id <<
" DCC id " << dcc_id << std::endl;
246 econn->fetchConfigSet(&srp);
254 for (std::string::iterator it = SRPClob.begin(); it < SRPClob.end(); it++)
257 std::ifstream
f(
"srp.txt");
259 throw cms::Exception(
"EcalSRPHandler") <<
" Failed to open file srp.txt";
261 fout <<
" Failed to open file srp.txt" << std::endl;
265 int rv = system(
"rm srp.txt");
266 if (m_debug && rv != 0)
267 fout <<
"rm srp.txt result code: " << rv <<
"\n";
277 econn->fetchConfigSet(&dcc);
280 fout <<
" DCC weightsMode " << weightsMode << std::endl
282 if (weightsMode ==
"CLOB") {
285 fout <<
" will read weights from DCC CLOB " << std::endl;
291 std::ostringstream osd;
295 for (std::string::iterator it = DCCClob.begin(); it < DCCClob.end(); it++)
298 importDccConfigFile(*sr,
fname, FromCLOB);
301 rv = system(
"rm dcc.txt");
302 if (m_debug && rv != 0)
303 fout <<
"rm dcc.txt result code: " << rv <<
"\n";
306 std::cout <<
"ERROR: This config does not exist: tag " << myconfig_tag <<
" version " << myconfig_version
309 fout <<
"ERROR: This config does not exist: tag " << myconfig_tag <<
" version " << myconfig_version
314 fout <<
" FromCLOB " << FromCLOB << std::endl;
318 myconfig.
setId(fe_conf_id);
319 econn->fetchConfigSet(&myconfig);
324 fout <<
" WEI_ID " << mywei << std::endl;
329 econn->fetchConfigSet(&samp);
339 std::vector<std::vector<float> > my_dccw =
weights.getWeight();
340 int imax = my_dccw.size();
342 fout <<
" weight size before check " << imax << std::endl;
344 bool WeightsChange =
false, WeightsChangeEB =
false, WeightsChangeEE =
false;
345 for (
int i = 1;
i < 61200;
i++)
346 for (
int ich = 0; ich < 6; ich++)
347 if (my_dccw[
i][ich] != my_dccw[0][ich])
348 WeightsChangeEB =
true;
350 fout <<
" WeightsChangeEB " << WeightsChangeEB << std::endl;
351 for (
int i = 61201;
i < 75848;
i++)
352 for (
int ich = 0; ich < 6; ich++)
353 if (my_dccw[
i][ich] != my_dccw[61200][ich])
354 WeightsChangeEE =
true;
356 fout <<
" WeightsChangeEE " << WeightsChangeEE << std::endl;
357 for (
int ich = 0; ich < 6; ich++)
358 if (my_dccw[0][ich] != my_dccw[61200][ich])
359 WeightsChange =
true;
361 fout <<
" WeightsChange " << WeightsChange << std::endl;
363 if (WeightsChangeEB || WeightsChangeEE)
365 else if (WeightsChange) {
366 std::vector<float> dccwRowEB, dccwRowEE;
367 for (
int ich = 0; ich < 6; ich++) {
368 dccwRowEB.push_back(my_dccw[0][ich]);
369 dccwRowEE.push_back(my_dccw[61200][ich]);
374 std::vector<float> dccwRow;
375 for (
int ich = 0; ich < 6; ich++) {
376 dccwRow.push_back(my_dccw[0][ich]);
381 for (
int ich = 0; ich < 6; ich++)
398 float def[] = {-1215, 20, 297, 356, 308, 232};
399 std::vector<float> dccw(
def,
def + 6);
401 fout <<
" default weights ";
402 for (
int i = 0;
i < 6;
i++) {
404 fout <<
" i " <<
i <<
" def " <<
def[
i] <<
" dccw " << dccw[
i] <<
" \n";
411 fout <<
" weight size " << imax <<
" normalized weights : " << std::endl;
412 for (
int i = 0;
i < imax;
i++)
413 for (
int ich = 0; ich < 6; ich++) {
415 if (m_debug &&
i == 0)
423 fout <<
" checking for change " << std::endl;
424 bool nochange =
true;
425 int imaxref, imaxnew;
432 if (imaxref != imaxnew) {
433 fout <<
" deltaEta_ size ref " << imaxref <<
" now " << imaxnew << std::endl;
435 for (
int i = 0;
i < imaxref;
i++) {
450 if (imaxref != imaxnew) {
451 fout <<
" deltaPhi size ref " << imaxref <<
" now " << imaxnew << std::endl;
453 for (
int i = 0;
i < imaxref;
i++) {
468 if (imaxref != imaxnew) {
469 fout <<
" ecalDccZs1stSample size ref " << imaxref <<
" now " << imaxnew << std::endl;
471 for (
int i = 0;
i < imaxref;
i++) {
493 if (imaxref != imaxnew) {
494 fout <<
" dccNormalizedWeights size ref " << imaxref <<
" now " << imaxnew << std::endl;
497 for (
int ich = 0; ich < 6; ich++) {
499 fout <<
" dccNormalizedWeights_[" <<
i <<
"][" << ich <<
"] ref "
513 if (imaxref != imaxnew) {
514 fout <<
" symetricZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
516 for (
int i = 0;
i < imaxref;
i++) {
531 if (imaxref != imaxnew) {
532 fout <<
" srpLowInterestChannelZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
534 for (
int i = 0;
i < imaxref;
i++) {
549 if (imaxref != imaxnew) {
550 fout <<
" srpHighInterestChannelZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
552 for (
int i = 0;
i < imaxref;
i++) {
565 for (
int i = 0;
i < 4;
i++) {
576 for (
int i = 0;
i < 108;
i++) {
588 for (
int i = 0;
i < 12;
i++) {
589 for (
int ich = 0; ich < 8; ich++) {
602 for (
int i = 0;
i < 54;
i++) {
613 for (
int i = 0;
i < 12;
i++) {
624 for (
int i = 0;
i < 12;
i++) {
625 for (
int ich = 0; ich < 68; ich++) {
638 for (
int i = 0;
i < 12;
i++) {
648 for (
int i = 0;
i < 12;
i++) {
657 for (
int i = 0;
i < 12;
i++) {
666 for (
int i = 0;
i < 12;
i++) {
675 for (
int i = 0;
i < 12;
i++) {
701 fout <<
" no change has been found " << std::endl;
702 std::ostringstream
ss;
703 ss <<
"Run=" << irun <<
"_SRPunchanged_" << std::endl;
704 m_userTextLog =
ss.str() +
";";
707 fout <<
" Change has been found !\n New payload :" << std::endl;
708 PrintPayload(*sr,
fout);
710 ChangePayload(*sref, *sr);
713 ChangePayload(*srp_pop, *sr);
714 m_to_transfer.push_back(std::make_pair(srp_pop, irun));
716 std::ostringstream
ss;
717 ss <<
"Run=" << irun <<
"_SRPchanged_" << std::endl;
718 m_userTextLog =
ss.str() +
";";
720 if (m_to_transfer.size() >= 20)
724 m_i_tag = myconfig_tag;
725 m_i_version = myconfig_version;
726 fe_conf_id_old = fe_conf_id;
739 XercesDOMParser*
parser =
new XercesDOMParser;
740 parser->setValidationScheme(XercesDOMParser::Val_Never);
741 parser->setDoNamespaces(
false);
742 parser->setDoSchema(
false);
746 DOMDocument* xmlDoc =
parser->getDocument();
748 std::cout <<
"importDccConfigFile Error parsing document" << std::endl;
751 DOMElement* element = xmlDoc->getDocumentElement();
756 int L1ZS[2] = {0, 0}, L2ZS[2] = {0, 0};
757 for (DOMNode* childNode = element->getFirstChild(); childNode; childNode = childNode->getNextSibling()) {
758 if (childNode->getNodeType() == DOMNode::ELEMENT_NODE) {
760 DOMElement*
child = static_cast<DOMElement*>(childNode);
761 DOMNamedNodeMap* attributes =
child->getAttributes();
762 unsigned int numAttributes = attributes->getLength();
763 for (
unsigned int j = 0;
j < numAttributes; ++
j) {
764 DOMNode* attributeNode = attributes->item(
j);
765 DOMAttr* attribute = static_cast<DOMAttr*>(attributeNode);
768 if (
info ==
"_scope") {
769 if (scope.substr(0, 2) ==
"EE")
776 for (DOMNode* subchildNode = childNode->getFirstChild(); subchildNode;
777 subchildNode = subchildNode->getNextSibling()) {
778 if (subchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
781 for (DOMNode* subsubchildNode = subchildNode->getFirstChild(); subsubchildNode;
782 subsubchildNode = subsubchildNode->getNextSibling()) {
783 if (subsubchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
785 if (subName ==
"L1ZSUPPRESSION")
787 if (subName ==
"L2ZSUPPRESSION")
789 if (subName ==
"FIRSTZSSAMPLE") {
795 if (subName ==
"CXTALWEIGHTS") {
796 std::vector<float> dcc(6);
798 for (
int iw = 0; iw < 6; iw++) {
821 fout <<
" deltaEta[" << imax <<
"] ";
822 for (
int i = 0;
i < imax;
i++) {
828 fout <<
" deltaPhi[" << imax <<
"] ";
829 for (
int i = 0;
i < imax;
i++) {
835 fout <<
" ecalDccZs1stSample[" << imax <<
"] ";
836 for (
int i = 0;
i < imax;
i++) {
845 fout <<
" dccNormalizedWeights" << std::endl;
847 fout <<
" Channel " <<
i;
854 fout <<
" symetricZS[" << imax <<
"] ";
855 for (
int i = 0;
i < imax;
i++) {
861 fout <<
" srpLowInterestChannelZS[" << imax <<
"] ";
862 for (
int i = 0;
i < imax;
i++) {
868 fout <<
" srpHighInterestChannelZS[" << imax <<
"] ";
869 for (
int i = 0;
i < imax;
i++) {
875 fout <<
" actions[" << imax <<
"] ";
876 for (
int i = 0;
i < imax;
i++) {
882 fout <<
" tccMasksFromConfig[" << imax <<
"] ";
883 for (
int i = 0;
i < imax;
i++) {
888 fout <<
" srpMasksFromConfig" << std::endl;
896 fout <<
" dccMasks[" << imax <<
"] ";
897 for (
int i = 0;
i < imax;
i++) {
903 fout <<
" srfMasks[" << imax <<
"] ";
904 for (
int i = 0;
i < imax;
i++) {
909 fout <<
"substitutionSrfs" << std::endl;
917 fout <<
" testerTccEmuSrpIds[" << imax <<
"] ";
918 for (
int i = 0;
i < imax;
i++) {
924 fout <<
" testerSrpEmuSrpIds[" << imax <<
"] ";
925 for (
int i = 0;
i < imax;
i++) {
931 fout <<
" testerDccTestSrpIds[" << imax <<
"] ";
932 for (
int i = 0;
i < imax;
i++) {
938 fout <<
" testerSrpTestSrpIds[" << imax <<
"] ";
939 for (
int i = 0;
i < imax;
i++) {
945 fout <<
" bxOffsets[" << imax <<
"] ";
946 for (
int i = 0;
i < imax;
i++) {