CMS 3D CMS Logo

SiStripPopConConfigDbObjHandler.h
Go to the documentation of this file.
1 #ifndef SISTRIPPOPCON_CONFIGDB_HANDLER_H
2 #define SISTRIPPOPCON_CONFIGDB_HANDLER_H
3 
9 
12 
16 
17 #include <sstream>
18 #include <vector>
19 #include <string>
20 #include <iostream>
21 #include <typeinfo>
22 
23 namespace popcon {
24 
25  template <typename T>
27  public:
28  //---------------------------------------
29  //
31  : m_name(pset.getUntrackedParameter<std::string>("name", "SiStripPopPopConConfigDbObjHandler")),
32  m_since(pset.getUntrackedParameter<uint32_t>("since", 5)),
33  m_debugMode(pset.getUntrackedParameter<bool>("debug", false)){};
34 
35  //---------------------------------------
36  //
38 
39  //---------------------------------------
40  //
41  void getNewObjects() override {
42  edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name;
43 
44  if (m_debugMode) {
45  std::stringstream ss;
46  ss << "\n\n------- " << m_name << " - > getNewObjects\n";
47  if (this->tagInfo().size) {
48  //check whats already inside of database
49  ss << "got offlineInfo" << this->tagInfo().name << ", size " << this->tagInfo().size
50  << " , last object valid since " << this->tagInfo().lastInterval.since << " token "
51  << this->tagInfo().lastInterval.payloadId << "\n\n UserText " << this->userTextLog() << "\n LogDBEntry \n"
52  << this->logDBEntry().logId << "\n"
53  << this->logDBEntry().destinationDB << "\n"
54  << this->logDBEntry().provenance << "\n"
55  << this->logDBEntry().usertext << "\n"
56  << this->logDBEntry().iovtag << "\n"
57  << this->logDBEntry().iovtimetype << "\n"
58  << this->logDBEntry().payloadIdx << "\n"
59  << this->logDBEntry().payloadClass << "\n"
60  << this->logDBEntry().payloadToken << "\n"
61  << this->logDBEntry().exectime << "\n"
62  << this->logDBEntry().execmessage << "\n"
63  << "\n\n-- user text "
64  << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of('@'));
65  } else {
66  ss << " First object for this tag ";
67  }
68  edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << ss.str();
69  }
70  if (isTransferNeeded())
72 
73  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
74  << "[getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
75  }
76 
77  //---------------------------------------
78  //
79  std::string id() const override { return m_name; }
80 
81  //---------------------------------------
82  //
84  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
85  << "[isTransferNeeded] checking for transfer: " << typeid(T).name() << std::endl;
86  std::stringstream ss_logdb, ss;
87 
88  //get log information from previous upload
89  if (!this->logDBEntry().usertext.empty())
90  ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_first_of('@'));
91  else
92  ss_logdb << "";
93 
94  std::string label = "";
95  if (typeid(T) == typeid(SiStripFedCabling))
96  label = "Cabling";
97 
98  if (typeid(T) == typeid(SiStripApvGain))
99  label = "ApvTiming";
100 
101  if (typeid(T) == typeid(SiStripLatency))
102  label = "ApvLatency";
103 
104  if (!condObjBuilder->checkForCompatibility(ss_logdb, ss, label)) {
105  //string are equal, no need to do transfer
106  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
107  << "[isTransferNeeded] the selected conditions are already uploaded in the last iov ("
108  << this->tagInfo().lastInterval.since << ") open for the object " << this->logDBEntry().payloadClass
109  << " in the db " << this->logDBEntry().destinationDB << " parameters: " << ss_logdb.str()
110  << "\n NO TRANSFER NEEDED";
111  return false;
112  }
113 
114  this->m_userTextLog = ss.str();
115  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
116  << "[isTransferNeeded] the selected conditions will be uploaded: " << ss.str()
117  << "\n Going to Upload: " << ss.str() << "\n Last Upload: " << ss_logdb.str() << "\n Fine";
118 
119  return true;
120  }
121 
122  //---------------------------------------
123  //
124  void setForTransfer() {
125  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
126  << "[setForTransfer] " << m_name << " getting data to be transferred " << std::endl;
127 
128  T* obj = nullptr;
130 
131  edm::LogInfo("SiStripPopPopConConfigDbObjHandler")
132  << "[setForTransfer] " << m_name << " got data to be transferred from condObjBuilder " << std::endl;
133 
134  if (!this->tagInfo().size)
135  m_since = 1;
136  else if (m_debugMode)
137  m_since = this->tagInfo().lastInterval.since + 1;
138  edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] setting since = " << m_since << std::endl;
139 
140  if (obj != nullptr) {
141  edm::LogInfo("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] filling map m_to_transfer" << std::endl;
142  this->m_to_transfer.push_back(std::make_pair(obj, m_since));
143  } else {
144  edm::LogError("SiStripPopPopConConfigDbObjHandler")
145  << "[setForTransfer] " << m_name << " : NULL pointer of obj " << typeid(T).name()
146  << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted" << std::endl;
147  }
148  }
149 
150  private:
151  // data members
153  unsigned long long m_since;
156  };
157 } // namespace popcon
158 
159 #endif //SISTRIPPOPCON_CONFIGDB_HANDLER_H
Iov_t lastInterval
Definition: Types.h:73
edm::Service< SiStripCondObjBuilderFromDb > condObjBuilder
unsigned long long logId
Definition: Types.h:87
std::string provenance
Definition: Types.h:89
std::string payloadToken
Definition: Types.h:96
Time_t since
Definition: Types.h:53
size_t size
Definition: Types.h:74
std::string execmessage
Definition: Types.h:98
Log< level::Error, false > LogError
SiStripPopConConfigDbObjHandler(const edm::ParameterSet &pset)
std::string name
Definition: Types.h:72
cond::TagInfo_t const & tagInfo() const
char const * label
bool checkForCompatibility(std::stringstream &input, std::stringstream &output, std::string &label)
std::vector< std::pair< T *, Time_t > > m_to_transfer
std::string payloadClass
Definition: Types.h:95
void getValue(SiStripFedCabling *&val)
Hash payloadId
Definition: Types.h:55
std::string destinationDB
Definition: Types.h:88
Log< level::Info, false > LogInfo
std::string exectime
Definition: Types.h:97
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
cond::LogDBEntry_t const & logDBEntry() const
std::string const & userTextLog() const
unsigned int payloadIdx
Definition: Types.h:93
std::string usertext
Definition: Types.h:90
long double T
std::string iovtimetype
Definition: Types.h:92
std::string iovtag
Definition: Types.h:91