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