27 {
28 cool::IDatabasePtr
29 CoolRpc::
30 coolDbInstance(const std::string& dbStr, bool readOnly) {
31 try {
32
33 cool::IDatabaseSvc&
dbSvc = this->databaseService();
34
35 return dbSvc.openDatabase(dbStr.c_str(), readOnly);
36 }
37 catch (cool::DatabaseDoesNotExist&) {
38 std::cout << "Error! Database does not exist!" << std::endl;
39 throw;
40 }
41 }
42
43 cool::IFolderPtr
44 CoolRpc::
45 coolFolderInstance(const std::string& folderStr) {
46 try {
47 cool::IFolderPtr
folder = m_coolDb->getFolder(folderStr.c_str());
48
50 }
51 catch (cool::FolderNotFound&) {
52 std::cout << "Error! Folder '" << folderStr << "' does not exist!" << std::endl;
53 throw;
54 }
55 }
56
57 void
58 CoolRpc::coolDbFolder(const std::string& dbStr, const std::string& folderStr) {
59 m_coolDb = this->coolDbInstance(dbStr, false);
60 m_coolFolder = this->coolFolderInstance(folderStr);
61 }
62
63 void
64 CoolRpc::
65 setSince(cool::Int64
run, cool::Int64 lumi) {
67 }
68
69 void
70 CoolRpc::
71 setUntil(cool::Int64 iovmax, cool::Int64 lumi) {
72 m_until = ((iovmax << 32) +
lumi);
73 }
74
75 void
76 CoolRpc::
77 setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU) {
78 this->setSince(runS, lumiS);
79 this->setUntil(runU, lumiU);
80 this->printIOV();
81 }
82
83 void
84 CoolRpc::
85 setIOV(cool::Int64
run) {
86 this->setSince(
run, 0);
87 this->setUntil(
run, 4294967295U);
88 this->printIOV();
89 }
90
91 void
92 CoolRpc::
93 printIOV() {
94 cool::Int64 runS = m_since >> 32;
95 cool::Int64 lumiS = m_since - (runS << 32);
96 cool::Int64 runU = m_until >> 32;
97 cool::Int64 lumiU = m_until - (runU << 32);
98 std::cout << "Using IOVrange [(" << runS << "," << lumiS << "),(" << runU << "," << lumiU << ")] " << "[" <<
99 m_since << "," << m_until << "]" << std::endl;
100 }
101
102 void
103 CoolRpc::
104 CoolOpen(const std::string& dbStr) {
105 m_coolDb = this->coolDbInstance(dbStr, false);
106 }
107
108 CoolRpc::
109 ~CoolRpc () {
110 m_coolDb->closeDatabase();
111 std::cout << "Cleared!" << std::endl;
112 }
113
114 cool::RecordSpecification
115 CoolRpc::
116 createSpecData() {
117
118 cool::RecordSpecification
spec;
119 spec.extend(
"recEta", cool::StorageType::String4k);
120 spec.extend(
"detEta", cool::StorageType::String4k);
121 spec.extend(
"recPhi1", cool::StorageType::String4k);
122 spec.extend(
"recPhi2", cool::StorageType::String4k);
123 spec.extend(
"detPhi1", cool::StorageType::String4k);
124 spec.extend(
"detPhi2", cool::StorageType::String4k);
125 m_coolFolder = this->coolFolderInstance("/OFFLINE/OFFLINE_DQMF");
126 if (!(spec == m_coolFolder->payloadSpecification())) {
127 std::cout << "ERROR Source and destination folder specifications differ." << std::endl;
128 }
129
131 }
132
133 cool::RecordSpecification
134 CoolRpc::
135 createSpecDataCondDB() {
136
137 cool::RecordSpecification
spec;
138 spec.extend(
"PanelRes", cool::StorageType::String255);
139 spec.extend(
"StripStatus", cool::StorageType::String4k);
140 m_coolFolder = this->coolFolderInstance("/OFFLINE/FINAL");
141 if (!(spec == m_coolFolder->payloadSpecification())) {
142 std::cout << "ERROR Source and destination folder specifications differ." << std::endl;
143 }
144
146 }
147
148 coral::AttributeList
149 CoolRpc::
150 createPayloadData(const std::string& recEta,
151 const std::string& detEta,
152 const std::string& recPhi1,
153 const std::string& recPhi2,
154 const std::string& detPhi1,
155 const std::string& detPhi2,
156 const cool::RecordSpecification& spec) {
157
158
159 coral::AttributeList
payload = cool::Record(spec).attributeList();
160
161 payload[
"recEta"].data<cool::String4k>() = recEta;
162 payload[
"detEta"].data<cool::String4k>() = detEta;
163 payload[
"recPhi1"].data<cool::String4k>() = recPhi1;
164
165 payload[
"recPhi2"].data<cool::String4k>() = recPhi2;
166 payload[
"detPhi1"].data<cool::String4k>() = detPhi1;
167 payload[
"detPhi2"].data<cool::String4k>() = detPhi2;
168
169
170
171
173 }
174
175 coral::AttributeList
176 CoolRpc::
177 createPayloadDataCondDB(const std::string& PanelRes, const std::string& StripStatus,
178 const cool::RecordSpecification& spec) {
179
180
181 coral::AttributeList
payload = cool::Record(spec).attributeList();
182
183 payload[
"PanelRes"].data<cool::String255>() = PanelRes;
184 payload[
"StripStatus"].data<cool::String4k>() = StripStatus;
185
187 }
188
189 void
190 CoolRpc::
192 try {
193 cool::IObjectIteratorPtr
objects = m_coolFolder->browseObjects(m_since, m_until,
selection,
"");
195 const cool::IObject& element =
objects->currentRef();
196 std::cout << element << std::endl;
197 }
198 }
199 catch (cool::Exception& e) {
200 std::cout <<
"Unknown exception caught!" <<
e.what() << std::endl;
201 std::cout << " Inside create payload" << std::endl;
202 }
203 }
204
205 std::string
206 CoolRpc::
207 dumpField(cool::ChannelId channelId, std::string field) {
209 try {
210 cool::ChannelSelection
selection = cool::ChannelSelection(channelId);
211 cool::IObjectIteratorPtr
objects = m_coolFolder->browseObjects(m_since, m_until,
selection,
"");
213 const cool::IObject& element =
objects->currentRef();
214 result = element.payloadValue(field);
215 }
216 }
217 catch (cool::Exception& e) {
218 std::cout <<
"Unknown exception caught!" <<
e.what() << std::endl;
219 }
221 }
222
223 int
224 CoolRpc::
225 dumpCode(const std::string& channelName) {
226 std::string
result = this->dumpField(this->getCoolFolder()->
channelId(channelName.c_str()),
"Code");
228 }
229
230 void
231 CoolRpc::
232 dumpall() {
233 this->
dump(cool::ChannelSelection::all());
234 }
235
236
237
238 void
239 CoolRpc::
240 insert_withTag(cool::Int64
run,
241 cool::ChannelId channelId,
242 const std::string& recEta,
243 const std::string& detEta,
244 const std::string& recPhi1,
245 const std::string& recPhi2,
246 const std::string& detPhi1,
247 const std::string& detPhi2,
248 const std::string& cool_tag) {
249
250 try {
251 cool::RecordSpecification
spec = this->createSpecData();
252 coral::AttributeList
payload = this->createPayloadData(recEta, detEta, recPhi1, recPhi2, detPhi1, detPhi2, spec);
253 cool::ValidityKey since_u = (
run << 32);
254 cool::ValidityKey until_u = (
run + 1) << 32;
255 m_coolFolder->storeObject(since_u, until_u, cool::Record(
256 m_coolFolder->payloadSpecification(), payload), channelId, cool_tag);
257
258 }
259 catch (cool::Exception& e) {
260 std::cout << " Inside create insert" << std::endl;
261 std::cout <<
"Unknown exception caught!" <<
e.what() << std::endl;
262 }
263 }
264
265 void
266 CoolRpc::
267 insertCondDB_withTag(cool::Int64
run,
268 cool::ChannelId channelId,
269 const std::string& PanelRes,
270 const std::string& StripStatus,
271 const std::string& cool_tag) {
272
273 try {
274 cool::RecordSpecification
spec = this->createSpecDataCondDB();
275 coral::AttributeList
payload = this->createPayloadDataCondDB(PanelRes, StripStatus, spec);
276 cool::ValidityKey since_u = (
run << 32) * 0;
277 cool::ValidityKey until_u = (
run + 1) << 32;
278 m_coolFolder->storeObject(since_u, until_u, cool::Record(
279 m_coolFolder->payloadSpecification(), payload), channelId, cool_tag);
280
281 }
282 catch (cool::Exception& e) {
283 std::cout << " Inside create insert" << std::endl;
284 std::cout <<
"Unknown exception caught!" <<
e.what() << std::endl;
285 }
286 }
287
288 void
289 CoolRpc::
290 insert(cool::Int64
run,
291 cool::ChannelId channelId,
292 const std::string& recEta,
293 const std::string& detEta,
294 const std::string& recPhi1,
295 const std::string& recPhi2,
296 const std::string& detPhi1,
297 const std::string& detPhi2) {
298 std::cout << "Trying to store payload [channel " << std::endl;
299 try {
300 cool::RecordSpecification
spec = this->createSpecData();
301 coral::AttributeList
payload = this->createPayloadData(recEta, detEta, recPhi1, recPhi2, detPhi1, detPhi2, spec);
302 cool::ValidityKey since_u = (
run << 32);
303 cool::ValidityKey until_u = (
run + 1) << 32;
304 m_coolFolder->storeObject(since_u, until_u, cool::Record(m_coolFolder->payloadSpecification(), payload),
305 channelId);
306 std::cout << "stored! without Tag" << std::endl;
307 }
308 catch (cool::Exception& e) {
309 std::cout << " Inside create insert" << std::endl;
310 std::cout <<
"Unknown exception caught!" <<
e.what() << std::endl;
311 }
312 }
313
314 cool::IFolderPtr
315 CoolRpc::
316 getCoolFolder() {
317 return this->m_coolFolder;
318 }
319
320 cool::IDatabasePtr
321 CoolRpc::
322 getCoolDb() {
323 return this->m_coolDb;
324 }
325}
const std::string selection
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...