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>
30 using namespace XERCES_CPP_NAMESPACE;
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;
160 econn->fetchDataSet(&dataset, &run_vec[kr]);
162 int myconfig_version = 0;
163 std::map<EcalLogicID, RunConfigDat>::const_iterator it;
164 if (dataset.size() != 1) {
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;
171 it = dataset.begin();
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();
224 econn->fetchConfigSet(&seq);
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);
332 fout <<
" SAMPLE_ID " << mySample << std::endl;
336 weights.
setId(mywei);
337 econn->fetchConfigSet(&weights);
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;
376 for (
int ich = 0; ich < 6; ich++) {
377 dccwRow.push_back(my_dccw[0][ich]);
382 for (
int ich = 0; ich < 6; ich++)
399 float def[] = {-1215, 20, 297, 356, 308, 232};
400 std::vector<float> dccw(def, def + 6);
402 fout <<
" default weights ";
403 for (
int i = 0;
i < 6;
i++) {
405 fout <<
" i " <<
i <<
" def " << def[
i] <<
" dccw " << dccw[
i] <<
" \n";
412 fout <<
" weight size " << imax <<
" normalized weights : " << std::endl;
413 for (
int i = 0;
i < imax;
i++)
414 for (
int ich = 0; ich < 6; ich++) {
416 if (m_debug &&
i == 0)
424 fout <<
" checking for change " << std::endl;
425 bool nochange =
true;
426 int imaxref, imaxnew;
433 if (imaxref != imaxnew) {
434 fout <<
" deltaEta_ size ref " << imaxref <<
" now " << imaxnew << std::endl;
436 for (
int i = 0;
i < imaxref;
i++) {
451 if (imaxref != imaxnew) {
452 fout <<
" deltaPhi size ref " << imaxref <<
" now " << imaxnew << std::endl;
454 for (
int i = 0;
i < imaxref;
i++) {
469 if (imaxref != imaxnew) {
470 fout <<
" ecalDccZs1stSample size ref " << imaxref <<
" now " << imaxnew << std::endl;
472 for (
int i = 0;
i < imaxref;
i++) {
494 if (imaxref != imaxnew) {
495 fout <<
" dccNormalizedWeights size ref " << imaxref <<
" now " << imaxnew << std::endl;
498 for (
int ich = 0; ich < 6; ich++) {
500 fout <<
" dccNormalizedWeights_[" << i <<
"][" << ich <<
"] ref "
514 if (imaxref != imaxnew) {
515 fout <<
" symetricZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
517 for (
int i = 0;
i < imaxref;
i++) {
532 if (imaxref != imaxnew) {
533 fout <<
" srpLowInterestChannelZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
535 for (
int i = 0;
i < imaxref;
i++) {
550 if (imaxref != imaxnew) {
551 fout <<
" srpHighInterestChannelZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
553 for (
int i = 0;
i < imaxref;
i++) {
566 for (
int i = 0;
i < 4;
i++) {
568 fout <<
" actions " <<
i <<
" ref " << sref->
actions_[
i] <<
" now " << sr->
actions_[
i] << std::endl;
577 for (
int i = 0;
i < 108;
i++) {
589 for (
int i = 0;
i < 12;
i++) {
590 for (
int ich = 0; ich < 8; ich++) {
603 for (
int i = 0;
i < 54;
i++) {
605 fout <<
" dccMasks " <<
i <<
" ref " << sref->
dccMasks_[
i] <<
" now " << sr->
dccMasks_[
i] << std::endl;
614 for (
int i = 0;
i < 12;
i++) {
616 fout <<
" srfMasks " <<
i <<
" ref " << sref->
srfMasks_[
i] <<
" now " << sr->
srfMasks_[
i] << std::endl;
625 for (
int i = 0;
i < 12;
i++) {
626 for (
int ich = 0; ich < 68; ich++) {
628 fout <<
" substitutionSrfs " <<
i <<
" " << ich <<
" ref " << sref->
substitutionSrfs_[
i][ich]
639 for (
int i = 0;
i < 12;
i++) {
649 for (
int i = 0;
i < 12;
i++) {
658 for (
int i = 0;
i < 12;
i++) {
667 for (
int i = 0;
i < 12;
i++) {
676 for (
int i = 0;
i < 12;
i++) {
702 fout <<
" no change has been found " << std::endl;
703 std::ostringstream
ss;
704 ss <<
"Run=" << irun <<
"_SRPunchanged_" << std::endl;
705 m_userTextLog = ss.str() +
";";
708 fout <<
" Change has been found !\n New payload :" << std::endl;
709 PrintPayload(*sr, fout);
711 ChangePayload(*sref, *sr);
714 ChangePayload(*srp_pop, *sr);
715 m_to_transfer.push_back(std::make_pair(srp_pop, irun));
717 std::ostringstream
ss;
718 ss <<
"Run=" << irun <<
"_SRPchanged_" << std::endl;
719 m_userTextLog = ss.str() +
";";
721 if (m_to_transfer.size() >= 20)
725 m_i_tag = myconfig_tag;
726 m_i_version = myconfig_version;
727 fe_conf_id_old = fe_conf_id;
740 XercesDOMParser*
parser =
new XercesDOMParser;
741 parser->setValidationScheme(XercesDOMParser::Val_Never);
742 parser->setDoNamespaces(
false);
743 parser->setDoSchema(
false);
745 parser->parse(filename.c_str());
747 DOMDocument* xmlDoc = parser->getDocument();
749 std::cout <<
"importDccConfigFile Error parsing document" << std::endl;
752 DOMElement* element = xmlDoc->getDocumentElement();
757 int L1ZS[2] = {0, 0}, L2ZS[2] = {0, 0};
758 for (DOMNode* childNode = element->getFirstChild(); childNode; childNode = childNode->getNextSibling()) {
759 if (childNode->getNodeType() == DOMNode::ELEMENT_NODE) {
761 DOMElement*
child =
static_cast<DOMElement*
>(childNode);
762 DOMNamedNodeMap* attributes = child->getAttributes();
763 unsigned int numAttributes = attributes->getLength();
764 for (
unsigned int j = 0;
j < numAttributes; ++
j) {
765 DOMNode* attributeNode = attributes->item(
j);
766 DOMAttr* attribute =
static_cast<DOMAttr*
>(attributeNode);
769 if (info ==
"_scope") {
770 if (scope.substr(0, 2) ==
"EE")
777 for (DOMNode* subchildNode = childNode->getFirstChild(); subchildNode;
778 subchildNode = subchildNode->getNextSibling()) {
779 if (subchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
782 for (DOMNode* subsubchildNode = subchildNode->getFirstChild(); subsubchildNode;
783 subsubchildNode = subsubchildNode->getNextSibling()) {
784 if (subsubchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
786 if (subName ==
"L1ZSUPPRESSION")
788 if (subName ==
"L2ZSUPPRESSION")
790 if (subName ==
"FIRSTZSSAMPLE") {
796 if (subName ==
"CXTALWEIGHTS") {
797 std::vector<float> dcc(6);
799 for (
int iw = 0; iw < 6; iw++) {
822 fout <<
" deltaEta[" << imax <<
"] ";
823 for (
int i = 0;
i < imax;
i++) {
829 fout <<
" deltaPhi[" << imax <<
"] ";
830 for (
int i = 0;
i < imax;
i++) {
836 fout <<
" ecalDccZs1stSample[" << imax <<
"] ";
837 for (
int i = 0;
i < imax;
i++) {
846 fout <<
" dccNormalizedWeights" << std::endl;
848 fout <<
" Channel " <<
i;
855 fout <<
" symetricZS[" << imax <<
"] ";
856 for (
int i = 0;
i < imax;
i++) {
862 fout <<
" srpLowInterestChannelZS[" << imax <<
"] ";
863 for (
int i = 0;
i < imax;
i++) {
869 fout <<
" srpHighInterestChannelZS[" << imax <<
"] ";
870 for (
int i = 0;
i < imax;
i++) {
876 fout <<
" actions[" << imax <<
"] ";
877 for (
int i = 0;
i < imax;
i++) {
883 fout <<
" tccMasksFromConfig[" << imax <<
"] ";
884 for (
int i = 0;
i < imax;
i++) {
889 fout <<
" srpMasksFromConfig" << std::endl;
897 fout <<
" dccMasks[" << imax <<
"] ";
898 for (
int i = 0;
i < imax;
i++) {
904 fout <<
" srfMasks[" << imax <<
"] ";
905 for (
int i = 0;
i < imax;
i++) {
910 fout <<
"substitutionSrfs" << std::endl;
918 fout <<
" testerTccEmuSrpIds[" << imax <<
"] ";
919 for (
int i = 0;
i < imax;
i++) {
925 fout <<
" testerSrpEmuSrpIds[" << imax <<
"] ";
926 for (
int i = 0;
i < imax;
i++) {
932 fout <<
" testerDccTestSrpIds[" << imax <<
"] ";
933 for (
int i = 0;
i < imax;
i++) {
939 fout <<
" testerSrpTestSrpIds[" << imax <<
"] ";
940 for (
int i = 0;
i < imax;
i++) {
946 fout <<
" bxOffsets[" << imax <<
"] ";
947 for (
int i = 0;
i < imax;
i++) {
void setRunTypeDef(const RunTypeDef &runTypeDef)
void setSequenceId(int x)
unsigned int getDCCClobSize() const
int def(FILE *, FILE *, int)
std::vector< RunIOV > getRuns()
void setSequenceNumber(int x)
std::vector< short > srfMasks_
EcalSRPHandler(edm::ParameterSet const &)
std::vector< std::vector< float > > dccNormalizedWeights_
std::vector< int > testerSrpEmuSrpIds_
unsigned int getSRPClobSize() const
std::vector< float > srpHighInterestChannelZS_
int getSequenceId() const
std::vector< int > actions_
int getAutomaticMasks() const
std::string toString(XMLCh const *toTranscode)
std::vector< std::vector< short > > substitutionSrfs_
std::vector< int > testerDccTestSrpIds_
void ChangePayload(EcalSRSettings &sref, EcalSRSettings &sr)
int getConfigVersion() const
std::vector< int > ecalDccZs1stSample_
int getAutomaticSrpSelect() const
std::string getDCCWeightsMode() const
std::vector< short > tccMasksFromConfig_
void setLocationDef(const LocationDef &locDef)
std::vector< short > bxOffsets_
int getSRP0BunchAdjustPosition() const
std::vector< short > dccMasks_
std::vector< int > deltaPhi_
unsigned char * getDCCClob() const
void getNewObjects() override
unsigned char * getSRPClob() const
std::vector< std::vector< float > > getWeight() const
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
std::vector< int > symetricZS_
void setRunType(std::string runtype)
T getParameter(std::string const &) const
float ebDccAdcToGeV_
ADC to GeV conversion factor used in ZS filter for EB.
void importDccConfigFile(EcalSRSettings &sr, const std::string &filename, bool debug=false)
static std::vector< std::string > checklist dat
std::vector< int > testerTccEmuSrpIds_
void setEcalConfigId(int x)
std::unique_ptr< EcalSRSettings > Ref
std::vector< float > srpLowInterestChannelZS_
std::vector< int > deltaEta_
std::string getConfigTag() const
std::vector< int > testerSrpTestSrpIds_
void setTag(std::string x)
~EcalSRPHandler() override
void setLocation(std::string loc)
float eeDccAdcToGeV_
ADC to GeV conversion factor used in ZS filter for EE.
void setGeneralTag(std::string tag)
void PrintPayload(EcalSRSettings &sr, std::ofstream &fout)
std::vector< std::vector< short > > srpMasksFromConfig_