File indexing completed on 2024-04-06 12:03:10
0001 #include <stdlib.h>
0002 #include <iostream>
0003 #include <fstream>
0004 #include <string>
0005
0006 #include "CondTools/Hcal/interface/HcalDbXml.h"
0007 #include "CondFormats/HcalObjects/interface/HcalRawGains.h"
0008
0009 bool hasKey (const std::string& line, const std::string& key) {
0010 return line.find ("<"+key+">") != std::string::npos;
0011 }
0012
0013 double getValue (const std::string& line) {
0014 unsigned pos1 = line.find (">");
0015 unsigned pos2 = line.find ("</");
0016 if (pos1 != std::string::npos && pos2 != std::string::npos) {
0017 std::string valueStr (line, pos1+1, pos2-pos1);
0018 return atof (valueStr.c_str());
0019 }
0020 std::cerr << "Can not decode line: " << line << std::endl;
0021 return 0;
0022 }
0023
0024 int getIntValue (const std::string& line) {
0025 unsigned pos1 = line.find (">");
0026 unsigned pos2 = line.find ("</");
0027 if (pos1 != std::string::npos && pos2 != std::string::npos) {
0028 std::string valueStr (line, pos1+1, pos2-pos1);
0029 return atoi (valueStr.c_str());
0030 }
0031 std::cerr << "Can not decode line: " << line << std::endl;
0032 return 0;
0033 }
0034
0035 int main (int argn, char* argv []) {
0036 std::ifstream inStream (argv[1]);
0037 std::ofstream outStream (argv[2]);
0038 HcalRawGains gains;
0039 float gain = 0;
0040 int eta = 0;
0041 int phi = 0;
0042 int depth = 0;
0043 int z = 0;
0044 char buffer [1024];
0045 while (inStream.getline (buffer, 1024)) {
0046 std::string line (buffer);
0047 if (hasKey (line, "Z")) z = getIntValue (line);
0048 else if (hasKey (line, "PHI")) phi = getIntValue (line);
0049 else if (hasKey (line, "ETA")) eta = getIntValue (line);
0050 else if (hasKey (line, "DEPTH")) depth = getIntValue (line);
0051 else if (hasKey (line, "COEFFICIENT")) gain = getValue (line);
0052 else if (hasKey (line, "PHI")) phi = getIntValue (line);
0053 else if (hasKey (line, "PHI")) phi = getIntValue (line);
0054 else if (hasKey (line, "/DATA")) {
0055 HcalDetId id (HcalEndcap, z*eta, phi, depth);
0056 HcalRawGain newItem (id.rawId(), gain, 0., 0., HcalRawGain::GOOD);
0057 gains.addValues (id, newItem);
0058
0059 }
0060 }
0061 gains.sort ();
0062 HcalDbXml::dumpObject (outStream, 1, 1, 0xfffffffful, "he_signal_leveling_from_Petr", gains);
0063 return 0;
0064 }
0065