add TDirectory option to any2many.
This commit is contained in:
@@ -582,6 +582,58 @@ PRawRunData::~PRawRunData()
|
||||
fRedGreenOffset.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// CalcStartDateTime (public)
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Calculate time_t of the present fStartDate and fStartTime.
|
||||
*
|
||||
* @param ok, true if time_t conversion has been successful
|
||||
*
|
||||
* @return time_t of the present fStartDate and fStartTime
|
||||
*/
|
||||
const time_t PRawRunData::CalcStartDateTime(bool &ok)
|
||||
{
|
||||
time_t dt=0;
|
||||
ok = true;
|
||||
struct tm tmStruct;
|
||||
char date_time[256];
|
||||
snprintf(date_time, sizeof(date_time), "%s %s", fStartDate.Data(), fStartTime.Data());
|
||||
char *p_char = strptime(date_time, "%Y-%m-%d %H:%M:%S", &tmStruct);
|
||||
if (*p_char != '\0') {
|
||||
ok = false;
|
||||
return dt;
|
||||
}
|
||||
dt = mktime(&tmStruct);
|
||||
return dt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// CalcStopDateTime (public)
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Calculate time_t of the present fStopDate and fStopTime.
|
||||
*
|
||||
* @param ok, true if time_t conversion has been successful
|
||||
*
|
||||
* @return time_t of the present fStopDate and fStopTime
|
||||
*/
|
||||
const time_t PRawRunData::CalcStopDateTime(bool &ok)
|
||||
{
|
||||
time_t dt=0;
|
||||
ok = true;
|
||||
struct tm tmStruct;
|
||||
char date_time[256];
|
||||
snprintf(date_time, sizeof(date_time), "%s %s", fStopDate.Data(), fStopTime.Data());
|
||||
char *p_char = strptime(date_time, "%Y-%m-%d %H:%M:%S", &tmStruct);
|
||||
if (*p_char != '\0') {
|
||||
ok = false;
|
||||
return dt;
|
||||
}
|
||||
dt = mktime(&tmStruct);
|
||||
return dt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// GetTemperature (public)
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -72,16 +72,6 @@
|
||||
#define PRH_NPP_OFFSET 0
|
||||
#define PRH_PPC_OFFSET 20
|
||||
|
||||
#define A2M_UNDEFINED 0
|
||||
#define A2M_ROOT 1
|
||||
#define A2M_MUSR_ROOT 2
|
||||
#define A2M_PSIBIN 3
|
||||
#define A2M_PSIMDU 4
|
||||
#define A2M_MUD 5
|
||||
#define A2M_NEXUS 6
|
||||
#define A2M_WKM 7
|
||||
#define A2M_ASCII 8
|
||||
|
||||
#define PHR_INIT_ALL 0
|
||||
#define PHR_INIT_MSR 1
|
||||
#define PHR_INIT_ANY2MANY 2
|
||||
@@ -373,6 +363,8 @@ Bool_t PRunDataHandler::WriteData(TString fileName)
|
||||
if (fAny2ManyInfo != nullptr) {
|
||||
if (!fAny2ManyInfo->outFormat.CompareTo("musrroot", TString::kIgnoreCase))
|
||||
outTag = A2M_MUSR_ROOT;
|
||||
else if (!fAny2ManyInfo->outFormat.CompareTo("musrrootdir", TString::kIgnoreCase))
|
||||
outTag = A2M_MUSR_ROOT_DIR;
|
||||
else if (!fAny2ManyInfo->outFormat.CompareTo("psibin", TString::kIgnoreCase))
|
||||
outTag = A2M_PSIBIN;
|
||||
else if (!fAny2ManyInfo->outFormat.CompareTo("psimdu", TString::kIgnoreCase))
|
||||
@@ -395,10 +387,11 @@ Bool_t PRunDataHandler::WriteData(TString fileName)
|
||||
Bool_t success{true};
|
||||
switch (outTag) {
|
||||
case A2M_MUSR_ROOT:
|
||||
case A2M_MUSR_ROOT_DIR:
|
||||
if (fAny2ManyInfo->outFileName.Length() == 0)
|
||||
success = WriteMusrRootFile(fileName);
|
||||
success = WriteMusrRootFile(outTag, fileName);
|
||||
else
|
||||
success = WriteMusrRootFile(fAny2ManyInfo->outFileName);
|
||||
success = WriteMusrRootFile(outTag, fAny2ManyInfo->outFileName);
|
||||
break;
|
||||
case A2M_PSIBIN:
|
||||
case A2M_PSIMDU:
|
||||
@@ -603,6 +596,8 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
|
||||
outTag = A2M_ROOT;
|
||||
else if (!fAny2ManyInfo->outFormat.CompareTo("musrroot", TString::kIgnoreCase))
|
||||
outTag = A2M_MUSR_ROOT;
|
||||
else if (!fAny2ManyInfo->outFormat.CompareTo("musrrootdir", TString::kIgnoreCase))
|
||||
outTag = A2M_MUSR_ROOT_DIR;
|
||||
else if (!fAny2ManyInfo->outFormat.CompareTo("psi-bin", TString::kIgnoreCase))
|
||||
outTag = A2M_PSIBIN;
|
||||
else if (!fAny2ManyInfo->outFormat.CompareTo("mud",TString::kIgnoreCase))
|
||||
@@ -669,10 +664,11 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
|
||||
success = WriteRootFile(fAny2ManyInfo->outFileName);
|
||||
break;
|
||||
case A2M_MUSR_ROOT:
|
||||
case A2M_MUSR_ROOT_DIR:
|
||||
if (fAny2ManyInfo->outFileName.Length() == 0)
|
||||
success = WriteMusrRootFile();
|
||||
success = WriteMusrRootFile(outTag);
|
||||
else
|
||||
success = WriteMusrRootFile(fAny2ManyInfo->outFileName);
|
||||
success = WriteMusrRootFile(outTag, fAny2ManyInfo->outFileName);
|
||||
break;
|
||||
case A2M_PSIBIN:
|
||||
if (fAny2ManyInfo->outFileName.Length() == 0)
|
||||
@@ -781,7 +777,8 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
|
||||
success = WriteRootFile(fln);
|
||||
break;
|
||||
case A2M_MUSR_ROOT:
|
||||
success = WriteMusrRootFile(fln);
|
||||
case A2M_MUSR_ROOT_DIR:
|
||||
success = WriteMusrRootFile(outTag, fln);
|
||||
break;
|
||||
case A2M_PSIBIN:
|
||||
success = WritePsiBinFile(fln);
|
||||
@@ -3730,8 +3727,6 @@ Bool_t PRunDataHandler::ReadAsciiFile()
|
||||
{
|
||||
Bool_t success = true;
|
||||
|
||||
std::cout << "as35> in ReadAsciiFile() ..." << std::endl;
|
||||
|
||||
// open file
|
||||
std::ifstream f;
|
||||
|
||||
@@ -4541,13 +4536,12 @@ Bool_t PRunDataHandler::ReadDatFile()
|
||||
/**
|
||||
* <p> Write the MusrRoot file format. Only the required entries will be handled.
|
||||
*
|
||||
* <b>return:</b>
|
||||
* - true on successful writting,
|
||||
* - otherwise false.
|
||||
*
|
||||
* \param tag = A2M_MUSR_ROOT (TFolder MusrRoot, deprecated), = A2M_MUSR_ROOT_DIR (TDirectory MusrRoot).
|
||||
* \param fln file name. If empty, the routine will try to construct one
|
||||
*
|
||||
* \return true on successful writting, false otherwise.
|
||||
*/
|
||||
Bool_t PRunDataHandler::WriteMusrRootFile(TString fln)
|
||||
Bool_t PRunDataHandler::WriteMusrRootFile(Int_t tag, TString fln)
|
||||
{
|
||||
Bool_t ok = false;
|
||||
fln = GenerateOutputFileName(fln, ".root", ok);
|
||||
@@ -4557,24 +4551,34 @@ Bool_t PRunDataHandler::WriteMusrRootFile(TString fln)
|
||||
if (!fAny2ManyInfo->useStandardOutput)
|
||||
std::cout << std::endl << ">> PRunDataHandler::WriteMusrRootFile(): writing a root data file (" << fln.Data() << ") ... " << std::endl;
|
||||
|
||||
// write file
|
||||
std::unique_ptr<TFile> fout = std::make_unique<TFile>(fln, "RECREATE", fln);
|
||||
if (fout == nullptr) {
|
||||
std::cerr << std::endl << "PRunDataHandler::WriteMusrRootFile(): **ERROR** Couldn't create ROOT file '" << fln << "'" << std::endl;
|
||||
return false;
|
||||
}
|
||||
fout->cd();
|
||||
|
||||
// generate data file
|
||||
TFolder *histosFolder;
|
||||
TFolder *decayAnaModule;
|
||||
TFolder *runHeader;
|
||||
|
||||
histosFolder = gROOT->GetRootFolder()->AddFolder("histos", "Histograms");
|
||||
gROOT->GetListOfBrowsables()->Add(histosFolder, "histos");
|
||||
decayAnaModule = histosFolder->AddFolder("DecayAnaModule", "muSR decay histograms");
|
||||
|
||||
runHeader = gROOT->GetRootFolder()->AddFolder("RunHeader", "MusrRoot Run Header Info");
|
||||
gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader");
|
||||
std::unique_ptr<TMusrRunHeader> header = std::make_unique<TMusrRunHeader>(true);
|
||||
gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader");
|
||||
TFolder *histosFolder, *decayAnaModule, *runHeader;
|
||||
TDirectory *histosDir, *decayAnaDir, *runHeaderDir;
|
||||
if (tag == A2M_MUSR_ROOT) { // TFolder
|
||||
histosFolder = new TFolder("histos", "Histograms");
|
||||
decayAnaModule = histosFolder->AddFolder("DecayAnaModule", "muSR decay histograms");
|
||||
runHeader = new TFolder("RunHeader", "MusrRoot Run Header Info");
|
||||
} else { // TDirectory
|
||||
histosDir = fout->mkdir("histos");
|
||||
decayAnaDir = histosDir->mkdir("decayAnaModule");
|
||||
runHeaderDir = fout->mkdir("RunHeader");
|
||||
}
|
||||
|
||||
// feed header info
|
||||
TString str, pathName;
|
||||
Int_t ival;
|
||||
Double_t dval[2];
|
||||
time_t start{0}, stop{0};
|
||||
Bool_t valid{false};
|
||||
TMusrRunPhysicalQuantity prop;
|
||||
|
||||
// feed RunInfo
|
||||
@@ -4593,7 +4597,11 @@ Bool_t PRunDataHandler::WriteMusrRootFile(TString fln)
|
||||
header->Set("RunInfo/Run Start Time", str);
|
||||
str = fData[0].GetStopDate()->Copy() + " " + fData[0].GetStopTime()->Copy();
|
||||
header->Set("RunInfo/Run Stop Time", str);
|
||||
ival = fData[0].GetStopDateTime() - fData[0].GetStartDateTime();
|
||||
start = fData[0].CalcStartDateTime(valid);
|
||||
if (valid)
|
||||
stop = fData[0].CalcStopDateTime(valid);
|
||||
if (valid)
|
||||
ival = (int)stop - (int)start;
|
||||
prop.Set("Run Duration", ival, "sec");
|
||||
header->Set("RunInfo/Run Duration", prop);
|
||||
str = fData[0].GetLaboratory()->Copy();
|
||||
@@ -4723,29 +4731,28 @@ Bool_t PRunDataHandler::WriteMusrRootFile(TString fln)
|
||||
}
|
||||
}
|
||||
|
||||
// add histos to the DecayAnaModule folder
|
||||
for (UInt_t i=0; i<histos.size(); i++)
|
||||
decayAnaModule->Add(histos[i]);
|
||||
|
||||
// write file
|
||||
std::unique_ptr<TFile> fout = std::make_unique<TFile>(fln, "RECREATE", fln);
|
||||
if (fout == nullptr) {
|
||||
std::cerr << std::endl << "PRunDataHandler::WriteMusrRootFile(): **ERROR** Couldn't create ROOT file '" << fln << "'" << std::endl;
|
||||
return false;
|
||||
if (tag == A2M_MUSR_ROOT) { // TFolder
|
||||
// add histos to the DecayAnaModule folder
|
||||
for (UInt_t i=0; i<histos.size(); i++)
|
||||
decayAnaModule->Add(histos[i]);
|
||||
} else { // TDirectory
|
||||
// add histos to the DecayAnaModule directory
|
||||
for (UInt_t i=0; i<histos.size(); i++)
|
||||
decayAnaDir->Add(histos[i]);
|
||||
}
|
||||
|
||||
fout->cd();
|
||||
if (header->FillFolder(runHeader))
|
||||
runHeader->Write();
|
||||
histosFolder->Write();
|
||||
if (tag == A2M_MUSR_ROOT) { // TFolder
|
||||
if (header->FillFolder(runHeader))
|
||||
runHeader->Write();
|
||||
histosFolder->Write();
|
||||
} else { // TDirectory
|
||||
if (header->FillDirectory(runHeaderDir)) {
|
||||
runHeaderDir->Write();
|
||||
}
|
||||
histosDir->Write();
|
||||
}
|
||||
fout->Close();
|
||||
|
||||
// cleanup
|
||||
for (UInt_t i=0; i<histos.size(); i++) {
|
||||
if (histos[i])
|
||||
delete histos[i];
|
||||
}
|
||||
|
||||
// check if root file shall be streamed to stdout
|
||||
if (fAny2ManyInfo->useStandardOutput && (fAny2ManyInfo->compressionTag == 0)) {
|
||||
// stream file to stdout
|
||||
|
||||
Reference in New Issue
Block a user