musrfit  1.9.2
write_musrRoot_runHeader.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  write_musrRoot_runHeader.cpp
4 
5  Author: Andreas Suter
6  e-mail: andreas.suter@psi.ch
7 
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * Copyright (C) 2007-2023 by Andreas Suter *
12  * andreas.suter@psi.ch *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the *
26  * Free Software Foundation, Inc., *
27  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28  ***************************************************************************/
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #include <cstdlib>
35 #include <ctime>
36 #include <cstring>
37 
38 #include <iostream>
39 
40 #include <TROOT.h>
41 #include <TFile.h>
42 #include <TFolder.h>
43 
44 #ifdef HAVE_GIT_REV_H
45 #include "git-revision.h"
46 #endif
47 
48 #include "PMusr.h"
49 #include "TMusrRunHeader.h"
50 
52 {
53  std::cout << std::endl << "usage: write_musrRoot_runHeader [<fileName>] | --version";
54  std::cout << std::endl << " <fileName> is the file name including the extention root, e.g. test.root";
55  std::cout << std::endl << std::endl;
56 }
57 
58 int main(int argc, char *argv[])
59 {
60  if (argc != 2) {
62  return 1;
63  }
64 
65  if (!strcmp(argv[1], "--version")) {
66 #ifdef HAVE_CONFIG_H
67 #ifdef HAVE_GIT_REV_H
68  std::cout << std::endl << "write_musrRoot_runHeader version: " << PACKAGE_VERSION << ", git-branch: " << GIT_BRANCH << ", git-rev: " << GIT_CURRENT_SHA1 << " (" << BUILD_TYPE << "), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
69 #else
70  std::cout << std::endl << "write_musrRoot_runHeader version: " << PACKAGE_VERSION << " (" << BUILD_TYPE << "), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
71 #endif
72 #else
73 #ifdef HAVE_GIT_REV_H
74  std::cout << std::endl << "write_musrRoot_runHeader git-branch: " << GIT_BRANCH << ", git-rev: " << GIT_CURRENT_SHA1 << std::endl << std::endl;
75 #else
76  std::cout << std::endl << "write_musrRoot_runHeader version: unknown." << std::endl << std::endl;
77 #endif
78 #endif
79  return 0;
80  }
81 
82  // MusrRoot Run Header object
83  TMusrRunHeader *header = new TMusrRunHeader(argv[1]);
85 
86  // run info
87  header->Set("RunInfo/Generic Validator URL", "http://lmu.web.psi.ch/facilities/software/MusrRoot/Validation/MusrRoot.xsd");
88  header->Set("RunInfo/Specific Validator URL", "http://lmu.web.psi.ch/facilities/software/MusrRoot/Validation/MusrRootGPS.xsd");
89  header->Set("RunInfo/Generator", "any2many");
90  header->Set("RunInfo/File Name", "deltat_tdc_gps_2871.root");
91  header->Set("RunInfo/Run Title", "here comes the run title");
92  header->Set("RunInfo/Run Number", 2871);
93 
94  // run info - start/stop time and duration
95  TString startTime("2012-04-19 14:25:22"), stopTime("2012-04-19 19:13:47");
96  struct tm tm_start, tm_stop;
97  header->Set("RunInfo/Run Start Time", startTime);
98  header->Set("RunInfo/Run Stop Time", stopTime);
99  // calculate run duration
100  memset(&tm_start, 0, sizeof(tm_start));
101  strptime(startTime.Data(), "%Y-%m-%d %H:%M:%S", &tm_start);
102  memset(&tm_stop, 0, sizeof(tm_stop));
103  strptime(stopTime.Data(), "%Y-%m-%d %H:%M:%S", &tm_stop);
104  Double_t duration = difftime(mktime(&tm_stop), mktime(&tm_start));
105  prop.Set("Run Duration", (Int_t)duration, "sec");
106  header->Set("RunInfo/Run Duration", prop);
107 
108  header->Set("RunInfo/Laboratory", "PSI");
109  header->Set("RunInfo/Instrument", "GPS");
110 
111  prop.Set("Muon Beam Momentum", 28.1, "MeV/c");
112  header->Set("RunInfo/Muon Beam Momentum", prop);
113 
114  header->Set("RunInfo/Muon Species", "positive muon");
115  header->Set("RunInfo/Muon Source", "target M");
116  header->Set("RunInfo/Setup", "a very special setup with Heliox");
117  header->Set("RunInfo/Comment", "nothing more to be said");
118  header->Set("RunInfo/Sample Name", "the best ever");
119 
120  prop.Set("Sample Temperature", 3.2, 3.21, 0.05, "K", "CF1");
121  header->Set("RunInfo/Sample Temperature", prop);
122 
123  prop.Set("Sample Magnetic Field", 350.0, 350.002, 0.005, "G", "WXY");
124  header->Set("RunInfo/Sample Magnetic Field", prop);
125 
126  header->Set("RunInfo/No of Histos", 4);
127 
128  prop.Set("Time Resolution", 0.1953125, "ns", "TDC 9999");
129  header->Set("RunInfo/Time Resolution", prop);
130 
131  header->Set("DetectorInfo/Detector000/Name", "Left - NPP");
132  header->Set("DetectorInfo/Detector000/Histo Number", 0);
133  header->Set("DetectorInfo/Detector000/Histo Length", 66661);
134  header->Set("DetectorInfo/Detector000/Time Zero Bin", 3419.0);
135  header->Set("DetectorInfo/Detector000/First Good Bin", 3419);
136  header->Set("DetectorInfo/Detector000/Last Good Bin", 66661);
137 
138  header->Set("DetectorInfo/Detector001/Name", "Top - NPP");
139  header->Set("DetectorInfo/Detector001/Histo Number", 1);
140  header->Set("DetectorInfo/Detector001/Histo Length", 66661);
141  header->Set("DetectorInfo/Detector001/Time Zero Bin", 3419.0);
142  header->Set("DetectorInfo/Detector001/First Good Bin", 3419);
143  header->Set("DetectorInfo/Detector001/Last Good Bin", 66661);
144 
145  header->Set("DetectorInfo/Detector002/Name", "Right - NPP");
146  header->Set("DetectorInfo/Detector002/Histo Number", 2);
147  header->Set("DetectorInfo/Detector002/Histo Length", 66661);
148  header->Set("DetectorInfo/Detector002/Time Zero Bin", 3419.0);
149  header->Set("DetectorInfo/Detector002/First Good Bin", 3419);
150  header->Set("DetectorInfo/Detector002/Last Good Bin", 66661);
151 
152  header->Set("DetectorInfo/Detector003/Name", "Bottom - NPP");
153  header->Set("DetectorInfo/Detector003/Histo Number", 3);
154  header->Set("DetectorInfo/Detector003/Histo Length", 66661);
155  header->Set("DetectorInfo/Detector003/Time Zero Bin", 3419.0);
156  header->Set("DetectorInfo/Detector003/First Good Bin", 3419);
157  header->Set("DetectorInfo/Detector003/Last Good Bin", 66661);
158 
159  header->Set("DetectorInfo/Detector004/Name", "Left - PPC");
160  header->Set("DetectorInfo/Detector004/Histo Number", 20);
161  header->Set("DetectorInfo/Detector004/Histo Length", 66661);
162  header->Set("DetectorInfo/Detector004/Time Zero Bin", 3419.0);
163  header->Set("DetectorInfo/Detector004/First Good Bin", 3419);
164  header->Set("DetectorInfo/Detector004/Last Good Bin", 66661);
165 
166  header->Set("DetectorInfo/Detector005/Name", "Top - PPC");
167  header->Set("DetectorInfo/Detector005/Histo Number", 21);
168  header->Set("DetectorInfo/Detector005/Histo Length", 66661);
169  header->Set("DetectorInfo/Detector005/Time Zero Bin", 3419.0);
170  header->Set("DetectorInfo/Detector005/First Good Bin", 3419);
171  header->Set("DetectorInfo/Detector005/Last Good Bin", 66661);
172 
173  header->Set("DetectorInfo/Detector006/Name", "Right - PPC");
174  header->Set("DetectorInfo/Detector006/Histo Number", 22);
175  header->Set("DetectorInfo/Detector006/Histo Length", 66661);
176  header->Set("DetectorInfo/Detector006/Time Zero Bin", 3419.0);
177  header->Set("DetectorInfo/Detector006/First Good Bin", 3419);
178  header->Set("DetectorInfo/Detector006/Last Good Bin", 66661);
179 
180  header->Set("DetectorInfo/Detector007/Name", "Bottom - PPC");
181  header->Set("DetectorInfo/Detector007/Histo Number", 23);
182  header->Set("DetectorInfo/Detector007/Histo Length", 66661);
183  header->Set("DetectorInfo/Detector007/Time Zero Bin", 3419.0);
184  header->Set("DetectorInfo/Detector007/First Good Bin", 3419);
185  header->Set("DetectorInfo/Detector007/Last Good Bin", 66661);
186 
187  TStringVector scHistoNames;
188  scHistoNames.push_back("Sample Temperature");
189  scHistoNames.push_back("Sample Magnetic Field");
190  header->Set("RunInfo/Slow Control Histo Names", scHistoNames);
191 
192  TStringVector dummyTest;
193  dummyTest.push_back("dummy1");
194  dummyTest.push_back("dummy2");
195  dummyTest.push_back("dummy3");
196  header->Set("RunInfo/Dummy Test", dummyTest);
197 
198  // sample environment
199  header->Set("SampleEnvironmentInfo/Cryo", "Konti-1");
200  header->Set("SampleEnvironmentInfo/Insert", "X123");
201  header->Set("SampleEnvironmentInfo/Orientation", "c-axis perp spin, perp field. spin perp field");
202 
203  prop.Set("CF2", 3.2, 3.22, 0.04, "K");
204  header->Set("SampleEnvironmentInfo/CF2", prop);
205 
206  prop.Set("CF3", MRH_UNDEFINED, 3.27, 0.09, "K", "strange temperature");
207  header->Set("SampleEnvironmentInfo/CF3", prop);
208 
209  prop.Set("CF4", 3.25, 3.28, "K");
210  header->Set("SampleEnvironmentInfo/CF4", prop);
211 
212  prop.Set("CF5", 3.26, 3.29, "K", "another strange temperature");
213  header->Set("SampleEnvironmentInfo/CF5", prop);
214 
215  prop.Set("Dummy Prop", -2.0, -2.001, 0.002, "SI-unit");
216  header->Set("SampleEnvironmentInfo/Dummy Prop", prop);
217 
218  // magnetic field environment
219  header->Set("MagneticFieldEnvironmentInfo/Magnet Name", "Bpar");
220  prop.Set("Current", 1.34, "A");
221  header->Set("MagneticFieldEnvironmentInfo/Current", prop);
222 
223  // beamline
224  header->Set("BeamlineInfo/Name", "piM3.2");
225  header->Set("BeamlineInfo/WSX61a", "DAC = 3289, ADC = 0.800");
226 
227  TIntVector dummyInt;
228  for (UInt_t i=0; i<3; i++) dummyInt.push_back(i+1000);
229  header->Set("BeamlineInfo/Dummy Int", dummyInt);
230 
231 
232  // scaler
233  header->Set("ScalerInfo/Ip", 12332123);
234 
235  // funny sub/sub/../sub-structure
236  header->Set("aa/bb/cc/dd/ee/ff/name", "funny");
237  header->Set("aa/bb/cc/dd/ee/ff/gg/xyz", 123);
238 
239  TFile *f = new TFile(argv[1], "RECREATE", "write_musrRoot_runHeader");
240  if (f->IsZombie()) {
241  delete f;
242  return -1;
243  }
244 
245  // root file header related things
246  TFolder *runHeader = new TFolder("RunHeader", "MusrRoot Run Header Info");
247 
248  if (header->FillFolder(runHeader)) {
249  runHeader->Write();
250  }
251 
252  f->Close();
253 
254  // clean up
255  delete f;
256  delete header;
257 
258  return 0;
259 }
std::vector< Int_t > TIntVector
int main(int argc, char *argv[])
virtual void Set(TString pathName, TString value)
#define MRH_UNDEFINED
std::vector< TString > TStringVector
virtual void Set(TString label, Double_t demand, Double_t value, Double_t error, TString unit, TString description=TString("n/a"))
void write_musrRoot_runHeader_syntax()
virtual Bool_t FillFolder(TFolder *folder)