6 #include "RelationalAccess/ISessionProxy.h"
7 #include "RelationalAccess/ISchema.h"
8 #include "RelationalAccess/IQuery.h"
9 #include "RelationalAccess/ICursor.h"
10 #include "CoralBase/AttributeList.h"
11 #include "CoralBase/Attribute.h"
12 #include "CoralBase/AttributeSpecification.h"
13 #include "CoralBase/TimeStamp.h"
22 m_firstFill((unsigned short)
pset.getUntrackedParameter<unsigned
int>(
"firstFill", 1)),
23 m_lastFill((unsigned short)
pset.getUntrackedParameter<unsigned
int>(
"lastFill", m_firstFill)),
24 m_name(
pset.getUntrackedParameter<
std::
string>(
"name",
"FillInfoPopConSourceHandler")),
25 m_connectionString(
pset.getUntrackedParameter<
std::
string>(
"connectionString",
"")),
26 m_dipSchema(
pset.getUntrackedParameter<
std::
string>(
"DIPSchema",
"")),
27 m_authpath(
pset.getUntrackedParameter<
std::
string>(
"authenticationPath",
"")) {}
42 << boost::posix_time::to_iso_extended_string(
44 <<
" ); from " <<
m_name <<
"::getNewObjects";
51 << *previousFill <<
"from " <<
m_name <<
"::getNewObjects";
52 if (m_firstFill <= previousFill->fillNumber()) {
55 std::ostringstream es;
56 es <<
"Trying to insert fill number " <<
m_firstFill
57 << ((
m_firstFill < previousFill->fillNumber()) ?
", which is an older fill than "
58 :
", which is the same fill as ")
59 <<
"the last one in the destination tag " << previousFill->fillNumber()
60 <<
": the first fill to be looked for will become " << previousFill->fillNumber() + 1;
70 <<
" cannot be larger than the last one " <<
m_lastFill <<
" EXITING. from " <<
m_name
88 coral::ISchema &runTimeLoggerSchema = session.
nominalSchema();
92 std::unique_ptr<coral::IQuery> fillDataQuery(runTimeLoggerSchema.newQuery());
94 fillDataQuery->addToTableList(
std::string(
"RUNTIME_SUMMARY"));
96 fillDataQuery->addToOutputList(
std::string(
"LHCFILL"));
97 fillDataQuery->addToOutputList(
std::string(
"NBUNCHESBEAM1"));
98 fillDataQuery->addToOutputList(
std::string(
"NBUNCHESBEAM2"));
99 fillDataQuery->addToOutputList(
std::string(
"NCOLLIDINGBUNCHES"));
100 fillDataQuery->addToOutputList(
std::string(
"NTARGETBUNCHES"));
101 fillDataQuery->addToOutputList(
std::string(
"RUNTIME_TYPE_ID"));
102 fillDataQuery->addToOutputList(
std::string(
"PARTY1"));
103 fillDataQuery->addToOutputList(
std::string(
"PARTY2"));
104 fillDataQuery->addToOutputList(
std::string(
"CROSSINGANGLE"));
105 fillDataQuery->addToOutputList(
std::string(
"BETASTAR"));
106 fillDataQuery->addToOutputList(
std::string(
"INTENSITYBEAM1"));
107 fillDataQuery->addToOutputList(
std::string(
"INTENSITYBEAM2"));
108 fillDataQuery->addToOutputList(
std::string(
"ENERGY"));
109 fillDataQuery->addToOutputList(
std::string(
"CREATETIME"));
110 fillDataQuery->addToOutputList(
std::string(
"BEGINTIME"));
111 fillDataQuery->addToOutputList(
std::string(
"ENDTIME"));
112 fillDataQuery->addToOutputList(
std::string(
"INJECTIONSCHEME"));
114 coral::AttributeList fillDataBindVariables;
115 fillDataBindVariables.extend(
std::string(
"firstFillNumber"),
typeid(
unsigned short));
117 fillDataBindVariables.extend(
std::string(
"lastFillNumber"),
typeid(
unsigned short));
121 std::string conditionStr(
"BEGINTIME IS NOT NULL AND LHCFILL BETWEEN :firstFillNumber AND :lastFillNumber");
122 fillDataQuery->setCondition(conditionStr, fillDataBindVariables);
124 fillDataQuery->addToOrderList(
std::string(
"LHCFILL"));
126 coral::AttributeList fillDataOutput;
127 fillDataOutput.extend<
unsigned short>(
std::string(
"LHCFILL"));
128 fillDataOutput.extend<
unsigned short>(
std::string(
"NBUNCHESBEAM1"));
129 fillDataOutput.extend<
unsigned short>(
std::string(
"NBUNCHESBEAM2"));
130 fillDataOutput.extend<
unsigned short>(
std::string(
"NCOLLIDINGBUNCHES"));
131 fillDataOutput.extend<
unsigned short>(
std::string(
"NTARGETBUNCHES"));
132 fillDataOutput.extend<
int>(
std::string(
"RUNTIME_TYPE_ID"));
135 fillDataOutput.extend<
float>(
std::string(
"CROSSINGANGLE"));
136 fillDataOutput.extend<
float>(
std::string(
"BETASTAR"));
137 fillDataOutput.extend<
float>(
std::string(
"INTENSITYBEAM1"));
138 fillDataOutput.extend<
float>(
std::string(
"INTENSITYBEAM2"));
139 fillDataOutput.extend<
float>(
std::string(
"ENERGY"));
140 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"CREATETIME"));
141 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"BEGINTIME"));
142 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"ENDTIME"));
144 fillDataQuery->defineOutput(fillDataOutput);
146 coral::ICursor &fillDataCursor = fillDataQuery->execute();
148 unsigned short previousFillNumber = 1, currentFill =
m_firstFill;
149 cond::Time_t previousFillEndTime = 0ULL, afterPreviousFillEndTime = 0ULL, beforeStableBeamStartTime = 0ULL;
151 previousFillNumber = previousFill->fillNumber();
152 previousFillEndTime = previousFill->endTime();
154 unsigned short bunches1 = 0, bunches2 = 0, collidingBunches = 0, targetBunches = 0;
157 float crossingAngle = 0., betastar = 0., intensityBeam1 = 0., intensityBeam2 = 0.,
energy = 0.;
158 coral::TimeStamp stableBeamStartTimeStamp, beamDumpTimeStamp;
159 cond::Time_t creationTime = 0ULL, stableBeamStartTime = 0ULL, beamDumpTime = 0ULL;
161 std::ostringstream
ss;
163 while (fillDataCursor.next()) {
165 std::ostringstream qs;
166 fillDataCursor.currentRow().toOutputStream(qs);
169 currentFill = fillDataCursor.currentRow()[
std::string(
"LHCFILL")].data<
unsigned short>();
170 coral::Attribute
const &bunches1Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM1")];
171 if (bunches1Attribute.isNull()) {
174 bunches1 = bunches1Attribute.data<
unsigned short>();
176 coral::Attribute
const &bunches2Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM2")];
177 if (bunches2Attribute.isNull()) {
180 bunches2 = bunches2Attribute.data<
unsigned short>();
182 coral::Attribute
const &collidingBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NCOLLIDINGBUNCHES")];
183 if (collidingBunchesAttribute.isNull()) {
184 collidingBunches = 0;
186 collidingBunches = collidingBunchesAttribute.data<
unsigned short>();
188 coral::Attribute
const &targetBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NTARGETBUNCHES")];
189 if (targetBunchesAttribute.isNull()) {
192 targetBunches = targetBunchesAttribute.data<
unsigned short>();
196 static_cast<FillInfo::FillTypeId>(fillDataCursor.currentRow()[
std::string(
"RUNTIME_TYPE_ID")].data<
int>());
197 coral::Attribute
const &particleType1Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY1")];
198 if (particleType1Attribute.isNull()) {
201 particleType1 = static_cast<FillInfo::ParticleTypeId>(particleType1Attribute.data<
int>());
203 coral::Attribute
const &particleType2Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY2")];
204 if (particleType2Attribute.isNull()) {
207 particleType2 = static_cast<FillInfo::ParticleTypeId>(particleType2Attribute.data<
int>());
209 coral::Attribute
const &crossingAngleAttribute = fillDataCursor.currentRow()[
std::string(
"CROSSINGANGLE")];
210 if (crossingAngleAttribute.isNull()) {
213 crossingAngle = crossingAngleAttribute.data<
float>();
215 coral::Attribute
const &betastarAttribute = fillDataCursor.currentRow()[
std::string(
"BETASTAR")];
216 if (betastarAttribute.isNull()) {
219 betastar = betastarAttribute.data<
float>();
221 coral::Attribute
const &intensityBeam1Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM1")];
222 if (intensityBeam1Attribute.isNull()) {
225 intensityBeam1 = intensityBeam1Attribute.data<
float>();
227 coral::Attribute
const &intensityBeam2Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM2")];
228 if (intensityBeam2Attribute.isNull()) {
231 intensityBeam2 = intensityBeam2Attribute.data<
float>();
233 coral::Attribute
const &energyAttribute = fillDataCursor.currentRow()[
std::string(
"ENERGY")];
234 if (energyAttribute.isNull()) {
237 energy = energyAttribute.data<
float>();
243 stableBeamStartTimeStamp = fillDataCursor.currentRow()[
std::string(
"BEGINTIME")].data<coral::TimeStamp>();
245 coral::Attribute
const &beamDumpTimeAttribute = fillDataCursor.currentRow()[
std::string(
"ENDTIME")];
246 if (beamDumpTimeAttribute.isNull()) {
249 beamDumpTimeStamp = beamDumpTimeAttribute.data<coral::TimeStamp>();
252 coral::Attribute
const &injectionSchemeAttribute = fillDataCursor.currentRow()[
std::string(
"INJECTIONSCHEME")];
253 if (injectionSchemeAttribute.isNull()) {
256 injectionScheme = injectionSchemeAttribute.data<
std::string>();
276 if (beamDumpTime == 0) {
277 edm::LogWarning(
m_name) <<
"NO TRANSFER NEEDED: the fill number " << currentFill <<
" is still ongoing"
278 <<
"; from " <<
m_name <<
"::getNewObjects";
286 coral::AttributeList bunchConfBindVariables;
287 bunchConfBindVariables.extend<coral::TimeStamp>(
std::string(
"stableBeamStartTimeStamp"));
288 bunchConfBindVariables[
std::string(
"stableBeamStartTimeStamp")].data<coral::TimeStamp>() = stableBeamStartTimeStamp;
289 conditionStr =
std::string(
"DIPTIME <= :stableBeamStartTimeStamp");
291 coral::AttributeList bunchConfOutput;
292 bunchConfOutput.extend<coral::TimeStamp>(
std::string(
"DIPTIME"));
293 bunchConfOutput.extend<
unsigned short>(
std::string(
"BUCKET"));
295 std::unique_ptr<coral::IQuery> bunchConf1Query(beamCondSchema.newQuery());
296 bunchConf1Query->addToTableList(
std::string(
"LHC_CIRCBUNCHCONFIG_BEAM1"),
297 std::string(
"BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS"));
300 bunchConf1Query->setCondition(conditionStr, bunchConfBindVariables);
301 bunchConf1Query->addToOrderList(
std::string(
"DIPTIME DESC"));
303 bunchConf1Query->defineOutput(bunchConfOutput);
304 coral::ICursor &bunchConf1Cursor = bunchConf1Query->execute();
305 std::bitset<FillInfo::bunchSlots + 1> bunchConfiguration1(0ULL);
306 while (bunchConf1Cursor.next()) {
308 std::ostringstream b1s;
309 fillDataCursor.currentRow().toOutputStream(b1s);
313 if (bunchConf1Cursor.currentRow()[
std::string(
"BUCKET")].data<
unsigned short>() != 0) {
314 unsigned short slot =
315 (bunchConf1Cursor.currentRow()[
std::string(
"BUCKET")].data<
unsigned short>() - 1) / 10 + 1;
316 bunchConfiguration1[slot] =
true;
320 std::unique_ptr<coral::IQuery> bunchConf2Query(beamCondSchema.newQuery());
321 bunchConf2Query->addToTableList(
std::string(
"LHC_CIRCBUNCHCONFIG_BEAM2"),
322 std::string(
"BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS"));
325 bunchConf2Query->setCondition(conditionStr, bunchConfBindVariables);
326 bunchConf2Query->addToOrderList(
std::string(
"DIPTIME DESC"));
328 bunchConf2Query->defineOutput(bunchConfOutput);
329 coral::ICursor &bunchConf2Cursor = bunchConf2Query->execute();
330 std::bitset<FillInfo::bunchSlots + 1> bunchConfiguration2(0ULL);
331 while (bunchConf2Cursor.next()) {
333 std::ostringstream b2s;
334 fillDataCursor.currentRow().toOutputStream(b2s);
337 if (bunchConf2Cursor.currentRow()[
std::string(
"BUCKET")].data<
unsigned short>() != 0) {
338 unsigned short slot =
339 (bunchConf2Cursor.currentRow()[
std::string(
"BUCKET")].data<
unsigned short>() - 1) / 10 + 1;
340 bunchConfiguration2[slot] =
true;
351 if (afterPreviousFillEndTime < stableBeamStartTime) {
352 edm::LogInfo(
m_name) <<
"Entering fake fill between fill number " << previousFillNumber
353 <<
" and current fill number " << currentFill <<
", from " << afterPreviousFillEndTime
356 <<
" ) to " << beforeStableBeamStartTime <<
" ( "
358 <<
" ); from " <<
m_name <<
"::getNewObjects";
363 <<
" beams were dumped at timestamp "
365 <<
", which is not before the timestamp "
367 <<
" when current fill number " << currentFill <<
" entered stable beams. EXITING. from "
368 <<
m_name <<
"::getNewObjects";
373 fillInfo->
setBeamInfo(const_cast<unsigned short const &>(bunches1),
374 const_cast<unsigned short const &>(bunches2),
375 const_cast<unsigned short const &>(collidingBunches),
376 const_cast<unsigned short const &>(targetBunches),
377 const_cast<FillInfo::FillTypeId const &>(fillType),
378 const_cast<FillInfo::ParticleTypeId const &>(particleType1),
379 const_cast<FillInfo::ParticleTypeId const &>(particleType2),
380 const_cast<float const &>(crossingAngle),
381 const_cast<float const &>(betastar),
382 const_cast<float const &>(intensityBeam1),
383 const_cast<float const &>(intensityBeam2),
384 const_cast<float const &>(
energy),
385 const_cast<cond::Time_t const &>(creationTime),
386 const_cast<cond::Time_t const &>(stableBeamStartTime),
387 const_cast<cond::Time_t const &>(beamDumpTime),
388 const_cast<std::string const &>(injectionScheme),
389 const_cast<std::bitset<FillInfo::bunchSlots + 1>
const &
>(bunchConfiguration1),
390 const_cast<std::bitset<FillInfo::bunchSlots + 1>
const &
>(bunchConfiguration2));
394 << stableBeamStartTime <<
" ( "
396 <<
" ) has values:\n"
397 << *fillInfo <<
"from " <<
m_name <<
"::getNewObjects";
399 ss <<
" fill = " << currentFill <<
";\tinjection scheme: " << injectionScheme
400 <<
";\tstart time: " << boost::posix_time::to_iso_extended_string(stableBeamStartTimeStamp.time())
401 <<
";\tend time: " << boost::posix_time::to_iso_extended_string(beamDumpTimeStamp.time()) <<
"." << std::endl;
403 previousFillNumber = currentFill;
404 previousFillEndTime = beamDumpTime;
413 <<
"::getNewObjects";