Skip to content

Commit ac6c2bc

Browse files
author
Pierre Depasse
committed
ECAL: Tool to create sqlite files for DB
1 parent f1dac78 commit ac6c2bc

File tree

4 files changed

+204
-0
lines changed

4 files changed

+204
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef CondTools_Ecal_EcalTimeCalibHandler_h
2+
#define CondTools_Ecal_EcalTimeCalibHandler_h
3+
4+
#include "CondCore/PopCon/interface/PopConSourceHandler.h"
5+
#include "CondFormats/EcalObjects/interface/EcalTimeCalibConstants.h"
6+
#include "CondTools/Ecal/interface/EcalCondHeader.h"
7+
8+
#include "FWCore/Framework/interface/Event.h"
9+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
10+
#include "FWCore/ServiceRegistry/interface/Service.h"
11+
12+
#include "OnlineDB/EcalCondDB/interface/all_monitoring_types.h"
13+
#include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
14+
15+
#include <string>
16+
17+
namespace popcon {
18+
class EcalTimeCalibHandler : public popcon::PopConSourceHandler<EcalTimeCalibConstants> {
19+
public:
20+
EcalTimeCalibHandler(edm::ParameterSet const&);
21+
~EcalTimeCalibHandler() override = default;
22+
23+
void getNewObjects() override;
24+
void readXML(const std::string& filename, EcalFloatCondObjectContainer& record);
25+
void readTXT(const std::string& filename, EcalFloatCondObjectContainer& record);
26+
27+
std::string id() const override { return m_name; }
28+
EcalCondDBInterface* econn;
29+
30+
private:
31+
const std::string m_name;
32+
const unsigned int m_firstRun;
33+
const std::string m_file_name;
34+
const std::string m_file_type;
35+
};
36+
} // namespace popcon
37+
#endif
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "CondCore/PopCon/interface/PopConAnalyzer.h"
2+
#include "CondTools/Ecal/interface/EcalTimeCalibHandler.h"
3+
#include "FWCore/Framework/interface/MakerMacros.h"
4+
5+
typedef popcon::PopConAnalyzer<popcon::EcalTimeCalibHandler> ExTestEcalTimeCalibAnalyzer;
6+
7+
//define this as a plug-in
8+
DEFINE_FWK_MODULE(ExTestEcalTimeCalibAnalyzer);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import FWCore.ParameterSet.Config as cms
2+
3+
process = cms.Process("ProcessOne")
4+
5+
process.load("FWCore.MessageService.MessageLogger_cfi")
6+
process.MessageLogger.cerr.enable = False
7+
process.MessageLogger.cout.enable = True
8+
process.MessageLogger.cout.threshold = cms.untracked.string('DEBUG')
9+
process.MessageLogger.debugModules = cms.untracked.vstring('*')
10+
11+
process.source = cms.Source("EmptyIOVSource",
12+
lastValue = cms.uint64(100000000000),
13+
timetype = cms.string('runnumber'),
14+
firstValue = cms.uint64(100000000000),
15+
interval = cms.uint64(1)
16+
)
17+
18+
process.load("CondCore.CondDB.CondDB_cfi")
19+
20+
process.CondDB.connect = 'sqlite_file:EcalTimeCalibConstants_minus_delays.db'
21+
22+
process.PoolDBOutputService = cms.Service("PoolDBOutputService",
23+
process.CondDB,
24+
logconnect = cms.untracked.string('sqlite_file:log.db'),
25+
toPut = cms.VPSet(
26+
cms.PSet(
27+
record = cms.string('EcalTimeCalibConstantsRcd'),
28+
tag = cms.string('EcalTimeCalibConstants')
29+
)
30+
)
31+
)
32+
33+
process.Test1 = cms.EDAnalyzer("ExTestEcalTimeCalibAnalyzer",
34+
record = cms.string('EcalTimeCalibConstantsRcd'),
35+
loggingOn= cms.untracked.bool(True),
36+
IsDestDbCheckedInQueryLog=cms.untracked.bool(True),
37+
SinceAppendMode=cms.bool(True),
38+
Source=cms.PSet(
39+
firstRun = cms.string('1'),
40+
type = cms.string('txt'),
41+
fileName = cms.string('dump_EcalTimeCalibConstants__new_minus_delays.dat'),
42+
# type = cms.string('xml'),
43+
# fileName = cms.string('EcalTimeCalibConstants_minus_delays.xml'),
44+
)
45+
)
46+
47+
process.p = cms.Path(process.Test1)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include "CondTools/Ecal/interface/EcalTimeCalibHandler.h"
2+
#include "DataFormats/EcalDetId/interface/EEDetId.h"
3+
#include "DataFormats/EcalDetId/interface/EBDetId.h"
4+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
5+
#include <cstddef>
6+
#include <cstdio>
7+
#include <fstream>
8+
#include <sstream>
9+
#include <utility>
10+
11+
const Int_t kEBChannels = 61200, kEEChannels = 14648;
12+
13+
popcon::EcalTimeCalibHandler::EcalTimeCalibHandler(const edm::ParameterSet& ps)
14+
: m_name(ps.getUntrackedParameter<std::string>("name", "EcalTimeCalibHandler")),
15+
m_firstRun(static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()))),
16+
m_file_name(ps.getParameter<std::string>("fileName")),
17+
m_file_type(ps.getParameter<std::string>("type")) // xml/txt
18+
{
19+
edm::LogInfo("EcalTimeCalib Source handler constructor\n");
20+
}
21+
22+
void popcon::EcalTimeCalibHandler::getNewObjects() {
23+
edm::LogInfo("going to open file ") << m_file_name;
24+
25+
// EcalCondHeader header;
26+
EcalTimeCalibConstants* payload = new EcalTimeCalibConstants;
27+
if (m_file_type == "xml")
28+
readXML(m_file_name, *payload);
29+
else
30+
readTXT(m_file_name, *payload);
31+
Time_t snc = (Time_t)m_firstRun;
32+
33+
popcon::PopConSourceHandler<EcalTimeCalibConstants>::m_to_transfer.push_back(std::make_pair(payload, snc));
34+
}
35+
36+
void popcon::EcalTimeCalibHandler::readXML(const std::string& file_, EcalFloatCondObjectContainer& record) {
37+
std::string dummyLine, bid;
38+
std::ifstream fxml;
39+
fxml.open(file_);
40+
if (!fxml.is_open()) {
41+
throw cms::Exception("ERROR : cannot open file ") << file_;
42+
}
43+
// header
44+
for (int i = 0; i < 6; i++) {
45+
getline(fxml, dummyLine); // skip first lines
46+
}
47+
fxml >> bid;
48+
std::string stt = bid.substr(7, 5);
49+
std::istringstream iEB(stt);
50+
int nEB;
51+
iEB >> nEB;
52+
if (nEB != kEBChannels) {
53+
throw cms::Exception("Strange number of EB channels ") << nEB;
54+
}
55+
fxml >> bid; // <item_version>0</item_version>
56+
for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
57+
EBDetId myEBDetId = EBDetId::unhashIndex(iChannel);
58+
fxml >> bid;
59+
std::size_t found = bid.find("</");
60+
stt = bid.substr(6, found - 6);
61+
float val = std::stof(stt);
62+
record[myEBDetId] = val;
63+
}
64+
for (int i = 0; i < 5; i++) {
65+
getline(fxml, dummyLine); // skip first lines
66+
}
67+
fxml >> bid;
68+
stt = bid.substr(7, 5);
69+
std::istringstream iEE(stt);
70+
int nEE;
71+
iEE >> nEE;
72+
if (nEE != kEEChannels) {
73+
throw cms::Exception("Strange number of EE channels ") << nEE;
74+
}
75+
fxml >> bid; // <item_version>0</item_version>
76+
// now endcaps
77+
for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
78+
EEDetId myEEDetId = EEDetId::unhashIndex(iChannel);
79+
fxml >> bid;
80+
std::size_t found = bid.find("</");
81+
stt = bid.substr(6, found - 6);
82+
float val = std::stof(stt);
83+
record[myEEDetId] = val;
84+
}
85+
}
86+
87+
void popcon::EcalTimeCalibHandler::readTXT(const std::string& file_, EcalFloatCondObjectContainer& record) {
88+
std::ifstream ftxt;
89+
ftxt.open(file_);
90+
if (!ftxt.is_open()) {
91+
throw cms::Exception("ERROR : cannot open file ") << file_;
92+
}
93+
int number_of_lines = 0, eta, phi, x, y, z;
94+
float val;
95+
std::string line;
96+
while (std::getline(ftxt, line)) {
97+
if (number_of_lines < kEBChannels) { // barrel
98+
std::sscanf(line.c_str(), "%i %i %i %f", &eta, &phi, &z, &val);
99+
EBDetId ebdetid(eta, phi, EBDetId::ETAPHIMODE);
100+
record[ebdetid] = val;
101+
} else { // endcaps
102+
std::sscanf(line.c_str(), "%i %i %i %f", &x, &y, &z, &val);
103+
EEDetId eedetid(x, y, z, EEDetId::XYMODE);
104+
record[eedetid] = val;
105+
}
106+
number_of_lines++;
107+
}
108+
edm::LogInfo("Number of lines in text file: ") << number_of_lines;
109+
int kChannels = kEBChannels + kEEChannels;
110+
if (number_of_lines != kChannels)
111+
throw cms::Exception("Wrong number of channels! Please check ");
112+
}

0 commit comments

Comments
 (0)