ATLAS Offline Software
Loading...
Searching...
No Matches
MakeReferenceFile.cxx File Reference
#include "CoolKernel/DatabaseId.h"
#include "CoolKernel/Exception.h"
#include "CoolKernel/IDatabaseSvc.h"
#include "CoolKernel/IDatabase.h"
#include "CoolApplication/Application.h"
#include "CoolKernel/IFolder.h"
#include "CoolKernel/FolderSpecification.h"
#include "CoolKernel/RecordSpecification.h"
#include "CoolKernel/Record.h"
#include "CoolKernel/FieldSpecification.h"
#include "CoolKernel/IObject.h"
#include "CoolKernel/IObjectIterator.h"
#include "CoolKernel/IRecordIterator.h"
#include "CoolKernel/StorageType.h"
#include "CoolKernel/ChannelSelection.h"
#include "RelationalAccess/ConnectionService.h"
#include <iostream>
#include <fstream>
#include <string>
#include <string_view>
#include <stdexcept>
#include <ctime>
#include <sstream>
#include <unordered_map>

Go to the source code of this file.

Classes

class  DbConnection
struct  FolderSpec
class  Folder

Typedefs

using iovNamePair = std::pair<std::string, std::string >

Functions

std::string timeRep (const cool::ValidityKey &t, bool isEnd=false, bool runLumi=true)
std::string iovToString (const cool::IObject &obj, bool runLumi=true)
std::string payloadToString (const cool::IObject &obj)
int main (int argc, char *argv[])

Typedef Documentation

◆ iovNamePair

using iovNamePair = std::pair<std::string, std::string >

Definition at line 39 of file MakeReferenceFile.cxx.

Function Documentation

◆ iovToString()

std::string iovToString ( const cool::IObject & obj,
bool runLumi = true )

Definition at line 248 of file MakeReferenceFile.cxx.

249{
250 std::string sinceStr = timeRep(obj.since(), false, runLumi);
251 std::string untilStr = timeRep(obj.until(), true, runLumi);
252 return sinceStr + " - " + untilStr;
253}
std::string timeRep(const cool::ValidityKey &t, bool isEnd=false, bool runLumi=true)

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 274 of file MakeReferenceFile.cxx.

275{
276
277 std::string tagName{"PixelChargeCalibration-DATA-RUN2-UPD4-28"};
278 std::string folderName{"/PIXEL/ChargeCalibration"};
279 std::string outputFileName{"test"};
280 std::string dbName{"COOLOFL_PIXEL/CONDBR2"};
281 std::string useIOV{"latest"};
282 bool useLastIOV{true};
283
284 for(int i=1; i<argc; i++){
285 std::string aux(argv[i]);
286 std::string variable(aux.substr(0,aux.find("=")));
287 std::string value(aux.substr(aux.find("=")+1));
288 if (variable.compare("tagName") == 0) {
289 tagName = std::move(value);
290 }
291 else if(variable.compare("folder") == 0) folderName = std::move(value);
292 else if(variable.compare("outputFile") == 0) outputFileName = std::move(value);
293 else if(variable.compare("dbName") == 0) dbName = std::move(value);
294 else if(variable.compare("IOV") == 0){
295 // By selecting an IOV is understood you dont want to use the last one
296 // hence use the "IOV=runNumber_LB" (it should exist in the DB)
297 // if you want to print all of them use "IOV=all"
298 useIOV = std::move(value);
299 useLastIOV = false;
300 }
301 else{
302 std::cout<< "ERROR - Option not found:"<< aux <<"\n";
303 return 1;
304 }
305
306 }
307
308 if (outputFileName.compare("test") == 0){
309 if(useLastIOV){
310 outputFileName = tagName+".log";
311 }
312 else if (useIOV.compare("all") == 0){
313 outputFileName = "XXXXXX_"+tagName+".log";
314 }
315 else{
316 outputFileName = useIOV+"_"+tagName+".log";
317 }
318 }
319
320 printf("%-11s: %s\n", "Tag Name" ,tagName.c_str());
321 printf("%-11s: %s\n", "Folder Name",folderName.c_str()) ;
322 printf("%-11s: %s\n", "DB Name" ,dbName.c_str()) ;
323 printf("%-11s: %s\n", "Output File",outputFileName.c_str()) ;
324 printf("%-11s: %s\n", "Last IOV" ,useLastIOV ? "True" : "False");
325 printf("%-11s: %s\n", "IOV used" ,useIOV.c_str()) ;
326
327 int returnCode = 0;
328 DbConnection connection(dbName);
329 FolderSpec fs(folderName, tagName);
330 Folder f(connection, fs);
331
332 cool::IObjectIteratorPtr objectsIterator = f.objectIterator(useLastIOV); // True to use the last IOV
333 std::vector< iovNamePair > myIOVs;
334 while (objectsIterator->goToNext())
335 {
336 const cool::IObject &thisObject = objectsIterator->currentRef();
337 std::size_t posPar = iovToString(thisObject).find("]");
338 std::size_t posCom = iovToString(thisObject).find(",");
339 std::string name = iovToString(thisObject).substr(1,posPar-1).replace(posCom-1,1,"_");
340 std::string display = iovToString(thisObject) + " (" + std::to_string(thisObject.channelId()) + ")\n";
341 display += payloadToString(thisObject);
342 myIOVs.push_back(std::make_pair(name,display));
343 }
344
345 if(!useLastIOV){
346 bool found = false;
347 // Saving all the IOVs in different files, just used for experts - Evolution monitoring
348 for(const auto & [IOVname,iov]:myIOVs){
349 if(IOVname.compare(useIOV)!=0 && useIOV.compare("all") != 0){
350 continue;
351 }
352 found = true;
353 std::cout<<IOVname<<"\n";
354 const std::string filename= IOVname +"_"+tagName+".log";
355 std::ofstream opFile(filename);
356 opFile <<iov<<"\n";
357 opFile.close();
358 }
359 if(!found){
360 std::cout<< "IOV not found - Choose between one of the following:\n";
361 for(const auto & [IOVname,iov]:myIOVs){
362 std::cout<<IOVname<<" ";
363 }
364 std::cout << "\n";
365 }
366
367 }
368 else{
369 const std::string fileName = tagName + ".log";
370 std::ofstream opFile(fileName);
371 printf("%-11s: %s\n", "RunNumber" ,(myIOVs.back().first).c_str()) ;
372 opFile << myIOVs.back().second << "\n";
373 opFile.close();
374 }
375
376 return returnCode;
377}
static Double_t fs
std::string iovToString(const cool::IObject &obj, bool runLumi=true)
std::string payloadToString(const cool::IObject &obj)
static const std::string outputFileName
display
Definition pyroot.py:42

◆ payloadToString()

std::string payloadToString ( const cool::IObject & obj)

Definition at line 256 of file MakeReferenceFile.cxx.

257{
258 std::string result;
259 const cool::IRecord &record = obj.payload();
260 const auto &thisSpec = record.specification();
261 for (cool::UInt32 i = 0; i != thisSpec.size(); ++i)
262 {
263 const std::string delimiter = (i == 0) ? ("") : (",");
264 std::string typeName = thisSpec[i].storageType().name();
265 result += "[\'" + thisSpec[i].name() + " (" + typeName + ")\' : ";
266 std::ostringstream os;
267 record[i].printValue(os);
268 result += os.str();
269 }
270 result += "]";
271 return result;
272}

◆ timeRep()

std::string timeRep ( const cool::ValidityKey & t,
bool isEnd = false,
bool runLumi = true )

Definition at line 217 of file MakeReferenceFile.cxx.

218{
219 std::string result;
220 const std::string trail = isEnd ? (")") : ("]");
221 if (not runLumi)
222 { // ns of epoch
223 if (t == cool::ValidityKeyMin)
224 {
225 result = "ValidityKeyMin";
226 }
227 else if (t == cool::ValidityKeyMax)
228 {
229 result = "ValidityKeyMax";
230 }
231 else
232 {
233 long int seconds = static_cast<long int>(t / 1000000000);
234 std::string timeStr{std::asctime(std::gmtime(&seconds))};
235 result = timeStr + " UTC";
236 }
237 }
238 else
239 { // runLumi
240 auto run = t >> 32;
241 auto lumiblock = t & 0xFFFFFFFF;
242 result = "[" + std::to_string(run) + "," + std::to_string(lumiblock) + trail;
243 }
244 return result;
245}
Definition run.py:1