0% found this document useful (0 votes)
6 views1 page

Run Start Time

This C++ code reads a ROOT file to extract and print the run start time as a Unix timestamp and in a human-readable format. It checks for proper file input and handles errors if the file cannot be opened or if the 'starttime' parameter is not found. The program uses the standard library to convert the timestamp into local time for display.

Uploaded by

Manoj Adhikari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Run Start Time

This C++ code reads a ROOT file to extract and print the run start time as a Unix timestamp and in a human-readable format. It checks for proper file input and handles errors if the file cannot be opened or if the 'starttime' parameter is not found. The program uses the standard library to convert the timestamp into local time for display.

Uploaded by

Manoj Adhikari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//This code prints the run starttime of the specific run.

And prints the starttime


in human readable format.
#include <TFile.h>
#include <TParameter.h>
#include <iostream>
#include <ctime>

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


// Check if the user provided a file name
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <ROOT filename>" << std::endl;
return 1;
}

// Open the ROOT file


TFile *f = TFile::Open(argv[1]);
if (!f || f->IsZombie()) {
std::cerr << "Error: Could not open ROOT file: " << argv[1] << std::endl;
return 1;
}

// Retrieve the 'starttime' parameter


auto tsstart = (TParameter<Long64_t> *) f->Get("starttime");
if (tsstart) {
Long64_t run_starttime = tsstart->GetVal();
std::cout << "Run Start Time (Unix Timestamp): " << run_starttime <<
std::endl;

// Convert to human-readable format


time_t rawtime = (time_t) run_starttime;
struct tm *timeinfo = localtime(&rawtime);
std::cout << "Run Start Time (Local Time): " << asctime(timeinfo);
} else {
std::cerr << "Error: 'starttime' not found in the ROOT file." << std::endl;
}

// Close the file


f->Close();
delete f;

return 0;
}

You might also like