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")) {
54 std::ostringstream
ss;
57 unsigned long long max_since = 1;
60 max_since =
tagInfo().lastInterval.first;
63 Ref srp_db = lastPayload();
66 <<
"\n retrieved last payload " << std::endl;
96 std::cout <<
"Retrieving DAQ status from OMDS DB ... " << std::endl;
98 std::cout <<
"Connection done" << std::endl;
101 std::cout <<
" Problem with OMDS: connection parameters " << m_sid <<
"/" << m_user << std::endl;
118 if(m_firstRun <= (
unsigned long)max_since) {
119 min_run= (int)max_since+1;
121 else { min_run=(int)m_firstRun; }
123 int max_run=(int)m_lastRun;
125 std::cout <<
"min_run " << min_run <<
" max_run " << max_run << std::endl;
130 sprintf(outfile,
"SRP_run%d.txt",min_run);
132 fout <<
" ORCOFF last run max_since : " << max_since << std::endl;
133 PrintPayload(*sref, fout);
137 my_list = econn->fetchRunListByLocation(my_runtag, min_run, max_run, my_locdef);
139 std::vector<RunIOV> run_vec = my_list.
getRuns();
140 int num_runs = run_vec.size();
143 fout <<
" number of runs is : " << num_runs << std::endl;
145 unsigned long irun = 0;
147 int fe_conf_id_old = 0;
150 for(
int kr = 0; kr < num_runs; kr++) {
152 std::string geneTag = run_vec[kr].getRunTag().getGeneralTag();
153 if(geneTag !=
"GLOBAL") {
155 fout <<
"\n New run " << irun <<
" with tag " << geneTag <<
" giving up " << std::endl;
159 fout <<
"\n New run " << irun <<
" geneTag " << geneTag << std::endl;
162 std::map<EcalLogicID, RunConfigDat>
dataset;
163 econn->fetchDataSet(&dataset, &run_vec[kr]);
165 int myconfig_version = 0;
166 std::map< EcalLogicID, RunConfigDat>::const_iterator it;
167 if(dataset.size() != 1) {
168 std::cout <<
"\n\n run " << irun <<
" strange number of dataset "
169 << dataset.size() << std::endl;
171 fout <<
"\n\n run " << irun <<
" strange number of dataset "
172 << dataset.size() <<
" giving up " << std::endl;
176 it = dataset.begin();
179 if(myconfig_tag.substr(0,15) ==
"ZeroSuppression") {
181 fout <<
" run " << irun <<
" tag " << myconfig_tag <<
" giving up " << std::endl;
186 typedef std::map<EcalLogicID, RunFEConfigDat>::const_iterator feConfIter;
187 std::map<EcalLogicID, RunFEConfigDat> feconfig;
188 econn->fetchDataSet(&feconfig, &run_vec[kr]);
189 if(feconfig.size() != 1) {
191 fout <<
"\n\n run " << irun <<
" strange number of FE config "
192 << feconfig.size() <<
" giving up " << std::endl;
197 feConfIter
p=feconfig.begin();
203 fout <<
" run " << irun <<
" tag " << myconfig_tag
204 <<
" version " << myconfig_version
205 <<
" Fe config " << fe_conf_id << std::endl;
207 if(myconfig_tag != m_i_tag || myconfig_version != m_i_version || fe_conf_id != fe_conf_id_old) {
209 fout <<
" run= " << irun
210 <<
" different tag ... retrieving last config set from DB" << std::endl;
212 bool FromCLOB =
false;
219 od_run_info.
setTag(myconfig_tag);
223 econn-> fetchConfigSet(&od_run_info);
224 int config_id = od_run_info.
getId();
229 econn-> fetchConfigSet(&seq);
234 econn-> fetchConfigSet(&ecal_cycle);
235 int cycle_id = ecal_cycle.
getId();
239 fout <<
" no SRP config for this run, give up " << std::endl;
245 fout <<
" cycleid " << cycle_id <<
" SRP id " << srp_id <<
" DCC id " << dcc_id << std::endl;
251 econn-> fetchConfigSet(&srp);
259 for (std::string::iterator it = SRPClob.begin() ; it < SRPClob.end(); it++ )
262 std::ifstream
f(
"srp.txt");
264 throw cms::Exception(
"EcalSRPHandler") <<
" Failed to open file srp.txt";
266 fout <<
" Failed to open file srp.txt" << std::endl;
270 int rv = system(
"rm srp.txt");
271 if(m_debug && rv != 0) fout <<
"rm srp.txt result code: " << rv <<
"\n";
281 econn-> fetchConfigSet(&dcc);
284 fout <<
" DCC weightsMode " << weightsMode << std::endl
286 if(weightsMode ==
"CLOB") {
289 fout <<
" will read weights from DCC CLOB " << std::endl;
295 std::ostringstream osd;
299 for (std::string::iterator it = DCCClob.begin() ; it < DCCClob.end(); it++ )
302 importDccConfigFile(*sr, fname, FromCLOB);
305 rv = system(
"rm dcc.txt");
306 if(m_debug && rv != 0) fout <<
"rm dcc.txt result code: " << rv <<
"\n";
310 std::cout <<
"ERROR: This config does not exist: tag " << myconfig_tag
311 <<
" version "<< myconfig_version<< std::endl;
313 fout <<
"ERROR: This config does not exist: tag " << myconfig_tag
314 <<
" version "<< myconfig_version<< std::endl;
318 fout <<
" FromCLOB " << FromCLOB << std::endl;
322 myconfig.
setId(fe_conf_id);
323 econn->fetchConfigSet(&myconfig);
328 fout <<
" WEI_ID " << mywei << std::endl;
333 econn->fetchConfigSet(&samp);
336 fout <<
" SAMPLE_ID " << mySample << std::endl;
340 weights.
setId(mywei);
341 econn->fetchConfigSet(&weights);
343 std::vector<std::vector<float> > my_dccw = weights.
getWeight();
344 int imax = my_dccw.size();
346 fout <<
" weight size before check " << imax << std::endl;
348 bool WeightsChange =
false, WeightsChangeEB =
false, WeightsChangeEE =
false;
349 for (
int i = 1;
i < 61200 ;
i++)
350 for (
int ich = 0; ich < 6 ; ich++)
351 if(my_dccw[
i][ich] != my_dccw[0][ich]) WeightsChangeEB =
true;
353 fout <<
" WeightsChangeEB " << WeightsChangeEB << std::endl;
354 for(
int i = 61201;
i < 75848 ;
i++)
355 for (
int ich = 0; ich < 6 ; ich++)
356 if(my_dccw[
i][ich] != my_dccw[61200][ich]) WeightsChangeEE =
true;
358 fout <<
" WeightsChangeEE " << WeightsChangeEE << std::endl;
359 for(
int ich = 0; ich < 6 ; ich++)
360 if(my_dccw[0][ich] != my_dccw[61200][ich]) WeightsChange =
true;
362 fout <<
" WeightsChange " << WeightsChange << std::endl;
364 if(WeightsChangeEB || WeightsChangeEE)
366 else if (WeightsChange) {
367 std::vector<float> dccwRowEB, dccwRowEE;
368 for (
int ich = 0; ich < 6 ; ich++) {
369 dccwRowEB.push_back(my_dccw[0][ich]);
370 dccwRowEE.push_back(my_dccw[61200][ich]);
376 std::vector<float> dccwRow;
377 for (
int ich = 0; ich < 6 ; ich++) {
378 dccwRow.push_back(my_dccw[0][ich]);
383 for(
int ich = 0; ich < 6 ; ich++)
400 float def[] = {-1215, 20, 297, 356, 308, 232};
401 std::vector<float> dccw(def,def+6);
403 fout <<
" default weights " ;
404 for(
int i = 0;
i < 6;
i++) {
406 fout <<
" i " <<
i <<
" def " << def [
i] <<
" dccw " << dccw[
i] <<
" \n";
413 fout <<
" weight size " << imax <<
" normalized weights : "<< std::endl;
414 for(
int i = 0;
i < imax ;
i++)
415 for(
int ich = 0; ich < 6 ; ich++) {
417 if (m_debug &&
i == 0)
425 fout <<
" checking for change " << std::endl;
426 bool nochange =
true;
427 int imaxref, imaxnew;
434 if(imaxref != imaxnew) {
435 fout <<
" deltaEta_ size ref " << imaxref <<
" now " << imaxnew << std::endl;
438 for(
int i = 0;
i < imaxref ;
i++) {
440 fout <<
" deltaEta_[" <<
i <<
"] ref "<< sref->
deltaEta_[
i]
453 if(imaxref != imaxnew) {
454 fout <<
" deltaPhi size ref " << imaxref <<
" now " << imaxnew << std::endl;
457 for(
int i = 0;
i < imaxref ;
i++) {
459 fout <<
" deltaPhi[" <<
i <<
"] ref "<< sref->
deltaPhi_[
i]
472 if(imaxref != imaxnew) {
473 fout <<
" ecalDccZs1stSample size ref " << imaxref <<
" now " << imaxnew << std::endl;
476 for(
int i = 0;
i < imaxref ;
i++) {
498 if(imaxref != imaxnew) {
499 fout <<
" dccNormalizedWeights size ref " << imaxref <<
" now " << imaxnew << std::endl;
503 for(
int ich = 0; ich < 6 ; ich++) {
505 fout <<
" dccNormalizedWeights_[" << i <<
"][" << ich <<
"] ref "
519 if(imaxref != imaxnew) {
520 fout <<
" symetricZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
523 for(
int i = 0;
i < imaxref ;
i++) {
525 fout <<
" symetricZS[" <<
i <<
"] ref "<< sref->
symetricZS_[
i]
538 if(imaxref != imaxnew) {
539 fout <<
" srpLowInterestChannelZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
542 for(
int i = 0;
i < imaxref ;
i++) {
557 if(imaxref != imaxnew) {
558 fout <<
" srpHighInterestChannelZS size ref " << imaxref <<
" now " << imaxnew << std::endl;
561 for(
int i = 0;
i < imaxref ;
i++) {
574 for(
int i = 0;
i < 4;
i++) {
576 fout <<
" actions " <<
i <<
" ref " << sref->
actions_[
i]
577 <<
" now " << sr->
actions_[
i] << std::endl;
586 for(
int i = 0;
i < 108;
i++) {
598 for(
int i = 0;
i < 12;
i++) {
599 for(
int ich = 0; ich < 8; ich++) {
612 for(
int i = 0;
i < 54;
i++) {
614 fout <<
" dccMasks " <<
i <<
" ref " << sref->
dccMasks_[
i]
624 for(
int i = 0;
i < 12;
i++) {
626 fout <<
" srfMasks " <<
i <<
" ref " << sref->
srfMasks_[
i]
636 for(
int i = 0;
i < 12;
i++) {
637 for(
int ich = 0; ich < 68; ich++) {
639 fout <<
" substitutionSrfs " <<
i <<
" " << ich <<
" ref " << sref->
substitutionSrfs_[
i][ich]
650 for(
int i = 0;
i < 12;
i++) {
660 for(
int i = 0;
i < 12;
i++) {
669 for(
int i = 0;
i < 12;
i++) {
678 for(
int i = 0;
i < 12;
i++) {
687 for(
int i = 0;
i < 12;
i++) {
688 fout <<
" bxOffsets " <<
i <<
" ref " << sref->
bxOffsets_[
i]
716 fout <<
" no change has been found " << std::endl;
717 std::ostringstream
ss;
718 ss <<
"Run=" << irun <<
"_SRPunchanged_"<<std::endl;
719 m_userTextLog = ss.str()+
";";
723 fout <<
" Change has been found !\n New payload :" << std::endl;
724 PrintPayload(*sr, fout);
726 ChangePayload(*sref, *sr);
729 ChangePayload(*srp_pop, *sr);
730 m_to_transfer.push_back(std::make_pair(srp_pop, irun));
732 std::ostringstream
ss;
733 ss <<
"Run=" << irun <<
"_SRPchanged_"<<std::endl;
734 m_userTextLog = ss.str()+
";";
736 if(m_to_transfer.size() >= 20 )
break;
739 m_i_tag = myconfig_tag;
740 m_i_version = myconfig_version;
741 fe_conf_id_old = fe_conf_id;
755 XercesDOMParser*
parser =
new XercesDOMParser;
756 parser->setValidationScheme( XercesDOMParser::Val_Never );
757 parser->setDoNamespaces(
false );
758 parser->setDoSchema(
false );
760 parser->parse(filename.c_str());
762 DOMDocument* xmlDoc = parser->getDocument();
764 std::cout <<
"importDccConfigFile Error parsing document" << std::endl;
767 DOMElement* element = xmlDoc->getDocumentElement();
772 int L1ZS[2] = {0, 0}, L2ZS[2] = {0, 0};
773 for (DOMNode* childNode = element->getFirstChild();
774 childNode; childNode = childNode->getNextSibling()) {
775 if (childNode->getNodeType() == DOMNode::ELEMENT_NODE) {
777 DOMElement *
child =
static_cast<DOMElement *
>(childNode);
778 DOMNamedNodeMap *attributes = child->getAttributes();
779 unsigned int numAttributes = attributes->getLength();
780 for (
unsigned int j = 0;
j < numAttributes; ++
j) {
781 DOMNode *attributeNode = attributes->item(
j);
782 DOMAttr *attribute =
static_cast<DOMAttr *
>(attributeNode);
785 if(info ==
"_scope") {
786 if(scope.substr(0,2) ==
"EE") EBEE = 1;
791 for (DOMNode* subchildNode = childNode->getFirstChild();
792 subchildNode; subchildNode = subchildNode->getNextSibling()) {
793 if (subchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
796 for (DOMNode* subsubchildNode = subchildNode->getFirstChild();
797 subsubchildNode; subsubchildNode = subsubchildNode->getNextSibling()) {
798 if (subsubchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
800 if(subName ==
"L1ZSUPPRESSION")
802 if(subName ==
"L2ZSUPPRESSION")
804 if(subName ==
"FIRSTZSSAMPLE") {
809 if(subName ==
"CXTALWEIGHTS") {
810 std::vector<float> dcc(6);
812 for(
int iw = 0; iw < 6; iw++) {
834 fout <<
" deltaEta[" << imax <<
"] ";
835 for(
int i = 0;
i < imax ;
i++) {
841 fout <<
" deltaPhi[" << imax <<
"] ";
842 for(
int i = 0;
i < imax ;
i++) {
848 fout <<
" ecalDccZs1stSample[" << imax <<
"] ";
849 for(
int i = 0;
i < imax ;
i++) {
858 fout <<
" dccNormalizedWeights" << std::endl;
860 fout <<
" Channel " <<
i;
867 fout <<
" symetricZS["<< imax <<
"] ";
868 for(
int i = 0;
i < imax ;
i++) {
874 fout <<
" srpLowInterestChannelZS["<< imax <<
"] ";
875 for(
int i = 0;
i < imax ;
i++) {
881 fout <<
" srpHighInterestChannelZS["<< imax <<
"] ";
882 for(
int i = 0;
i < imax ;
i++) {
888 fout <<
" actions["<< imax <<
"] ";
889 for(
int i = 0;
i < imax ;
i++) {
895 fout <<
" tccMasksFromConfig["<< imax <<
"] ";
896 for(
int i = 0;
i < imax ;
i++) {
901 fout <<
" srpMasksFromConfig" << std::endl;
909 fout <<
" dccMasks[" << imax <<
"] ";
910 for(
int i = 0;
i < imax ;
i++) {
916 fout <<
" srfMasks[" << imax <<
"] ";
917 for(
int i = 0;
i < imax ;
i++) {
922 fout <<
"substitutionSrfs" << std::endl;
930 fout <<
" testerTccEmuSrpIds[" << imax <<
"] ";
931 for(
int i = 0;
i < imax ;
i++) {
937 fout <<
" testerSrpEmuSrpIds[" << imax <<
"] ";
938 for(
int i = 0;
i < imax ;
i++) {
944 fout <<
" testerDccTestSrpIds[" << imax <<
"] ";
945 for(
int i = 0;
i < imax ;
i++) {
950 imax = sr. testerSrpTestSrpIds_.size();
951 fout <<
" testerSrpTestSrpIds[" << imax <<
"] ";
952 for(
int i = 0;
i < imax ;
i++) {
958 fout <<
" bxOffsets[" << imax <<
"] ";
959 for(
int i = 0;
i < imax ;
i++) {
T getParameter(std::string const &) const
void setRunTypeDef(const RunTypeDef &runTypeDef)
void setSequenceId(int x)
unsigned int getDCCClobSize() const
std::vector< RunIOV > getRuns()
edm::Ref< Container > Ref
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::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
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)
float ebDccAdcToGeV_
ADC to GeV conversion factor used in ZS filter for EB.
void importDccConfigFile(EcalSRSettings &sr, const std::string &filename, bool debug=false)
std::vector< int > testerTccEmuSrpIds_
void setEcalConfigId(int x)
std::vector< float > srpLowInterestChannelZS_
std::vector< int > deltaEta_
std::string getConfigTag() const
std::vector< int > testerSrpTestSrpIds_
void setTag(std::string x)
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::string toNative(const XMLCh *str)
std::vector< std::vector< short > > srpMasksFromConfig_