CMS 3D CMS Logo

AlignPCLThresholdsReader.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <map>
11 
12 namespace edmtest {
14  public:
16  ~AlignPCLThresholdsReader() override;
17 
18  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
19 
20  private:
21  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
22 
23  // ----------member data ---------------------------
24  const bool printdebug_;
26  };
27 
29  : printdebug_(p.getUntrackedParameter<bool>("printDebug", true)),
30  formatedOutput_(p.getUntrackedParameter<std::string>("outputFile", "")) {
31  edm::LogInfo("AlignPCLThresholdsReader") << "AlignPCLThresholdsReader" << std::endl;
32  }
33 
35  edm::LogInfo("AlignPCLThresholdsReader") << "~AlignPCLThresholdsReader " << std::endl;
36  }
37 
39  edm::LogInfo("AlignPCLThresholdsReader") << "### AlignPCLThresholdsReader::analyze ###" << std::endl;
40  edm::LogInfo("AlignPCLThresholdsReader") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
41  edm::LogInfo("AlignPCLThresholdsReader") << " ---EVENT NUMBER " << e.id().event() << std::endl;
42 
45 
47  //record not found
48  edm::LogInfo("AlignPCLThresholdsReader") << "Record \"AlignPCLThresholdsRcd"
49  << "\" does not exist " << std::endl;
50  }
51 
52  //this part gets the handle of the event source and the record (i.e. the Database)
53  edm::ESHandle<AlignPCLThresholds> thresholdHandle;
54  edm::LogInfo("AlignPCLThresholdsReader") << "got eshandle" << std::endl;
55 
56  context.get<AlignPCLThresholdsRcd>().get(thresholdHandle);
57  edm::LogInfo("AlignPCLThresholdsReader") << "got context" << std::endl;
58 
59  const AlignPCLThresholds* thresholds = thresholdHandle.product();
60  edm::LogInfo("AlignPCLThresholdsReader") << "got AlignPCLThresholds* " << std::endl;
61  edm::LogInfo("AlignPCLThresholdsReader") << "print pointer address : ";
62  edm::LogInfo("AlignPCLThresholdsReader") << thresholds << std::endl;
63 
64  edm::LogInfo("AlignPCLThresholdsReader") << "Size " << thresholds->size() << std::endl;
65  edm::LogInfo("AlignPCLThresholdsReader") << "Content of myThresholds " << std::endl;
66  // use built-in method in the CondFormat to print the content
67  if (printdebug_) {
68  thresholds->printAll();
69  }
70 
71  FILE* pFile = nullptr;
72  if (!formatedOutput_.empty())
73  pFile = fopen(formatedOutput_.c_str(), "w");
74  if (pFile) {
75  fprintf(pFile, "AlignPCLThresholds::printAll() \n");
76  fprintf(pFile,
77  " ======================================================================================================="
78  "============ \n");
79  fprintf(pFile, "N records cut: %i \n", thresholds->getNrecords());
80 
81  AlignPCLThresholds::threshold_map m_thresholds = thresholds->getThreshold_Map();
82 
83  for (auto it = m_thresholds.begin(); it != m_thresholds.end(); ++it) {
84  fprintf(pFile,
85  " ====================================================================================================="
86  "============== \n");
87  fprintf(pFile, "key : %s \n ", (it->first).c_str());
88  fprintf(pFile, "- Xcut : %8.3f um ", (it->second).getXcut());
89  fprintf(pFile, "| sigXcut : %8.3f ", (it->second).getSigXcut());
90  fprintf(pFile, "| maxMoveXcut : %8.3f um ", (it->second).getMaxMoveXcut());
91  fprintf(pFile, "| ErrorXcut : %8.3f um\n ", (it->second).getErrorXcut());
92 
93  fprintf(pFile, "- thetaXcut : %8.3f urad ", (it->second).getThetaXcut());
94  fprintf(pFile, "| sigThetaXcut : %8.3f ", (it->second).getSigThetaXcut());
95  fprintf(pFile, "| maxMoveThetaXcut : %8.3f urad ", (it->second).getMaxMoveThetaXcut());
96  fprintf(pFile, "| ErrorThetaXcut : %8.3f urad\n ", (it->second).getErrorThetaXcut());
97 
98  fprintf(pFile, "- Ycut : %8.3f um ", (it->second).getYcut());
99  fprintf(pFile, "| sigYcut : %8.3f ", (it->second).getSigXcut());
100  fprintf(pFile, "| maxMoveYcut : %8.3f um ", (it->second).getMaxMoveYcut());
101  fprintf(pFile, "| ErrorYcut : %8.3f um\n ", (it->second).getErrorYcut());
102 
103  fprintf(pFile, "- thetaYcut : %8.3f urad ", (it->second).getThetaYcut());
104  fprintf(pFile, "| sigThetaYcut : %8.3f ", (it->second).getSigThetaYcut());
105  fprintf(pFile, "| maxMoveThetaYcut : %8.3f urad ", (it->second).getMaxMoveThetaYcut());
106  fprintf(pFile, "| ErrorThetaYcut : %8.3f urad\n ", (it->second).getErrorThetaYcut());
107 
108  fprintf(pFile, "- Zcut : %8.3f um ", (it->second).getZcut());
109  fprintf(pFile, "| sigZcut : %8.3f ", (it->second).getSigZcut());
110  fprintf(pFile, "| maxMoveZcut : %8.3f um ", (it->second).getMaxMoveZcut());
111  fprintf(pFile, "| ErrorZcut : %8.3f um\n ", (it->second).getErrorZcut());
112 
113  fprintf(pFile, "- thetaZcut : %8.3f urad ", (it->second).getThetaZcut());
114  fprintf(pFile, "| sigThetaZcut : %8.3f ", (it->second).getSigThetaZcut());
115  fprintf(pFile, "| maxMoveThetaZcut : %8.3f urad ", (it->second).getMaxMoveThetaZcut());
116  fprintf(pFile, "| ErrorThetaZcut : %8.3f urad\n ", (it->second).getErrorThetaZcut());
117 
118  if ((it->second).hasExtraDOF()) {
119  for (unsigned int j = 0; j < (it->second).extraDOFSize(); j++) {
120  std::array<float, 4> extraDOFCuts = thresholds->getExtraDOFCutsForAlignable(it->first, j);
121  const char* theLabel = (thresholds->getExtraDOFLabelForAlignable(it->first, j)).c_str();
122  fprintf(pFile, "Extra DOF: %i with label %s \n ", j, theLabel);
123  fprintf(pFile, "- cut : %8.3f ", extraDOFCuts.at(0));
124  fprintf(pFile, "| sigCut : %8.3f ", extraDOFCuts.at(1));
125  fprintf(pFile, "| maxMoveCut : %8.3f ", extraDOFCuts.at(2));
126  fprintf(pFile, "| maxErrorCut : %8.3f \n ", extraDOFCuts.at(3));
127  }
128  }
129  }
130  }
131  }
132 
135  desc.setComment("Reads payloads of type AlignPCLThresholds");
136  desc.addUntracked<bool>("printDebug", true);
137  desc.addUntracked<std::string>("outputFile", "");
138  descriptions.add("AlignPCLThresholdsReader", desc);
139  }
140 
142 } // namespace edmtest
RunNumber_t run() const
Definition: EventID.h:38
const threshold_map & getThreshold_Map() const
EventNumber_t event() const
Definition: EventID.h:40
double size() const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::map< std::string, AlignPCLThreshold > threshold_map
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
std::string getExtraDOFLabelForAlignable(const std::string &AlignableId, const unsigned int i) const
void setComment(std::string const &value)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &e, const edm::EventSetup &c) override
std::array< float, 4 > getExtraDOFCutsForAlignable(const std::string &AlignableId, const unsigned int i) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
AlignPCLThresholdsReader(edm::ParameterSet const &p)
const int & getNrecords() const
heterocontainer::HCTypeTag TypeTag
edm::EventID id() const
Definition: EventBase.h:59
T get() const
Definition: EventSetup.h:73
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
Definition: ESHandle.h:86