ATLAS Offline Software
CalibrationDataBackend.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 //
7 // 'Back-end' utilities for the CalibrationDataInterface code
8 //
10 
13 
14 #include <iostream>
15 #include <string>
16 
17 #include "TFile.h"
18 #include "TMap.h"
19 #include "TObjString.h"
20 #include "TDirectory.h"
21 
22 // Name of the object holding the MC hadronisation references
23 // (this is used for the application of MC-to-MC calibration scale factors)
24 
25 static const std::string hadronisationRefs("MChadronisation_ref");
26 
27 // Back-end method for addition of a container to an existing file.
28 // Notes:
29 // - "name" should be the full name (i.e., include the "_Eff" or "_SF" suffix)
30 // - this function will change the global gDirectory. If the working directory is to be
31 // preserved then the variable needs to be saved by the user prior to the function call
32 
33 Int_t
35  const char* jetAuthor, const char* OP, const char* flavour, const char* name,
36  bool isReference) {
37  file->cd("/"); TDirectory* dir = gDirectory;
38  // top level: tagger
39  TDirectory* taggerDir = dir->GetDirectory(tagger);
40  if (! taggerDir) taggerDir = dir->mkdir(tagger);
41  // then: jet author
42  TDirectory* authorDir = taggerDir->GetDirectory(jetAuthor);
43  if (! authorDir) authorDir = taggerDir->mkdir(jetAuthor);
44  // then: operating point
45  TDirectory* OPDir = authorDir->GetDirectory(OP);
46  if (! OPDir) OPDir = authorDir->mkdir(OP);
47  // finally: flavour
48  TDirectory* flavourDir = OPDir->GetDirectory(flavour);
49  if (! flavourDir) flavourDir = OPDir->mkdir(flavour);
50 
51  Int_t nbytes = flavourDir->WriteTObject (cnt, name, "SingleKey");
52 
53  if (isReference) {
54  // first retrieve the hadronisation reference for this container
55  std::string ref = cnt->getHadronisation();
56  // make sure that the name is well defined
57  const char* cntname = (name) ? name : cnt->GetName();
58  if (ref.empty())
59  std::cerr << "addContainer(): container does not have a MC hadronisation reference!" << std::endl;
60  else if (std::string(cntname).find("_Eff") == std::string::npos)
61  std::cerr << "addContainer(): container is not a MC efficiency object!" << std::endl;
62  else {
63  // retrieve the map (or create it if it doesn't already exist)
64  TMap* map;
65  flavourDir->GetObject(hadronisationRefs.c_str(), map);
66  if (!map) map = new TMap;
67  // add (or replace, if it already exists) the histogram name for this hadronisation reference
68  if (TPair* p = (TPair*) map->FindObject(ref.c_str())) map->DeleteEntry(p->Key());
69  map->Add(new TObjString(ref.c_str()), new TObjString(cntname));
70  // save the map to file (deleting any previous version)
71  flavourDir->WriteTObject (map, hadronisationRefs.c_str(), "WriteDelete SingleKey");
72  }
73  }
74 
75  return nbytes;
76 }
77 
Analysis::CalibrationDataContainer
Definition: CalibrationDataContainer.h:51
CalibrationDataContainer.h
ParseInputs.flavourDir
flavourDir
Definition: Final2012/ParseInputs.py:46
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
file
TFile * file
Definition: tile_monitor.h:29
Analysis::addContainer
Int_t addContainer(Analysis::CalibrationDataContainer *cnt, TFile *file, const char *tagger, const char *jetAuthor, const char *OP, const char *flavour, const char *name=0, bool isReference=false)
python.iconfTool.models.loaders.isReference
list isReference(value, compname, conf, svcCache={})
Definition: loaders.py:337
beamspotman.dir
string dir
Definition: beamspotman.py:623
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
ref
const boost::regex ref(r_ef)
CalibrationDataBackend.h