1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*----------------------------------------------------------------------
This is a generic main that can be used with any plugin and a
PSet script. It shows the minimum machinery necessary for a
"standalone" program to issue MessageLogger messages.
N. B. In this context, standalone means a job where the user
has provided the main program instead of supplying a module
for cmsRun to call on.
----------------------------------------------------------------------*/
#include <cmath>
#include <exception>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/PluginManager/interface/ProblemTracker.h"
#include "FWCore/Utilities/interface/Presence.h"
#include "FWCore/ParameterSetReader/interface/ParameterSetReader.h"
#include "FWCore/PluginManager/interface/PresenceFactory.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
// -----------------------------------------------
std::string indirectWarn(int /*num*/) {
// std::cout << " Returning the string Emit Warning level message " << num << std::endl;
return std::string("\t\tEmit Warning level message ");
}
std::string indirectInfo(int /*num*/) {
// std::cout << " Returning the string Emit Info level message " << num << std::endl;
return std::string("\t\tEmit Info level message ");
}
void DoMyStuff() {
// Issue several types of logger messages. This function could
// be substantially more complex. This example is about as simple
// as can be.
double d = M_PI;
edm::LogWarning("cat_A") << "Test of std::setprecision(p):"
<< " Pi with precision 12 is " << std::setprecision(12) << d;
for (int i = 0; i < 25; ++i) {
// edm::LogInfo("cat_B") << "\t\tEmit Info level message " << i+1;
edm::LogInfo("cat_B") << indirectInfo(i + 1) << i + 1;
// edm::LogWarning("cat_C") << "\t\tEmit Warning level message " << i+1;
edm::LogWarning("cat_C") << indirectWarn(i + 1) << i + 1;
}
}
int main(int, char* argv[]) {
std::string const kProgramName = argv[0];
int rc = 0;
try {
// A. Instantiate a plug-in manager first.
edm::AssertHandler ah;
// B. Load the message service plug-in. Forget this and bad things happen!
// In particular, the job hangs as soon as the output buffer fills up.
// That's because, without the message service, there is no mechanism for
// emptying the buffers.
std::shared_ptr<edm::Presence> theMessageServicePresence;
theMessageServicePresence =
std::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->makePresence("SingleThreadMSPresence").release());
// C. Manufacture a configuration and establish it.
std::string config =
"process x = {"
"service = MessageLogger {"
"untracked vstring destinations = {'infos.mlog','warnings.mlog'}"
"untracked PSet infos = {"
"untracked string threshold = 'INFO'"
"untracked PSet default = {untracked int32 limit = 1000000}"
"}"
"untracked PSet warnings = {"
"untracked string threshold = 'WARNING'"
"untracked PSet default = {untracked int32 limit = 1000000}"
"}"
"untracked vstring categories = {}"
"}"
"service = JobReportService{}"
"service = SiteLocalConfigService{}"
"}";
// D. Create the services.
std::unique_ptr<edm::ParameterSet> params;
edm::makeParameterSets(config, params);
edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
// E. Make the services available.
edm::ServiceRegistry::Operate operate(tempToken);
// Generate a bunch of messages.
DoMyStuff();
}
// Deal with any exceptions that may have been thrown.
catch (cms::Exception& e) {
std::cout << "cms::Exception caught in " << kProgramName << "\n" << e.explainSelf();
rc = 1;
} catch (std::exception& e) {
std::cout << "Standard library exception caught in " << kProgramName << "\n" << e.what();
rc = 1;
} catch (...) {
std::cout << "Unknown exception caught in " << kProgramName;
rc = 2;
}
return rc;
}
|