KaliVeda
Toolkit for HIC analysis
KVFAZIADB.cpp
1 //Created by KVClassFactory on Tue Jan 20 11:52:49 2015
2 //Author: ,,,
3 
4 #include "KVFAZIADB.h"
5 #include "TSystem.h"
6 #include "KVNumberList.h"
7 #include "KVDataSetManager.h"
8 #include "KVRunListLine.h"
9 
10 #include "KVDBParameterList.h"
11 #include "KVDBParameterSet.h"
12 #include "IRODS.h"
13 #include "TRandom.h"
14 #include "KVMultiDetArray.h"
15 
16 KVFAZIADB* gFaziaDB;
17 
19 
20 // BEGIN_HTML <!--
22 /* -->
23 <h2>KVFAZIADB</h2>
24 <h4>database for FAZIA detector</h4>
25 <!-- */
26 // --> END_HTML
28 
29 
30 
33 void KVFAZIADB::init()
34 {
35  //default initialisations
36 
37  fDBType = "FAZIADB";
38 
39  fExceptions = AddTable("Exceptions", "List signals with different PSA parameters");
40  fCalibrations = AddTable("Calibrations", "Available calibration for FAZIA detectors");
41  fOoODets = nullptr;
42  //filenames to manage the data transfer via IRODS
43  fDONEfile = "FromKVFAZIADB_transferdone.list";
44  fFAILEDfile = "FromKVFAZIADB_transferfailed.list";
45 
46  Info("init", "file names for tranfert:\n%s\n%s", fDONEfile.Data(), fFAILEDfile.Data());
47 }
48 
49 
50 
52 
54  "FAZIA experiment parameter database")
55 {
56  init();
57 }
58 
59 
60 
61 
63 
65  "FAZIA experiment parameter database")
66 {
67  init();
68 }
69 
70 
71 
74 
76 {
77  //reset global pointer gFaziaDB if it was pointing to this database
78 
79  if (gFaziaDB == this)
80  gFaziaDB = 0;
81 }
82 
83 
84 
86 
88 {
89  KVExpDB::cd();
90  gFaziaDB = this;
91 
92 }
93 
94 
95 
96 
100 
101 void KVFAZIADB::Build(bool minimal)
102 {
103 
104  //Use KVINDRARunListReader utility subclass to read complete runlist
105 
106  //get full path to runlist file, using environment variables for the current dataset
107 
108  ReadNewRunList();
109  ReadSystemList();
110 
111  if(minimal)
112  return;
113 
114  ReadExceptions();
117  ReadComments();
119  gMultiDetArray->MakeCalibrationTables(this);
121 
122 }
123 
124 
125 
130 
132 {
133  //Read first runlist.dat file if exists
134  //and then read
135  //runsheets
136  KVString line;
137  KVFAZIADBRun* run = 0;
138  TObjArray* toks = 0;
139 
140  std::ifstream fin;
141  if (!OpenCalibFile("Runlist", fin)) {
142  Error("ReadNewRunList()", "Could not open file %s",
143  GetCalibFileName("Runlist").Data());
144  return;
145  }
146  Info("ReadNewRunList()", "Reading run list ...");
147 
148  while (fin.good() && !fin.eof()) {
149  line.ReadLine(fin);
150  if (line.Length() > 1 && !line.BeginsWith("#") && !line.BeginsWith("Version")) {
151 
152  toks = line.Tokenize("|");
153  for (Int_t ii = 0; ii < toks->GetEntries(); ii += 1) {
154  KVString couple = ((TObjString*)toks->At(ii))->GetString();
155  couple.Begin("=");
156  KVString name = couple.Next();
157  name = name.Strip(TString::kBoth);
158  KVString value = "";
159  if (!couple.End()) {
160  value = couple.Next();
161  value = value.Strip(TString::kBoth);
162  }
163  if (name == "run") {
164  run = new KVFAZIADBRun(value.Atoi());
165  }
166  else if (name == "read events") {
167  run->SetEvents(value.Atoi());
168  }
169  else if (name == "good events") {
170  run->SetGoodEvents(value.Atoi());
171  }
172  else if (name == "starting date") {
173  run->SetStartDate(value);
174  }
175  else if (name == "stopping date") {
176  run->SetEndDate(value);
177  }
178  else if (name == "aqcuisition status") {
179  run->SetACQStatus(value);
180  }
181  else if (name == "wrong number of blocks") { //events rejected due to the wrong number of blocks
182  run->SetError_WrongNumberOfBlocks(value.Atoi());
183  }
184  else if (name == "block errors") { //events rejected due to internal error in one block
185  run->SetError_InternalBlockError(value.Atoi());
186  }
187  else if (name == "nfiles") { //number of acquisition files
188  run->SetNumberOfAcqFiles(value.Atoi());
189  }
190  else if (name == "duration") { //duration in seconds of the run
191  run->SetDuration(value.Atof());
192  }
193  else if (name == "frequency") { //number of evts per seconds (aquisition rate)
194  run->SetFrequency(value.Atof());
195  }
196  else if (name == "triggerrate") { //trigger rate
197  run->SetTriggerRate(value.Atof());
198  }
199  else if (name == "mtrigger") { //trigger multiplicity
200  run->SetTrigger(value.Atof());
201  }
202  else if (name == "deadtime") { //deadtime of the acquisition between 0 and 1
203  run->SetDeadTime(value.Atof());
204  }
205  else if (name == "trig info") { //number of trigger block in the acquisition file
206  run->SetNumberOfTriggerBlocks(value.Atoi());
207  }
208  else if (name == "size(GB)") { //size in GB
209  run->SetSize(value.Atof());
210  }
211  else {
212  //Info("ReadNewRunList","Unknown field %s=%s",name.Data(),value.Data());
213  }
214  }
215  delete toks;
216  if (run->GetNumber() < 1) {
217  delete run;
218  }
219  else {
220  //run->ReadRunSheet();
221  AddRun(run);
222  }
223  }
224  }
225  fin.close();
226 
227  std::ifstream ffin;
228  if (!OpenCalibFile("Runsheets", ffin)) {
229  Error("ReadNewRunList()", "Could not open file %s",
230  GetCalibFileName("Runsheets").Data());
231  return;
232  }
233  Info("ReadNewRunList()", "Reading run sheets ...");
234 
235  Bool_t newrun = kFALSE;
236  while (ffin.good() && !ffin.eof()) {
237  line.ReadLine(ffin);
238  if (line.Length() > 1 && !line.BeginsWith("#") && !line.BeginsWith("Version")) {
239 
240  toks = line.Tokenize("|");
241  for (Int_t ii = 0; ii < toks->GetEntries(); ii += 1) {
242  KVString couple = ((TObjString*)toks->At(ii))->GetString();
243  couple.Begin("=");
244  KVString name = couple.Next();
245  name = name.Strip(TString::kBoth);
246  KVString value = "";
247  if (!couple.End()) {
248  value = couple.Next();
249  value = value.Strip(TString::kBoth);
250  }
251  if (name == "run") {
252  Int_t number = value.Atoi();
253  newrun = kFALSE;
254  if (!(run = GetRun(number))) {
255  run = new KVFAZIADBRun(number);
256  newrun = kTRUE;
257  }
258  }
259  else if (name == "read events") {
260  run->SetEvents(value.Atoi());
261  }
262  else if (name == "good events") {
263  run->SetGoodEvents(value.Atoi());
264  }
265  else if (name == "starting date") {
266  run->SetStartDate(value);
267  }
268  else if (name == "stopping date") {
269  run->SetEndDate(value);
270  }
271  else if (name == "aqcuisition status") {
272  run->SetACQStatus(value);
273  }
274  else if (name == "wrong number of blocks") { //events rejected due to the wrong number of blocks
275  run->SetError_WrongNumberOfBlocks(value.Atoi());
276  }
277  else if (name == "block errors") { //events rejected due to internal error in one block
278  run->SetError_InternalBlockError(value.Atoi());
279  }
280  else if (name == "nfiles") { //number of acquisition files
281  run->SetNumberOfAcqFiles(value.Atoi());
282  }
283  else if (name == "duration") { //duration in seconds of the run
284  run->SetDuration(value.Atof());
285  }
286  else if (name == "frequency") { //number of evts per seconds (aquisition rate)
287  run->SetFrequency(value.Atof());
288  }
289  else if (name == "triggerrate") { //trigger rate
290  run->SetTriggerRate(value.Atof());
291  }
292  else if (name == "mtrigger") { //trigger multiplicity
293  run->SetTrigger(value.Atof());
294  }
295  else if (name == "deadtime") { //deadtime of the acquisition between 0 and 1
296  run->SetDeadTime(value.Atof());
297  }
298  else if (name == "trig info") { //number of trigger block in the acquisition file
299  run->SetNumberOfTriggerBlocks(value.Atoi());
300  }
301  else {
302  //Info("ReadNewRunList","Unknown field %s=%s",name.Data(),value.Data());
303  }
304  }
305  delete toks;
306  if (newrun) {
307  if (run->GetNumber() < 1) {
308  delete run;
309  }
310  else {
311  AddRun(run);
312  }
313  }
314  }
315  }
316  ffin.close();
317 }
318 
319 
320 
327 
329 {
330 //Perform the tranfer via irods to ccali for the indicated directory [file]
331 //return status of the iput command
332 // OK if the transfer is done
333 // not OK if it has failed
334 //
335 
336  IRODS ir;
337  Int_t retour = ir.put(
338  Form("-%s %s", option.Data(), file.Data()),
339  Form("%s/%s/%s", ccali_rep.Data(), gDataSet->GetDataPathSubdir(), gDataSet->GetDataTypeSubdir("bin").Data())
340  );
341  return (retour == 0);
342 
343  /*
344  //some lines to test all the process
345  Double_t val = gRandom->Uniform(0,1);
346  printf("%s %lf\n",file.Data(),val);
347  return (val<0.5);
348  */
349 
350 }
351 
352 
353 
358 
360 {
361 // test the status of the transfer
362 // write to the corresponding file : done or failed
363 //
364 
365  Bool_t retour = TransferAcquisitionFileToCcali(Form("%s/run%06d", path.Data(), run), ccali_rep, option);
366  if (retour) {
367  FILE* ff = fopen(fDONEfile.Data(), "a");
368  fprintf(ff, "%d\n", run);
369  fclose(ff);
370  }
371  else {
372  FILE* ff = fopen(fFAILEDfile.Data(), "a");
373  fprintf(ff, "%d\n", run);
374  fclose(ff);
375  }
376 
377  return retour;
378 
379 }
380 
381 
382 
386 
388 {
389 
390 //Remove file where failed tranfer runs are listed
391 //
392  KVNumberList lFAILED;
393  gSystem->Exec(Form("rm %s", fFAILEDfile.Data()));
394 
395 //Loop on run list
396 //If transfer fails, the run number is kept in a kvnumberlist
397 //for status at the end
398 //
399  lrun.Begin();
400  while (!lrun.End()) {
401  Int_t run = lrun.Next();
402  if (!TransferRunToCcali(run, path, ccali_rep, option)) {
403  lFAILED.Add(run);
404  }
405  }
406 
407 //print list of failed tranfers
408  if (!lFAILED.IsEmpty())
409  Warning("TransferRunListToCcali", "Transfer failed for %d runs :\n%s", lFAILED.GetNValues(), lFAILED.AsString());
410 
411 }
412 
413 
414 
416 
417 void KVFAZIADB::StartTransfer(TString filename, TString ccali_rep, TString option)
418 {
419 
420  Int_t run;
421  TString datadir = "";
422 
423 //-----------
424 // list of runs for which transfer failed during the last tentative
425 //-----------
426  KVNumberList lFAILED;
427  KVFileReader fr;
429  while (fr.IsOK()) {
430  fr.ReadLine(0);
431  if (fr.GetCurrentLine() != "") {
432  run = fr.GetCurrentLine().Atoi();
433  lFAILED.Add(run);
434  }
435  }
436  fr.CloseFile();
437 
438 //-----------
439 // list of runs for which transfer succeeded since the beginning
440 //-----------
441  KVNumberList lDONE;
442  fr.Clear();
444  while (fr.IsOK()) {
445  fr.ReadLine(0);
446  if (fr.GetCurrentLine() != "") {
447  run = fr.GetCurrentLine().Atoi();
448  lDONE.Add(run);
449  }
450  }
451  if (lDONE.GetNValues() > 0)
452  Info("StartTransfer", "%d runs already tranfered:\n%s", lDONE.GetNValues(), lDONE.AsString());
453  fr.CloseFile();
454 
455 //-----------
456 // all runs produced
457 //-----------
458 
459  KVNumberList lALL;
460  fr.Clear();
461  fr.OpenFileToRead(filename.Data());
462  while (fr.IsOK()) {
463 
464  fr.ReadLine("|");
465  if (fr.GetCurrentLine().BeginsWith("#")) {
467  line.ReplaceAll("#", "");
468  line = line.StripAllExtraWhiteSpace();
469  line.Begin("=");
470  KVString name = line.Next();
471  if (!line.End() && name == "--dir") {
472  datadir = line.Next();
473  Info("ReadDBFile", "acquisition file directory: %s", datadir.Data());
474  }
475  }
476  else {
477  if (datadir == "") {
478  fr.CloseFile();
479  Warning("ReadDBFile", "no data directory has been found ...");
480  return;
481  }
482  if (fr.GetNparRead() > 0) {
483  for (Int_t ii = 0; ii < fr.GetNparRead(); ii += 1) {
484 
485  KVString couple = fr.GetReadPar(ii);
486  couple.Begin("=");
487  KVString name = couple.Next();
488  name = name.Strip(TString::kBoth);
489  KVString value = "";
490  if (!couple.End()) {
491  value = couple.Next();
492  value = value.Strip(TString::kBoth);
493  }
494  if (name == "run") {
495  run = value.Atoi();
496  if (!lDONE.Contains(run))
497  lALL.Add(run);
498  }
499  }
500  }
501  }
502  }
503  fr.CloseFile();
504 
505  if (lALL.GetNValues() > 0) {
506  Info("StartTransfer", "Start transfer for %d runs:\n%s", lALL.GetNValues(), lALL.AsString());
507  TransferRunListToCcali(lALL, datadir.Data(), ccali_rep, option);
508  }
509  else
510  Info("StartTransfer", "no runs to tranfer ...");
511 
512 }
513 
514 
515 
516 
518 
519 const Char_t* KVFAZIADB::GetFileName(const Char_t* meth, const Char_t* keyw)
520 {
521 
522  TString basic_name = GetCalibFileName(keyw);
523  if (basic_name == "") {
524  Info(meth, "No name found for \"%s\" file", keyw);
525  return "";
526  }
527  Info(meth, "Search for %s for dataset %s ...", basic_name.Data(), gDataSet->GetName());
528  static TString fp;
529  fp = gDataSet->GetFullPathToDataSetFile(basic_name.Data());
530  if (fp == "") {
531  Info(meth, "\tNo file found ...");
532  return "";
533  }
534  return fp.Data();
535 
536 }
537 
538 
539 
541 
543 {
544 
545  TString fp = GetFileName(meth, keyw);
546  if (fp == "")
547  return 0;
548 
549  KVFileReader* fr = new KVFileReader();
550  if (!fr->OpenFileToRead(fp.Data())) {
551  Error(meth, "Error in opening file %s", fp.Data());
552  delete fr;
553  return 0;
554  }
555 
556  Info(meth, "Reading %s file", fp.Data());
557  return fr;
558 
559 }
560 
561 
562 
564 
565 TEnv* KVFAZIADB::GetFileTEnv(const Char_t* meth, const Char_t* keyw)
566 {
567 
568  TString fp = GetFileName(meth, keyw);
569  if (fp == "")
570  return 0;
571 
572  Info(meth, "Reading %s file", fp.Data());
573  TEnv* env = new TEnv();
574  env->ReadFile(fp.Data(), kEnvAll);
575  return env;
576 
577 }
578 
579 
580 
582 
584 {
585  KVFileReader* fr = GetKVFileReader("ReadExceptions()", "Exceptions");
586  if (!fr)
587  return;
588 
589  TList* ll = new TList();
590  KVNumberList lruns;
591  KVDBParameterList* dbp = 0;
592 
593  ll->SetOwner(kFALSE);
594  while (fr->IsOK()) {
595  fr->ReadLine(":");
596  if (fr->GetNparRead() == 2) {
597  if (fr->GetReadPar(0) == "RunRange") {
598  if (ll->GetEntries() > 0) {
599  LinkListToRunRange(ll, lruns);
600  ll->Clear();
601  }
602  lruns.SetList(fr->GetReadPar(1));
603  //printf("nouvelle plage : %s\n", lruns.AsString());
604  }
605  else {
606  KVString name(fr->GetReadPar(0));
607  name.Begin(".");
608  KVString sdet = name.Next();
609 
610  KVString sig = name.Next();
611  if (sig == "QH1" || sig == "QL1" || sig == "I1") sdet.Prepend("SI1-");
612  else if (sig == "Q2" || sig == "I2") sdet.Prepend("SI2-");
613  else if (sig == "Q3") sdet.Prepend("CSI-");
614 
615  KVString par = name.Next();
616  if (!(dbp = (KVDBParameterList*)ll->FindObject(Form("%s.%s", sdet.Data(), sig.Data())))) {
617  dbp = new KVDBParameterList(Form("%s.%s", sdet.Data(), sig.Data()), sdet.Data());
618  dbp->AddKey("Runs", "List of Runs");
619  fExceptions->AddRecord(dbp);
620  ll->Add(dbp);
621  dbp->GetParameters()->SetValue("RunRange", lruns.AsString());
622  dbp->GetParameters()->SetValue("Detector", sdet.Data());
623  dbp->GetParameters()->SetValue("Signal", sig.Data());
624  }
625  dbp->GetParameters()->SetValue(par.Data(), fr->GetDoubleReadPar(1));
626  }
627  }
628  }
629 
630  if (ll->GetEntries() > 0) {
631  LinkListToRunRange(ll, lruns);
632  ll->Clear();
633  }
634 
635  delete ll;
636  delete fr;
637 
638 }
639 
640 
642 
644 {
645  KVFileReader* fr = GetKVFileReader("ReadComments()", "Comments");
646  if (!fr)
647  return;
648 
649  KVFAZIADBRun* dbrun = 0;
650  while (fr->IsOK()) {
651  fr->ReadLine("|");
652  if (fr->GetCurrentLine().BeginsWith("#")) {
653 
654  }
655  else if (fr->GetCurrentLine() == "") {
656 
657  }
658  else {
659  if (fr->GetNparRead() == 2) {
660  KVString srun(fr->GetReadPar(0));
661  srun.Begin("=");
662  srun.Next();
663  KVNumberList lruns(srun.Next());
664  KVString comments(fr->GetReadPar(1));
665  lruns.Begin();
666  while (!lruns.End()) {
667  Int_t run = lruns.Next();
668  dbrun = (KVFAZIADBRun*)GetRun(run);
669  if (dbrun)
670  dbrun->SetComments(comments.Data());
671  }
672  }
673  }
674  }
675  delete fr;
676 
677 }
678 
679 
680 
682 
684 {
685 
686  TEnv* env = GetFileTEnv("ReadRutherfordCounting()", "RutherfordCounting");
687  if (!env)
688  return;
689 
690  TIter next(env->GetTable());
691  TEnvRec* rec = 0;
692  KVFAZIADBRun* dbrun = 0;
693  while ((rec = (TEnvRec*)next())) {
694  TString sname(rec->GetName());
695  dbrun = GetRun(sname.Atoi());
696  dbrun->SetRutherfordCount(TString(rec->GetValue()).Atoi());
697  }
698  delete env;
699 }
700 
701 
702 
704 
706 {
707  KVFileReader* fr = GetKVFileReader("ReadRutherfordCrossSection()", "RutherfordCrossSection");
708  if (!fr)
709  return;
710 
711  while (fr->IsOK()) {
712  fr->ReadLine(":");
713  if (fr->GetCurrentLine().BeginsWith("#")) {
714 
715  }
716  else if (fr->GetCurrentLine() == "") {
717 
718  }
719  else {
720  if (fr->GetNparRead() == 2) {
721  auto dbsys = GetSystem(fr->GetReadPar(0));
722  if (dbsys) {
723  Double_t val = fr->GetDoubleReadPar(1);
724  for(auto dbrun : dbsys->GetRuns())
725  {
726  dynamic_cast<KVFAZIADBRun*>(dbrun)->SetRutherfordCrossSection(val);
727  }
728  }
729  }
730  }
731  }
732  fr->CloseFile();
733  delete fr;
734 
735 }
736 
737 
738 
740 
742 {
743 
744  KVFileReader* fr = GetKVFileReader("ReadCalibrationFiles()", "CalibrationFiles");
745  if (!fr)
746  return;
747 
748  while (fr->IsOK()) {
749  fr->ReadLine(0);
750  if (fr->GetCurrentLine().BeginsWith("#") || fr->GetCurrentLine() == "") {}
751  else {
753  }
754  }
755  fr->CloseFile();
756  delete fr;
757 
758 }
759 
760 
762 
763 void KVFAZIADB::ReadCalibFile(const Char_t* filename)
764 {
765 
766  Bool_t find = kFALSE;
767  TString fullpath = "";
768  if (gSystem->Exec(Form("test -e %s/%s", GetDataSetDir(), filename)) == 0) {
769  //Info("ReadCalibFile", "%s/%s do not exist", GetDataSetDir(), filename);
770  //return;
771  find = kTRUE;
772  fullpath.Form("%s/%s", GetDataSetDir(), filename);
773  }
774  else if (gSystem->Exec(Form("test -e %s", filename)) == 0) {
775  //Info("ReadCalibFile", "%s do not exist", filename);
776  //return;
777  find = kTRUE;
778  fullpath.Form("%s", filename);
779  }
780  if (!find) {
781  Info("ReadCalibFile", "%s does not exist or not found", filename);
782  return;
783  }
784 
785  Info("ReadCalibFile", "file : %s found", fullpath.Data());
786  TEnv env;
787  env.ReadFile(Form("%s", fullpath.Data()), kEnvAll);
788  TIter next(env.GetTable());
789  TEnvRec* rec = 0;
790  KVDBParameterSet* par = 0;
791  KVNumberList default_run_list = GetRunList();
792 
793  TString ssignal = "";
794  TString stype = "";
795 
796  while ((rec = (TEnvRec*)next())) {
797  TString sname(rec->GetName());
798  if (sname == "Signal") {
799  ssignal = rec->GetValue();
800  }
801  else if (sname == "CalibType") {
802  stype = rec->GetValue();
803  }
804  else if (sname == "RunList") {
805  default_run_list.Set(rec->GetValue());
806  }
807  else {
808  KVString lval(rec->GetValue());
809  Int_t np = 0;
810  lval.Begin(",");
811  while (!lval.End()) {
812  KVString sval = lval.Next();
813  np += 1;
814  }
815  par = new KVDBParameterSet(sname.Data(), stype.Data(), np);
816 
817  np = 0;
818  lval.Begin(",");
819  while (!lval.End()) {
820  par->SetParameter(np++, lval.Next().Atof());
821  }
822  fCalibrations->AddRecord(par);
823  LinkRecordToRunRange(par, default_run_list);
824  }
825  }
826 
827  if (ssignal == "") Error("ReadCalibFile", "No signal defined");
828  if (stype == "") Error("ReadCalibFile", "No calibration type defined");
829 }
830 
831 
832 
836 
838 {
839 
840  //Lit le fichier ou sont listes les dedtecteurs ne marchant plus au cours
841  //de la manip
842  TEnv* env = GetFileTEnv("ReadOoODetectors()", "OoODet");
843  if (!env)
844  return;
845 
846  fOoODets = AddTable("OoO Detectors", "Name of out of order detectors");
847 
848  KVDBRecord* dbrec = 0;
849 
850  TEnvRec* rec = 0;
851 
852  TIter it(env->GetTable());
853  while ((rec = (TEnvRec*)it.Next())) {
854  KVString srec(rec->GetName());
855  KVNumberList nl(rec->GetValue());
856 
857  if (srec.Contains(",")) {
858  srec.Begin(",");
859  while (!srec.End()) {
860  dbrec = new KVDBRecord(srec.Next(), "OoO Detector");
861  dbrec->AddKey("Runs", "List of Runs");
862  fOoODets->AddRecord(dbrec);
863  LinkRecordToRunRange(dbrec, nl);
864  }
865  }
866  else {
867  dbrec = new KVDBRecord(rec->GetName(), "OoO Detector");
868  dbrec->AddKey("Runs", "List of Runs");
869  fOoODets->AddRecord(dbrec);
870  LinkRecordToRunRange(dbrec, nl);
871  }
872  }
873  delete env;
874 }
875 
876 
877 //---------------------------------------
879 //---------------------------------------
880 
881 
896 {
897  /*
898  Use this method in order to read runs written on disk
899  during the experiment
900  File is produced with main information for each run :
901  number of files
902  size
903  starting date
904  Information on runs has to completed after reading acquisition file
905  specially information on trigger and deatdime
906 
907  usage : acqfiles_dir is the repository where acquisition files are written
908 
909  2 output files are written
910  - runlist.dat containing all runs
911  - database.log giving a summarize of stored data
912  the two file names are set by default in .kvrootrc
913 
914  */
915  if (gSystem->Exec(Form("test -d %s", acqfiles_dir.Data())) != 0) {
916  Error("BuildQuickAndDirtyDataBase", "%s is not an existing directory", acqfiles_dir.Data());
917  return;
918  }
919 
920  TString sfout = GetCalibFileName("Runlist");
921  FILE* fout = fopen(sfout.Data(), "w");
922  fprintf(fout, "# DataSet %s\n", gDataSet->GetName());
923  fprintf(fout, "# Runlist generated by KVFAZIADB::BuildQuickAndDirtyDataBase from files located at:\n");
924  fprintf(fout, "# --dir=%s\n", acqfiles_dir.Data());
925 
926  TString sflog = GetCalibFileName("DBLog");
927  FILE* flog = fopen(sflog.Data(), "w");
928  fprintf(flog, "# DataSet %s\n", gDataSet->GetName());
929  fprintf(flog, "# Log generated by KVFAZIADB::BuildQuickAndDirtyDataBase from files located at:\n");
930  fprintf(flog, "# --dir=%s\n", acqfiles_dir.Data());
931 
932  Int_t run, nfiles;
933  Long64_t size = 0;
934  Long64_t totalsize = 0;
935  Int_t date, idx;
936  KVDatime kvdate;
937 
938  KVString ldir = gSystem->GetFromPipe(Form("du %s", acqfiles_dir.Data()));
939  ldir.Begin("\n");
940  Int_t numberofruns = 0;
941  KVNumberList lruns;
942 
943  while (!ldir.End()) {
944  KVString sdir = ldir.Next();
945  sdir.Begin("\t");
946  size = sdir.Next().Atoll(); // /TMath::Power(2,10)+1; //read values are in KB
947  sdir = gSystem->BaseName(sdir.Next());
948  if (sscanf(sdir.Data(), "run%d", &run) == 1) {
949  totalsize += size;
950  Int_t dmin = 0;
951  Int_t dmax = 0;
952  KVString lfile = gSystem->GetFromPipe(Form("ls %s/%s", acqfiles_dir.Data(), sdir.Data()));
953  lfile.Begin("\n");
954  nfiles = 0;
955  while (!lfile.End()) {
956  KVString sfile = lfile.Next();
957  //FzEventSet-1434434675-41784.pb
958  if (sscanf(sfile.Data(), "FzEventSet-%d-%d.pb", &date, &idx) == 2) {
959  if (dmin == 0) {
960  dmin = dmax = date;
961  }
962  else {
963  if (date < dmin) dmin = date;
964  if (date > dmax) dmax = date;
965  }
966  nfiles += 1;
967  }
968  }
969  if (nfiles == 0 || size == 0) {
970  Warning("BuildQuickAndDirtyDataBase", "%d -> empty run", run);
971  }
972  kvdate.Set(dmin);
973  fprintf(fout, "run=%d | starting date=%s | nfiles=%d | size(GB)=%1.2lf\n", run, kvdate.AsString(), nfiles, size * TMath::Power(2., -20));
974  numberofruns += 1;
975  lruns.Add(run);
976  }
977  else {
978  Double_t conv = TMath::Power(2., -30);
979  fprintf(flog, "total size %lld - %lld\n", size, totalsize);
980  fprintf(flog, "total size (TB) %1.2lf - %1.2lf\n", size * conv, totalsize * conv);
981  fprintf(flog, "number of runs %d\n", numberofruns);
982  fprintf(flog, "last run %d done at %s\n", lruns.Last(), kvdate.AsString());
983  }
984  }
985 
986  fclose(fout);
987  fclose(flog);
988 }
989 
990 
int Int_t
size_t size(const MatrixT &matrix)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
kEnvAll
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Interface to IRODS (Integrated Rule-Oriented Data System) DMS client.
Definition: IRODS.h:15
Int_t put(const Char_t *source, const Char_t *target=".") override
put a new file into IRODS space.
Definition: IRODS.cpp:101
To store calibration parameters in a database ,.
KVNameValueList * GetParameters()
To store calibration parameters in a database ,.
void SetParameter(UShort_t i, Double_t val)
Record folder for the database.
Definition: KVDBRecord.h:43
virtual Bool_t AddKey(KVDBKey *key, Bool_t check=kTRUE)
Definition: KVDBRecord.cpp:65
virtual Int_t GetNumber() const
Definition: KVDBRecord.h:73
void SetComments(const KVString &comments)
Definition: KVDBRun.h:272
void SetTrigger(Int_t trig)
Definition: KVDBRun.h:244
virtual Bool_t AddRecord(KVDBRecord *add)
Definition: KVDBTable.cpp:74
virtual Bool_t AddTable(KVDBTable *table)
Definition: KVDataBase.cpp:84
TString GetFullPathToDataSetFile(const Char_t *filename) const
Definition: KVDataSet.cpp:2053
KVString GetDataTypeSubdir(const Char_t *type) const
Definition: KVDataSet.h:206
virtual const Char_t * GetDataPathSubdir() const
Definition: KVDataSet.h:201
Extension of TDatime to handle various useful date formats.
Definition: KVDatime.h:33
Base class to describe database of an experiment ,,.
Definition: KVExpDB.h:61
virtual KVDBSystem * GetSystem(const Char_t *system) const
Definition: KVExpDB.h:155
virtual void ReadSystemList()
Definition: KVExpDB.cpp:423
virtual void cd()
Definition: KVExpDB.cpp:757
void AddRun(KVDBRun *r)
Definition: KVExpDB.h:126
TString GetCalibFileName(const Char_t *type) const
Definition: KVExpDB.h:179
const KVNumberList & GetRunList() const
Definition: KVExpDB.h:147
virtual void LinkListToRunRange(TList *list, const KVNumberList &nl)
Link the records contained in the list to the set of runs (see LinkRecordToRunRanges).
Definition: KVExpDB.cpp:394
const Char_t * GetDataSetDir() const
Definition: KVExpDB.h:206
virtual void LinkRecordToRunRange(KVDBRecord *rec, UInt_t first_run, UInt_t last_run)
Definition: KVExpDB.cpp:285
Bool_t OpenCalibFile(const Char_t *type, std::ifstream &fs) const
Definition: KVExpDB.cpp:613
TString fDataSet
the name of the dataset to which this database is associated
Definition: KVExpDB.h:64
Database entry for a run in a FAZIA experiment.
Definition: KVFAZIADBRun.h:15
void SetNumberOfAcqFiles(Int_t)
void SetDuration(Double_t)
void SetGoodEvents(Int_t)
void SetError_InternalBlockError(Int_t)
void SetEvents(ULong64_t evt_number)
Definition: KVFAZIADBRun.h:63
void SetError_WrongNumberOfBlocks(Int_t)
void SetStartDate(const KVString &date)
Definition: KVFAZIADBRun.h:67
void SetRutherfordCount(Int_t)
void SetSize(Double_t s)
Definition: KVFAZIADBRun.h:75
void SetACQStatus(const KVString &status)
void SetFrequency(Double_t)
void SetTriggerRate(Double_t)
void SetDeadTime(Double_t)
void SetNumberOfTriggerBlocks(Double_t)
void SetEndDate(const KVString &d)
Definition: KVFAZIADBRun.h:71
Experiment database for FAZIA.
Definition: KVFAZIADB.h:22
const Char_t * GetFileName(const Char_t *meth, const Char_t *keyw)
Definition: KVFAZIADB.cpp:519
Bool_t TransferRunToCcali(Int_t run, TString path, TString ccali_rep="/fazia", TString option="frv")
Definition: KVFAZIADB.cpp:359
TString fFAILEDfile
Definition: KVFAZIADB.h:37
void ReadRutherfordCrossSection()
Definition: KVFAZIADB.cpp:705
Bool_t TransferAcquisitionFileToCcali(TString file, TString ccali_rep="/fazia", TString option="frv")
Definition: KVFAZIADB.cpp:328
TString fDONEfile
Definition: KVFAZIADB.h:36
void TransferRunListToCcali(KVNumberList lrun, TString path, TString ccali_rep="/fazia", TString option="frv")
Definition: KVFAZIADB.cpp:387
void init()
default initialisations
Definition: KVFAZIADB.cpp:33
void BuildQuickAndDirtyDataBase(TString)
Definition: KVFAZIADB.cpp:878
KVDBTable * fExceptions
table of exceptions
Definition: KVFAZIADB.h:27
void ReadNewRunList()
Definition: KVFAZIADB.cpp:131
void cd() override
Definition: KVFAZIADB.cpp:87
KVFileReader * GetKVFileReader(const Char_t *meth, const Char_t *keyw)
Definition: KVFAZIADB.cpp:542
KVDBTable * fCalibrations
table for calibrations
Definition: KVFAZIADB.h:28
void ReadRutherfordCounting()
Definition: KVFAZIADB.cpp:683
void ReadExceptions()
Definition: KVFAZIADB.cpp:583
void ReadComments() override
Definition: KVFAZIADB.cpp:643
void ReadCalibrationFiles()
Definition: KVFAZIADB.cpp:741
void StartTransfer(TString filename="runlist.dat", TString ccali_rep="/fazia", TString option="frv")
Definition: KVFAZIADB.cpp:417
virtual ~KVFAZIADB()
reset global pointer gFaziaDB if it was pointing to this database
Definition: KVFAZIADB.cpp:75
KVFAZIADBRun * GetRun(Int_t run) const
Definition: KVFAZIADB.h:48
void Build(bool=false) override
Definition: KVFAZIADB.cpp:101
KVDBTable * fOoODets
(optional) Liste les detecteurs hors service
Definition: KVFAZIADB.h:29
TEnv * GetFileTEnv(const Char_t *meth, const Char_t *keyw)
Definition: KVFAZIADB.cpp:565
virtual void ReadOoODetectors()
Definition: KVFAZIADB.cpp:837
void ReadCalibFile(const Char_t *filename)
Definition: KVFAZIADB.cpp:763
Handle reading columns of numeric data in text files.
Definition: KVFileReader.h:121
KVString GetCurrentLine()
Definition: KVFileReader.h:320
void CloseFile()
Definition: KVFileReader.h:237
ReadStatus ReadLine(const KVString &pattern="")
Definition: KVFileReader.h:243
void Clear(Option_t *="") override
Definition: KVFileReader.h:195
Double_t GetDoubleReadPar(Int_t pos) const
Definition: KVFileReader.h:334
Int_t GetNparRead() const
Definition: KVFileReader.h:325
Bool_t IsOK()
Definition: KVFileReader.h:231
KVString GetReadPar(Int_t pos) const
Definition: KVFileReader.h:342
Bool_t OpenFileToRead(const KVString &filename)
Definition: KVFileReader.h:210
static KVMultiDetArray * MakeMultiDetector(const Char_t *dataset_name, Int_t run=-1, TString classname="KVMultiDetArray", KVExpDB *db=nullptr)
virtual void MakeCalibrationTables(KVExpDB *)
void SetValue(const Char_t *name, value_type value)
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:85
Bool_t Contains(Int_t val) const
returns kTRUE if the value 'val' is contained in the ranges defined by the number list
const Char_t * AsString(Int_t maxchars=0) const
Bool_t End(void) const
Definition: KVNumberList.h:199
Int_t GetNValues() const
void Begin(void) const
void SetList(const TString &)
void Add(Int_t)
Add value 'n' to the list.
void Set(const TString &l)
Definition: KVNumberList.h:135
Bool_t IsEmpty() const
Definition: KVNumberList.h:175
Int_t Last() const
Returns largest number included in list.
Int_t Next(void) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
virtual Int_t GetEntries() const
virtual void SetOwner(Bool_t enable=kTRUE)
void Set()
const char * AsString() const
THashList * GetTable() const
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
TObject * Next()
void Clear(Option_t *option="") override
TObject * FindObject(const char *name) const override
void Add(TObject *obj) override
const char * GetName() const override
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
Int_t Atoi() const
Double_t Atof() const
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Prepend(char c, Ssiz_t rep=1)
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Long64_t Atoll() const
virtual Int_t Exec(const char *shellcmd)
virtual const char * BaseName(const char *pathname)
virtual TString GetFromPipe(const char *command)
long long Long64_t
TLine * line
void Info(const char *location, const char *fmt,...)
rec
Double_t Power(Double_t x, Double_t y)
ClassImp(TPyArg)