41 << boost::posix_time::to_iso_extended_string(
43 <<
" ); from " <<
m_name <<
"::getNewObjects";
50 << *previousFill <<
"from " <<
m_name <<
"::getNewObjects";
51 if (m_firstFill <= previousFill->fillNumber()) {
54 std::ostringstream es;
55 es <<
"Trying to insert fill number " <<
m_firstFill 56 << ((
m_firstFill < previousFill->fillNumber()) ?
", which is an older fill than " 57 :
", which is the same fill as ")
58 <<
"the last one in the destination tag " << previousFill->fillNumber()
59 <<
": the first fill to be looked for will become " << previousFill->fillNumber() + 1;
69 <<
" cannot be larger than the last one " <<
m_lastFill <<
" EXITING. from " <<
m_name 87 coral::ISchema &runTimeLoggerSchema =
session.nominalSchema();
89 session.transaction().start(
true);
91 std::unique_ptr<coral::IQuery> fillDataQuery(runTimeLoggerSchema.newQuery());
93 fillDataQuery->addToTableList(
std::string(
"RUNTIME_SUMMARY"));
95 fillDataQuery->addToOutputList(
std::string(
"LHCFILL"));
96 fillDataQuery->addToOutputList(
std::string(
"NBUNCHESBEAM1"));
97 fillDataQuery->addToOutputList(
std::string(
"NBUNCHESBEAM2"));
98 fillDataQuery->addToOutputList(
std::string(
"NCOLLIDINGBUNCHES"));
99 fillDataQuery->addToOutputList(
std::string(
"NTARGETBUNCHES"));
100 fillDataQuery->addToOutputList(
std::string(
"RUNTIME_TYPE_ID"));
101 fillDataQuery->addToOutputList(
std::string(
"PARTY1"));
102 fillDataQuery->addToOutputList(
std::string(
"PARTY2"));
103 fillDataQuery->addToOutputList(
std::string(
"CROSSINGANGLE"));
104 fillDataQuery->addToOutputList(
std::string(
"BETASTAR"));
105 fillDataQuery->addToOutputList(
std::string(
"INTENSITYBEAM1"));
106 fillDataQuery->addToOutputList(
std::string(
"INTENSITYBEAM2"));
107 fillDataQuery->addToOutputList(
std::string(
"ENERGY"));
108 fillDataQuery->addToOutputList(
std::string(
"CREATETIME"));
109 fillDataQuery->addToOutputList(
std::string(
"BEGINTIME"));
110 fillDataQuery->addToOutputList(
std::string(
"ENDTIME"));
111 fillDataQuery->addToOutputList(
std::string(
"INJECTIONSCHEME"));
113 coral::AttributeList fillDataBindVariables;
114 fillDataBindVariables.extend(
std::string(
"firstFillNumber"),
typeid(
unsigned short));
116 fillDataBindVariables.extend(
std::string(
"lastFillNumber"),
typeid(
unsigned short));
120 std::string conditionStr(
"BEGINTIME IS NOT NULL AND LHCFILL BETWEEN :firstFillNumber AND :lastFillNumber");
121 fillDataQuery->setCondition(conditionStr, fillDataBindVariables);
123 fillDataQuery->addToOrderList(
std::string(
"LHCFILL"));
125 coral::AttributeList fillDataOutput;
126 fillDataOutput.extend<
unsigned short>(
std::string(
"LHCFILL"));
127 fillDataOutput.extend<
unsigned short>(
std::string(
"NBUNCHESBEAM1"));
128 fillDataOutput.extend<
unsigned short>(
std::string(
"NBUNCHESBEAM2"));
129 fillDataOutput.extend<
unsigned short>(
std::string(
"NCOLLIDINGBUNCHES"));
130 fillDataOutput.extend<
unsigned short>(
std::string(
"NTARGETBUNCHES"));
131 fillDataOutput.extend<
int>(
std::string(
"RUNTIME_TYPE_ID"));
134 fillDataOutput.extend<
float>(
std::string(
"CROSSINGANGLE"));
135 fillDataOutput.extend<
float>(
std::string(
"BETASTAR"));
136 fillDataOutput.extend<
float>(
std::string(
"INTENSITYBEAM1"));
137 fillDataOutput.extend<
float>(
std::string(
"INTENSITYBEAM2"));
138 fillDataOutput.extend<
float>(
std::string(
"ENERGY"));
139 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"CREATETIME"));
140 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"BEGINTIME"));
141 fillDataOutput.extend<coral::TimeStamp>(
std::string(
"ENDTIME"));
143 fillDataQuery->defineOutput(fillDataOutput);
145 coral::ICursor &fillDataCursor = fillDataQuery->execute();
147 unsigned short previousFillNumber = 1;
148 cond::Time_t previousFillEndTime = 0ULL, afterPreviousFillEndTime = 0ULL, beforeStableBeamStartTime = 0ULL;
150 previousFillNumber = previousFill->fillNumber();
151 previousFillEndTime = previousFill->endTime();
153 unsigned short bunches1 = 0, bunches2 = 0, collidingBunches = 0, targetBunches = 0;
156 float crossingAngle = 0., betastar = 0., intensityBeam1 = 0., intensityBeam2 = 0.,
energy = 0.;
157 coral::TimeStamp stableBeamStartTimeStamp, beamDumpTimeStamp;
160 std::ostringstream
ss;
162 while (fillDataCursor.next()) {
164 std::ostringstream qs;
165 fillDataCursor.currentRow().toOutputStream(qs);
168 unsigned short currentFill = fillDataCursor.currentRow()[
std::string(
"LHCFILL")].data<
unsigned short>();
169 coral::Attribute
const &bunches1Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM1")];
170 if (bunches1Attribute.isNull()) {
173 bunches1 = bunches1Attribute.data<
unsigned short>();
175 coral::Attribute
const &bunches2Attribute = fillDataCursor.currentRow()[
std::string(
"NBUNCHESBEAM2")];
176 if (bunches2Attribute.isNull()) {
179 bunches2 = bunches2Attribute.data<
unsigned short>();
181 coral::Attribute
const &collidingBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NCOLLIDINGBUNCHES")];
182 if (collidingBunchesAttribute.isNull()) {
183 collidingBunches = 0;
185 collidingBunches = collidingBunchesAttribute.data<
unsigned short>();
187 coral::Attribute
const &targetBunchesAttribute = fillDataCursor.currentRow()[
std::string(
"NTARGETBUNCHES")];
188 if (targetBunchesAttribute.isNull()) {
191 targetBunches = targetBunchesAttribute.data<
unsigned short>();
196 coral::Attribute
const &particleType1Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY1")];
197 if (particleType1Attribute.isNull()) {
202 coral::Attribute
const &particleType2Attribute = fillDataCursor.currentRow()[
std::string(
"PARTY2")];
203 if (particleType2Attribute.isNull()) {
208 coral::Attribute
const &crossingAngleAttribute = fillDataCursor.currentRow()[
std::string(
"CROSSINGANGLE")];
209 if (crossingAngleAttribute.isNull()) {
214 coral::Attribute
const &betastarAttribute = fillDataCursor.currentRow()[
std::string(
"BETASTAR")];
215 if (betastarAttribute.isNull()) {
218 betastar = betastarAttribute.data<
float>();
220 coral::Attribute
const &intensityBeam1Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM1")];
221 if (intensityBeam1Attribute.isNull()) {
224 intensityBeam1 = intensityBeam1Attribute.data<
float>();
226 coral::Attribute
const &intensityBeam2Attribute = fillDataCursor.currentRow()[
std::string(
"INTENSITYBEAM2")];
227 if (intensityBeam2Attribute.isNull()) {
230 intensityBeam2 = intensityBeam2Attribute.data<
float>();
232 coral::Attribute
const &energyAttribute = fillDataCursor.currentRow()[
std::string(
"ENERGY")];
233 if (energyAttribute.isNull()) {
236 energy = energyAttribute.data<
float>();
242 stableBeamStartTimeStamp = fillDataCursor.currentRow()[
std::string(
"BEGINTIME")].data<coral::TimeStamp>();
244 coral::Attribute
const &beamDumpTimeAttribute = fillDataCursor.currentRow()[
std::string(
"ENDTIME")];
245 if (beamDumpTimeAttribute.isNull()) {
248 beamDumpTimeStamp = beamDumpTimeAttribute.data<coral::TimeStamp>();
251 coral::Attribute
const &injectionSchemeAttribute = fillDataCursor.currentRow()[
std::string(
"INJECTIONSCHEME")];
252 if (injectionSchemeAttribute.isNull()) {
255 injectionScheme = injectionSchemeAttribute.data<
std::string>();
275 if (beamDumpTime == 0) {
276 edm::LogWarning(
m_name) <<
"NO TRANSFER NEEDED: the fill number " << currentFill <<
" is still ongoing" 277 <<
"; from " <<
m_name <<
"::getNewObjects";
283 session.transaction().start(
true);
285 coral::AttributeList bunchConfBindVariables;
286 bunchConfBindVariables.extend<coral::TimeStamp>(
std::string(
"stableBeamStartTimeStamp"));
287 bunchConfBindVariables[
std::string(
"stableBeamStartTimeStamp")].data<coral::TimeStamp>() = stableBeamStartTimeStamp;
288 conditionStr =
std::string(
"DIPTIME <= :stableBeamStartTimeStamp");
290 coral::AttributeList bunchConfOutput;
291 bunchConfOutput.extend<coral::TimeStamp>(
std::string(
"DIPTIME"));
292 bunchConfOutput.extend<
unsigned short>(
std::string(
"BUCKET"));
294 std::unique_ptr<coral::IQuery> bunchConf1Query(beamCondSchema.newQuery());
295 bunchConf1Query->addToTableList(
std::string(
"LHC_CIRCBUNCHCONFIG_BEAM1"),
296 std::string(
"BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS"));
299 bunchConf1Query->setCondition(conditionStr, bunchConfBindVariables);
300 bunchConf1Query->addToOrderList(
std::string(
"DIPTIME DESC"));
302 bunchConf1Query->defineOutput(bunchConfOutput);
303 coral::ICursor &bunchConf1Cursor = bunchConf1Query->execute();
304 std::bitset<FillInfo::bunchSlots + 1> bunchConfiguration1(0ULL);
305 while (bunchConf1Cursor.next()) {
307 std::ostringstream b1s;
308 fillDataCursor.currentRow().toOutputStream(b1s);
312 if (bunchConf1Cursor.currentRow()[
std::string(
"BUCKET")].data<
unsigned short>() != 0) {
313 unsigned short slot =
314 (bunchConf1Cursor.currentRow()[
std::string(
"BUCKET")].data<
unsigned short>() - 1) / 10 + 1;
315 bunchConfiguration1[
slot] =
true;
319 std::unique_ptr<coral::IQuery> bunchConf2Query(beamCondSchema.newQuery());
320 bunchConf2Query->addToTableList(
std::string(
"LHC_CIRCBUNCHCONFIG_BEAM2"),
321 std::string(
"BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS"));
324 bunchConf2Query->setCondition(conditionStr, bunchConfBindVariables);
325 bunchConf2Query->addToOrderList(
std::string(
"DIPTIME DESC"));
327 bunchConf2Query->defineOutput(bunchConfOutput);
328 coral::ICursor &bunchConf2Cursor = bunchConf2Query->execute();
329 std::bitset<FillInfo::bunchSlots + 1> bunchConfiguration2(0ULL);
330 while (bunchConf2Cursor.next()) {
332 std::ostringstream b2s;
333 fillDataCursor.currentRow().toOutputStream(b2s);
336 if (bunchConf2Cursor.currentRow()[
std::string(
"BUCKET")].data<
unsigned short>() != 0) {
337 unsigned short slot =
338 (bunchConf2Cursor.currentRow()[
std::string(
"BUCKET")].data<
unsigned short>() - 1) / 10 + 1;
339 bunchConfiguration2[
slot] =
true;
343 session.transaction().commit();
350 if (afterPreviousFillEndTime < stableBeamStartTime) {
351 edm::LogInfo(
m_name) <<
"Entering fake fill between fill number " << previousFillNumber
352 <<
" and current fill number " << currentFill <<
", from " << afterPreviousFillEndTime
355 <<
" ) to " << beforeStableBeamStartTime <<
" ( " 357 <<
" ); from " <<
m_name <<
"::getNewObjects";
362 <<
" beams were dumped at timestamp " 364 <<
", which is not before the timestamp " 366 <<
" when current fill number " << currentFill <<
" entered stable beams. EXITING. from " 367 <<
m_name <<
"::getNewObjects";
372 fillInfo->
setBeamInfo(const_cast<unsigned short const &>(bunches1),
373 const_cast<unsigned short const &>(bunches2),
374 const_cast<unsigned short const &>(collidingBunches),
375 const_cast<unsigned short const &>(targetBunches),
376 const_cast<FillInfo::FillTypeId const &>(fillType),
377 const_cast<FillInfo::ParticleTypeId const &>(particleType1),
378 const_cast<FillInfo::ParticleTypeId const &>(particleType2),
380 const_cast<float const &>(betastar),
381 const_cast<float const &>(intensityBeam1),
382 const_cast<float const &>(intensityBeam2),
383 const_cast<float const &>(
energy),
385 const_cast<cond::Time_t const &>(stableBeamStartTime),
386 const_cast<cond::Time_t const &>(beamDumpTime),
387 const_cast<std::string const &>(injectionScheme),
388 const_cast<std::bitset<FillInfo::bunchSlots + 1>
const &
>(bunchConfiguration1),
389 const_cast<std::bitset<FillInfo::bunchSlots + 1>
const &
>(bunchConfiguration2));
393 << stableBeamStartTime <<
" ( " 395 <<
" ) has values:\n" 396 << *fillInfo <<
"from " <<
m_name <<
"::getNewObjects";
398 ss <<
" fill = " << currentFill <<
";\tinjection scheme: " << injectionScheme
399 <<
";\tstart time: " << boost::posix_time::to_iso_extended_string(stableBeamStartTimeStamp.time())
400 <<
";\tend time: " << boost::posix_time::to_iso_extended_string(beamDumpTimeStamp.time()) <<
"." << std::endl;
402 previousFillNumber = currentFill;
403 previousFillEndTime = beamDumpTime;
406 session.transaction().commit();
412 <<
"::getNewObjects";
edm::ErrorSummaryEntry Error
std::string m_userTextLog
void setBeamInfo(unsigned short const &bunches1, unsigned short const &bunches2, unsigned short const &collidingBunches, unsigned short const &targetBunches, FillTypeId const &fillType, ParticleTypeId const &particleType1, ParticleTypeId const &particleType2, float const &angle, float const &beta, float const &intensity1, float const &intensity2, float const &energy, cond::Time_t const &createTime, cond::Time_t const &beginTime, cond::Time_t const &endTime, std::string const &scheme, std::bitset< bunchSlots+1 > const &bunchConf1, std::bitset< bunchSlots+1 > const &bunchConf2)
cond::Time_t pack(cond::UnpackedTime iValue)
Log< level::Error, false > LogError
static size_t const availableBunchSlots
cond::TagInfo_t const & tagInfo() const
U second(std::pair< T, U > const &p)
unsigned long long Time_t
std::vector< std::pair< FillInfo *, Time_t > > m_to_transfer
Session createSession(const std::string &connectionString, bool writeCapable=false)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
Log< level::Info, false > LogInfo
unsigned short m_lastFill
std::string m_connectionString
std::unique_ptr< FillInfo > Ref
unsigned short m_firstFill
Log< level::Warning, false > LogWarning
void setAuthenticationPath(const std::string &p)
boost::posix_time::ptime to_boost(Time_t iValue)
cond::UnpackedTime unpack(cond::Time_t iValue)